From 9c70ad73ea5056b74879099b1378ad18162d36dc Mon Sep 17 00:00:00 2001 From: zxd Date: Thu, 24 Jan 2019 18:50:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E6=9E=B6=E6=97=A0?= =?UTF-8?q?=E4=BA=BA=E6=9C=BA=E5=90=8C=E6=97=B6=E6=A0=A1=E5=87=86=20?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E9=83=A8=E5=88=86=E8=88=AA=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formation/CopterManager.cs | 1 + .../Formation/Extensions.cs | 2 +- .../Formation/FlightTaskManager.cs | 46 ++++++++++++ Plane.FormationCreator/Styles/Button.xaml | 1 + .../ViewModels/CalibrationViewModel.cs | 70 +++++++++---------- .../ViewModels/CopterListViewModel.cs | 33 +++++++++ .../ViewModels/ModifyTaskViewModel.cs | 23 ++++++ .../Views/CalibrationWindow.xaml | 14 ++-- .../Views/CopterListView.xaml | 12 +++- .../Views/MapView_CopterDrawing.cs | 43 ++++++++++-- .../Views/ModifyTaskView.xaml | 1 + 11 files changed, 198 insertions(+), 48 deletions(-) diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs index 8b8d26c..3c0f614 100644 --- a/Plane.FormationCreator/Formation/CopterManager.cs +++ b/Plane.FormationCreator/Formation/CopterManager.cs @@ -82,6 +82,7 @@ namespace Plane.FormationCreator.Formation } + public List ShowCopter = new List(); public CopterCollection Copters { get;} = new CopterCollection(); diff --git a/Plane.FormationCreator/Formation/Extensions.cs b/Plane.FormationCreator/Formation/Extensions.cs index 8f2fb6e..b2f9e08 100644 --- a/Plane.FormationCreator/Formation/Extensions.cs +++ b/Plane.FormationCreator/Formation/Extensions.cs @@ -14,7 +14,7 @@ namespace Plane.FormationCreator.Formation { public const float GpsArrivedDis = 2.0f; //GPS模式下航点到达精度 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模式下碰撞检测最近距离 diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index e82b101..b06a02f 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -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 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) { var copters = _copterManager.Copters; diff --git a/Plane.FormationCreator/Styles/Button.xaml b/Plane.FormationCreator/Styles/Button.xaml index a8ebedc..63613dd 100644 --- a/Plane.FormationCreator/Styles/Button.xaml +++ b/Plane.FormationCreator/Styles/Button.xaml @@ -95,4 +95,5 @@ + \ No newline at end of file diff --git a/Plane.FormationCreator/ViewModels/CalibrationViewModel.cs b/Plane.FormationCreator/ViewModels/CalibrationViewModel.cs index dab88f9..22fe1c5 100644 --- a/Plane.FormationCreator/ViewModels/CalibrationViewModel.cs +++ b/Plane.FormationCreator/ViewModels/CalibrationViewModel.cs @@ -96,39 +96,37 @@ namespace Plane.FormationCreator.ViewModels } } - - private ICommand _CalibrationAccelerometerCommand; - public ICommand CalibrationAccelerometerCommand + /// + /// 开始校准加速计 + /// + private ICommand _CalibrationAccelerometerStartCommand; + public ICommand CalibrationAccelerometerStartCommand { get { - return _CalibrationAccelerometerCommand ?? (_CalibrationAccelerometerCommand = new RelayCommand(async () => + return _CalibrationAccelerometerStartCommand ?? (_CalibrationAccelerometerStartCommand = new RelayCommand(async () => { - ICopter copter = _copterManager.SelectedCopters.FirstOrDefault(); - short copterId = short.Parse(copter.Name); - - 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); - } + if (_copterManager.SelectedCopters.Count() == 0) return; + await commModule.DoStartPreflightCompassAsync(_copterManager.SelectedCopters); })); } } + /// + /// 校准加速计下一步 + /// + 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; public int CompassPercent @@ -151,17 +149,17 @@ namespace Plane.FormationCreator.ViewModels { 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); - Message.Show("开始校准指南针:" + copter.Name); - //for (int i = 0; i < 3; i++) - //{ - await commModule.DoCalibrationCompassAsync(copterId); - await Task.Delay(50).ConfigureAwait(false); - //} + await commModule.DoCalibrationCompassAsync(_copterManager.SelectedCopters); + await Task.Delay(50).ConfigureAwait(false); + + /* IsCalibration = true; CompassPercent = 0; @@ -195,7 +193,7 @@ namespace Plane.FormationCreator.ViewModels } IsCalibration = false; - + */ })); } } @@ -207,7 +205,7 @@ namespace Plane.FormationCreator.ViewModels { return _CancelCalibrationCompassCommand ?? (_CancelCalibrationCompassCommand = new RelayCommand(async () => { - if (_copterManager.SelectedCopters.Count() != 1) return; + if (_copterManager.SelectedCopters.Count() == 1) return; ICopter copter = _copterManager.SelectedCopters.FirstOrDefault(); diff --git a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs index 341f335..0481826 100644 --- a/Plane.FormationCreator/ViewModels/CopterListViewModel.cs +++ b/Plane.FormationCreator/ViewModels/CopterListViewModel.cs @@ -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; public ICommand AddVirtualCopterCommand { diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs index 508cecb..6da4e04 100644 --- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs @@ -506,6 +506,29 @@ namespace Plane.FormationCreator.ViewModels } } + private ICommand _ImportBlenderWayPointCommand; + public ICommand ImportBlenderWayPointCommand + { + get + { + return _ImportBlenderWayPointCommand ?? (_ImportBlenderWayPointCommand = new RelayCommand(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; public ICommand OptimizeRouteCommand { diff --git a/Plane.FormationCreator/Views/CalibrationWindow.xaml b/Plane.FormationCreator/Views/CalibrationWindow.xaml index 540cf5e..897162b 100644 --- a/Plane.FormationCreator/Views/CalibrationWindow.xaml +++ b/Plane.FormationCreator/Views/CalibrationWindow.xaml @@ -9,15 +9,19 @@ Title="校准" Height="320" Width="450"> - - + +