Compare commits

..

No commits in common. "e770082c28d264adf80d4ca337a1fe0b0e5a31e5" and "1b574fa118e949d0c35913af1f9a8a7d0c183929" have entirely different histories.

16 changed files with 138 additions and 735 deletions

View File

@ -69,7 +69,6 @@ namespace Plane.FormationCreator
} }
set set
{ {
if (_config!=null)
_config.Center = $"{value.Lat},{value.Lng}"; _config.Center = $"{value.Lat},{value.Lng}";
} }
} }
@ -90,8 +89,7 @@ namespace Plane.FormationCreator
} }
set set
{ {
if (_config != null) _config.ZoomLevel = value;
_config.ZoomLevel = value;
} }
} }
@ -101,8 +99,7 @@ namespace Plane.FormationCreator
{ {
Directory.CreateDirectory(_dirPath); Directory.CreateDirectory(_dirPath);
} }
if (_config != null) File.WriteAllText(_filePath, JsonConvert.SerializeObject(_config));
File.WriteAllText(_filePath, JsonConvert.SerializeObject(_config));
} }
} }
} }

View File

@ -87,11 +87,6 @@ namespace Plane.FormationCreator.Formation
//} //}
public bool shiftkeydown;
public IEnumerable<ICopter> SelectedCopters { get { return _selectedCoptersGetter().Cast<ICopter>(); } } public IEnumerable<ICopter> SelectedCopters { get { return _selectedCoptersGetter().Cast<ICopter>(); } }
/// <summary> /// <summary>

View File

