From e2dcb04d629ecfdc2a924e3526c6d5d1fdc69f6f Mon Sep 17 00:00:00 2001 From: zxd Date: Wed, 2 Jan 2019 11:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9C=AC=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=20version=3D255=E4=B8=BA=E5=AE=8C=E6=95=B4=E7=89=88?= =?UTF-8?q?=E6=9C=AC=20=E4=BF=AE=E6=94=B9=E8=B5=B7=E9=A3=9E=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E6=A8=A1=E6=8B=9F=E5=AE=9E=E9=99=85=E8=88=AA=E7=82=B9?= =?UTF-8?q?=E7=9A=84=E8=B5=B7=E9=A3=9E=E6=A8=A1=E5=BC=8F=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A0=A1=E5=87=86=E6=8C=87=E5=8D=97=E9=92=88=E5=92=8C?= =?UTF-8?q?=E5=8A=A0=E9=80=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plane.FormationCreator/App.xaml.cs | 3 + .../Formation/FlightTaskManager.cs | 5 +- .../FlightTaskSingleCopterInfo_Land.cs | 2 +- .../Formation/FlightTask_TakeOff.cs | 50 ++-- .../Formation/View3DManager.cs | 19 ++ Plane.FormationCreator/ModifyParam.xaml | 125 +++++----- Plane.FormationCreator/ModifyParam.xaml.cs | 18 +- .../Plane.FormationCreator.csproj | 1 + Plane.FormationCreator/Util/VersionControl.cs | 25 ++ .../ViewModels/CalibrationViewModel.cs | 224 ++++++++++++++++++ .../ViewModels/ControlPanelViewModel.cs | 28 ++- .../ViewModels/ModifyTaskViewModel.cs | 7 +- .../Views/CalibrationWindow.xaml | 36 +++ .../Views/CalibrationWindow.xaml.cs | 36 +++ .../Views/ConnectWindow.xaml | 12 +- .../Views/CopterInfoView.xaml | 17 +- .../Views/ModifyTaskView.xaml | 14 +- 17 files changed, 508 insertions(+), 114 deletions(-) create mode 100644 Plane.FormationCreator/Formation/View3DManager.cs create mode 100644 Plane.FormationCreator/Util/VersionControl.cs create mode 100644 Plane.FormationCreator/ViewModels/CalibrationViewModel.cs create mode 100644 Plane.FormationCreator/Views/CalibrationWindow.xaml create mode 100644 Plane.FormationCreator/Views/CalibrationWindow.xaml.cs diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs index 63bd207..c558e60 100644 --- a/Plane.FormationCreator/App.xaml.cs +++ b/Plane.FormationCreator/App.xaml.cs @@ -19,6 +19,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; using Plane.CommunicationManagement; +using Plane.FormationCreator.Util; namespace Plane.FormationCreator { @@ -68,6 +69,8 @@ namespace Plane.FormationCreator }; //new Test().Prepare().Run(); + + VersionControl.GetVersionFromIni(); } private ILogger _logger; diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 85f7866..e82b101 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -374,8 +374,8 @@ namespace Plane.FormationCreator.Formation CurrentRunningTask = null; //起飞任务需要跳过 - if (CurrentRunningTaskIndex == 0) - CurrentRunningTaskIndex++; +// if (CurrentRunningTaskIndex == 0) +// CurrentRunningTaskIndex++; CurrentRunningTaskIndex++; await RunTaskAsync(); } @@ -572,6 +572,7 @@ namespace Plane.FormationCreator.Formation { var singleCopterInfoObj = singleCopterInfos[i]; takeOffTask.SingleCopterInfos[i].TakeOffWaitTime = (ushort)singleCopterInfoObj.waitTime; + //Message.Show(((ushort)singleCopterInfoObj.waitTime).ToString()); } } diff --git a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs index 14ebc27..84be95e 100644 --- a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs +++ b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs @@ -19,7 +19,7 @@ namespace Plane.FormationCreator.Formation return info; } - private ushort _LandWaitTime = 5; + private ushort _LandWaitTime = 1; public ushort LandWaitTime { get { return _LandWaitTime; } diff --git a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs index f20fbbe..0f44e08 100644 --- a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs +++ b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs @@ -76,7 +76,15 @@ namespace Plane.FormationCreator.Formation var tasksTakeOff = new Task[infos.Count]; for (int i = 0; i < infos.Count; i++) { - tasksTakeOff[i] = NewSingleRunTaskOffTaskAsunc(infos[i]); + //tasksTakeOff[i] = NewSingleRunTaskOffTaskAsunc(infos[i]); + + + tasksTakeOff[i] = await Task.Factory.StartNew(async () => + { + var internalInfo = infos[i]; + + await NewSingleRunTaskOffTaskAsunc(internalInfo); + }); } await Task.WhenAll(tasksTakeOff).ConfigureAwait(false); //await Task.Delay(100); @@ -90,31 +98,24 @@ namespace Plane.FormationCreator.Formation int copterIndex = SingleCopterInfos.IndexOf(info); var copter = info.Copter; - - await copter.UnlockAsync(); - for (int i = 0; !copter.IsUnlocked; i++) - { - //8秒内每1000毫秒尝试解锁一次 - //解锁间隔一定要超过1s否则导致飞控以后无法解锁 - - if (i > 320) - return; //无法解锁后面不用执行了 - if (i % (1000 / 25) == 1000 / 25 - 1) - { - await copter.UnlockAsync(); // 每 1000 毫秒重试一次。 - } - - await Task.Delay(25).ConfigureAwait(false); - } //等待起飞时间 - while (ts.TotalMilliseconds < info.TakeOffWaitTime * 1000) + Windows.Messages.Message.Show($"{copter.Name}:等待起飞 = {info.TakeOffWaitTime}"); + while ((int)ts.TotalMilliseconds < (int)info.TakeOffWaitTime * 1000) { + if (_flightTaskManager.IsPaused == true) + { + await info.Copter.HoverAsync(); + return; + } await Task.Delay(100); dtNow = DateTime.Now; - ts = dtNow - dtLastTime; + ts = dtNow - dtLastTime; } + //虚拟飞机5秒后不起飞会自动上锁 + await copter.UnlockAsync(); + for (int i = 0; i < 5; i++) // added by ZJF { await copter.TakeOffAsync(); @@ -124,6 +125,9 @@ namespace Plane.FormationCreator.Formation var copterNextTask = _flightTaskManager.Tasks[TaskIndex + 1].SingleCopterInfos[copterIndex]; float takeOffAlt = copterNextTask.TargetAlt; + info.TargetLat = info.Copter.Latitude; + info.TargetLng = info.Copter.Longitude; + for (int j = 0; j < 3; j++) { await info.Copter.FlyToAsync(info.TargetLat, info.TargetLng, takeOffAlt); @@ -133,8 +137,16 @@ namespace Plane.FormationCreator.Formation dtNow = DateTime.Now; ts = dtNow - dtLastTime; FlightTask task = _flightTaskManager.CurrentRunningTask; + + Windows.Messages.Message.Show($"{copter.Name}:等待到达飞行时间 = {task.TakeOffTime}"); while (ts.TotalMilliseconds < task.TakeOffTime * 1000) { + if (_flightTaskManager.IsPaused == true) + { + //Windows.Messages.Message.Show($"{copter.Name}:悬停"); + await info.Copter.HoverAsync(); + return; + } await Task.Delay(100).ConfigureAwait(false); dtNow = DateTime.Now; ts = dtNow - dtLastTime; diff --git a/Plane.FormationCreator/Formation/View3DManager.cs b/Plane.FormationCreator/Formation/View3DManager.cs new file mode 100644 index 0000000..41d6dbf --- /dev/null +++ b/Plane.FormationCreator/Formation/View3DManager.cs @@ -0,0 +1,19 @@ +using Plane.FormationCreator.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Plane.FormationCreator.Formation +{ + public class View3DManager + { + public View3DViewModel _view3DViewModel { get; set; } + + public void ClearCopters() + { + this._view3DViewModel.Clear3DCopters(); + } + } +} diff --git a/Plane.FormationCreator/ModifyParam.xaml b/Plane.FormationCreator/ModifyParam.xaml index c10bb94..6b7bed8 100644 --- a/Plane.FormationCreator/ModifyParam.xaml +++ b/Plane.FormationCreator/ModifyParam.xaml @@ -12,75 +12,80 @@ + + +