间隔选中
通信模式测试的一些修改(目前未启用)
This commit is contained in:
parent
cb188feb48
commit
b427d32b44
@ -92,18 +92,38 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
// private ICommand _WriteCommand;
|
||||
// public ICommand WriteCommand
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _WriteCommand ?? (_WriteCommand = new RelayCommand(async () =>
|
||||
// {
|
||||
// await WriteCommandAsync();
|
||||
// }
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
// private ICommand _WriteCommand;
|
||||
// public ICommand WriteCommand
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _WriteCommand ?? (_WriteCommand = new RelayCommand(async () =>
|
||||
// {
|
||||
// await WriteCommandAsync();
|
||||
// }
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
|
||||
private ICommand _CloseCommand;
|
||||
public ICommand CloseCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _CloseCommand ?? (_CloseCommand = new RelayCommand(() =>
|
||||
{
|
||||
commModule.Close();
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private int _CopterNum;
|
||||
public int CopterNum
|
||||
{
|
||||
get { return _CopterNum; }
|
||||
set { Set(nameof(CopterNum), ref _CopterNum, value); }
|
||||
}
|
||||
|
||||
private ICommand _WriteIdCommand;
|
||||
public ICommand WriteIdCommand
|
||||
@ -112,7 +132,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _WriteIdCommand ?? (_WriteIdCommand = new RelayCommand(async () =>
|
||||
{
|
||||
await WriteIdCommandAsync();
|
||||
await WriteIdCommandAsync(CopterNum);
|
||||
}
|
||||
));
|
||||
}
|
||||
@ -143,22 +163,27 @@ namespace Plane.FormationCreator.ViewModels
|
||||
///写航线开始
|
||||
//var missions = new IMission[taskcount]; //不要起飞任务但增加一个起飞后低空航点,见起飞任务,再增加一个降落低空航点,见降落部分
|
||||
var missions = new List<IMission>();
|
||||
missions.Add(PLCopter.PRE_TAKE_OFF_MISSION);
|
||||
|
||||
int missindex = 0;
|
||||
ICopter copter = _copterManager.Copters[i];
|
||||
if (copter is PLCopter)
|
||||
//if (copter is PLCopter)
|
||||
{
|
||||
for (int j = 0; j < _flightTaskManager.Tasks.Count; j++)
|
||||
{
|
||||
|
||||
switch (_flightTaskManager.Tasks[j].TaskType)
|
||||
{
|
||||
|
||||
case FlightTaskType.TakeOff:
|
||||
//计算起飞需要的时间,5秒是上升加速和最后稳定时间
|
||||
int takeofftime = (int)(_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetAlt / 2.5 + 5);
|
||||
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
|
||||
missions.Add(Mission.CreateTakeoffMission(
|
||||
1,//1,
|
||||
5,//takeofftime,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TakeOffWaitTime,
|
||||
_flightTaskManager.Tasks[j].TakeOffTime,
|
||||
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat,
|
||||
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng,
|
||||
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetAlt)
|
||||
@ -169,42 +194,44 @@ namespace Plane.FormationCreator.ViewModels
|
||||
break;
|
||||
|
||||
case FlightTaskType.FlyTo:
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
|
||||
foreach (LEDInfo ledInfo in _flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos)
|
||||
double Lat = _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat;
|
||||
double Lng = _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng;
|
||||
if (_flightTaskManager.Tasks[j].SingleCopterInfos[i].IsLandWaypoint)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString("#" + ledInfo.LEDRGB);
|
||||
IMission LEDMission = Mission.CreateLEDControlMission(
|
||||
(int)(ledInfo.Delay * 10),
|
||||
ledInfo.LEDMode,
|
||||
ledInfo.LEDRate,
|
||||
0, //ledInfo.LEDTimes,
|
||||
color.R,
|
||||
color.G,
|
||||
color.B
|
||||
);
|
||||
missions.Add(LEDMission);
|
||||
Lat = 90;
|
||||
Lng = 180;
|
||||
}
|
||||
missions.Add(Mission.CreateWaypointMission(
|
||||
|
||||
//5,//_flightTaskManager.Tasks[j].SingleCopterInfos[i].LoiterTime,
|
||||
//5,// _flightTaskManager.Tasks[j].SingleCopterInfos[i].FlytoTime,
|
||||
_flightTaskManager.Tasks[j].LoiterTime,
|
||||
_flightTaskManager.Tasks[j].FlytoTime,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng,
|
||||
|
||||
Lat,
|
||||
Lng,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt)
|
||||
);
|
||||
|
||||
break;
|
||||
case FlightTaskType.Loiter:
|
||||
|
||||
// missions[missindex++] = Mission.CreateWaypointMission(10,10,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
|
||||
// _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng, _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt);
|
||||
break;
|
||||
case FlightTaskType.ReturnToLand:
|
||||
|
||||
//降落低空航点
|
||||
// missions[missindex++] = Mission.CreateWaypointMission(_flightTaskManager.Tasks[j - 1].SingleCopterInfos[i].TargetLat,
|
||||
// _flightTaskManager.Tasks[j - 1].SingleCopterInfos[i].TargetLng, 3);
|
||||
//返航
|
||||
missions.Add(Mission.CreateReturnToLaunchMission());
|
||||
break;
|
||||
|
||||
case FlightTaskType.Land:
|
||||
missions.Add(Mission.CreateLandMission(5));
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
|
||||
missions.Add(Mission.CreateLandMission(
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].LandWaitTime)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -231,10 +258,30 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task WriteIdCommandAsync()
|
||||
private List<IMission> CreateLEDMissions(IEnumerable<LEDInfo> LEDInfos)
|
||||
{
|
||||
await commModule.GeneratePacketAsync(3, (byte)Protocols.MavComm.COMMANDTYPE4);
|
||||
List<IMission> missions = new List<IMission>();
|
||||
foreach (LEDInfo ledInfo in LEDInfos)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString("#" + ledInfo.LEDRGB);
|
||||
IMission LEDMission = Mission.CreateLEDControlMission(
|
||||
(int)(ledInfo.Delay * 10),
|
||||
ledInfo.LEDMode,
|
||||
ledInfo.LEDRate,
|
||||
0, //ledInfo.LEDTimes,
|
||||
color.R,
|
||||
color.G,
|
||||
color.B
|
||||
);
|
||||
missions.Add(LEDMission);
|
||||
}
|
||||
return missions;
|
||||
}
|
||||
|
||||
|
||||
private async Task WriteIdCommandAsync(int num)
|
||||
{
|
||||
await commModule.GeneratePacketAsync((short)num, (byte)Protocols.MavComm.COMMANDTYPE4);
|
||||
}
|
||||
|
||||
|
||||
@ -254,9 +301,11 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
var req = new MAVLink.mavlink_mission_item_t();
|
||||
|
||||
PLCopter plCopter = (PLCopter)copter;
|
||||
req.target_system = plCopter._internalCopter.sysid;
|
||||
req.target_component = plCopter._internalCopter.compid;
|
||||
//PLCopter plCopter = (PLCopter)copter;
|
||||
//req.target_system = plCopter._internalCopter.sysid;
|
||||
//req.target_component = plCopter._internalCopter.compid;
|
||||
req.target_system = 1;
|
||||
req.target_component = 1;
|
||||
|
||||
req.command = (byte)mission.Command;
|
||||
|
||||
@ -295,7 +344,12 @@ namespace Plane.FormationCreator.ViewModels
|
||||
private async Task ConnectAsync()
|
||||
{
|
||||
await commModule.ConnectAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DisConnetAsync()
|
||||
{
|
||||
await Task.Delay(20).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private Action _closeWindowCallback;
|
||||
public void SetCloseWindowAction(Action closeWindowAction)
|
||||
|
@ -624,10 +624,12 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _ConnectCommand ?? (_ConnectCommand = new RelayCommand(async () =>
|
||||
{
|
||||
//await ConnectAsync();
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(async copter =>
|
||||
{
|
||||
//await commModule.ConnectAsync();
|
||||
await copter.ConnectAsync();
|
||||
await copter.GetCopterDataAsync();
|
||||
//await copter.GetCopterDataAsync();
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
@ -81,6 +81,36 @@ namespace Plane.FormationCreator.ViewModels
|
||||
set { Set(nameof(Communinfo), ref _Communinfo, value); }
|
||||
}
|
||||
|
||||
private int _IntervalNum;
|
||||
public int IntervalNum
|
||||
{
|
||||
get { return _IntervalNum; }
|
||||
set { Set(nameof(IntervalNum), ref _IntervalNum, value); }
|
||||
}
|
||||
|
||||
private ICommand _IntervalSelectCoptersCommand;
|
||||
public ICommand IntervalSelectCoptersCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _IntervalSelectCoptersCommand ?? (_IntervalSelectCoptersCommand = new RelayCommand(() =>
|
||||
{
|
||||
if (_copterManager.AcceptingControlCopters.Count() == 0 || IntervalNum == 0)
|
||||
return;
|
||||
|
||||
ICopter copter = _copterManager.AcceptingControlCopters.FirstOrDefault();
|
||||
_copterManager.Select(null);
|
||||
int index = _copterManager.Copters.IndexOf(copter);
|
||||
_copterManager.shiftkeydown = true;
|
||||
for (; index < _copterManager.Copters.Count; index += IntervalNum + 1)
|
||||
{
|
||||
_copterManager.Select(_copterManager.Copters[index]);
|
||||
}
|
||||
_copterManager.shiftkeydown = false;
|
||||
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _AddVirtualCopterCommand;
|
||||
public ICommand AddVirtualCopterCommand
|
||||
|
@ -124,9 +124,11 @@
|
||||
HorizontalAlignment="Center"
|
||||
Grid.Row="2"
|
||||
Grid.ColumnSpan="3">
|
||||
<Button Content="设置20台" Margin="10" Command="{Binding Path=SendCommand}" />
|
||||
<Button Content="写入航点" Margin="10" Command="{Binding Path=CommWriteMissionCommand}" />
|
||||
<Button Content="广播编号3" Margin="10" Command="{Binding Path=WriteIdCommand}" />
|
||||
<Button Content="关闭TCP" Margin="5" Command="{Binding CloseCommand}"/>
|
||||
<Button Content="设置20台" Margin="5" Command="{Binding Path=SendCommand}" />
|
||||
<Button Content="写入航点" Margin="5" Command="{Binding Path=CommWriteMissionCommand}" />
|
||||
<Button Content="广播编号" Margin="5,5,0,5" Command="{Binding Path=WriteIdCommand}" />
|
||||
<TextBox Margin="2,5,5,5" Width="30" Text="{Binding CopterNum}"></TextBox>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
@ -1,10 +1,11 @@
|
||||
<UserControl x:Class="Plane.FormationCreator.Views.CopterListView"
|
||||
<UserControl
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Plane.FormationCreator.Views"
|
||||
xmlns:m="clr-namespace:Plane.FormationCreator.Formation"
|
||||
xmlns:ControlzEx="clr-namespace:ControlzEx;assembly=MahApps.Metro" x:Class="Plane.FormationCreator.Views.CopterListView"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="600"
|
||||
d:DesignWidth="300">
|
||||
@ -13,11 +14,12 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListBox x:Name="lvwDrones"
|
||||
ItemsSource="{Binding Path=CopterManager.Copters}"
|
||||
SelectedItem="{Binding Path=SelectedCopter}"
|
||||
ItemsSource="{Binding CopterManager.Copters}"
|
||||
SelectedItem="{Binding SelectedCopter}"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
SelectionMode="Extended"
|
||||
@ -32,9 +34,8 @@
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox Width="20"
|
||||
IsChecked="{Binding Path=IsConnected, Mode=OneWay}"
|
||||
IsEnabled="False">
|
||||
</CheckBox>
|
||||
IsChecked="{Binding IsConnected, Mode=OneWay}"
|
||||
IsEnabled="False"/>
|
||||
<Rectangle Width="15"
|
||||
Height="15"
|
||||
Margin="3,0">
|
||||
@ -46,31 +47,38 @@
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<TextBlock MaxWidth="100"
|
||||
Text="{Binding Path=Name}" />
|
||||
Text="{Binding Name}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<StackPanel Grid.Row="1"
|
||||
<StackPanel Grid.Row="1" Margin="0,0,0,5"
|
||||
Orientation="Horizontal">
|
||||
<Button Content="间隔选中" Command="{Binding IntervalSelectCoptersCommand}"/>
|
||||
<TextBlock Text="间隔数量" Margin="5,5,0,0"/>
|
||||
<TextBox Width="30" Margin="5,0,0,0" Text="{Binding IntervalNum}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2"
|
||||
Orientation="Horizontal">
|
||||
<TextBox x:Name="txtVirtualCopterCount"
|
||||
Width="35"
|
||||
Margin="0,0,5,0"
|
||||
Text="10"
|
||||
VerticalContentAlignment="Center" />
|
||||
<Button Content="添加虚拟飞行器"
|
||||
<Button Content="添加虚拟飞机"
|
||||
VerticalContentAlignment="Center"
|
||||
Command="{Binding AddVirtualCopterCommand}"
|
||||
CommandParameter="{Binding ElementName=txtVirtualCopterCount, Path=Text}" />
|
||||
CommandParameter="{Binding Text, ElementName=txtVirtualCopterCount}" />
|
||||
<Button Content="清除"
|
||||
Margin="5,0,5,0"
|
||||
Command="{Binding ClearCoptersCommand}" />
|
||||
<TextBlock Text="总数"
|
||||
Margin="5,5,0,0"/>
|
||||
<TextBlock Text="{Binding Path=CopterManager.Copters.Count}"
|
||||
<TextBlock Text="{Binding CopterManager.Copters.Count}"
|
||||
Margin="0,5,0,0"/>
|
||||
<TextBlock Text="{Binding Path=Communinfo}"
|
||||
<TextBlock Text="{Binding Communinfo}"
|
||||
Margin="5,5,0,0"/>
|
||||
|
||||
</StackPanel>
|
||||
|
@ -29,16 +29,16 @@
|
||||
</StackPanel.Resources>
|
||||
<TextBlock Margin="5" Text="起飞任务"/>
|
||||
<Separator/>
|
||||
<!-- <StackPanel>
|
||||
|
||||
<StackPanel>
|
||||
|
||||
<TextBlock Text="起飞数量:" Margin="5,10,5,0" />
|
||||
<TextBox x:Name="txttakeoff"
|
||||
Width="25"
|
||||
Margin="0,10,5,0"
|
||||
VerticalContentAlignment="Center"
|
||||
Text="{Binding FlightTaskManager.TakeOffNumAttr, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</StackPanel>-->
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<Separator />
|
||||
<Grid DataContext="{Binding FlightTaskManager.SelectedTask.ModifyingSingleCopterInfo}"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user