@ -13,9 +13,9 @@ namespace Plane.FormationCreator.Formation
static class Extensions static class Extensions
{ {
public const float GpsArrivedDis = 2.0f; //GPS模式下航点到达精度 public const float GpsArrivedDis = 2.0f; //GPS模式下航点到达精度
public const float RTKArrivedDis = 1.5f; //RTK模式航点达到精度 public const float RTKArrivedDis = 0.8f; //RTK模式航点达到精度
public const float GpsCloseDis = 2.0f; //GPS模式下碰撞检测最近距离 public const float GpsCloseDis = 2.0f; //GPS模式下碰撞检测最近距离
public const float RTKClosedDis = 1.0f; //RTK模式下碰撞检测最近距离 public const float RTKClosedDis = 0.5f; //RTK模式下碰撞检测最近距离
public static LatLng? GetCenter(this IEnumerable<ICopter> copters) public static LatLng? GetCenter(this IEnumerable<ICopter> copters)

View File

@ -224,7 +224,7 @@ namespace Plane.FormationCreator.Formation
var newTask = new FlightTask(FlightTaskType.FlyTo); var newTask = new FlightTask(FlightTaskType.FlyTo);
int coptindex = 0; int coptindex = 0;
int colnum = 4; //自动生成列数=4 int colnum = 5; //自动生成列数=4
float coldis = 5;//列相距5米 float coldis = 5;//列相距5米
float rowdis = 5;//行相距5米 float rowdis = 5;//行相距5米
float matrixdis = 20; //生成方阵距离30米 float matrixdis = 20; //生成方阵距离30米
@ -363,7 +363,6 @@ namespace Plane.FormationCreator.Formation
public void RestoreFlyToTask(bool staggerRoutes, dynamic singleCopterInfos) public void RestoreFlyToTask(bool staggerRoutes, dynamic singleCopterInfos)
{ {
var copters = _copterManager.Copters; var copters = _copterManager.Copters;
float tagalt = 15;
if (!copters.Any()) return; if (!copters.Any()) return;
AppEx.Current.AppMode = AppMode.ModifyingTask; AppEx.Current.AppMode = AppMode.ModifyingTask;
var lastTask = Tasks.LastOrDefault(); var lastTask = Tasks.LastOrDefault();
@ -372,23 +371,11 @@ namespace Plane.FormationCreator.Formation
var center = nullableCenter.Value; var center = nullableCenter.Value;
var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = staggerRoutes }; var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = staggerRoutes };
// TODO: 林俊清, 20150801, 处理实际飞行器数目与记录中数目不一致的情况。 // TODO: 林俊清, 20150801, 处理实际飞行器数目与记录中数目不一致的情况。
for (int i = 0; i < copters.Count; i++) for (int i = 0; i < copters.Count && i < singleCopterInfos.Count; i++)
{ {
var copter = copters[i]; var copter = copters[i];
FlightTaskSingleCopterInfo newSingleCopterInfo; var singleCopterInfoObj = singleCopterInfos[i];
if (i < singleCopterInfos.Count) var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, new LatLng((double)singleCopterInfoObj.latOffset, (double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt,(bool)singleCopterInfoObj.showLED);
{
var singleCopterInfoObj = singleCopterInfos[i];
tagalt = (float)singleCopterInfoObj.targetAlt;
newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, new LatLng((double)singleCopterInfoObj.latOffset, (double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt, (bool)singleCopterInfoObj.showLED);
}
else
{
newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask
(copter, (double)copter.Latitude, (double)copter.Longitude, tagalt, (bool)false);
}
newTask.SingleCopterInfos.Add(newSingleCopterInfo); newTask.SingleCopterInfos.Add(newSingleCopterInfo);
} }
Tasks.Add(newTask); Tasks.Add(newTask);
@ -484,7 +471,7 @@ namespace Plane.FormationCreator.Formation
// added by ZJF // added by ZJF
private void RestoreLoiterTimeTask(float LoiteTimeTmp, bool flashCheck, float flashCheckPeriod, private void RestoreLoiterTimeTask(float LoiteTimeTmp, bool flashCheck, float flashCheckPeriod,
bool oneByOneCheck, float oneByOneCheckPeriod, string flashNameArray, string flashIndexArray, bool oneByOneCheck, float oneByOneCheckPeriod, string flashNameArray, string flashIndexArray,
bool ChangeYaw, float HeadYaw,bool numberShow, bool ChangeYaw, float HeadYaw,
dynamic singleCopterInfos) dynamic singleCopterInfos)
{ {
var copters = _copterManager.Copters; var copters = _copterManager.Copters;
@ -504,36 +491,14 @@ namespace Plane.FormationCreator.Formation
loiterTimeTask.flashCopterIndexArray = flashIndexArray; loiterTimeTask.flashCopterIndexArray = flashIndexArray;
loiterTimeTask.ChangeYaw = ChangeYaw; loiterTimeTask.ChangeYaw = ChangeYaw;
loiterTimeTask.HeadYaw = HeadYaw; loiterTimeTask.HeadYaw = HeadYaw;
loiterTimeTask.numberShow = numberShow;
// foreach (var copter in copters) // foreach (var copter in copters)
for (int i=0; i < copters.Count ; i++) for (int i=0; i < copters.Count && i < singleCopterInfos.Count; i++)
{ {
var copter = copters[i]; var copter = copters[i];
float tagalt = 15; var singleCopterInfoObj = singleCopterInfos[i];
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForLoiterTimeTask(copter, new LatLng((double)singleCopterInfoObj.latOffset, (double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt);
// var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForLoiterTimeTask(copter, new LatLng((double)singleCopterInfoObj.latOffset, (double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt);
FlightTaskSingleCopterInfo newSingleCopterInfo;
if (i < singleCopterInfos.Count)
{
var singleCopterInfoObj = singleCopterInfos[i];
tagalt = (float)singleCopterInfoObj.targetAlt;
newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForLoiterTimeTask(copter, new LatLng((double)singleCopterInfoObj.latOffset, (double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt);
}
else
{
newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForLoiterTimeTask
(copter, (double)copter.Latitude,
(double)copter.Longitude, tagalt);
}
loiterTimeTask.SingleCopterInfos.Add(newSingleCopterInfo); loiterTimeTask.SingleCopterInfos.Add(newSingleCopterInfo);
} }
Tasks.Add(loiterTimeTask); Tasks.Add(loiterTimeTask);
TaskAdded?.Invoke(this, new FlightTaskAddedEventArgs { LastTask = lastTask, AddedTask = loiterTimeTask }); TaskAdded?.Invoke(this, new FlightTaskAddedEventArgs { LastTask = lastTask, AddedTask = loiterTimeTask });
@ -690,7 +655,6 @@ namespace Plane.FormationCreator.Formation
flashIndexArray = task.flashCopterIndexArray, flashIndexArray = task.flashCopterIndexArray,
ChangeYaw = task.ChangeYaw, ChangeYaw = task.ChangeYaw,
HeadYaw = task.HeadYaw, HeadYaw = task.HeadYaw,
numberShow= task.numberShow,
singleCopterInfos = task.SingleCopterInfos.Select(info => singleCopterInfos = task.SingleCopterInfos.Select(info =>
@ -788,15 +752,9 @@ namespace Plane.FormationCreator.Formation
RestoreCircleTask(task.singleCopterInfos); RestoreCircleTask(task.singleCopterInfos);
break; break;
case FlightTaskType.Loiter: case FlightTaskType.Loiter:
if (task.numberShow!=null) RestoreLoiterTimeTask((float)task.loiterTimeAttr, (bool)task.flashCheck, (float)task.flashCheckPeriod,
RestoreLoiterTimeTask((float)task.loiterTimeAttr, (bool)task.flashCheck, (float)task.flashCheckPeriod, (bool)task.oneByOneCheck, (float)task.oneByOneCheckPeriod, (string)task.flashNameArray,
(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);
else
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, false, task.singleCopterInfos);
break; break;
case FlightTaskType.SimpleCircle: case FlightTaskType.SimpleCircle:
@ -835,14 +793,9 @@ namespace Plane.FormationCreator.Formation
RestoreCircleTask(task.singleCopterInfos); RestoreCircleTask(task.singleCopterInfos);
break; break;
case FlightTaskType.Loiter: case FlightTaskType.Loiter:
if (task.numberShow != null) RestoreLoiterTimeTask( (float)task.loiterTimeAttr, (bool)task.flashCheck, (float)task.flashCheckPeriod,
RestoreLoiterTimeTask((float)task.loiterTimeAttr, (bool)task.flashCheck, (float)task.flashCheckPeriod, (bool)task.oneByOneCheck, (float)task.oneByOneCheckPeriod, (string)task.flashNameArray,
(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);
else
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, false, task.singleCopterInfos);
break; break;
case FlightTaskType.SimpleCircle: case FlightTaskType.SimpleCircle:
@ -862,7 +815,7 @@ namespace Plane.FormationCreator.Formation
// 在悬停任务时左键waypoint为选中 // 在悬停任务时左键waypoint为选中
// 在悬停任务模式且LED控制被选中时 // 在悬停任务模式且LED控制被选中时
if ((this.SelectedTask.TaskType == FlightTaskType.Loiter) && (this.SelectedTask.flashAttr || this.SelectedTask.oneByOneAttr || this.SelectedTask.numberShow)) if ((this.SelectedTask.TaskType == FlightTaskType.Loiter) && (this.SelectedTask.flashAttr || this.SelectedTask.oneByOneAttr))
{ {
string copterNameStr = this.SelectedTask.flashCopterNameArray; string copterNameStr = this.SelectedTask.flashCopterNameArray;
@ -883,22 +836,15 @@ namespace Plane.FormationCreator.Formation
if (copterArray[0].Equals("")) if (copterArray[0].Equals(""))
{ {
this.SelectedTask.flashCopterNameArray += copter.Name; this.SelectedTask.flashCopterNameArray += copter.Name;
// SelectedTask.flashCopterIndexArray += Name2Index(copter.Name); SelectedTask.flashCopterIndexArray += Name2Index(copter.Name);
} }
else else
{ {
this.SelectedTask.flashCopterNameArray += "," + copter.Name; this.SelectedTask.flashCopterNameArray += "," + copter.Name;
// SelectedTask.flashCopterIndexArray += "," + Name2Index(copter.Name); SelectedTask.flashCopterIndexArray += "," + Name2Index(copter.Name);
} }
} }
}
else
{
} }
} }
@ -1039,9 +985,9 @@ namespace Plane.FormationCreator.Formation
//RTK //RTK
if (gpstype == 15) if (gpstype == 15)
{ {
if ((copter.GpsFixType != GpsFixType.RTKFIXED) && (copter.GpsFixType != GpsFixType.RTKFLOAT)) if (copter.GpsFixType != GpsFixType.RTKFIXED)
{ {
Message.Show(copter.Id+ ",是RTK定位但未进入RTKFIX或RTKFLOAT模式"); Message.Show(copter.Id+ ",是RTK定位但未进入RTKFIX模式");
return; return;
} }
} }

View File

@ -18,20 +18,5 @@ namespace Plane.FormationCreator.Formation
}; };
return info; return info;
} }
public static FlightTaskSingleCopterInfo CreateForLoiterTimeTask(ICopter copter, double targetLat, double targetLng, float targetAlt)
{
var info = new FlightTaskSingleCopterInfo(copter)
{
TargetLat = targetLat,
TargetLng = targetLng,
TargetAlt = targetAlt,
};
return info;
}
} }
} }

View File

@ -11,8 +11,7 @@ namespace Plane.FormationCreator.Formation
{ {
public partial class FlightTask public partial class FlightTask
{ {
//默认不开这个功能 private bool _StaggerRoutes = true;
private bool _StaggerRoutes = false;
//是否有交错 //是否有交错
public bool StaggerRoutes public bool StaggerRoutes
@ -56,18 +55,6 @@ namespace Plane.FormationCreator.Formation
var tasks = new Task[infos.Count]; var tasks = new Task[infos.Count];
for (int i = 0; i < infos.Count; i++) for (int i = 0; i < infos.Count; i++)
{ {
var info = infos[i];
tasks[i] = await Task.Factory.StartNew(async () =>
{
var internalInfo = info;
await FlyToTaskFlySingleCopterAsync(internalInfo);
});
/*
//检测交叉可能导致整个编队停主无法继续组队,前面飞机没到位后面就没法飞
//如果后面要加,需要多测试解决前序飞机可靠到达和记录日志确认是这里导致任务暂定
var info = infos[i]; var info = infos[i];
var copter = info.Copter; var copter = info.Copter;
var i1 = i; var i1 = i;
@ -85,7 +72,6 @@ namespace Plane.FormationCreator.Formation
} }
await FlyToTaskFlySingleCopterAsync(info); await FlyToTaskFlySingleCopterAsync(info);
}); });
*/
} }
await Task.WhenAll(tasks).ConfigureAwait(false); await Task.WhenAll(tasks).ConfigureAwait(false);

View File

@ -1,18 +1,14 @@
using GalaSoft.MvvmLight.Command; using System;
using Plane.Windows.Messages;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
namespace Plane.FormationCreator.Formation namespace Plane.FormationCreator.Formation
{ {
public partial class FlightTask public partial class FlightTask
{ {
private float _LoiterTimeAttr = 0.0f; private float _LoiterTimeAttr = 0.0f;
private bool numberisend = false;
public float LoiterTimeAttr public float LoiterTimeAttr
{ {
get { return _LoiterTimeAttr; } get { return _LoiterTimeAttr; }
@ -22,95 +18,6 @@ namespace Plane.FormationCreator.Formation
} }
} }
private ICommand _NumberCommand5;
public ICommand NumberCommand5
{
get
{
return _NumberCommand5 ?? (_NumberCommand5 = new RelayCommand<double>(async param =>
{
await LEDNumberAsync(numberfive);
}));
}
}
private ICommand _NumberCommand4;
public ICommand NumberCommand4
{
get
{
return _NumberCommand4 ?? (_NumberCommand4 = new RelayCommand<double>(async param =>
{
await LEDNumberAsync(numberFour);
}));
}
}
private ICommand _NumberCommand3;
public ICommand NumberCommand3
{
get
{
return _NumberCommand3 ?? (_NumberCommand3 = new RelayCommand<double>(async param =>
{
await LEDNumberAsync(numberthree);
}));
}
}
private ICommand _NumberCommand2;
public ICommand NumberCommand2
{
get
{
return _NumberCommand2 ?? (_NumberCommand2 = new RelayCommand<double>(async param =>
{
await LEDNumberAsync(numbertwo);
}));
}
}
private ICommand _NumberCommand1;
public ICommand NumberCommand1
{
get
{
return _NumberCommand1 ?? (_NumberCommand1 = new RelayCommand<double>(async param =>
{
await LEDNumberAsync(numberone);
}));
}
}
private ICommand _NumberCommand0;
public ICommand NumberCommand0
{
get
{
return _NumberCommand0 ?? (_NumberCommand0 = new RelayCommand<double>(async param =>
{
await LEDNumberAsync(numberzero);
await Task.Delay(200).ConfigureAwait(false);
await LEDNumberFlashAsync(false);
await Task.Delay(200).ConfigureAwait(false);
await LEDNumberAsync(numberzero);
await Task.Delay(200).ConfigureAwait(false);
await LEDNumberFlashAsync(false);
await Task.Delay(200).ConfigureAwait(false);
await LEDNumberAsync(numberzero);
}));
}
}
private ICommand _NumberCommandok;
public ICommand NumberCommandok
{
get
{
return _NumberCommandok ?? (_NumberCommandok = new RelayCommand<double>(async param =>
{
await LEDNumberFlashAsync(true);
numberisend = true;
}));
}
}
@ -125,20 +32,6 @@ namespace Plane.FormationCreator.Formation
} }
} }
// 数字倒计时 要设定13架飞机
private bool _numberShow = false;
public bool numberShow
{
get { return _numberShow; }
set
{
Set(nameof(numberShow), ref _numberShow, value);
}
}
// 机头方向0为北顺时针360 // 机头方向0为北顺时针360
private float _HeadYaw = 1.0f; private float _HeadYaw = 1.0f;
public float HeadYaw public float HeadYaw
@ -201,10 +94,7 @@ namespace Plane.FormationCreator.Formation
for (int i = 0; i < copterArray.Length; i++) for (int i = 0; i < copterArray.Length; i++)
{ {
flashCopterIndexArray += Name2Index(copterArray[i]); flashCopterIndexArray += Name2Index(copterArray[i])+',';
//最后一个编号不要加","
if (i!= (copterArray.Length-1))
flashCopterIndexArray += ',';
} }
} }
} }
@ -277,22 +167,9 @@ namespace Plane.FormationCreator.Formation
private int[] lineNine = { 20, 26 }; private int[] lineNine = { 20, 26 };
private int[] lineTen = { 25 }; private int[] lineTen = { 25 };
private int[] numberfive = { 0, 1, 2, 4, 5, 6, 7, 8,10,11, 12 };
private int[] numberFour = { 2, 4, 5, 6, 7,8, 9,10, 12 };
private int[] numberthree = { 0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 12 };
private int[] numbertwo = { 0, 1, 2, 3, 5, 6, 7, 9, 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() public async Task RunLoiterTimeTaskAsync()
{ {
numberisend = false;
if (ChangeYaw) if (ChangeYaw)
{ {
await Task.WhenAll(SingleCopterInfos.Select(info => SetCopterYawAsync(info,HeadYaw))); await Task.WhenAll(SingleCopterInfos.Select(info => SetCopterYawAsync(info,HeadYaw)));
@ -323,6 +200,8 @@ namespace Plane.FormationCreator.Formation
await LEDFlashParaModifyPlanAsync(); await LEDFlashParaModifyPlanAsync();
return; return;
} }
var infos = SingleCopterInfos; var infos = SingleCopterInfos;
if (flashAttr) // LED闪烁显示效果 if (flashAttr) // LED闪烁显示效果
{ {
@ -353,26 +232,8 @@ namespace Plane.FormationCreator.Formation
// LED灯全亮 // LED灯全亮
await Task.WhenAll(SingleCopterInfos.Select(info => LEDFlashTaskFlySingleCopterAsync(info, true))); await Task.WhenAll(SingleCopterInfos.Select(info => LEDFlashTaskFlySingleCopterAsync(info, true)));
//延时等待 //延时等待
await Task.Delay((int)(LoiterTimeAttr * 1000)).ConfigureAwait(false);
//判断是否下一步
DateTime start = DateTime.Now;
while (true)
{
if (_flightTaskManager.IsPaused == true)
{
await Task.WhenAll(SingleCopterInfos.Select(info => (info.Copter.HoverAsync())));
return;
}
DateTime end = DateTime.Now;
TimeSpan ts = end - start;
//等待指定时间
if (ts.TotalMilliseconds > LoiterTimeAttr * 1000)
return;
await Task.Delay(20).ConfigureAwait(false);
}
} }
else if (oneByOneAttr) // LED走马灯显示效果 else if (oneByOneAttr) // LED走马灯显示效果
@ -425,63 +286,9 @@ namespace Plane.FormationCreator.Formation
// LED灯全亮 // LED灯全亮
await Task.WhenAll(SingleCopterInfos.Select(info => LEDFlashTaskFlySingleCopterAsync(info, true))); await Task.WhenAll(SingleCopterInfos.Select(info => LEDFlashTaskFlySingleCopterAsync(info, true)));
//延时等待 //延时等待
await Task.Delay((int)(LoiterTimeAttr * 1000)).ConfigureAwait(false);
//判断是否下一步
DateTime start = DateTime.Now;
while (true)
{
if (_flightTaskManager.IsPaused == true)
{
await Task.WhenAll(SingleCopterInfos.Select(info => (info.Copter.HoverAsync())));
return;
}
DateTime end = DateTime.Now;
TimeSpan ts = end - start;
//等待指定时间
if (ts.TotalMilliseconds> LoiterTimeAttr* 1000)
return;
await Task.Delay(20).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)
{
if (_flightTaskManager.IsPaused == true)
{
await Task.WhenAll(SingleCopterInfos.Select(info => (info.Copter.HoverAsync())));
return;
}
await Task.Delay(25).ConfigureAwait(false); //判断是否下一步20hz
}
}
else // 没有LED显示效果只等待 else // 没有LED显示效果只等待
{ {
await Task.Delay((int)(LoiterTimeAttr * 1000)).ConfigureAwait(false); await Task.Delay((int)(LoiterTimeAttr * 1000)).ConfigureAwait(false);
@ -843,87 +650,5 @@ namespace Plane.FormationCreator.Formation
await Task.WhenAll(tasks_selected).ConfigureAwait(false); await Task.WhenAll(tasks_selected).ConfigureAwait(false);
} }
// 显示LED数字
private async Task LEDNumberAsync(int[] Ledshowarray)
{
List<int> numberfivenew = new List<int>();
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);
}
private async Task LEDNumberFlashAsync(bool isOn)
{
List<int> numberfivenew = new List<int>();
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];
tasks_selected[i] = await Task.Factory.StartNew(async () =>
{
var internalInfo = info;
await LEDFlashTaskFlySingleCopterAsync(internalInfo, isOn);
});
}
await Task.WhenAll(tasks_selected).ConfigureAwait(false);
}
} }
} }

View File

@ -8,7 +8,7 @@ namespace Plane.FormationCreator.Formation
{ {
public partial class FlightTask public partial class FlightTask
{ {
private float _RTLAlt = 20.0f;// 15.0f; private float _RTLAlt = 15.0f;
public float RTLAlt public float RTLAlt
{ {
get { return _RTLAlt; } get { return _RTLAlt; }

View File

@ -227,7 +227,7 @@ namespace Plane.FormationCreator.Formation
//执行第二第三阶段起飞任务-------------使用中 //执行第二第三阶段起飞任务-------------使用中
private async Task TakeOffSecondTaskAsync(FlightTaskSingleCopterInfo info) private async Task TakeOffSecondTaskAsync(FlightTaskSingleCopterInfo info)
{ {
float takeOffAlt = 20; float takeOffAlt = 15;
int copterIndex = SingleCopterInfos.IndexOf(info); int copterIndex = SingleCopterInfos.IndexOf(info);
var copterNextTask = _flightTaskManager.Tasks[1].SingleCopterInfos[copterIndex]; var copterNextTask = _flightTaskManager.Tasks[1].SingleCopterInfos[copterIndex];

View File

@ -107,9 +107,7 @@ namespace Plane.FormationCreator
case Key.LeftShift: case Key.LeftShift:
{ {
var copters = _copterManager.AcceptingControlCopters;
Shiftkeydown = true; Shiftkeydown = true;
_copterManager.shiftkeydown = true;
break; break;
} }
//开关SHOWLED //开关SHOWLED
@ -361,8 +359,6 @@ namespace Plane.FormationCreator
case Key.LeftShift: case Key.LeftShift:
{ {
Shiftkeydown = false; Shiftkeydown = false;
_copterManager.shiftkeydown = false;
break; break;
} }
case Key.W: case Key.W:

View File

@ -196,7 +196,7 @@ namespace Plane.FormationCreator.ViewModels
})); }));
} }
} }
private string _RTKcomvalue = "COM7"; private string _RTKcomvalue = "COM3";
public string RTKcomvalue public string RTKcomvalue
{ {
get { return _RTKcomvalue; } get { return _RTKcomvalue; }

View File

@ -54,7 +54,7 @@ namespace Plane.FormationCreator.ViewModels
var center = _mapManager.Center; var center = _mapManager.Center;
string id; string id;
int colnum = 4; //自动生成列数=4 int colnum = 5; //自动生成列数=4
float coldis = 5;//列相距5米 float coldis = 5;//列相距5米
float rowdis = 5;//行相距5米 float rowdis = 5;//行相距5米
int currcol = 0; //当前列号 int currcol = 0; //当前列号

View File

@ -290,58 +290,54 @@ namespace Plane.FormationCreator.ViewModels
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
if (_flightTaskManager.SelectedTask != null) bool copterisselect;
int selectednumber = _copterManager.SelectedCopters.Count() - 1;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
bool copterisselect; copterisselect = false;
int selectednumber = _copterManager.SelectedCopters.Count() - 1; selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++) foreach (var capter in _copterManager.SelectedCopters)
{ {
copterisselect = false; if (capter == selectedCopter)
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter; copterisselect = true;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
}
if (copterisselect)
{
tlng = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng;
if (minlng == 0)
minlng = tlng;
if (tlng > maxlng)
maxlng = tlng;
else if (tlng < minlng)
minlng = tlng;
}
} }
avgl = (maxlng - minlng) / selectednumber; if (copterisselect)
int coptnum = 0;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
} tlng = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng;
if (copterisselect) if (minlng == 0)
{ minlng = tlng;
if (tlng > maxlng)
maxlng = tlng;
else if (tlng < minlng)
minlng = tlng;
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng = minlng + avgl * coptnum;
coptnum++;
}
} }
} }
} avgl = (maxlng - minlng) / selectednumber;
int coptnum = 0;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
}
if (copterisselect)
{
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng = minlng + avgl * coptnum;
coptnum++;
}
}
}
/////////////////////// ///////////////////////
@ -375,59 +371,56 @@ namespace Plane.FormationCreator.ViewModels
////////////////////// //////////////////////
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
if (_flightTaskManager.SelectedTask != null) bool copterisselect;
int selectednumber = _copterManager.SelectedCopters.Count() - 1;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
bool copterisselect; copterisselect = false;
int selectednumber = _copterManager.SelectedCopters.Count() - 1; selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++) foreach (var capter in _copterManager.SelectedCopters)
{ {
copterisselect = false; if (capter == selectedCopter)
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter; copterisselect = true;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
}
if (copterisselect)
{
tlat = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
if (minlat == 0)
minlat = tlat;
if (tlat > maxlat)
maxlat = tlat;
else if (tlat < minlat)
minlat = tlat;
}
} }
avgl = (maxlat - minlat) / selectednumber; if (copterisselect)
int coptnum = 0;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
} tlat = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
if (copterisselect) if (minlat == 0)
{ minlat = tlat;
if (tlat > maxlat)
maxlat = tlat;
else if (tlat < minlat)
minlat = tlat;
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat = maxlat - avgl * coptnum;
coptnum++;
}
} }
///////////////////////
// await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
} }
avgl = (maxlat - minlat) / selectednumber;
int coptnum = 0;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
}
if (copterisselect)
{
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat = maxlat - avgl * coptnum;
coptnum++;
}
}
///////////////////////
// await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
} }
})); }));
} }
@ -449,8 +442,6 @@ namespace Plane.FormationCreator.ViewModels
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
if (_flightTaskManager.SelectedTask != null)
{
bool copterisselect; bool copterisselect;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++) for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
@ -491,48 +482,13 @@ namespace Plane.FormationCreator.ViewModels
} }
} }
//await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。 //await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
} }));
else
//调整飞机
{
//模拟飞机才能调整
if (selectedCopter is FakeCopter)
{
foreach (var capter in _copterManager.SelectedCopters)
{
tlat = capter.Latitude;
if (tlat > maxlat)
maxlat = tlat;
}
foreach (var capter in _copterManager.SelectedCopters)
{
var copterfk = (FakeCopter)capter;
copterfk.SetProperties(
latitude: maxlat,
longitude: copterfk.Longitude);
}
}
}
}));
} }
} }
@ -554,8 +510,6 @@ public ICommand VerticlAlignmentCommand
double tlng = 0; double tlng = 0;
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
bool copterisselect; bool copterisselect;
if (_flightTaskManager.SelectedTask != null)
{
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++) for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
copterisselect = false; copterisselect = false;
@ -596,32 +550,9 @@ public ICommand VerticlAlignmentCommand
} }
} }
//await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。 //await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
else
//调整飞机
{
//模拟飞机才能调整
if (selectedCopter is FakeCopter)
{
foreach (var capter in _copterManager.SelectedCopters)
{
tlng = capter.Longitude;
if (tlng > maxlng)
maxlng = tlng;
}
foreach (var capter in _copterManager.SelectedCopters) }));
{
var copterfk = (FakeCopter)capter;
copterfk.SetProperties(
latitude: copterfk.Latitude,
longitude: maxlng );
}
}
}
}));
} }
} }
@ -697,11 +628,8 @@ public ICommand VerticlAlignmentCommand
double centlng = 0; double centlng = 0;
double centlat = 0; double centlat = 0;
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
if (_flightTaskManager.SelectedTask != null) bool copterisselect;
{ for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
bool copterisselect;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
copterisselect = false; copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter; selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
@ -762,76 +690,7 @@ public ICommand VerticlAlignmentCommand
//// ////
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。 await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}));
}
else
//调整飞机
{
//模拟飞机才能调整
if (selectedCopter is FakeCopter)
{
foreach (var capter in _copterManager.SelectedCopters)
{
lngsum += capter.Longitude;
latsum += capter.Latitude;
selectcount++;
}
//计算旋转中心
if (selectcount > 0)
{
centlng = lngsum / selectcount;
centlat = latsum / selectcount;
}
else return;
foreach (var capter in _copterManager.SelectedCopters)
{
double lpDistance = CalculationLogLatDistance.GetDistanceOne(centlng, centlat,
capter.Longitude,
capter.Latitude);
CalculationLogLatDistance.MyLatLng mypos1, mypos2;
mypos1 = new CalculationLogLatDistance.MyLatLng(centlng, centlat);
mypos2 = new CalculationLogLatDistance.MyLatLng(
capter.Longitude
, capter.Latitude);
double lpAzimuth = CalculationLogLatDistance.getAngle(mypos1, mypos2);
double lng2 = 0;
double lat2 = 0;
CalculationLogLatDistance.ConvertDistanceToLogLat(centlng, centlat, lpDistance,
lpAzimuth + (double)RotateLine, out lng2, out lat2);
var copterfk = (FakeCopter)capter;
copterfk.SetProperties(
latitude: lat2,
longitude: lng2);
}
}
}
}));
} }
} }
@ -937,9 +796,7 @@ public ICommand VerticlAlignmentCommand
double centlat = 0; double centlat = 0;
double centalt = 0; double centalt = 0;
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
if (_flightTaskManager.SelectedTask != null) bool copterisselect;
{
bool copterisselect;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++) for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{ {
copterisselect = false; copterisselect = false;
@ -1031,15 +888,13 @@ public ICommand VerticlAlignmentCommand
} }
} }
//// ////
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。 await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}));
}
}));
} }
} }

