From 5dc074fc0bb30f0ce6f4e4a35ae4d47ee0edb2ac Mon Sep 17 00:00:00 2001 From: pxzleo Date: Fri, 15 Sep 2017 11:14:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=AC=E5=81=9C=E4=BB=BB=E5=8A=A1=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=80=92=E8=AE=A1=E6=97=B6=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E6=9C=8913=E6=9E=B6=E4=BB=A5=E4=B8=8A?= =?UTF-8?q?=E9=A3=9E=E6=9C=BA=EF=BC=8C=E6=8E=92=E5=A5=BD8=E5=AD=97?= =?UTF-8?q?=E6=8C=89=E4=BB=8E=E5=B7=A6=E5=88=B0=E5=8F=B3=E4=BB=8E=E4=B8=8A?= =?UTF-8?q?=E5=88=B0=E4=B8=8B=E7=9A=84=E9=A1=BA=E5=BA=8F=E8=AE=BE=E5=AE=9A?= =?UTF-8?q?=E5=A5=BD=E9=A1=BA=E5=BA=8F=20=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E9=83=A8=E9=A1=BA=E5=BA=8F=E5=8F=B7=E5=A4=9A=E4=BA=86=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E6=95=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formation/FlightTaskManager.cs | 15 +- .../Formation/FlightTask_LoiterTime.cs | 198 +++++++++++++++++- .../Views/ModifyTaskView.xaml | 80 ++++++- 3 files changed, 278 insertions(+), 15 deletions(-) diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 2413585..6751c95 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -471,7 +471,7 @@ 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 ChangeYaw, float HeadYaw, + bool ChangeYaw, float HeadYaw,bool numberShow, dynamic singleCopterInfos) { var copters = _copterManager.Copters; @@ -491,6 +491,8 @@ namespace Plane.FormationCreator.Formation loiterTimeTask.flashCopterIndexArray = flashIndexArray; loiterTimeTask.ChangeYaw = ChangeYaw; loiterTimeTask.HeadYaw = HeadYaw; + loiterTimeTask.numberShow = numberShow; + // foreach (var copter in copters) for (int i=0; i < copters.Count && i < singleCopterInfos.Count; i++) @@ -655,6 +657,7 @@ namespace Plane.FormationCreator.Formation flashIndexArray = task.flashCopterIndexArray, ChangeYaw = task.ChangeYaw, HeadYaw = task.HeadYaw, + numberShow= task.numberShow, singleCopterInfos = task.SingleCopterInfos.Select(info => @@ -754,7 +757,7 @@ 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, (bool)task.ChangeYaw, (float)task.HeadYaw, task.singleCopterInfos); + (string)task.flashIndexArray, (bool)task.ChangeYaw, (float)task.HeadYaw , (bool)task.numberShow, task.singleCopterInfos); break; case FlightTaskType.SimpleCircle: @@ -795,7 +798,7 @@ 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, (bool)task.ChangeYaw, (float)task.HeadYaw, task.singleCopterInfos); + (string)task.flashIndexArray, (bool)task.ChangeYaw, (float)task.HeadYaw, (bool)task.numberShow, task.singleCopterInfos); break; case FlightTaskType.SimpleCircle: @@ -815,7 +818,7 @@ namespace Plane.FormationCreator.Formation // 在悬停任务时,左键waypoint为选中 // 在悬停任务模式,且LED控制被选中时 - if ((this.SelectedTask.TaskType == FlightTaskType.Loiter) && (this.SelectedTask.flashAttr || this.SelectedTask.oneByOneAttr)) + if ((this.SelectedTask.TaskType == FlightTaskType.Loiter) && (this.SelectedTask.flashAttr || this.SelectedTask.oneByOneAttr|| this.SelectedTask.numberShow)) { string copterNameStr = this.SelectedTask.flashCopterNameArray; @@ -836,12 +839,12 @@ namespace Plane.FormationCreator.Formation if (copterArray[0].Equals("")) { this.SelectedTask.flashCopterNameArray += copter.Name; - SelectedTask.flashCopterIndexArray += Name2Index(copter.Name); + // SelectedTask.flashCopterIndexArray += Name2Index(copter.Name); } else { this.SelectedTask.flashCopterNameArray += "," + copter.Name; - SelectedTask.flashCopterIndexArray += "," + Name2Index(copter.Name); + // SelectedTask.flashCopterIndexArray += "," + Name2Index(copter.Name); } } diff --git a/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs b/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs index f6e5218..86661db 100644 --- a/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs +++ b/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs @@ -1,14 +1,18 @@ -using System; +using GalaSoft.MvvmLight.Command; +using Plane.Windows.Messages; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; namespace Plane.FormationCreator.Formation { public partial class FlightTask { private float _LoiterTimeAttr = 0.0f; + private bool numberisend = false; public float LoiterTimeAttr { get { return _LoiterTimeAttr; } @@ -18,6 +22,86 @@ namespace Plane.FormationCreator.Formation } } + private ICommand _NumberCommand5; + public ICommand NumberCommand5 + { + get + { + return _NumberCommand5 ?? (_NumberCommand5 = new RelayCommand(async => + { + LEDNumberAsync(numberfive); + })); + } + } + + private ICommand _NumberCommand4; + public ICommand NumberCommand4 + { + get + { + return _NumberCommand4 ?? (_NumberCommand4 = new RelayCommand(async => + { + LEDNumberAsync(numberFour); + })); + } + } + private ICommand _NumberCommand3; + public ICommand NumberCommand3 + { + get + { + return _NumberCommand3 ?? (_NumberCommand3 = new RelayCommand(async => + { + LEDNumberAsync(numberthree); + })); + } + } + private ICommand _NumberCommand2; + public ICommand NumberCommand2 + { + get + { + return _NumberCommand2 ?? (_NumberCommand2 = new RelayCommand(async => + { + LEDNumberAsync(numbertwo); + })); + } + } + private ICommand _NumberCommand1; + public ICommand NumberCommand1 + { + get + { + return _NumberCommand1 ?? (_NumberCommand1 = new RelayCommand(async => + { + LEDNumberAsync(numberone); + })); + } + } + private ICommand _NumberCommand0; + public ICommand NumberCommand0 + { + get + { + return _NumberCommand0 ?? (_NumberCommand0 = new RelayCommand(async => + { + LEDNumberAsync(numberzero); + })); + } + } + + + private ICommand _NumberCommandok; + public ICommand NumberCommandok + { + get + { + return _NumberCommandok ?? (_NumberCommandok = new RelayCommand(async => + { + numberisend = true; + })); + } + } @@ -32,6 +116,20 @@ namespace Plane.FormationCreator.Formation } } + // 数字倒计时 要设定13架飞机 + private bool _numberShow = false; + public bool numberShow + { + get { return _numberShow; } + set + { + Set(nameof(numberShow), ref _numberShow, value); + } + } + + + + // 机头方向0为北,顺时针360 private float _HeadYaw = 1.0f; public float HeadYaw @@ -94,7 +192,10 @@ namespace Plane.FormationCreator.Formation for (int i = 0; i < copterArray.Length; i++) { - flashCopterIndexArray += Name2Index(copterArray[i])+','; + flashCopterIndexArray += Name2Index(copterArray[i]); + //最后一个编号不要加"," + if (i!= (copterArray.Length-1)) + flashCopterIndexArray += ','; } } } @@ -167,9 +268,22 @@ namespace Plane.FormationCreator.Formation private int[] lineNine = { 20, 26 }; private int[] lineTen = { 25 }; + + private int[] numberfive = { 0, 1, 2, 3, 5, 6, 7, 9,10,11, 12 }; + private int[] numberFour = { 0, 2, 3, 4, 5, 6, 7, 9, 12 }; + private int[] numberthree = { 0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 12 }; + private int[] numbertwo = { 0, 1, 2, 4, 5, 6, 7, 8, 10, 11, 12 }; + private int[] numberone = { 2, 4, 7, 9, 12 }; + private int[] numberzero = { 0, 1, 2, 3, 4,5, 7, 8,9, 10, 11, 12 }; + + + + + + public async Task RunLoiterTimeTaskAsync() { - + numberisend = false; if (ChangeYaw) { await Task.WhenAll(SingleCopterInfos.Select(info => SetCopterYawAsync(info,HeadYaw))); @@ -200,8 +314,6 @@ namespace Plane.FormationCreator.Formation await LEDFlashParaModifyPlanAsync(); return; } - - var infos = SingleCopterInfos; if (flashAttr) // LED闪烁显示效果 { @@ -289,6 +401,33 @@ namespace Plane.FormationCreator.Formation await Task.Delay((int)(LoiterTimeAttr * 1000)).ConfigureAwait(false); } + else if (numberShow) // LED数字倒计时,目前固定需要13架飞机,并且在跑马灯\数字顺序里设置13架飞机的顺序 + { + if (flashCopterNameArray.Equals("")) + return; + string[] copterArray = flashCopterIndexArray.Split(','); + //没有13架 + if (copterArray.Count()!=13) + return; + + + + + //LED全灭 + await Task.WhenAll(SingleCopterInfos.Select(info => LEDFlashTaskFlySingleCopterAsync(info, false))); + await Task.Delay(100).ConfigureAwait(false); + + //判断是否下一步 + while (! numberisend) + { + await Task.Delay(25).ConfigureAwait(false); //判断是否下一步20hz + } + + + } + + + else // 没有LED显示效果只等待 { await Task.Delay((int)(LoiterTimeAttr * 1000)).ConfigureAwait(false); @@ -650,5 +789,54 @@ namespace Plane.FormationCreator.Formation await Task.WhenAll(tasks_selected).ConfigureAwait(false); } + + // 显示LED数字 + private async Task LEDNumberAsync(int[] Ledshowarray) + { + List numberfivenew = new List(); + var infos = SingleCopterInfos; + + if (flashCopterNameArray.Equals("")) + return; + string[] copterArray = flashCopterIndexArray.Split(','); + //没有13架 + if (copterArray.Count() != 13) + return; + var tasks_selected = new Task[copterArray.Count()]; + + // 转换序号 + for (int i = 0; i < copterArray.Length; i++) + { + if (copterArray[i] == "") break; + + + int index = int.Parse(copterArray[i]); + var info = infos[index]; + + + if (Array.IndexOf(Ledshowarray, i) != -1) + { + + tasks_selected[i] = await Task.Factory.StartNew(async () => + { + var internalInfo = info; + await LEDFlashTaskFlySingleCopterAsync(internalInfo, true); + }); + } + else + { + + tasks_selected[i] = await Task.Factory.StartNew(async () => + { + var internalInfo = info; + await LEDFlashTaskFlySingleCopterAsync(internalInfo, false); + }); + + } + + } + await Task.WhenAll(tasks_selected).ConfigureAwait(false); + } + } } diff --git a/Plane.FormationCreator/Views/ModifyTaskView.xaml b/Plane.FormationCreator/Views/ModifyTaskView.xaml index 3164a68..a325257 100644 --- a/Plane.FormationCreator/Views/ModifyTaskView.xaml +++ b/Plane.FormationCreator/Views/ModifyTaskView.xaml @@ -17,7 +17,7 @@ - + @@ -266,7 +266,7 @@ Grid.Column="1" Margin="0,5,10,0" Text="{Binding TargetAlt, UpdateSourceTrigger=PropertyChanged}" /> - + @@ -398,6 +398,7 @@ + @@ -422,8 +423,8 @@ - - + + @@ -452,6 +453,77 @@ IsChecked="{Binding ChangeYaw, UpdateSourceTrigger=PropertyChanged}" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +