From b729f6b78ef5d071949d71c67b5d6e3e8809fb65 Mon Sep 17 00:00:00 2001 From: pxzleo Date: Thu, 16 Nov 2023 23:34:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=97=B6=E9=97=B4=E4=BC=B0?= =?UTF-8?q?=E8=AE=A1=EF=BC=8C=E5=85=BC=E5=AE=B9=E6=96=B0=E9=A3=9E=E6=9C=BA?= =?UTF-8?q?=E5=9B=BA=E4=BB=B6=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=BB=98=E8=AE=A4=E5=8A=A0=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=EF=BC=8C=E9=80=9F=E5=BA=A6=E7=AD=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formation/FlightTaskManager.cs | 402 +++++++++++++++++- .../FlightTaskSingleCopterInfo_FlyTo.cs | 48 ++- .../ViewModels/ControlPanelViewModel.cs | 60 +-- .../ViewModels/ModifyTaskViewModel.cs | 22 +- .../Views/ModifyTaskView.xaml | 12 +- 5 files changed, 487 insertions(+), 57 deletions(-) diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs index f4e5352..703c024 100644 --- a/Plane.FormationCreator/Formation/FlightTaskManager.cs +++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs @@ -17,6 +17,7 @@ using System.Windows.Media.Media3D; using System.Diagnostics; using Plane.FormationCreator.Util; using System.Collections; +using System.Windows; namespace Plane.FormationCreator.Formation { @@ -308,6 +309,71 @@ namespace Plane.FormationCreator.Formation set { Set(nameof(Orientation), ref _Orientation, value); } } + //水平加速度 + private float _FC_acc_xy = 0; + public float FC_acc_xy + { + get { return _FC_acc_xy; } + set { Set(nameof(FC_acc_xy), ref _FC_acc_xy, value); } + } + //垂直加速度 + private float _FC_acc_z = 0; + public float FC_acc_z + { + get { return _FC_acc_z; } + set { Set(nameof(FC_acc_z), ref _FC_acc_z, value); } + } + + //水平最大速度 + private float _FC_maxvel_xy = 0; + public float FC_maxvel_xy + { + get { return _FC_maxvel_xy; } + set { Set(nameof(FC_maxvel_xy), ref _FC_maxvel_xy, value); } + } + + //上升最大速度 + private float _FC_maxvel_up = 0; + public float FC_maxvel_up + { + get { return _FC_maxvel_up; } + set { Set(nameof(FC_maxvel_up), ref _FC_maxvel_up, value); } + } + //下降最大速度 + private float _FC_maxvel_down = 0; + public float FC_maxvel_down + { + get { return _FC_maxvel_down; } + set { Set(nameof(FC_maxvel_down), ref _FC_maxvel_down, value); } + } + + + //水平默认速度 + private float _FC_defvel_xy = 0; + public float FC_defvel_xy + { + get { return _FC_defvel_xy; } + set { Set(nameof(FC_defvel_xy), ref _FC_defvel_xy, value); } + } + + //上升默认速度 + private float _FC_defvel_up = 0; + public float FC_defvel_up + { + get { return _FC_defvel_up; } + set { Set(nameof(FC_defvel_up), ref _FC_defvel_up, value); } + } + //下降默认速度 + private float _FC_defvel_down = 0; + public float FC_defvel_down + { + get { return _FC_defvel_down; } + set { Set(nameof(FC_defvel_down), ref _FC_defvel_down, value); } + } + + + + private TasksStatus _TaskState = TasksStatus.Stop; public TasksStatus TaskState @@ -1523,22 +1589,35 @@ namespace Plane.FormationCreator.Formation Tasks[1].FlytoTime = 2; for (int taskIndex = 2; taskIndex < Tasks.Count; taskIndex++) SetTaskFlytime(taskIndex); + Message.Show($"任务时间计算执行完成----"); + } + public void CheckAllTaskFlytime() + { + if (_copterManager.FC_VER_NO < 3) + { + Alert.Show("不支持的功能", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + //第一个航点1,是调整航点根据地面摆放情况调整,默认2+1秒 + //从2开始检查 + for (int taskIndex = 2; taskIndex < Tasks.Count; taskIndex++) + CheckTaskFlytime(taskIndex); + Message.Show($"任务检测执行完成----"); } - - public void SetTaskFlytime(int taskIndex,bool settime=true,float currspeed=-1.0f) + public void SetTaskFlytime_v1(int taskIndex, bool settime = true) { double speed = 5.0f; //默认速度 - if ((taskIndex > 0 )&&(taskIndex < Tasks.Count) &&( Tasks[taskIndex].TaskType == FlightTaskType.FlyTo)) + if ((taskIndex > 0) && (taskIndex < Tasks.Count) && (Tasks[taskIndex].TaskType == FlightTaskType.FlyTo)) { if (_copterManager.Copters.Count() > 0) { //计算之前航点有没改变速度,有就取最后一次速度 - if (currspeed==-1.0) + //if (currspeed == -1.0) { - for (int _taskIndex = taskIndex-1; _taskIndex > 1; _taskIndex--) + for (int _taskIndex = taskIndex - 1; _taskIndex > 1; _taskIndex--) { var curWaypoint = Tasks[_taskIndex].SingleCopterInfos.FirstOrDefault(); @@ -1547,13 +1626,10 @@ namespace Plane.FormationCreator.Formation speed = curWaypoint.LevelSpeed; break; } - - } + } } double maxDistance = 0.0f; string copterName = ""; - - foreach (var copter in _copterManager.Copters) { var prevWaypoint = Tasks[taskIndex - 1].SingleCopterInfos.FirstOrDefault(c => c.Copter == copter); @@ -1561,7 +1637,7 @@ namespace Plane.FormationCreator.Formation if ((curWaypoint.IsChangeSpeed) && (curWaypoint.LevelSpeed == -1)) { Message.Show($"任务{taskIndex + 1}飞机编号:{copter.Id}是自动速度,无法计算时间!"); - return ; + return; } //当前航点是否改变速度,有就取修改的速度 @@ -1571,29 +1647,285 @@ namespace Plane.FormationCreator.Formation speed = curWaypoint.LevelSpeed; } - double distance = GeographyUtils.CalcDistance( - prevWaypoint.TargetLat, prevWaypoint.TargetLng, prevWaypoint.TargetAlt, - curWaypoint.TargetLat, curWaypoint.TargetLng, curWaypoint.TargetAlt); + prevWaypoint.TargetLat, prevWaypoint.TargetLng, prevWaypoint.TargetAlt, + curWaypoint.TargetLat, curWaypoint.TargetLng, curWaypoint.TargetAlt); if (distance > maxDistance) { maxDistance = distance; copterName = copter.Name; - // speed = curWaypoint.LevelSpeed; + // speed = curWaypoint.LevelSpeed; } } double time = CalculateFlyIime(maxDistance, speed); - Message.Show($"任务{taskIndex+1}最大航点间距 = {Math.Round(maxDistance, 2)}米, 水平速度={Math.Round(speed, 2)}, 飞行时间 = {Math.Round(time, 2)}秒, 飞机编号:{copterName}"); + Message.Show($"任务{taskIndex + 1}最大航点间距 = {Math.Round(maxDistance, 2)}米, 水平速度={Math.Round(speed, 2)}, 飞行时间 = {Math.Round(time, 2)}秒, 飞机编号:{copterName}"); if (settime) Tasks[taskIndex].FlytoTime = (int)Math.Round(time, 2); - } + } } - return ; - } + return; + } + public void SetTaskFlytime_v2(int taskIndex, + float acc_xy, float acc_z, + float defvel_xy, float defvel_up, float defvel_down, + bool settime = true) + { + if ((taskIndex > 0) && (taskIndex < Tasks.Count) && (Tasks[taskIndex].TaskType == FlightTaskType.FlyTo)) + { + if (_copterManager.Copters.Count() > 0) + { + string copterName = ""; + double maxDistance_xy = 0.0f; + double maxDistance_z = 0.0f; + double maxDistance_up = 0.0f; + double maxDistance_down = 0.0f; + string copterName_xy = ""; + string copterName_up = ""; + string copterName_down = ""; + foreach (var copter in _copterManager.Copters) + { + var prevWaypoint = Tasks[taskIndex - 1].SingleCopterInfos.FirstOrDefault(c => c.Copter == copter); + var curWaypoint = Tasks[taskIndex].SingleCopterInfos.FirstOrDefault(c => c.Copter == copter); + + double distance_xy = GeographyUtils.CalcDistance( + prevWaypoint.TargetLat, prevWaypoint.TargetLng, 0, + curWaypoint.TargetLat, curWaypoint.TargetLng, 0); + double distance_z = curWaypoint.TargetAlt - prevWaypoint.TargetAlt; + + + if (distance_xy > maxDistance_xy) + { + maxDistance_xy = distance_xy; + copterName_xy = copter.Name; + } + + if (Math.Abs(distance_z) > maxDistance_z) + { + maxDistance_z = Math.Abs(distance_z); + } + + + if (distance_z > 0) + { + if (distance_z > maxDistance_up) + { + maxDistance_up = distance_z; + copterName_up = copter.Name; + } + } + else + { + if (-distance_z > maxDistance_down) + { + maxDistance_down = -distance_z; + copterName_down = copter.Name; + } + } + }//循环结束 + + double time_xy = getMinfligthtime((float)maxDistance_xy, acc_xy, defvel_xy); + double time_up = getMinfligthtime((float)maxDistance_up, acc_z, defvel_up); + double time_down = getMinfligthtime((float)maxDistance_down, acc_z, defvel_down); + double tasktime = time_xy; + copterName = copterName_xy; + string divstr = "水平"; + if (time_up > tasktime) + { + tasktime = time_up; + copterName = copterName_up; + divstr = "上升"; + } + + if (time_down > tasktime) + { + tasktime = time_down; + copterName = copterName_down; + divstr = "下降"; + } + tasktime = Math.Max(time_xy, time_up); + tasktime = Math.Max(tasktime, time_down); + Message.Show($"任务{taskIndex + 1}距离:水平{Math.Round(maxDistance_xy, 2)}米;垂直:{Math.Round(maxDistance_z, 2)}米, " + + $"最长耗时:{Math.Round(tasktime, 2)}秒,用于{divstr}飞行,编号:{copterName}" + ); + if (settime) + Tasks[taskIndex].FlytoTime = (int)Math.Round(tasktime, 0); + } + } + + return; + + } + + public void SetTaskFlytime(int taskIndex, bool settime = true) + { + if (taskIndex <= 1) + { + Message.Show($"无法估计起飞或2号任务飞行时间,请根据现场情况调整"); + return; + } + + if (_copterManager.FC_VER_NO >= 3) + { + float _acc_xy = FC_acc_xy; + float _acc_z = FC_acc_z; + float _defvel_xy = FC_defvel_xy; + float _defvel_up = FC_defvel_up; + float _defvel_down = FC_defvel_down; + if (Tasks[taskIndex].SingleCopterInfos.FirstOrDefault().IsChangeSpeed) + { + _defvel_xy = Tasks[taskIndex].SingleCopterInfos.FirstOrDefault().LevelSpeed; + _defvel_up= Tasks[taskIndex].SingleCopterInfos.FirstOrDefault().UpSpeed; + _defvel_down = Tasks[taskIndex].SingleCopterInfos.FirstOrDefault().DownSpeed; + } + + SetTaskFlytime_v2(taskIndex, _acc_xy, _acc_z, _defvel_xy, _defvel_up, _defvel_down, settime); + } + else SetTaskFlytime_v1(taskIndex, settime); + } + //新版本才有的功能,老版本直接提示推出了 + public void CheckTaskFlytime(int taskIndex) + { + if ((taskIndex > 0) && (taskIndex < Tasks.Count) && (Tasks[taskIndex].TaskType == FlightTaskType.FlyTo)) + { + if (_copterManager.Copters.Count() > 0) + { + string copterName = ""; + double maxDistance_xy = 0.0f; + double maxDistance_z = 0.0f; + double maxDistance_up = 0.0f; + double maxDistance_down = 0.0f; + string copterName_xy = ""; + string copterName_up = ""; + string copterName_down = ""; + + foreach (var copter in _copterManager.Copters) + { + var prevWaypoint = Tasks[taskIndex - 1].SingleCopterInfos.FirstOrDefault(c => c.Copter == copter); + var curWaypoint = Tasks[taskIndex].SingleCopterInfos.FirstOrDefault(c => c.Copter == copter); + + double distance_xy = GeographyUtils.CalcDistance( + prevWaypoint.TargetLat, prevWaypoint.TargetLng, 0, + curWaypoint.TargetLat, curWaypoint.TargetLng, 0); + double distance_z = curWaypoint.TargetAlt - prevWaypoint.TargetAlt; + + + if (distance_xy > maxDistance_xy) + { + maxDistance_xy = distance_xy; + copterName_xy = copter.Name; + } + + if (Math.Abs(distance_z) > maxDistance_z) + { + maxDistance_z = Math.Abs(distance_z); + } + + + if (distance_z > 0) + { + if (distance_z > maxDistance_up) + { + maxDistance_up = distance_z; + copterName_up = copter.Name; + } + } + else + { + if (-distance_z > maxDistance_down) + { + maxDistance_down = -distance_z; + copterName_down = copter.Name; + } + } + }//循环结束 + + double time_xy = getMinfligthtime((float)maxDistance_xy, FC_acc_xy, FC_maxvel_xy); + double time_up = getMinfligthtime((float)maxDistance_up, FC_acc_z, FC_maxvel_up); + double time_down = getMinfligthtime((float)maxDistance_down, FC_acc_z, FC_maxvel_down); + double tasktime = time_xy; + copterName = copterName_xy; + string divstr = "水平"; + if (time_up > tasktime) + { + tasktime = time_up; + copterName = copterName_up; + divstr = "上升"; + } + + if (time_down > tasktime) + { + tasktime = time_down; + copterName = copterName_down; + divstr = "下降"; + } + tasktime = Math.Max(time_xy, time_up); + tasktime = Math.Max(tasktime, time_down); + if (Tasks[taskIndex].FlytoTime < tasktime) + { + + Message.Show($"任务{taskIndex + 1}距离:水平{Math.Round(maxDistance_xy, 2)}米;垂直:{Math.Round(maxDistance_z, 2)}米, " + + $"目前飞行时间:{Tasks[taskIndex].FlytoTime}秒,最少需要:{Math.Round(tasktime, 2)}秒,用于{divstr}飞行,编号:{copterName}" + ); + if (Alert.Show($"任务{taskIndex + 1}时间过短,目前{Tasks[taskIndex].FlytoTime}秒至少{Math.Round(tasktime, 2)}秒才能全部飞到目标,需要更改吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning) + == MessageBoxResult.OK) + { + Message.Show($"任务{taskIndex + 1}飞行时间{Tasks[taskIndex].FlytoTime}秒更改为{Math.Round(tasktime, 0)}秒"); + Tasks[taskIndex].FlytoTime = (int)Math.Round(tasktime, 0); + } + + + } + } + + + } + + return; + + } + + float fabsf(float vvalue) + { + return Math.Abs(vvalue); + + } + float sqrt(float vvalue) + { + return (float)Math.Sqrt(vvalue); + + } + + + float getMinfligthtime(float Distance, float fc_acc, float fc_maxspeed) + { + if ((Distance == 0) || (fc_acc == 0) || (fc_maxspeed == 0)) return 0; + float fDis = fabsf(Distance); + float facc = fabsf(fc_acc); + + float realflytime = 0.0f; + //计算一半的距离 + float hafdis = (fDis / 2); + //计算最大速度 + float vel = (float)sqrt(2 * facc * hafdis); + //如果速度超过最大速度 + if (vel > fc_maxspeed) + //使用最大速度 + vel = fc_maxspeed; + //加速时间 + float acctim = vel / facc; + //加速距离 + float accdis = vel * vel / (2 * facc); + //匀速段时间 + float vtime = (hafdis - accdis) / vel; + //到一半的时间 + float haftime = acctim + vtime; + realflytime = haftime * 2; + return realflytime; + } public static double CalculateFlyIime(double s, double v) { @@ -2459,6 +2791,40 @@ namespace Plane.FormationCreator.Formation if (readvalue != "" && int.TryParse(readvalue, out intTemp)) Orientation = int.Parse(readvalue); + readvalue = inifilse.IniReadvalue("Default", "FC_acc_xy"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_acc_xy = float.Parse(readvalue); + + readvalue = inifilse.IniReadvalue("Default", "FC_acc_z"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_acc_z = float.Parse(readvalue); + + readvalue = inifilse.IniReadvalue("Default", "FC_maxvel_xy"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_maxvel_xy = float.Parse(readvalue); + + readvalue = inifilse.IniReadvalue("Default", "FC_maxvel_up"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_maxvel_up = float.Parse(readvalue); + + readvalue = inifilse.IniReadvalue("Default", "FC_maxvel_down"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_maxvel_down = float.Parse(readvalue); + + + readvalue = inifilse.IniReadvalue("Default", "FC_defvel_xy"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_defvel_xy = float.Parse(readvalue); + + readvalue = inifilse.IniReadvalue("Default", "FC_defvel_up"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_defvel_up = float.Parse(readvalue); + + readvalue = inifilse.IniReadvalue("Default", "FC_defvel_down"); + if (readvalue != "" && float.TryParse(readvalue, out floatTemp)) + FC_defvel_down = float.Parse(readvalue); + + } diff --git a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_FlyTo.cs b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_FlyTo.cs index 0ae29a9..7fe9405 100644 --- a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_FlyTo.cs +++ b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_FlyTo.cs @@ -61,7 +61,16 @@ namespace Plane.FormationCreator.Formation public bool IsLandWaypoint { get { return _IsLandWaypoint; } - set { Set(nameof(IsLandWaypoint), ref _IsLandWaypoint, value); } + set { + + Set(nameof(IsLandWaypoint), ref _IsLandWaypoint, value); + if (_flightTaskManager.SelectedTask == null) return; + foreach (FlightTaskSingleCopterInfo info in _flightTaskManager.SelectedTask.SingleCopterInfos) + { + info._IsLandWaypoint = _IsLandWaypoint; + } + + } } private bool _IsChangeSpeed = false; @@ -72,7 +81,15 @@ namespace Plane.FormationCreator.Formation public bool IsChangeSpeed { get {return _IsChangeSpeed; } - set { Set(nameof(IsChangeSpeed), ref _IsChangeSpeed, value); } + set { + Set(nameof(IsChangeSpeed), ref _IsChangeSpeed, value); + if (_flightTaskManager.SelectedTask == null) return; + foreach (FlightTaskSingleCopterInfo info in _flightTaskManager.SelectedTask.SingleCopterInfos) + { + info._IsChangeSpeed = _IsChangeSpeed; + } + + } } @@ -83,7 +100,14 @@ namespace Plane.FormationCreator.Formation public float LevelSpeed { get { return _LevelSpeed; } - set { Set(nameof(LevelSpeed), ref _LevelSpeed, value); } + set { + Set(nameof(LevelSpeed), ref _LevelSpeed, value); + if (_flightTaskManager.SelectedTask == null) return; + foreach (FlightTaskSingleCopterInfo info in _flightTaskManager.SelectedTask.SingleCopterInfos) + { + info._LevelSpeed = _LevelSpeed; + } + } } @@ -94,7 +118,14 @@ namespace Plane.FormationCreator.Formation public float UpSpeed { get { return _UpSpeed; } - set { Set(nameof(UpSpeed), ref _UpSpeed, value); } + set { + Set(nameof(UpSpeed), ref _UpSpeed, value); + if (_flightTaskManager.SelectedTask == null) return; + foreach (FlightTaskSingleCopterInfo info in _flightTaskManager.SelectedTask.SingleCopterInfos) + { + info._UpSpeed = _UpSpeed; + } + } } private float _DownSpeed = 1.5f; @@ -104,7 +135,14 @@ namespace Plane.FormationCreator.Formation public float DownSpeed { get { return _DownSpeed; } - set { Set(nameof(DownSpeed), ref _DownSpeed, value); } + set { + Set(nameof(DownSpeed), ref _DownSpeed, value); + if (_flightTaskManager.SelectedTask == null) return; + foreach (FlightTaskSingleCopterInfo info in _flightTaskManager.SelectedTask.SingleCopterInfos) + { + info._DownSpeed = _DownSpeed; + } + } } /* diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs index 037978c..e58ce44 100644 --- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs @@ -1409,7 +1409,7 @@ namespace Plane.FormationCreator.ViewModels DateTime MissionTime_log = DateTime.Now.AddSeconds(5); Message.Show("任务开始:" + MissionTime_log.ToString()); //循环3次 发送起飞命令 避免通信问题 - for (int i = 0; i < 20; i++) + for (int i = 0; i < 20; i++) //20 { await _commModuleManager.DoMissionStartAsync(null, MissionTime.Hour, @@ -1583,7 +1583,7 @@ namespace Plane.FormationCreator.ViewModels await _RtcmInfoViewModel.RtcmManager.Close(_RtcmInfoViewModel.SerialPortsSelectdValue); } - Alert.Show("开始写入航点,请稍等!(先关灯再开可恢复飞机灯光)", "提示"); + Alert.Show("开始写入航点,飞机绿色成功红色失败!(先关灯再开灯可恢复飞机灯光)", "提示"); _commModuleManager.ClearMissionWriteState(); for (int i = 0; i < coptercount; i++) { @@ -1615,14 +1615,14 @@ namespace Plane.FormationCreator.ViewModels switch (_flightTaskManager.Tasks[j].TaskType) { case FlightTaskType.TakeOff: - int takeofftime = (int)(_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetAlt / 2.5 + 5); + //int takeofftime = (int)(_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetAlt / 2.5 + 5); missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos)); missions.Add(Mission.CreateTakeoffMission( - _flightTaskManager.Tasks[j].SingleCopterInfos[i].TakeOffWaitTime, - _flightTaskManager.Tasks[j].TakeOffTime, - _flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat, - _flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng, - _flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetAlt - groudAlt) + _flightTaskManager.Tasks[j].SingleCopterInfos[i].TakeOffWaitTime, //起飞等待时间 + _flightTaskManager.Tasks[j].TakeOffTime, //起飞时间 + _flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat, //位置没用 + _flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng, //位置没用 + _flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetAlt - groudAlt) //下一个航点的高度 ); break; @@ -1639,6 +1639,7 @@ namespace Plane.FormationCreator.ViewModels double Lat = _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat - _flightTaskManager.OriginLat; double Lng = _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng - _flightTaskManager.OriginLng; + //如果是返航点,位置写入固定值,这样直接返回起飞点 if (_flightTaskManager.Tasks[j].SingleCopterInfos[i].IsLandWaypoint) { Lat = 90; @@ -1665,30 +1666,37 @@ namespace Plane.FormationCreator.ViewModels break; } } - - //虚拟ID在排序时已经变为ID了,直接按ID写入 - // var targetCopter = _copterManager.Copters.FirstOrDefault(o => o.VirtualId == (i+1)); - // bool result = await _commModuleManager.WriteMissionListAsync(targetCopter, missions); - bool result = await _commModuleManager.WriteMissionListAsync(_copterManager.Copters[i], missions); - - //CommWriteMissinState state = new CommWriteMissinState(result); - //_commModuleManager.missionWriteState.Add(int.Parse(_copterManager.Copters[i].Id), state); - if (!result) + //186是通讯模块的限制--张伟那边 + if (missions.Count > 186) { - - if (_copterManager.SortType == CopterManager.CopterSortType.ByVID) - Message.Show($"飞机:{_copterManager.Copters[i].VirtualId} 通信模块传输失败!"); - else - Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输失败!"); + Message.Show($"飞机:{_copterManager.Copters[i].VirtualId} 航点数量超过186,请减少再重写该飞机!"); } else { - if (_copterManager.SortType == CopterManager.CopterSortType.ByVID) - Message.Show($"飞机:{_copterManager.Copters[i].VirtualId} 通信模块传输完成!"); + //虚拟ID在排序时已经变为ID了,直接按ID写入 + // var targetCopter = _copterManager.Copters.FirstOrDefault(o => o.VirtualId == (i+1)); + // bool result = await _commModuleManager.WriteMissionListAsync(targetCopter, missions); + bool result = await _commModuleManager.WriteMissionListAsync(_copterManager.Copters[i], missions); + + //CommWriteMissinState state = new CommWriteMissinState(result); + //_commModuleManager.missionWriteState.Add(int.Parse(_copterManager.Copters[i].Id), state); + if (!result) + { + + if (_copterManager.SortType == CopterManager.CopterSortType.ByVID) + Message.Show($"飞机:{_copterManager.Copters[i].VirtualId} 通信模块传输失败!"); + else + Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输失败!"); + } else - Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输完成!"); + { + if (_copterManager.SortType == CopterManager.CopterSortType.ByVID) + Message.Show($"飞机:{_copterManager.Copters[i].VirtualId} 通信模块传输完成!"); + else + Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输完成!"); + } + await Task.Delay(500).ConfigureAwait(false); } - await Task.Delay(500).ConfigureAwait(false); } catch (Exception ex) { diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs index 0fe587c..39ea3c9 100644 --- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs +++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs @@ -920,7 +920,7 @@ namespace Plane.FormationCreator.ViewModels return _AutoWayPointAllTmCommand ?? (_AutoWayPointAllTmCommand = new RelayCommand(async => { - if (Alert.Show("本操作将导致所有任务飞行时间重新计算,您确定要继续吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning) + if (Alert.Show("本操作将导致2号任务以后所有任务飞行时间重新计算(不修改悬停时间),您确定要继续吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK) { _flightTaskManager.SetAllTaskFlytime(); @@ -929,8 +929,24 @@ namespace Plane.FormationCreator.ViewModels } } - - private ICommand _OptimizeRouteCommandRet; + private ICommand _CheckTmCommand; + public ICommand CheckTmCommand + { + get + { + return _CheckTmCommand ?? (_CheckTmCommand = new RelayCommand(async => + { + + if (Alert.Show("本操作将检测2号任务以后所有任务飞行时间是否合理,您确定要继续吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning) + == MessageBoxResult.OK) + { + _flightTaskManager.CheckAllTaskFlytime(); + } + })); + } + } + + private ICommand _OptimizeRouteCommandRet; public ICommand OptimizeRouteCommandRet { get diff --git a/Plane.FormationCreator/Views/ModifyTaskView.xaml b/Plane.FormationCreator/Views/ModifyTaskView.xaml index 78e0d31..d3a9bb3 100644 --- a/Plane.FormationCreator/Views/ModifyTaskView.xaml +++ b/Plane.FormationCreator/Views/ModifyTaskView.xaml @@ -94,7 +94,7 @@ Margin="0,5,5,0" Width="105" Command="{Binding BackTakeOffPointCommand}" /> -