View File

@ -32,7 +32,7 @@ namespace Plane.FormationCreator.Views
_copterManager.SetSelectionDelegates( _copterManager.SetSelectionDelegates(
() => lvwDrones.SelectedItems, () => lvwDrones.SelectedItems,
SelectitemMessage copter => lvwDrones.SelectedItem = copter
); );
lvwDrones.SelectionChanged += (sender, e) => lvwDrones.SelectionChanged += (sender, e) =>
{ {
@ -41,14 +41,5 @@ namespace Plane.FormationCreator.Views
} }
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>(); private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private void SelectitemMessage(ICopter copter)
{
if (!_copterManager.shiftkeydown)
lvwDrones.SelectedItem = copter;
else
lvwDrones.SelectedItems.Add(copter);
}
} }
} }

View File

@ -345,7 +345,6 @@ namespace Plane.FormationCreator.Views
private void RegisterEventHandlersForTaskInfo(Ellipse wp, int taskIndex) private void RegisterEventHandlersForTaskInfo(Ellipse wp, int taskIndex)
{ {
var info = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.FirstOrDefault(i => i.Copter == this.Copter); var info = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.FirstOrDefault(i => i.Copter == this.Copter);
if (info == null) return;
info.PropertyChanged += (sender, e) => info.PropertyChanged += (sender, e) =>
{ {
switch (e.PropertyName) switch (e.PropertyName)

View File

@ -398,7 +398,6 @@
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
<RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
@ -424,7 +423,7 @@
Text="{Binding flashPeriodAttr, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding flashPeriodAttr, UpdateSourceTrigger=PropertyChanged}" />
</Grid> </Grid>
<TextBlock Grid.Row="2" Grid.Column="0" Text="走马灯/数字顺序: " /> <TextBlock Grid.Row="2" Grid.Column="0" Text="走马灯: " />
<Grid Grid.Row="2" Grid.Column="1"> <Grid Grid.Row="2" Grid.Column="1">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
@ -453,77 +452,6 @@
IsChecked="{Binding ChangeYaw, UpdateSourceTrigger=PropertyChanged}" /> IsChecked="{Binding ChangeYaw, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="1" Grid.Row="0" <TextBox Grid.Column="1" Grid.Row="0"
Text="{Binding HeadYaw, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding HeadYaw, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
<Grid Grid.Row="5" Grid.Column="0" Margin="0,0,28,0">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0"
IsChecked="{Binding numberShow, UpdateSourceTrigger=PropertyChanged}" Margin="0,5,0,0" />
</Grid>
<Grid Grid.Row="5" Grid.ColumnSpan="2" Margin="19,0,0,0">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Content="5"
Margin="0,5,0,0"
Command="{Binding NumberCommand5}" />
<Button Grid.Row="0" Grid.Column="1" Content="4"
Margin="0,5,0,0"
Command="{Binding NumberCommand4}" />
<Button Grid.Row="0" Grid.Column="2" Content="3"
Margin="0,5,0,0"
Command="{Binding NumberCommand3}" />
<Button Grid.Row="0" Grid.Column="3" Content="2"
Margin="0,5,0,0"
Command="{Binding NumberCommand2}" />
<Button Grid.Row="0" Grid.Column="4" Content="1"
Margin="0,5,0,0"
Command="{Binding NumberCommand1}" />
<Button Grid.Row="0" Grid.Column="5" Content="0"
Margin="0,5,0,0"
Command="{Binding NumberCommand0}"
/>
<Button Grid.Row="0" Grid.Column="6" Content="N"
Margin="0,5,0,0"
Command="{Binding NumberCommandok}"
/>
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>