diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs index 996f9f2..1682c13 100644 --- a/Plane.FormationCreator/App.xaml.cs +++ b/Plane.FormationCreator/App.xaml.cs @@ -140,13 +140,12 @@ namespace Plane.FormationCreator UdpServerConnectionManager.Instance.StartReceiving(); */ + //初始化地面站连接 CommModuleManager.Instance.CommunicationReceived += CommtionReceivedCopterInfo; CommModuleManager.Instance.CommunicationCopterDisconnect += CommCopterDisconnect; CommModuleManager.Instance.CommunicationConnected += CommCopterconnected; - - CommModuleManager.Instance.Connect(); - //CommModuleManager.Instance.test(); + } catch (Exception ex) { diff --git a/Plane.FormationCreator/Formation/Copter.cs b/Plane.FormationCreator/Formation/Copter.cs index 8c8d5be..c16fd4e 100644 --- a/Plane.FormationCreator/Formation/Copter.cs +++ b/Plane.FormationCreator/Formation/Copter.cs @@ -23,6 +23,8 @@ namespace Plane.FormationCreator.Formation Brush = _brushes[NextBrushIndex()]; RecordLat = lat; RecordLng = lng; + Latitude = lat; + Longitude = lng; //RaiseLocationChangedIfNeeded(); } diff --git a/Plane.FormationCreator/Formation/CopterManager.cs b/Plane.FormationCreator/Formation/CopterManager.cs index 2c9c860..474ce82 100644 --- a/Plane.FormationCreator/Formation/CopterManager.cs +++ b/Plane.FormationCreator/Formation/CopterManager.cs @@ -20,9 +20,13 @@ namespace Plane.FormationCreator.Formation /// public int AddCopter(ICopter entityObject) { - ////给第三方时候限制数量和时间用 - DateTime dateTime2019 = DateTime.Parse("2019-06-20"); + DateTime dateTime2019 = DateTime.Parse("2019-09-20"); + + //新增飞机区域限制:内蒙 +// if (entityObject.Latitude < 37.4307185218 || entityObject.Latitude > 45.6754821756 +// || entityObject.Longitude < 97.3493089056 || entityObject.Longitude > 115.8006783856) +// return 0; if (DateTime.UtcNow > dateTime2019) { diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index 6787b79..9042eb9 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -1374,13 +1374,19 @@ namespace Plane.FormationCreator.Formation } } + TimeSpan timeSpan; + DateTime taskStartTime; public async Task RunTaskAsync() - { - Message.Show("任务开始"); + taskStartTime = DateTime.Now; + Message.Show($"{DateTime.Now.ToString("HH:mm:ss")}:任务开始"); await RunAsync(); if ((IsPaused ?? false) == false) - Message.Show("任务完成"); + { + timeSpan = DateTime.Now - taskStartTime; + Message.Show($"{DateTime.Now.ToString("HH:mm:ss")}:任务完成"); + Message.Show($"总时长 = {timeSpan.Minutes}分{timeSpan.Seconds}秒"); + } } public async Task RunAsync() diff --git a/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs b/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs index ecd4079..fc01eb5 100644 --- a/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs +++ b/Plane.FormationCreator/Formation/FlightTask_FlyTo.cs @@ -169,7 +169,7 @@ namespace Plane.FormationCreator.Formation if (prevTask.TaskType == FlightTaskType.FlyTo && prevTask.LoiterTime == 0) flyToTime += prevTask.RuningTaskRemaining; } - int LEDIndex = 0; + //while (!info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt)) //按航点飞 :所有Copter到达目标点开始飞下个航点 while (ts.TotalMilliseconds < (flyToTime + loiterTime)) //按时间轴飞:当前任务时间到达后自动飞往下个航点 { @@ -212,21 +212,20 @@ namespace Plane.FormationCreator.Formation double time = 0; for (int i = 0; i < LedControl.Count; i++) { + var led = LedControl[i]; time += led.Delay * 1000; if (ts.TotalMilliseconds >= time) - { LEDRGB = info.LEDInfos[i].LEDRGB; - LEDIndex = i; - - } else break; } - Message.Show(LEDIndex.ToString()); info.Copter.LEDColor = LEDRGB; + } + + if (ts.TotalMilliseconds / 10 > sendFlyToTimes) // 每500ms发送一遍指点坐标 { sendFlyToTimes++; diff --git a/Plane.FormationCreator/Formation/GroupManager.cs b/Plane.FormationCreator/Formation/GroupManager.cs new file mode 100644 index 0000000..b1e10e1 --- /dev/null +++ b/Plane.FormationCreator/Formation/GroupManager.cs @@ -0,0 +1,174 @@ +using Plane.Copters; +using GalaSoft.MvvmLight; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Plane.FormationCreator.Util; +using System.Windows.Input; +using GalaSoft.MvvmLight.Command; +using Microsoft.Practices.ServiceLocation; + +namespace Plane.FormationCreator.Formation +{ + public class GroupManager: ObservableObject + { + public ObservableCollection copterGroups { get; } = new ObservableCollection(); + private CopterManager _copterManager = ServiceLocator.Current.GetInstance(); + private string _LastSelectedGroup; + public string LastSelectedGroup + { + get { return _LastSelectedGroup; } + set { Set(nameof(LastSelectedGroup), ref _LastSelectedGroup, value); } + } + public GroupManager() + { + } + + public void AddGroup(string name = "") + { + CopterGroup group = new CopterGroup(name); + copterGroups.Add(group); + group.RemoveGroupEvent += new CopterGroup.RemoveGroupEventHandler(GroupRemove); + group.SelectedGroupEvent += new CopterGroup.SelectedGroupEventHandler(SelectedGroup); + } + + public void SelectedGroup(object sender) + { + CopterGroup groups = sender as CopterGroup; + LastSelectedGroup = groups.groupName; + } + + public void GroupRemove(object sender) + { + CopterGroup groups = sender as CopterGroup; + copterGroups.Remove(groups); + } + + + public IEnumerable ExportGroups() + { + return copterGroups; + } + + public void ImportGroupsInfo(dynamic groupsInfo) + { + copterGroups.Clear(); + foreach (var group in groupsInfo) + { + string name = group.groupName; + CopterGroup copterGroup = new CopterGroup(name); + foreach (var index in group.copterIndexList) + { + copterGroup.copterIndexList.Add(Convert.ToInt32(index)); + } + copterGroups.Add(copterGroup); + copterGroup.RemoveGroupEvent += new CopterGroup.RemoveGroupEventHandler(GroupRemove); + copterGroup.SelectedGroupEvent += new CopterGroup.SelectedGroupEventHandler(SelectedGroup); + } + } + + + private ICommand _AddGroupsCommand; + public ICommand AddGroupsCommand + { + get + { + return _AddGroupsCommand ?? (_AddGroupsCommand = new RelayCommand(async => + { + AddGroup(); + })); + } + } + + + + } + + public class CopterGroup : ObservableObject + { + private CopterManager _copterManager = ServiceLocator.Current.GetInstance(); + public CopterGroup(string name = "") + { + groupName = name != "" ? name : "新分组"; + + } + public string groupName { get; set; } + public List copterIndexList { get; } = new List(); + + public delegate void RemoveGroupEventHandler(object sender); + public event RemoveGroupEventHandler RemoveGroupEvent; + private ICommand _RemoveGroupCommand; + [Newtonsoft.Json.JsonIgnore] + public ICommand RemoveGroupCommand + { + get + { + return _RemoveGroupCommand ?? (_RemoveGroupCommand = new RelayCommand(async => + { + RemoveGroupEvent(this); + })); + } + } + + + public delegate void SelectedGroupEventHandler(object sender); + public event SelectedGroupEventHandler SelectedGroupEvent; + private ICommand _SelectCoptersCommand; + [Newtonsoft.Json.JsonIgnore] + public ICommand SelectCoptersCommand + { + get + { + return _SelectCoptersCommand ?? (_SelectCoptersCommand = new RelayCommand(async => + { + _copterManager.Select(null); + _copterManager.shiftkeydown = true; + foreach (var copterIndex in copterIndexList) + { + //if (_copterManager.Copters.Count > copterIndex) + // { + //_copterManager.Select(_copterManager.Copters[copterIndex]); + ICopter copter = null; +// try +// { +// copter = _copterManager.Copters.First(o => o.Name == (copterIndex + 1).ToString()); +// } +// catch (Exception) +// { +// continue; +// } + copter = _copterManager.Copters.FirstOrDefault(o => o.Name == (copterIndex + 1).ToString()); + if (copter != null) + { + _copterManager.Select(copter); + } + //} + } + _copterManager.shiftkeydown = false; + SelectedGroupEvent(this); + })); + } + } + + private ICommand _SetGroupCoptersCommand; + [Newtonsoft.Json.JsonIgnore] + public ICommand SetGroupCoptersCommand + { + get + { + return _SetGroupCoptersCommand ?? (_SetGroupCoptersCommand = new RelayCommand(async => + { + copterIndexList.Clear(); + foreach (var copter in _copterManager.SelectedCopters) + { + copterIndexList.Add(_copterManager.Copters.IndexOf(copter)); + } + })); + } + } + } +} diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml index f3618a1..99688e1 100644 --- a/Plane.FormationCreator/MainWindow.xaml +++ b/Plane.FormationCreator/MainWindow.xaml @@ -92,7 +92,7 @@