From 517146971f70811e8acd1e0c82c976fb72004303 Mon Sep 17 00:00:00 2001 From: pxzleo Date: Fri, 10 Mar 2017 19:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B=E5=B0=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20[App.xaml.cs]=E4=BF=AE=E5=A4=8DCheckbox?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA=E5=AF=B9=E5=8B=BE=20[Fligh?= =?UTF-8?q?tTaskManager.cs]=E5=A2=9E=E5=8A=A0=E9=80=89=E4=B8=AD=E9=97=AA?= =?UTF-8?q?=E7=83=81=EF=BC=8C=E6=82=AC=E5=81=9C=E6=9C=BA=E5=A4=B4=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=20[FlightTask=5FLoiterTime.cs]=E6=94=B9=E5=8F=98?= =?UTF-8?q?=E6=9C=BA=E5=A4=B4=E6=96=B9=E5=90=91=E5=92=8C=E7=81=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AA=E7=83=81=E6=96=B9=E5=BC=8F=20[FlightTask=5FTakeOff.cs?= =?UTF-8?q?]=20=E8=A7=A3=E9=94=81=E8=B5=B7=E9=A3=9E=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E4=BA=AE=E7=81=AF=EF=BC=88=E6=9A=82=E6=97=B6=E6=B2=A1=E5=90=AF?= =?UTF-8?q?=E7=94=A8=EF=BC=89=20[MainWindow.xaml.cs]=E5=A2=9E=E5=8A=A0C?= =?UTF-8?q?=E6=8C=89=E9=94=AE=E6=8E=A7=E5=88=B6=E7=81=AF=E5=BC=80=E5=85=B3?= =?UTF-8?q?=EF=BC=8C=E6=9C=BA=E5=A4=B4=E8=BD=AC=E5=90=91=E9=87=87=E7=94=A8?= =?UTF-8?q?=E4=BB=A5=E5=89=8D=E7=9A=84=E6=96=B9=E6=B3=95=20[ModifyTaskView?= =?UTF-8?q?.xaml]=E5=A2=9E=E5=8A=A0=E6=9C=BA=E5=A4=B4=E6=96=B9=E5=90=91?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plane.FormationCreator/App.xaml.cs | 2 +- .../Formation/FlightTaskManager.cs | 14 +- .../Formation/FlightTask_LoiterTime.cs | 122 ++++++++++++++++-- .../Formation/FlightTask_TakeOff.cs | 1 + Plane.FormationCreator/MainWindow.xaml.cs | 25 +++- .../Views/ModifyTaskView.xaml | 21 ++- 6 files changed, 169 insertions(+), 16 deletions(-) diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs index d089e63..f8b5748 100644 --- a/Plane.FormationCreator/App.xaml.cs +++ b/Plane.FormationCreator/App.xaml.cs @@ -80,7 +80,7 @@ namespace Plane.FormationCreator base.OnStartup(e); var md = Resources.MergedDictionaries; - md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") }); + // md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") }); md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml") }); md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml") }); md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml") }); diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 07b8ea3..7420df7 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -47,6 +47,7 @@ namespace Plane.FormationCreator.Formation } } } + selectedCopter.SetShowLEDFlashAsync(1, 100); }; TaskAdded += (sender, e) => @@ -348,7 +349,8 @@ namespace Plane.FormationCreator.Formation // added by ZJF private void RestoreLoiterTimeTask(float LoiteTimeTmp, bool flashCheck, float flashCheckPeriod, - bool oneByOneCheck, float oneByOneCheckPeriod, string flashNameArray, string flashIndexArray, + bool oneByOneCheck, float oneByOneCheckPeriod, string flashNameArray, string flashIndexArray, + bool ChangeYaw, float HeadYaw, dynamic singleCopterInfos) { var copters = _copterManager.Copters; @@ -366,6 +368,9 @@ namespace Plane.FormationCreator.Formation loiterTimeTask.oneByOnePeriodAttr = oneByOneCheckPeriod; loiterTimeTask.flashCopterNameArray = flashNameArray; loiterTimeTask.flashCopterIndexArray = flashIndexArray; + loiterTimeTask.ChangeYaw = ChangeYaw; + loiterTimeTask.HeadYaw = HeadYaw; + // foreach (var copter in copters) for (int i=0; i < copters.Count && i < singleCopterInfos.Count; i++) { @@ -523,6 +528,10 @@ namespace Plane.FormationCreator.Formation oneByOneCheckPeriod = task.oneByOnePeriodAttr, flashNameArray = task.flashCopterNameArray, flashIndexArray = task.flashCopterIndexArray, + ChangeYaw = task.ChangeYaw, + HeadYaw = task.HeadYaw, + + singleCopterInfos = task.SingleCopterInfos.Select(info => { var offset = info.LatLngOffset; @@ -607,7 +616,8 @@ namespace Plane.FormationCreator.Formation case FlightTaskType.Loiter: RestoreLoiterTimeTask( (float)task.loiterTimeAttr, (bool)task.flashCheck, (float)task.flashCheckPeriod, (bool)task.oneByOneCheck, (float)task.oneByOneCheckPeriod, (string)task.flashNameArray, - (string)task.flashIndexArray, task.singleCopterInfos); + (string)task.flashIndexArray, (bool)task.ChangeYaw, (float)task.HeadYaw, task.singleCopterInfos); + break; case FlightTaskType.SimpleCircle: RestoreSimpleCircleTask(task.singleCopterInfos); diff --git a/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs b/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs index 15e0ba5..7721501 100644 --- a/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs +++ b/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs @@ -18,6 +18,33 @@ namespace Plane.FormationCreator.Formation } } + + + + // 改变机头 + private bool _ChangeYaw = false; + public bool ChangeYaw + { + get { return _ChangeYaw; } + set + { + Set(nameof(ChangeYaw), ref _ChangeYaw, value); + } + } + + // 机头方向0为北,顺时针360 + private float _HeadYaw = 1.0f; + public float HeadYaw + { + get { return _HeadYaw; } + set + { + Set(nameof(HeadYaw), ref _HeadYaw, value); + } + } + + + // LED灯闪烁 private bool _flashAttr = false; public bool flashAttr @@ -121,12 +148,24 @@ namespace Plane.FormationCreator.Formation public async Task RunLoiterTimeTaskAsync() { - // 判断flashPeriodAttr, oneByOnePeriodAttr的值,执行不同的闪烁模式 - // 当flashPeriodAttr小于10,正常闪烁,即没有预制闪烁模式 - // 当flashPeriodAttr大于等于10,小于20,执行预制闪烁模式 - // 当flashPeriodAttr大于等于20, 改变飞控闪烁模式,以oneByOnePeriodAttr作为周期值 - if ((flashPeriodAttr >= 10.0f) && (flashPeriodAttr < 20.0f)) + if (ChangeYaw) + { + await Task.WhenAll(SingleCopterInfos.Select(info => SetCopterYawAsync(info,HeadYaw))); + } + + + + + + + + + // 判断flashPeriodAttr, oneByOnePeriodAttr的值,执行不同的闪烁模式 + // 当flashPeriodAttr小于10,正常闪烁,即没有预制闪烁模式 + // 当flashPeriodAttr大于等于10,小于20,执行预制闪烁模式 + // 当flashPeriodAttr大于等于20, 改变飞控闪烁模式,以oneByOnePeriodAttr作为周期值 + if ((flashPeriodAttr >= 10.0f) && (flashPeriodAttr < 20.0f)) { await LEDFlashPlanAsync(); return; @@ -258,11 +297,58 @@ namespace Plane.FormationCreator.Formation } await Task.WhenAll(tasks_selected).ConfigureAwait(false); } + private async Task SetCopterYawAsync(FlightTaskSingleCopterInfo info, float headyaw) + { + var copter = info.Copter; + // await Task.Delay(200).ConfigureAwait(false); + + var tasks = new Task[1]; + tasks[0] = Task.Run(async () => + { + try + { + await copter.SetMobileControlAsync(yaw: headyaw); + + while (!copter.ArrivedHeading((short)headyaw)) + { + if (_flightTaskManager.IsPaused == true) + { + await info.Copter.HoverAsync(); + return; + } + await Task.Delay(25).ConfigureAwait(false); + } + } + catch (TimeoutException ex) + { + _logger.Log($"SetYAWtimeout, {ex.Message}, CopterId: {copter.Id}。"); + } + }); + await Task.WhenAll(tasks).ConfigureAwait(false); + } private async Task LEDParaModifySingleCopterAsync(FlightTaskSingleCopterInfo info, float count) { var copter = info.Copter; - + + var tasks = new Task[1]; + tasks[0] = Task.Run(async () => + { + try + { + if (count == 1.0) + await copter.SetShowLEDAsync(true); + else + await copter.SetShowLEDAsync(false); + //await copter.SetParamAsync("NTF_SHOWLED", count, 5000); + } + catch (TimeoutException ex) + { + _logger.Log($"SetShowLEDAsync 超时, {ex.Message}, CopterId: {copter.Id}。"); + } + }); + + /* var tasks = new Task[2]; tasks[0] = Task.Run(async () => { @@ -286,6 +372,7 @@ namespace Plane.FormationCreator.Formation _logger.Log($"NOTI_ARMLED 超时, {ex.Message}, CopterId: {copter.Id}。"); } }); + */ await Task.WhenAll(tasks).ConfigureAwait(false); } @@ -296,11 +383,29 @@ namespace Plane.FormationCreator.Formation { var copter = info.Copter; // float gpsLed = await c.GetParamAsync("NOTI_GPSLED"); - float ledControl = 0.0f; + + /* + float ledControl = 0.0f; //关灯 if (isOn) { - ledControl = 1.0f; + ledControl = 1.0f; //长亮 } + */ + var tasks = new Task[1]; + tasks[0] = Task.Run(async () => + { + try + { + await copter.SetShowLEDAsync(isOn); + // await copter.SetParamAsync("NTF_SHOWLED", ledControl, 5000); + } + catch (TimeoutException ex) + { + _logger.Log($"SetShowLED 超时, {ex.Message}, CopterId: {copter.Id}。"); + } + }); + + /* var tasks = new Task[2]; tasks[0] = Task.Run(async () => { @@ -324,6 +429,7 @@ namespace Plane.FormationCreator.Formation _logger.Log($"NOTI_ARMLED 超时, {ex.Message}, CopterId: {copter.Id}。"); } }); + */ await Task.WhenAll(tasks).ConfigureAwait(false); } diff --git a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs index 0d2ba85..98ad9f5 100644 --- a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs +++ b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs @@ -143,6 +143,7 @@ namespace Plane.FormationCreator.Formation { return; } + //await copter.SetShowLEDAsync(true); await copter.UnlockAsync(); for (int i = 0; !copter.IsUnlocked; i++) { diff --git a/Plane.FormationCreator/MainWindow.xaml.cs b/Plane.FormationCreator/MainWindow.xaml.cs index a8678ec..1bc63cf 100644 --- a/Plane.FormationCreator/MainWindow.xaml.cs +++ b/Plane.FormationCreator/MainWindow.xaml.cs @@ -101,8 +101,23 @@ namespace Plane.FormationCreator if (e.OriginalSource is TextBox || e.OriginalSource is PasswordBox) return; var isInFastMode = AppEx.Current.IsInFastMode; + bool isledon; switch (e.Key) { + //开关SHOWLED + case Key.C: + { + + var copters = _copterManager.AcceptingControlCopters; + await Task.WhenAll(copters.Select(async copter => + { + isledon = await copter.GetShowLEDAsync(); + await copter.SetShowLEDAsync(!isledon); + })).ConfigureAwait(false); + + break; + } + //俯仰控制 case Key.W: case Key.S: { @@ -120,6 +135,7 @@ namespace Plane.FormationCreator })).ConfigureAwait(false); break; } + //横滚控制 case Key.A: case Key.D: { @@ -137,6 +153,7 @@ namespace Plane.FormationCreator })).ConfigureAwait(false); break; } + //高度控制 case Key.I: case Key.K: { @@ -154,13 +171,14 @@ namespace Plane.FormationCreator })).ConfigureAwait(false); break; } + //航向控制 case Key.J: case Key.L: { var copters = _copterManager.AcceptingControlCopters; await Task.WhenAll(copters.Select(async copter => { - //await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360); + //await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -20 : 20)) % 360); await copter.SetChannelsAsync(ch4: e.Key == Key.J ? (ushort)1200 : (ushort)1800); })).ConfigureAwait(false); break; @@ -196,6 +214,7 @@ namespace Plane.FormationCreator } break; } + //设置6通道 case Key.P: { var copters = _copterManager.AcceptingControlCopters; @@ -219,6 +238,7 @@ namespace Plane.FormationCreator })).ConfigureAwait(false); break; } + //设置7通道 case Key.O: { var copters = _copterManager.AcceptingControlCopters; @@ -288,9 +308,10 @@ namespace Plane.FormationCreator var copters = _copterManager.AcceptingControlCopters; await Task.WhenAll(copters.Select(async copter => { - //await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360); + // await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360); await copter.SetChannelsAsync(ch4: 1500); })).ConfigureAwait(false); + break; } case Key.M: // 停止低速下降。 diff --git a/Plane.FormationCreator/Views/ModifyTaskView.xaml b/Plane.FormationCreator/Views/ModifyTaskView.xaml index 952ef55..a8f9b40 100644 --- a/Plane.FormationCreator/Views/ModifyTaskView.xaml +++ b/Plane.FormationCreator/Views/ModifyTaskView.xaml @@ -99,7 +99,7 @@ - + - + - + @@ -307,6 +308,20 @@ + + + + + + + + + + + +