支持多架无人机同时校准 隐藏部分航点

This commit is contained in:
zxd 2019-01-24 18:50:39 +08:00
parent 32b60bb059
commit 9c70ad73ea
11 changed files with 198 additions and 48 deletions

View File

@ -82,6 +82,7 @@ namespace Plane.FormationCreator.Formation
} }
public List<ICopter> ShowCopter = new List<ICopter>();
public CopterCollection Copters { get;} = new CopterCollection(); public CopterCollection Copters { get;} = new CopterCollection();

View File

@ -14,7 +14,7 @@ namespace Plane.FormationCreator.Formation
{ {
public const float GpsArrivedDis = 2.0f; //GPS模式下航点到达精度 public const float GpsArrivedDis = 2.0f; //GPS模式下航点到达精度
public const float RTKArrivedDis = 1.5f; //RTK模式航点达到精度 public const float RTKArrivedDis = 1.5f; //RTK模式航点达到精度
public const float GpsCloseDis = 2.0f; //GPS模式下碰撞检测最近距离 public const float GpsCloseDis = 1.5f; //GPS模式下碰撞检测最近距离
public const float RTKClosedDis = 0.5f; //RTK模式下碰撞检测最近距离 public const float RTKClosedDis = 0.5f; //RTK模式下碰撞检测最近距离

View File

@ -417,6 +417,52 @@ namespace Plane.FormationCreator.Formation
} }
} }
public void ImportBlenderFlyToTask(string blenderVectors)
{
string[] lineVectors = blenderVectors.Replace("\r\n","\n").Split('\n');
var lastTask = Tasks.LastOrDefault();
float alt = lastTask.SingleCopterInfos[0].TargetAlt;
double lat = lastTask.SingleCopterInfos[0].LatLngOffset.Lat;
double lng = lastTask.SingleCopterInfos[0].LatLngOffset.Lng;
foreach (var item in lineVectors)
{
string vector = item.Replace("Vector((", "").Replace("))", "");
var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = true, FlytoTime = 1, LoiterTime = 0 };
string[] vectors = vector.Split(',');
double x = double.Parse(vectors[1]);
double y = double.Parse(vectors[0]);
int x_directionDegrees = x > 0 ? 90 : -90;
int y_directionDegrees = y > 0 ? 0 : 180;
Tuple<double, double> observationLatLng = null;
observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
lat,
lng,
90,
(float)x);
observationLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
observationLatLng.Item1,
observationLatLng.Item2,
0,
(float)y);
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(
_copterManager.Copters[0], new LatLng((double)observationLatLng.Item1,
(double)observationLatLng.Item2), alt, false);
newTask.SingleCopterInfos.Add(newSingleCopterInfo);
Tasks.Add(newTask);
TaskAdded?.Invoke(this, new FlightTaskAddedEventArgs { LastTask = lastTask, AddedTask = newTask });
Message.Show(vector);
}
}
public void RestoreFlyToTask(bool staggerRoutes, int flytoTime, int loiterTime, dynamic singleCopterInfos) public void RestoreFlyToTask(bool staggerRoutes, int flytoTime, int loiterTime, dynamic singleCopterInfos)
{ {
var copters = _copterManager.Copters; var copters = _copterManager.Copters;

View File

@ -95,4 +95,5 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</ResourceDictionary> </ResourceDictionary>

View File

@ -96,39 +96,37 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
/// <summary>
private ICommand _CalibrationAccelerometerCommand; /// 开始校准加速计
public ICommand CalibrationAccelerometerCommand /// </summary>
private ICommand _CalibrationAccelerometerStartCommand;
public ICommand CalibrationAccelerometerStartCommand
{ {
get get
{ {
return _CalibrationAccelerometerCommand ?? (_CalibrationAccelerometerCommand = new RelayCommand(async () => return _CalibrationAccelerometerStartCommand ?? (_CalibrationAccelerometerStartCommand = new RelayCommand(async () =>
{ {
ICopter copter = _copterManager.SelectedCopters.FirstOrDefault(); if (_copterManager.SelectedCopters.Count() == 0) return;
short copterId = short.Parse(copter.Name); await commModule.DoStartPreflightCompassAsync(_copterManager.SelectedCopters);
switch (AccelerometerState)
{
case AccelerometerStates.Idle:
await commModule.DoStartPreflightCompassAsync(copterId);
break;
default:
await commModule.DoNextPreflightCompassAsync(copterId);
break;
}
if (AccelerometerState == AccelerometerStates.Back)
{
Alert.Show("校准结束,请检测灯光后重启飞机!\r\n 绿色:校准成功 红色:校准失败");
AccelerometerState = AccelerometerStates.Idle;
}
else
{
AccelerometerState = (AccelerometerStates)((int)AccelerometerState + 1);
}
})); }));
} }
} }
/// <summary>
/// 校准加速计下一步
/// </summary>
private ICommand _CalibrationAccelerometerNextCommand;
public ICommand CalibrationAccelerometerNextCommand
{
get
{
return _CalibrationAccelerometerNextCommand ?? (_CalibrationAccelerometerNextCommand = new RelayCommand(async () =>
{
if (_copterManager.SelectedCopters.Count() == 0) return;
await commModule.DoNextPreflightCompassAsync(_copterManager.SelectedCopters);
}));
}
}
private int _CompassPercent; private int _CompassPercent;
public int CompassPercent public int CompassPercent
@ -151,17 +149,17 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _CalibrationCompassCommand ?? (_CalibrationCompassCommand = new RelayCommand(async () => return _CalibrationCompassCommand ?? (_CalibrationCompassCommand = new RelayCommand(async () =>
{ {
if (IsCalibration || _copterManager.SelectedCopters.Count() != 1) return; if (_copterManager.SelectedCopters.Count() == 0) return;
ICopter copter = _copterManager.SelectedCopters.FirstOrDefault(); // ICopter copter = _copterManager.SelectedCopters.FirstOrDefault();
//
// short copterId = short.Parse(copter.Name);
Message.Show("开始校准指南针");
short copterId = short.Parse(copter.Name); await commModule.DoCalibrationCompassAsync(_copterManager.SelectedCopters);
Message.Show("开始校准指南针:" + copter.Name); await Task.Delay(50).ConfigureAwait(false);
//for (int i = 0; i < 3; i++)
//{ /*
await commModule.DoCalibrationCompassAsync(copterId);
await Task.Delay(50).ConfigureAwait(false);
//}
IsCalibration = true; IsCalibration = true;
CompassPercent = 0; CompassPercent = 0;
@ -195,7 +193,7 @@ namespace Plane.FormationCreator.ViewModels
} }
IsCalibration = false; IsCalibration = false;
*/
})); }));
} }
} }
@ -207,7 +205,7 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _CancelCalibrationCompassCommand ?? (_CancelCalibrationCompassCommand = new RelayCommand(async () => return _CancelCalibrationCompassCommand ?? (_CancelCalibrationCompassCommand = new RelayCommand(async () =>
{ {
if (_copterManager.SelectedCopters.Count() != 1) return; if (_copterManager.SelectedCopters.Count() == 1) return;
ICopter copter = _copterManager.SelectedCopters.FirstOrDefault(); ICopter copter = _copterManager.SelectedCopters.FirstOrDefault();

View File

@ -124,6 +124,39 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
private ICommand _OnlyShowSelectedCoptersCommand;
public ICommand OnlyShowSelectedCoptersCommand
{
get
{
return _OnlyShowSelectedCoptersCommand ?? (_OnlyShowSelectedCoptersCommand = new RelayCommand(async () =>
{
if (_copterManager.SelectedCopters.Count() > 0)
{
Plane.Windows.Messages.Message.Show("隐藏飞机");
_copterManager.ShowCopter.Clear();
_copterManager.ShowCopter.AddRange(_copterManager.SelectedCopters);
}
await Task.Delay(10);
}));
}
}
private ICommand _ShowAllCoptersCommand;
public ICommand ShowAllCoptersCommand
{
get
{
return _ShowAllCoptersCommand ?? (_ShowAllCoptersCommand = new RelayCommand(async () =>
{
Plane.Windows.Messages.Message.Show("显示飞机");
_copterManager.ShowCopter.Clear();
await Task.Delay(10);
}));
}
}
private ICommand _AddVirtualCopterCommand; private ICommand _AddVirtualCopterCommand;
public ICommand AddVirtualCopterCommand public ICommand AddVirtualCopterCommand
{ {

View File

@ -506,6 +506,29 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
private ICommand _ImportBlenderWayPointCommand;
public ICommand ImportBlenderWayPointCommand
{
get
{
return _ImportBlenderWayPointCommand ?? (_ImportBlenderWayPointCommand = new RelayCommand<int>(async =>
{
var dialog = new OpenFileDialog
{
DefaultExt = "txt",
Filter = "文本文件|*.txt"
};
if (dialog.ShowDialog() == true)
{
var tasksText = File.ReadAllText(dialog.FileName);
_flightTaskManager.ImportBlenderFlyToTask(tasksText);
}
}));
}
}
private ICommand _OptimizeRouteCommand; private ICommand _OptimizeRouteCommand;
public ICommand OptimizeRouteCommand public ICommand OptimizeRouteCommand
{ {

View File

@ -9,15 +9,19 @@
Title="校准" Height="320" Width="450"> Title="校准" Height="320" Width="450">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition/> <RowDefinition Height="70*"/>
<RowDefinition/> <RowDefinition Height="30*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Margin="10" > <StackPanel Margin="10" >
<Label Content="加速计" Margin="0,0,0,10" FontWeight="Bold" FontSize="14"/> <Label Content="加速计" Margin="0,0,0,10" FontWeight="Bold" FontSize="14"/>
<Button Content="{Binding AccelerometerBtnText,UpdateSourceTrigger=Default}" Width="100" <WrapPanel HorizontalAlignment="Center">
Command="{Binding CalibrationAccelerometerCommand}"/> <Button Content="开始校准" Width="100" Margin="10, 0"
<Label Margin="0,10" Content="{Binding AccelerometerTips, UpdateSourceTrigger=PropertyChanged}" HorizontalContentAlignment="Center"/> Command="{Binding CalibrationAccelerometerStartCommand}"/>
<Button Content="下一步" Width="100" Margin="10, 0"
Command="{Binding CalibrationAccelerometerNextCommand}"/>
</WrapPanel>
<Label Margin="0,10" Content="亮紫色:飞机水平放置(Front)&#13;亮黄色:飞机左侧接触地面竖立放置(Left)&#13;亮青色:飞机右侧接触地面竖立放置(Right)&#13;紫色:飞机机头向下接触地面竖立放置(Down)&#13;黄色:飞机机尾向下接触地面竖立放置(Up)&#13;青色:飞机翻过来水平放置(Back)" HorizontalContentAlignment="Center"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Margin="10,0,10,10"> <StackPanel Grid.Row="1" Margin="10,0,10,10">

View File

@ -9,7 +9,16 @@
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="600" d:DesignHeight="600"
d:DesignWidth="300"> d:DesignWidth="300">
<UserControl.Resources>
<ContextMenu x:Key="CoptersMenu" >
<MenuItem Header="只显示当前选中"
Foreground="White"
Command="{Binding OnlyShowSelectedCoptersCommand}"/>
<MenuItem Header="显示所有飞机"
Foreground="White"
Command="{Binding ShowAllCoptersCommand}"/>
</ContextMenu>
</UserControl.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
@ -18,6 +27,7 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<ListBox x:Name="lvwDrones" <ListBox x:Name="lvwDrones"
ContextMenu="{StaticResource CoptersMenu}"
ItemsSource="{Binding CopterManager.Copters}" ItemsSource="{Binding CopterManager.Copters}"
SelectedItem="{Binding SelectedCopter}" SelectedItem="{Binding SelectedCopter}"
PreviewKeyDown="_listBoxCopters_PreviewKeyDown" PreviewKeyDown="_listBoxCopters_PreviewKeyDown"

View File

@ -501,11 +501,28 @@ namespace Plane.FormationCreator.Views
{ {
if (showroute ?? false ) if (showroute ?? false )
{ {
_map.Markers.Add(this.Route); if (_copterManager.ShowCopter.Count > 0)
Route.ZIndex = 99; {
if (_copterManager.ShowCopter.Contains(Copter))
{
_map.Markers.Add(this.Route);
Route.ZIndex = 99;
}
}
else
{
_map.Markers.Add(this.Route);
Route.ZIndex = 99;
}
} }
else else
_map.Markers.Remove(this.Route); {
if(_map.Markers.Contains(this.Route))
_map.Markers.Remove(this.Route);
}
} }
public void SetShowtrack(bool? showtrack) public void SetShowtrack(bool? showtrack)
@ -587,8 +604,24 @@ namespace Plane.FormationCreator.Views
} }
else else
{ {
wp.Visibility = Visibility.Visible;
var info = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.Find(i => i.Copter == this.Copter); if (_copterManager.ShowCopter.Count > 0 )
{
if (_copterManager.ShowCopter.Contains(Copter))
{
wp.Visibility = Visibility.Visible;
}
else
{
wp.Visibility = Visibility.Hidden;
}
}
else
{
wp.Visibility = Visibility.Visible;
}
//var info = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.Find(i => i.Copter == this.Copter);
} }
} }

View File

@ -70,6 +70,7 @@
Visibility="Collapsed"/> Visibility="Collapsed"/>
<Button Content="优化路线" Command="{Binding OptimizeRouteCommand}" <Button Content="优化路线" Command="{Binding OptimizeRouteCommand}"
Visibility="Collapsed"/> Visibility="Collapsed"/>
<Button Content="导入航点" Command="{Binding ImportBlenderWayPointCommand}"/>
</StackPanel> </StackPanel>
<Separator Margin="0,1"/> <Separator Margin="0,1"/>