From 59b4669a7d1e1dea2e1934e55bef9577d5f81cc4 Mon Sep 17 00:00:00 2001 From: xu Date: Tue, 5 May 2020 13:29:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=81=AF=E5=85=89=E5=88=97=E8=A1=A8=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=8D=95=E7=8B=AC=E9=A1=B5=E9=9D=A2=20=E8=B7=91?= =?UTF-8?q?=E9=A9=AC=E7=81=AF=E5=92=8C=E7=81=AF=E5=B8=A6=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=96=B9=E5=90=91=20=E5=8A=A0=E5=85=A5=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E7=81=AF=E5=85=89=E6=97=B6=E9=97=B4=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E7=81=AF=E5=85=89=E6=96=B0=E7=B1=BB=E5=9E=8B=20=E6=8B=89?= =?UTF-8?q?=E7=83=9FID=E4=B9=8B=E5=89=8D=E6=98=AF8=E6=94=B9=E4=B8=BA11?= =?UTF-8?q?=EF=BC=8C=E5=88=B0=E5=9B=BA=E4=BB=B6=E4=BB=BB=E7=84=B6=E4=B8=BA?= =?UTF-8?q?50?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formation/FlightTaskManager.cs | 18 +- .../FlightTaskSingleCopterInfo_LED.cs | 80 ++++- .../ViewModels/ControlPanelViewModel.cs | 2 +- .../ViewModels/ModifyTaskViewModel.cs | 279 +++++++++++++++++- .../Views/ModifyTaskView.xaml | 217 +++++++++----- .../Views/ModifyTaskView.xaml.cs | 1 + 6 files changed, 498 insertions(+), 99 deletions(-) diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 824d13c..7628d6e 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -672,15 +672,15 @@ namespace Plane.FormationCreator.Formation { var copter = copters[j]; var fc = copter as FakeCopter; - fc.SetProperties( - latitude: Tasks[0].SingleCopterInfos[j].TargetLat, - longitude: Tasks[0].SingleCopterInfos[j].TargetLng, - altitude:0 - - ); - //设置灯光为默认颜色 - fc.LEDColor = CopterManager.CopterDefaultColor;// "000000"; - + if (fc != null) + { + fc.SetProperties( + latitude: Tasks[0].SingleCopterInfos[j].TargetLat, + longitude: Tasks[0].SingleCopterInfos[j].TargetLng, + altitude: 0 ); + //设置灯光为默认颜色 + fc.LEDColor = CopterManager.CopterDefaultColor;// "000000"; + } } } diff --git a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs index d118e23..3e06aa4 100644 --- a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs +++ b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_LED.cs @@ -1,15 +1,18 @@ -using GalaSoft.MvvmLight.Command; +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; using Plane.CommunicationManagement; using Plane.Copters; using Plane.Windows.Messages; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Input; +using System.Windows.Media; namespace Plane.FormationCreator.Formation { @@ -29,19 +32,24 @@ namespace Plane.FormationCreator.Formation { LEDInfo LedInfo = new LEDInfo(); LEDInfos.Add(LedInfo); - LedInfo.RemoveEvent += new LEDInfo.RemoveEventHandler(LEDRemove); + LedInfo.RemoveEvent += new LEDInfo.RemoveEventHandler(LEDRemove); + LedInfo.PropertyChanged += (sender, e) =>{RefLEDSumTime();}; + RefLEDSumTime(); } public void AddLEDInfo(LEDInfo LedInfo) { LEDInfos.Add(LedInfo); LedInfo.RemoveEvent += new LEDInfo.RemoveEventHandler(LEDRemove); + LedInfo.PropertyChanged += (sender, e) => { RefLEDSumTime(); }; + RefLEDSumTime(); } public void LEDRemove(object sender) { LEDInfo LedInfo = sender as LEDInfo; LEDInfos.Remove(LedInfo); + RefLEDSumTime(); } @@ -57,6 +65,7 @@ namespace Plane.FormationCreator.Formation return _AddLEDCommand ?? (_AddLEDCommand = new RelayCommand(async => { AddLEDInfo(); + })); } } @@ -85,15 +94,39 @@ namespace Plane.FormationCreator.Formation })); } } + + public void RefLEDSumTime() + { + float _ledSumTime = 0; + foreach (LEDInfo led in LEDInfos) + { + _ledSumTime += (float)led.Delay; + } + LEDSumTime = _ledSumTime; + } + + + //灯光总时长 + private float _LEDSumTime = 0; + public float LEDSumTime + { + get { return _LEDSumTime; } + set { Set(nameof(LEDSumTime), ref _LEDSumTime, value); } + + } + + + bool LEDTestRun = false; - /* + /* private string _TestLEDtxt = "测试"; public string TestLEDtxt { get { return _TestLEDtxt; } set { Set(nameof(TestLEDtxt), ref _TestLEDtxt, value); } } - + */ +/* LEDMode 0 = "常亮" 1="同步闪烁(单色)" /> @@ -130,7 +163,7 @@ namespace Plane.FormationCreator.Formation }else { LEDTestRun = false; - _commModuleManager.LED_TaskAsync(99, 0, 0, "000000", this.Copter); + _commModuleManager.LED_TaskAsync(255, 0, 0, "000000", this.Copter); } })); @@ -166,13 +199,22 @@ namespace Plane.FormationCreator.Formation } } - public class LEDInfo + public class LEDInfo :INotifyPropertyChanged { private double delay = 1; //灯光延时 单位:100ms (从当前任务开为0,延时几秒后设置LED) private int ledmode = 0; //灯光模式 0常亮 1闪烁 2随机闪烁(RGB无意义) private float ledInterval = 0; //闪烁延时 单位:秒 private int ledtimes = 0; //次数 (预留、暂取消其意义) private string ledRGB = "FFFFFF"; //灯光颜色 + private SolidColorBrush _DrawRGB = new SolidColorBrush(Color.FromRgb(0xFF, 0xFF, 0xFF)); + + protected internal virtual void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + public event PropertyChangedEventHandler PropertyChanged; + public LEDInfo() { @@ -184,12 +226,12 @@ namespace Plane.FormationCreator.Formation delay = led.delay; ledmode = led.ledmode; ledInterval = led.ledInterval; - ledRGB = led.ledRGB; + LEDRGB = led.ledRGB; } public double Delay { get { return delay; } - set { delay = value; } + set { delay = value; OnPropertyChanged("delay"); } } public int LEDMode @@ -211,9 +253,29 @@ namespace Plane.FormationCreator.Formation public string LEDRGB { get { return ledRGB; } - set { ledRGB = value; } + set { + + ledRGB = value; + DrawRGB.Color= (Color)ColorConverter.ConvertFromString("#" + ledRGB); + + } } + [Newtonsoft.Json.JsonIgnore] + public SolidColorBrush DrawRGB + { + get + { + return _DrawRGB; + } + set + { + _DrawRGB = value; + } + } + + + public delegate void RemoveEventHandler(object sender); public event RemoveEventHandler RemoveEvent; private ICommand _RemoveLEDCommand; diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index 756ecfb..a9e8f3d 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -1514,7 +1514,7 @@ namespace Plane.FormationCreator.ViewModels Color color = (Color)ColorConverter.ConvertFromString("#" + ledInfo.LEDRGB); int ledMode = ledInfo.LEDMode; //拉烟任务模式ID是50,需要改为50 - if (ledMode == 8) ledMode = 50; + if (ledMode == 11) ledMode = 50; IMission LEDMission = Mission.CreateLEDControlMission( (int)(ledInfo.Delay * 10), ledMode, diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs index 1585d66..3e565eb 100644 --- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs @@ -1680,14 +1680,29 @@ public ICommand VerticlAlignmentCommand #region 跑马灯参数 - private double _BeginTime = 10; + private double _BeginTime = 1; public double BeginTime { get { return _BeginTime; } set { Set(nameof(BeginTime), ref _BeginTime, value); } } - private double _EndTime = 11; + + //灯带扫光方向,默认从左到右 + private double _BeltDirection = 90; + public double BeltDirection + { + get { return _BeltDirection; } + set { Set(nameof(BeltDirection), ref _BeltDirection, value); } + } + + + + + + + + private double _EndTime = 3; public double EndTime { get { return _EndTime; } @@ -1701,22 +1716,55 @@ public ICommand VerticlAlignmentCommand set { Set(nameof(AverageSum), ref _AverageSum, value); } } - private string _ChangeRGB = "FFFFFF"; + private string _ChangeRGB = "FF0000"; public string ChangeRGB { get { return _ChangeRGB; } - set { Set(nameof(ChangeRGB), ref _ChangeRGB, value); } + set { Set(nameof(ChangeRGB), ref _ChangeRGB, value); + DrawChangeRGB.Color = (Color)ColorConverter.ConvertFromString("#" + value); + } } - private string _EndRGB = ""; + private string _EndRGB = "0000FF"; public string EndRGB { get { return _EndRGB; } - set { Set(nameof(EndRGB), ref _EndRGB, value); } + set { Set(nameof(EndRGB), ref _EndRGB, value); + DrawEndRGB.Color = (Color)ColorConverter.ConvertFromString("#" + value); + } } + + private SolidColorBrush _DrawChangeRGB = new SolidColorBrush(Color.FromRgb(0xFF, 0x00, 0x00)); + public SolidColorBrush DrawChangeRGB + { + get + { + return _DrawChangeRGB; + } + set + { + Set(nameof(DrawChangeRGB), ref _DrawChangeRGB, value); + + } + } + + private SolidColorBrush _DrawEndRGB = new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0xFF)); + public SolidColorBrush DrawEndRGB + { + get + { + return _DrawEndRGB; + } + set + { + Set(nameof(DrawEndRGB), ref _DrawEndRGB, value); + + } + } + #endregion - //跑马灯--按照经纬度变换灯光 + //灯带--按照经纬度变换灯光 private ICommand _SetHorseRaceLampCommand; public ICommand SetHorseRaceLampCommand { @@ -1724,10 +1772,18 @@ public ICommand VerticlAlignmentCommand { return _SetHorseRaceLampCommand ?? (_SetHorseRaceLampCommand = new RelayCommand(async () => { + float CopterDirection =90- (float)BeltDirection ; if (_copterManager.SelectedCopters.Count() <= 0) return; + //旋转飞机矩阵 + if (CopterDirection != 0) + { + LevelRotateCommand.Execute(CopterDirection); + await Task.Delay(100); + } + double minLat, maxLat; double minLng, maxLng; @@ -1749,10 +1805,12 @@ public ICommand VerticlAlignmentCommand foreach (var copterInfo in selectCopterInfos) { double interval = copterInfo.TargetLng - minLng; + double leddelay = 0; int time = (int)(interval / (averagelngCount / AverageSum)); LEDInfo led = new LEDInfo(); led.LEDMode = 0; led.Delay = BeginTime + time * (EndTime - BeginTime) / AverageSum; + leddelay += led.Delay; led.LEDRGB = ChangeRGB; copterInfo.AddLEDInfo(led); @@ -1767,16 +1825,39 @@ public ICommand VerticlAlignmentCommand else endLed.LEDRGB = EndRGB; copterInfo.AddLEDInfo(endLed); + + //为了每架飞机结束灯光时间一致,以便下次再做跑马灯之类的效果有个一致的起始时间,再增加一个 + //改为专门的按钮功能=AlignmentTimeCommand + /* + leddelay += endLed.Delay; + LEDInfo endLed1 = new LEDInfo(); + endLed1.LEDMode = 0; + endLed1.Delay = (EndTime - BeginTime)-leddelay; + if (EndRGB == "0") + endLed1.LEDRGB = copterInfo.LEDInfos[copterInfo.LEDInfos.Count - 2].LEDRGB; + else + endLed1.LEDRGB = EndRGB; + copterInfo.AddLEDInfo(endLed1); + */ } } await Task.Delay(100); + + + //旋转飞机矩阵 + if (CopterDirection != 0) + LevelRotateCommand.Execute(0-CopterDirection); + + + + })); } } - private double _StrokesTime = 10; + private double _StrokesTime = 1; public double StrokesTime { get { return _StrokesTime; } @@ -1855,6 +1936,16 @@ public ICommand VerticlAlignmentCommand } } + + + private double _AlignmentTime = 10; + public double AlignmentTime + { + get { return _AlignmentTime; } + set { Set(nameof(AlignmentTime), ref _AlignmentTime, value); } + } + + #region 渐变灯参数 @@ -1869,15 +1960,165 @@ public ICommand VerticlAlignmentCommand public string RightRGB { get { return _RightRGB; } - set { Set(nameof(RightRGB), ref _RightRGB, value); } + set { Set(nameof(RightRGB), ref _RightRGB, value); + DrawRightRGB.Color = (Color)ColorConverter.ConvertFromString("#" + value); + } } private string _LeftRGB = "FFFFFF"; public string LeftRGB { get { return _LeftRGB; } - set { Set(nameof(LeftRGB), ref _LeftRGB, value); } + set { Set(nameof(LeftRGB), ref _LeftRGB, value); + DrawLeftRGB.Color = (Color)ColorConverter.ConvertFromString("#" + value); + } } + + + + //渐变方向,默认从左到右 + private double _GradualDirection = 90; + public double GradualDirection + { + get { return _GradualDirection; } + set { Set(nameof(GradualDirection), ref _GradualDirection, value); } + } + + + + + + private SolidColorBrush _DrawLeftRGB = new SolidColorBrush(Color.FromRgb(0xFF, 0xFF, 0xFF)); + public SolidColorBrush DrawLeftRGB + { + get + { + return _DrawLeftRGB; + } + set + { + Set(nameof(DrawLeftRGB), ref _DrawLeftRGB, value); + + } + } + + private SolidColorBrush _DrawRightRGB = new SolidColorBrush(Color.FromRgb(0xFF, 0xFF, 0xFF)); + public SolidColorBrush DrawRightRGB + { + get + { + return _DrawRightRGB; + } + set + { + Set(nameof(DrawRightRGB), ref _DrawRightRGB, value); + + } + } + + + private ICommand _QueryMAXTimeCommand; + public ICommand QueryMAXTimeCommand + { + get + { + return _QueryMAXTimeCommand ?? (_QueryMAXTimeCommand = new RelayCommand(async => + { + //所以选中飞行当前任务信息 + var selectCopterInfos = _flightTaskManager.SelectedTask.SingleCopterInfos.FindAll(delegate (FlightTaskSingleCopterInfo p) + { + return _copterManager.SelectedCopters.Contains(p.Copter); + }); + double maxtime = 0.0f; + string maxid="" ; + foreach (var copterInfo in selectCopterInfos) + { + // AlignmentTime + double leddelay = 0; + foreach (LEDInfo led in copterInfo.LEDInfos) + { + leddelay += led.Delay; + } + if (leddelay > maxtime) + { + maxtime = leddelay; + maxid = copterInfo.Copter.Id; + } + } + + + Alert.Show($"ID={maxid}飞机的航点灯光时长为{maxtime}秒", "提示", MessageBoxButton.OK, MessageBoxImage.Information); + + + })); + } + } + + + + + + + + private ICommand _AlignmentTimeCommand; + public ICommand AlignmentTimeCommand + { + get + { + return _AlignmentTimeCommand ?? (_AlignmentTimeCommand = new RelayCommand(async => + { + //所以选中飞行当前任务信息 + var selectCopterInfos = _flightTaskManager.SelectedTask.SingleCopterInfos.FindAll(delegate (FlightTaskSingleCopterInfo p) + { + return _copterManager.SelectedCopters.Contains(p.Copter); + }); + + foreach (var copterInfo in selectCopterInfos) + { + // AlignmentTime + double leddelay = 0; + foreach (LEDInfo led in copterInfo.LEDInfos) + { + leddelay += led.Delay; + } + if (leddelay > AlignmentTime) + { + Alert.Show($"{AlignmentTime}秒对齐时间不够,ID={copterInfo.Copter.Id}飞机的航点灯光时长为{leddelay}秒", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + } + + + + + + foreach (var copterInfo in selectCopterInfos) + { + + double leddelay = 0; + foreach (LEDInfo led in copterInfo.LEDInfos) + { + leddelay += led.Delay; + } + if (leddelay<= AlignmentTime) + { + LEDInfo endLed = new LEDInfo(); + endLed.LEDMode = 0; + endLed.Delay = AlignmentTime - leddelay; + endLed.LEDRGB = copterInfo.LEDInfos[copterInfo.LEDInfos.Count - 1].LEDRGB; + copterInfo.AddLEDInfo(endLed); + } + } + })); + } + } + + + + + + #endregion //渐变色 @@ -1889,9 +2130,23 @@ public ICommand VerticlAlignmentCommand return _SetGradientRampCommand ?? (_SetGradientRampCommand = new RelayCommand(async () => { + float CopterDirection = 90 - (float)GradualDirection; + if (_copterManager.SelectedCopters.Count() <= 0) return; + //旋转飞机矩阵 + if (CopterDirection != 0) + { + LevelRotateCommand.Execute(CopterDirection); + await Task.Delay(100); + } + + + + + + double minLat, maxLat; double minLng, maxLng; @@ -1936,6 +2191,10 @@ public ICommand VerticlAlignmentCommand } await Task.Delay(100); + //旋转飞机矩阵 + if (CopterDirection != 0) + LevelRotateCommand.Execute(0 - CopterDirection); + })); } } diff --git a/Plane.FormationCreator/Views/ModifyTaskView.xaml b/Plane.FormationCreator/Views/ModifyTaskView.xaml index d11d36a..8304910 100644 --- a/Plane.FormationCreator/Views/ModifyTaskView.xaml +++ b/Plane.FormationCreator/Views/ModifyTaskView.xaml @@ -214,6 +214,7 @@ - +