From 70e70e182c92477da7b990bd8ed094b6dc9c9e97 Mon Sep 17 00:00:00 2001 From: pxzleo Date: Fri, 21 Jul 2017 11:05:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?=E5=B7=B2=E5=81=9A=E4=BA=86=E8=BE=83=E5=A4=9A=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E5=9F=BA=E6=9C=AC=E7=A8=B3=E5=AE=9A=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [FlightTaskManager.cs]加入强制下一个 [ModifyTaskViewModel.cs]加入调整所有任务高度 [MapView.xaml.cs]加入是否显示所有点 --- .../FlightTaskStatusToFillConverter.cs | 10 ++- .../Formation/FlightTask.cs | 2 +- .../Formation/FlightTaskManager.cs | 61 ++++++++++++++--- .../Formation/FlightTaskStatus.cs | 12 +++- .../Formation/FlightTask_TakeOff.cs | 4 +- Plane.FormationCreator/MainWindow.xaml | 3 +- .../ViewModels/ControlPanelViewModel.cs | 10 +-- .../ViewModels/ModifyTaskViewModel.cs | 65 +++++++++++++++++++ .../ViewModels/TaskBarViewModel.cs | 10 ++- Plane.FormationCreator/Views/MapView.xaml | 4 ++ Plane.FormationCreator/Views/MapView.xaml.cs | 22 +++++++ .../Views/ModifyTaskView.xaml | 21 +++++- Plane.FormationCreator/Views/TaskBarView.xaml | 5 +- .../Views/TaskBarView.xaml.cs | 48 +++++++++++++- 14 files changed, 245 insertions(+), 32 deletions(-) diff --git a/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs b/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs index 75e537b..e7f59ba 100644 --- a/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs +++ b/Plane.FormationCreator/Converters/FlightTaskStatusToFillConverter.cs @@ -16,10 +16,18 @@ namespace Plane.FormationCreator.Converters { static SolidColorBrush _normalFill = new SolidColorBrush(Colors.LightGray); static SolidColorBrush _runningFill = new SolidColorBrush(Colors.OrangeRed); + static SolidColorBrush _PausedFill = new SolidColorBrush(Colors.Yellow); public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var status = (FlightTaskStatus)value; - return status == FlightTaskStatus.Running ? _runningFill : _normalFill; + if (status == FlightTaskStatus.Running) + return _runningFill; + + if (status == FlightTaskStatus.Paused) + return _PausedFill; + + + return _normalFill; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/Plane.FormationCreator/Formation/FlightTask.cs b/Plane.FormationCreator/Formation/FlightTask.cs index 9817882..c1c0c3c 100644 --- a/Plane.FormationCreator/Formation/FlightTask.cs +++ b/Plane.FormationCreator/Formation/FlightTask.cs @@ -22,7 +22,7 @@ namespace Plane.FormationCreator.Formation private ILogger _logger = ServiceLocator.Current.GetInstance(); - private FlightTaskStatus _Status = FlightTaskStatus.Created; + private FlightTaskStatus _Status = FlightTaskStatus.Stop; public FlightTaskStatus Status { get { return _Status; } diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index e586c0c..117ee50 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -189,6 +189,14 @@ namespace Plane.FormationCreator.Formation private set { Set(nameof(CurrentRunningTaskIndex), ref _CurrentRunningTaskIndex, value); } } + + private TasksStatus _TaskState = TasksStatus.Stop; + public TasksStatus TaskState + { + get { return _TaskState; } + private set { Set(nameof(TaskState), ref _TaskState, value); } + } + public event EventHandler TaskAdded; public event EventHandler SingleCopterInfoChanged; @@ -288,14 +296,33 @@ namespace Plane.FormationCreator.Formation } - public void ForceNextTasks() + + public async Task ForceNextTasks() { + if (CurrentRunningTaskIndex == Tasks.Count - 1) + return; + Pause(); - //起飞任务需要跳过 - if (CurrentRunningTaskIndex == 0) + int i = 0; + //等待暂停或2s超时(80*25ms) + while ((TaskState != TasksStatus.Paused)||(i>80)) + { + await Task.Delay(25).ConfigureAwait(false); + i++; + } + + if (TaskState == TasksStatus.Paused) + { + CurrentRunningTask.Status = FlightTaskStatus.Stop; + CurrentRunningTask = null; + + //起飞任务需要跳过 + if (CurrentRunningTaskIndex == 0) + CurrentRunningTaskIndex++; CurrentRunningTaskIndex++; - CurrentRunningTaskIndex++; - } + await RunTaskAsync(); + } + } public void ResetTasks() { @@ -303,7 +330,7 @@ namespace Plane.FormationCreator.Formation CurrentRunningTaskIndex = 0; if (CurrentRunningTask != null) { - CurrentRunningTask.Status = FlightTaskStatus.Saved; + CurrentRunningTask.Status = FlightTaskStatus.Stop; CurrentRunningTask = null; } @@ -914,25 +941,41 @@ namespace Plane.FormationCreator.Formation } } + public async Task RunTaskAsync() + + { + Message.Show("任务开始"); + await RunAsync(); + if ((IsPaused ?? false) == false) + Message.Show("任务完成"); + } + public async Task RunAsync() { IsPaused = false; AppEx.Current.AppMode = AppMode.RunningTasks; StartAvoidingCrash(); //开始碰撞检测 + TaskState = TasksStatus.Running; for (int i = CurrentRunningTaskIndex; i < Tasks.Count; i++) { var task = Tasks[i]; + //task.Status目前只用于任务条下面状态显示不同颜色 task.Status = FlightTaskStatus.Running; CurrentRunningTask = task; CurrentRunningTaskIndex = i; await task.RunAsync().ConfigureAwait(false); // 1. 被暂停时,中断 RunAsync。继续运行时将把此时运行了一半的 CurrentRunningTask 重新运行一遍。 - if (IsPaused == true) return; - - task.Status = FlightTaskStatus.Saved; + if (IsPaused == true) + { + task.Status = FlightTaskStatus.Paused; + TaskState = TasksStatus.Paused; + return; + } + task.Status = FlightTaskStatus.Stop; } // 2. 正常结束时,重置 CurrentRunningTask、CurrentRunningTaskIndex 和 IsPaused。 + TaskState = TasksStatus.Stop; CurrentRunningTask = null; CurrentRunningTaskIndex = 0; IsPaused = null; diff --git a/Plane.FormationCreator/Formation/FlightTaskStatus.cs b/Plane.FormationCreator/Formation/FlightTaskStatus.cs index cf8541e..3e0ab4c 100644 --- a/Plane.FormationCreator/Formation/FlightTaskStatus.cs +++ b/Plane.FormationCreator/Formation/FlightTaskStatus.cs @@ -1,6 +1,12 @@ public enum FlightTaskStatus { - Created, - Saved, - Running + Stop, + Running, + Paused +} +public enum TasksStatus +{ + Stop, + Running, + Paused } \ No newline at end of file diff --git a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs index 6462f01..b088deb 100644 --- a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs +++ b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs @@ -163,10 +163,10 @@ namespace Plane.FormationCreator.Formation //{ // return; //} - //5秒内每1000毫秒尝试解锁一次 + //8秒内每1000毫秒尝试解锁一次 //解锁间隔一定要超过1s否则导致飞控以后无法解锁 - if (i > 200) + if (i > 320) return; //无法解锁后面不用执行了 if (i % (1000 / 25) == 1000 / 25 - 1) { diff --git a/Plane.FormationCreator/MainWindow.xaml b/Plane.FormationCreator/MainWindow.xaml index 5a9cd6e..8020bcf 100644 --- a/Plane.FormationCreator/MainWindow.xaml +++ b/Plane.FormationCreator/MainWindow.xaml @@ -85,7 +85,8 @@ diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index 685b3f8..f5e9f36 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -255,12 +255,13 @@ namespace Plane.FormationCreator.ViewModels { await SingleCopter.UnlockAsync(); await Task.Delay(25).ConfigureAwait(false); + for (int i = 0; !SingleCopter.IsUnlocked; i++) { - //5秒内每1000毫秒尝试解锁一次 + //8秒内每1000毫秒尝试解锁一次 //解锁间隔一定要超过1s否则导致飞控以后无法解锁 - if (i > 200) + if (i >320) return; //无法解锁后面不用执行了 if (i % (1000 / 25) == 1000 / 25 - 1) { @@ -268,6 +269,7 @@ namespace Plane.FormationCreator.ViewModels } await Task.Delay(25).ConfigureAwait(false); } + await Task.Delay(1000); if (SingleCopter.IsUnlocked) @@ -284,10 +286,10 @@ namespace Plane.FormationCreator.ViewModels await Task.Delay(25).ConfigureAwait(false); for (int i = 0; SingleCopter.IsUnlocked; i++) { - //5秒内每1000毫秒尝试解锁一次 + //8秒内每1000毫秒尝试解锁一次 //解锁间隔一定要超过1s否则导致飞控以后无法解锁 - if (i > 200) + if (i > 320) return; //无法解锁后面不用执行了 if (i % (1000 / 25) == 1000 / 25 - 1) { diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs index ae1a756..e3c49b2 100644 --- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs @@ -12,6 +12,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Input; using Plane.Geography; +using Plane.Windows.Messages; namespace Plane.FormationCreator.ViewModels { @@ -150,6 +151,15 @@ namespace Plane.FormationCreator.ViewModels set { Set(nameof(Distancevalue), ref _Distancevalue, value); } } + + private float _Modialtvalue; + public float Modialtvalue + { + get { return _Modialtvalue; } + set { Set(nameof(Modialtvalue), ref _Modialtvalue, value); } + } + + private int _txtStarindex=0; public int txtStarindex { @@ -863,6 +873,59 @@ public ICommand VerticlAlignmentCommand } } + //调整所有任务高度 + private ICommand _ModiAltCommand; + public ICommand ModiAltCommand + { + get + { + return _ModiAltCommand ?? (_ModiAltCommand = new RelayCommand(async => + { + if (_flightTaskManager.Tasks.Count < 2) return; + + float lowalt = 200; + + + int _startindex = 0; + int _endindex = _flightTaskManager.Tasks.Count-1; + int lowtask = 0; + int lowCopter = 0; + + if ((txtStarindex != 0) && (txtendindex != 0)) + { + _startindex = txtStarindex; + _endindex = txtendindex; + } + + for (int i = _startindex; i <= _endindex; i++) + { + + if ((_flightTaskManager.Tasks[i].TaskType == FlightTaskType.TakeOff) || + (_flightTaskManager.Tasks[i].TaskType == FlightTaskType.ReturnToLand)) + continue; + + + for (int j = 0; j < _flightTaskManager.Tasks[i].SingleCopterInfos.Count; j++) + { + _flightTaskManager.Tasks[i].SingleCopterInfos[j].TargetAlt += Modialtvalue; + if (lowalt > _flightTaskManager.Tasks[i].SingleCopterInfos[j].TargetAlt) + { + lowalt = _flightTaskManager.Tasks[i].SingleCopterInfos[j].TargetAlt; + lowtask = i; + lowCopter = j; + } + + } + } + Alert.Show("指定步骤任务高度已改变"+ Modialtvalue + "米,步骤["+ lowtask + "],ID["+ + _flightTaskManager.Tasks[lowtask].SingleCopterInfos[lowCopter].Copter.Id + + "]最低飞行高度"+ lowalt + "米,注意是否太低!"); + + })); + } + } + + @@ -880,6 +943,8 @@ public ICommand VerticlAlignmentCommand double distance = 0; var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); + if (_flightTaskManager.SelectedTask == null) return; + for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++) { diff --git a/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs b/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs index 09ca55c..6455bee 100644 --- a/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs +++ b/Plane.FormationCreator/ViewModels/TaskBarViewModel.cs @@ -54,9 +54,10 @@ namespace Plane.FormationCreator.ViewModels { get { - return _NextTasksCommand ?? (_NextTasksCommand = new RelayCommand( () => + return _NextTasksCommand ?? (_NextTasksCommand = new RelayCommand(async () => { - _flightTaskManager.ForceNextTasks(); + // await _flightTaskManager.RunAsync(); + await _flightTaskManager.ForceNextTasks(); // Message.Show("任务开始"); // await _flightTaskManager.RunAsync(); // Message.Show(_flightTaskManager.IsPaused == true ? "任务暂停" : "任务完成"); @@ -101,10 +102,7 @@ namespace Plane.FormationCreator.ViewModels // }); // Alert.Show(s); // return; - Message.Show("任务开始"); - await _flightTaskManager.RunAsync(); - if ((_flightTaskManager.IsPaused ?? false) == false) - Message.Show("任务完成"); + await _flightTaskManager.RunTaskAsync(); })); } } diff --git a/Plane.FormationCreator/Views/MapView.xaml b/Plane.FormationCreator/Views/MapView.xaml index d0d453c..98af68e 100644 --- a/Plane.FormationCreator/Views/MapView.xaml +++ b/Plane.FormationCreator/Views/MapView.xaml @@ -26,6 +26,10 @@ VerticalAlignment="Top" Orientation="Horizontal" > + - +