主要修改取消UDPserver 更换通信模块的通信
最小距离的修改 无悬停的快速航点模拟 时间长度的限定 如flyto的时间限定为4095 计划路线的修改:只显示当前航点的路线 飞控版本检测 航点失败续写和航点单写
This commit is contained in:
parent
c6de7dc49e
commit
6ade842b38
@ -18,6 +18,7 @@ using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Plane.CommunicationManagement;
|
||||
|
||||
namespace Plane.FormationCreator
|
||||
{
|
||||
@ -128,15 +129,22 @@ namespace Plane.FormationCreator
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
UdpServerConnectionManager.Instance.ExceptionThrown += (sender, e1) =>
|
||||
{
|
||||
_logger.Log(e1.Exception);
|
||||
};
|
||||
UdpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
|
||||
UdpServerConnectionManager.Instance.StartReceiving();
|
||||
|
||||
|
||||
/*
|
||||
UdpServerConnectionManager.Instance.ExceptionThrown += (sender, e1) =>
|
||||
{
|
||||
_logger.Log(e1.Exception);
|
||||
};
|
||||
UdpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
|
||||
UdpServerConnectionManager.Instance.StartReceiving();
|
||||
*/
|
||||
|
||||
CommModuleManager.Instance.CommunicationReceived += CommtionReceivedCopterInfo;
|
||||
CommModuleManager.Instance.CommunicationCopterDisconnect += CommCopterDisconnect;
|
||||
CommModuleManager.Instance.CommunicationConnected += CommCopterconnected;
|
||||
|
||||
|
||||
CommModuleManager.Instance.Connect();
|
||||
//CommModuleManager.Instance.test();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -144,6 +152,14 @@ namespace Plane.FormationCreator
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
CommModuleManager.Instance.CloseConnection();
|
||||
base.OnExit(e);
|
||||
}
|
||||
|
||||
|
||||
private void Copter_TextReceived(object sender, MessageCreatedEventArgs e)
|
||||
{
|
||||
_logger.Log(e.Message );
|
||||
@ -164,14 +180,10 @@ namespace Plane.FormationCreator
|
||||
Name = ip.Substring(ip.LastIndexOf('.') + 1)
|
||||
|
||||
};
|
||||
|
||||
|
||||
int _index;
|
||||
_index=copters.AddCopter(copter);
|
||||
copterStatus.Insert(_index,false);
|
||||
|
||||
copter.TextReceived += Copter_TextReceived;
|
||||
|
||||
}));
|
||||
}
|
||||
else
|
||||
@ -185,5 +197,81 @@ namespace Plane.FormationCreator
|
||||
{
|
||||
await AddOrUpdateCopter(e.RemoteAddress, e.Connection);
|
||||
}
|
||||
|
||||
private async void CommtionReceivedCopterInfo(object sender, CommunicationReceiveCopterInfoEventArgs e)
|
||||
{
|
||||
await UpdateCommCopterInfo(e.Id, e.Package);
|
||||
//await TaskUtils.CompletedTask;
|
||||
}
|
||||
|
||||
private async void CommCopterDisconnect(object sender, CommunicationCopterDisconnectEventArgs e)
|
||||
{
|
||||
await DisconnectCopter(e.Id);
|
||||
}
|
||||
|
||||
private async void CommCopterconnected(object sender, CommunicationConnectEventArgs e)
|
||||
{
|
||||
await AddCommCopter(e.Id);
|
||||
}
|
||||
|
||||
private async Task DisconnectCopter(int id)
|
||||
{
|
||||
var copters = _copterManager.Copters;
|
||||
var copter = copters.FirstOrDefault(c => c.Id == id.ToString());
|
||||
if (copter != null)
|
||||
{
|
||||
if (copter is PLCopter)
|
||||
{
|
||||
PLCopter plcopter = (PLCopter)copter;
|
||||
plcopter.CommModuleConnected = false;
|
||||
}
|
||||
}
|
||||
await TaskUtils.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
private static readonly object locker = new object();
|
||||
private async Task AddCommCopter(int id)
|
||||
{
|
||||
await Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
lock(locker)
|
||||
{
|
||||
var copter = _copterManager.Copters.FirstOrDefault(c => c.Id == id.ToString());
|
||||
if (copter == null)
|
||||
{
|
||||
var copterStatus = _copterManager.CopterStatus;
|
||||
var connection = new CommConnection();
|
||||
copter = new Copter(connection, SynchronizationContext.Current, _mapManager.Center.Lat, _mapManager.Center.Lng)
|
||||
{
|
||||
Id = id.ToString(),
|
||||
Name = id.ToString(),
|
||||
};
|
||||
int _index;
|
||||
_index = _copterManager.Copters.AddCopter(copter);
|
||||
copterStatus.Insert(_index, false);
|
||||
copter.TextReceived += Copter_TextReceived;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private async Task UpdateCommCopterInfo(int id, byte[] package)
|
||||
{
|
||||
await AddCommCopter(id);
|
||||
lock (locker)
|
||||
{
|
||||
var copter = _copterManager.Copters.FirstOrDefault(c => c.Id == id.ToString());
|
||||
if (copter!= null && copter is PLCopter)
|
||||
{
|
||||
PLCopter plcopter = (PLCopter)copter;
|
||||
if (!plcopter.CommModuleConnected) plcopter.CommModuleConnected = true;
|
||||
plcopter.InternalCopter.AnalyzeCommMouldePositionIntPacket(package);
|
||||
plcopter.CommModuleConnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ namespace Plane.FormationCreator.Formation
|
||||
bool isInsret = false;
|
||||
for (int i = 0; i < this.Count; i++)
|
||||
{
|
||||
if (String.Compare(this[i].Name, entityObject.Name, false) >= 0)
|
||||
if ( int.Parse(this[i].Id) > int.Parse(entityObject.Id))
|
||||
//if (String.Compare(this[i].Name, entityObject.Name, false) >= 0)
|
||||
{
|
||||
InsertItem(i, entityObject);
|
||||
isInsret = true;
|
||||
@ -62,6 +63,7 @@ namespace Plane.FormationCreator.Formation
|
||||
{
|
||||
Task.WhenAll(Copters.Select(c => c.DisconnectAsync()));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Plane.CommunicationManagement;
|
||||
|
||||
namespace Plane.FormationCreator.Formation
|
||||
{
|
||||
@ -17,7 +18,7 @@ namespace Plane.FormationCreator.Formation
|
||||
{
|
||||
public FlightTaskManager(CopterManager copterManager)
|
||||
{
|
||||
_copterManager = copterManager;
|
||||
_copterManager = copterManager;
|
||||
|
||||
//AddTakeOffTask(_copterManager.Copters);
|
||||
|
||||
@ -29,10 +30,16 @@ namespace Plane.FormationCreator.Formation
|
||||
|
||||
_copterManager.SelectedCoptersChanged += (sender, e) =>
|
||||
{
|
||||
foreach (ICopter copter in _copterManager.SelectedCopters)
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() == 1)
|
||||
CommModuleManager.Instance.LED_FlickerAsync(_copterManager.AcceptingControlCopters);
|
||||
|
||||
/*
|
||||
foreach (ICopter copter in _copterManager.AcceptingControlCopters)
|
||||
{
|
||||
copter.LEDAsync();
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: 林俊清, 20150803, 处理选中多个飞行器的情况。
|
||||
if (_copterManager.SelectedCopters.Count() > 1)
|
||||
{
|
||||
@ -54,8 +61,8 @@ namespace Plane.FormationCreator.Formation
|
||||
if (selectedCopter!=null)
|
||||
selectedCopter.SetShowLEDFlashAsync(1, 100);
|
||||
|
||||
if (selectedCopter != null)
|
||||
selectedCopter.LEDAsync();
|
||||
//if (selectedCopter != null)
|
||||
//selectedCopter.LEDAsync();
|
||||
};
|
||||
|
||||
TaskAdded += (sender, e) =>
|
||||
@ -220,9 +227,9 @@ namespace Plane.FormationCreator.Formation
|
||||
var newTask = new FlightTask(FlightTaskType.FlyTo);
|
||||
int coptindex = 0;
|
||||
|
||||
int colnum = 10; //自动生成列数=4
|
||||
float coldis = 5f;//列相距5米
|
||||
float rowdis = 2.5f;//行相距5米
|
||||
int colnum = 20; //自动生成列数=4
|
||||
float coldis = 2.5f;//列相距5米
|
||||
float rowdis = 5f;//行相距5米
|
||||
float matrixdis = 20; //生成方阵距离30米
|
||||
|
||||
|
||||
@ -510,7 +517,7 @@ namespace Plane.FormationCreator.Formation
|
||||
SelectedTaskIndex = Tasks.Count - 1;
|
||||
}
|
||||
|
||||
private void RestoreTakeOffTask(int takeOffTime, dynamic singleCopterInfos)
|
||||
private void RestoreTakeOffTask(byte takeOffTime, dynamic singleCopterInfos)
|
||||
{
|
||||
var copters = _copterManager.Copters;
|
||||
if (copters == null || !copters.Any()) return;
|
||||
@ -522,7 +529,7 @@ namespace Plane.FormationCreator.Formation
|
||||
for (int i = 0; i < copters.Count; i++)
|
||||
{
|
||||
var singleCopterInfoObj = singleCopterInfos[i];
|
||||
takeOffTask.SingleCopterInfos[i].TakeOffWaitTime = (int)singleCopterInfoObj.waitTime;
|
||||
takeOffTask.SingleCopterInfos[i].TakeOffWaitTime = (ushort)singleCopterInfoObj.waitTime;
|
||||
}
|
||||
}
|
||||
|
||||
@ -871,7 +878,10 @@ namespace Plane.FormationCreator.Formation
|
||||
RestoreSimpleCircleTask(task.singleCopterInfos);
|
||||
break;
|
||||
case FlightTaskType.ReturnToLand:
|
||||
// RestoreReturnToLandTask(copters, (int)task.retnumber, (int)task.rtlalt);
|
||||
RestoreReturnToLandTask(copters, (int)task.retnumber, (int)task.rtlalt);
|
||||
break;
|
||||
case FlightTaskType.Land:
|
||||
RestoreLandTask(task.singleCopterInfos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1035,7 +1045,7 @@ namespace Plane.FormationCreator.Formation
|
||||
case FlightTaskType.TakeOff:
|
||||
// AddTakeOffTask(copters); // added by ZJF
|
||||
TakeOffNumAttr = task.takeoffnumber;
|
||||
RestoreTakeOffTask((int)task.takeoffTime, task.singleCopterInfos);
|
||||
RestoreTakeOffTask((byte)task.takeoffTime, task.singleCopterInfos);
|
||||
break;
|
||||
case FlightTaskType.FlyTo:
|
||||
RestoreFlyToTask((bool)task.staggerRoutes, (int)task.flytoTime, (int)task.loiterTime, task.singleCopterInfos);
|
||||
|
@ -22,15 +22,15 @@ namespace Plane.FormationCreator.Formation
|
||||
{
|
||||
var info = new FlightTaskSingleCopterInfo(copter)
|
||||
{
|
||||
TakeOffWaitTime = waitTime
|
||||
TakeOffWaitTime = (ushort)waitTime
|
||||
};
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
//起飞等待时间
|
||||
private int _TakeOffWaitTime = 1;
|
||||
public int TakeOffWaitTime
|
||||
private ushort _TakeOffWaitTime = 1;
|
||||
public ushort TakeOffWaitTime
|
||||
{
|
||||
get { return _TakeOffWaitTime; }
|
||||
set { Set(nameof(TakeOffWaitTime), ref _TakeOffWaitTime, value); }
|
||||
|
@ -25,18 +25,27 @@ namespace Plane.FormationCreator.Formation
|
||||
public int FlytoTime
|
||||
{
|
||||
get { return _FlytoTime; }
|
||||
set { Set(nameof(FlytoTime), ref _FlytoTime, value); }
|
||||
set
|
||||
{
|
||||
if (value > 4095) value = 4095;
|
||||
if (value < 0) value = 0;
|
||||
Set(nameof(FlytoTime), ref _FlytoTime, value);
|
||||
}
|
||||
}
|
||||
private int _LoiterTime = 10;
|
||||
public int LoiterTime
|
||||
{
|
||||
get { return _LoiterTime; }
|
||||
set { Set(nameof(LoiterTime), ref _LoiterTime, value); }
|
||||
set
|
||||
{
|
||||
if (value > 4095) value = 4095;
|
||||
if (value < 0) value = 0;
|
||||
Set(nameof(LoiterTime), ref _LoiterTime, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private bool _VerticalLift = false;
|
||||
public bool VerticalLift // 垂直升降标志位,后面需要加入即使拖动地图上的飞机,也不会变化经纬度. added by ZJF
|
||||
{
|
||||
@ -106,6 +115,7 @@ namespace Plane.FormationCreator.Formation
|
||||
}
|
||||
|
||||
|
||||
private int RuningTaskRemaining = 0;
|
||||
|
||||
private async Task FlyToTaskFlySingleCopterAsync(FlightTaskSingleCopterInfo info)
|
||||
{
|
||||
@ -114,11 +124,12 @@ namespace Plane.FormationCreator.Formation
|
||||
TimeSpan ts = dtNow - dtLastTime;
|
||||
|
||||
FlightTask task = _flightTaskManager.CurrentRunningTask;
|
||||
int flyToTime = task.FlytoTime;
|
||||
int loiterTime = task.LoiterTime;
|
||||
int flyToTime = task.FlytoTime * 1000;
|
||||
int loiterTime = task.LoiterTime * 1000;
|
||||
int taskIndex = _flightTaskManager.CurrentRunningTaskIndex;
|
||||
int copterIndex = SingleCopterInfos.IndexOf(info);
|
||||
|
||||
|
||||
// 当该飞机被标记时,悬停并跳过飞行任务
|
||||
if ((bool)_copterManager.CopterStatus[copterIndex])
|
||||
{
|
||||
@ -150,10 +161,24 @@ namespace Plane.FormationCreator.Formation
|
||||
|
||||
int sendFlyToTimes = 0;
|
||||
|
||||
//while (!info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt)) //按航点飞 :所有Copter到达目标点开始飞下个航点
|
||||
while (ts.TotalMilliseconds < (flyToTime + loiterTime) * 1000) //按时间轴飞:当前任务时间到达后自动飞往下个航点
|
||||
//第0个任务为takeoff
|
||||
if (taskIndex > 0)
|
||||
{
|
||||
|
||||
FlightTask prevTask = _flightTaskManager.Tasks[taskIndex - 1];
|
||||
if (prevTask.TaskType == FlightTaskType.FlyTo && prevTask.LoiterTime == 0)
|
||||
flyToTime += prevTask.RuningTaskRemaining;
|
||||
}
|
||||
|
||||
//while (!info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt)) //按航点飞 :所有Copter到达目标点开始飞下个航点
|
||||
while (ts.TotalMilliseconds < (flyToTime + loiterTime)) //按时间轴飞:当前任务时间到达后自动飞往下个航点
|
||||
{
|
||||
//悬停时间等于0为快速航点 到达之后立即出发下个航点 切时间累积
|
||||
if (loiterTime == 0 &&
|
||||
info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt))
|
||||
{
|
||||
task.RuningTaskRemaining = flyToTime - (int)ts.TotalMilliseconds;
|
||||
break;
|
||||
}
|
||||
if (_flightTaskManager.IsPaused == true)
|
||||
{
|
||||
await info.Copter.HoverAsync();
|
||||
|
@ -24,8 +24,8 @@ namespace Plane.FormationCreator.Formation
|
||||
}
|
||||
|
||||
//起飞到第一个航点高度的飞行时间
|
||||
private int _TakeOffTime = 10;
|
||||
public int TakeOffTime
|
||||
private byte _TakeOffTime = 10;
|
||||
public byte TakeOffTime
|
||||
{
|
||||
get { return _TakeOffTime; }
|
||||
set { Set(nameof(TakeOffTime), ref _TakeOffTime, value); }
|
||||
|
@ -20,6 +20,7 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Plane.CommunicationManagement;
|
||||
|
||||
namespace Plane.FormationCreator
|
||||
{
|
||||
@ -40,7 +41,7 @@ namespace Plane.FormationCreator
|
||||
// //App.Current.Shutdown();
|
||||
//}
|
||||
}
|
||||
|
||||
private CommModuleManager _commModuleManager = CommModuleManager.Instance;
|
||||
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
|
||||
private FlightTaskManager _flightTaskManager= ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
private void ShowConnectDialog(ConnectWindow loginWindow = null)
|
||||
@ -162,17 +163,26 @@ namespace Plane.FormationCreator
|
||||
|
||||
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
if (isInFastMode)
|
||||
{
|
||||
if (isInFastMode)
|
||||
{
|
||||
await copter.SetChannelsAsync(ch2: e.Key == Key.W ? (ushort)1100 : (ushort)1900);
|
||||
}
|
||||
else
|
||||
{
|
||||
await copter.SetChannelsAsync(ch2: e.Key == Key.W ? (ushort)1350 : (ushort)1650);
|
||||
}
|
||||
})).ConfigureAwait(false);
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch2: e.Key == Key.W ? (ushort)1100 : (ushort)1900);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch2: e.Key == Key.W ? (ushort)1350 : (ushort)1650);
|
||||
}
|
||||
|
||||
// await Task.WhenAll(copters.Select(async copter =>
|
||||
// {
|
||||
// if (isInFastMode)
|
||||
// {
|
||||
// await copter.SetChannelsAsync(ch2: e.Key == Key.W ? (ushort)1100 : (ushort)1900);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await copter.SetChannelsAsync(ch2: e.Key == Key.W ? (ushort)1350 : (ushort)1650);
|
||||
// }
|
||||
// })).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
//横滚控制
|
||||
@ -226,17 +236,25 @@ namespace Plane.FormationCreator
|
||||
|
||||
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
if (isInFastMode)
|
||||
{
|
||||
if (isInFastMode)
|
||||
{
|
||||
await copter.SetChannelsAsync(ch1: e.Key == Key.A ? (ushort)1100 : (ushort)1900);
|
||||
}
|
||||
else
|
||||
{
|
||||
await copter.SetChannelsAsync(ch1: e.Key == Key.A ? (ushort)1350 : (ushort)1650);
|
||||
}
|
||||
})).ConfigureAwait(false);
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch1: e.Key == Key.A ? (ushort)1100 : (ushort)1900);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch1: e.Key == Key.A ? (ushort)1350 : (ushort)1650);
|
||||
}
|
||||
// await Task.WhenAll(copters.Select(async copter =>
|
||||
// {
|
||||
// if (isInFastMode)
|
||||
// {
|
||||
// await copter.SetChannelsAsync(ch1: e.Key == Key.A ? (ushort)1100 : (ushort)1900);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await copter.SetChannelsAsync(ch1: e.Key == Key.A ? (ushort)1350 : (ushort)1650);
|
||||
// }
|
||||
// })).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
//高度控制
|
||||
@ -244,6 +262,15 @@ namespace Plane.FormationCreator
|
||||
case Key.K:
|
||||
{
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
if (isInFastMode)
|
||||
{
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch3: e.Key == Key.K ? (ushort)1100 : (ushort)1900);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch3: e.Key == Key.K ? (ushort)1350 : (ushort)1650);
|
||||
}
|
||||
/*
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
{
|
||||
if (isInFastMode)
|
||||
@ -255,6 +282,8 @@ namespace Plane.FormationCreator
|
||||
await copter.SetChannelsAsync(ch3: e.Key == Key.K ? (ushort)1350 : (ushort)1650);
|
||||
}
|
||||
})).ConfigureAwait(false);
|
||||
*/
|
||||
|
||||
break;
|
||||
}
|
||||
//航向控制
|
||||
@ -262,11 +291,14 @@ namespace Plane.FormationCreator
|
||||
case Key.L:
|
||||
{
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch4: e.Key == Key.J ? (ushort)1200 : (ushort)1800);
|
||||
/*
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
{
|
||||
//await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -20 : 20)) % 360);
|
||||
await copter.SetChannelsAsync(ch4: e.Key == Key.J ? (ushort)1200 : (ushort)1800);
|
||||
})).ConfigureAwait(false);
|
||||
*/
|
||||
break;
|
||||
}
|
||||
case Key.M: // 低速下降。
|
||||
@ -368,42 +400,67 @@ namespace Plane.FormationCreator
|
||||
case Key.S:
|
||||
{
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
await copter.SetChannelsAsync(ch2: 1500);
|
||||
})).ConfigureAwait(false);
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch2: 1500);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
// await Task.WhenAll(copters.Select(async copter =>
|
||||
// {
|
||||
// await copter.SetChannelsAsync(ch2: 1500);
|
||||
// })).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
case Key.A:
|
||||
case Key.D:
|
||||
{
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
await copter.SetChannelsAsync(ch1: 1500);
|
||||
})).ConfigureAwait(false);
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch1: 1500);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
|
||||
// await Task.WhenAll(copters.Select(async copter =>
|
||||
// {
|
||||
// await copter.SetChannelsAsync(ch1: 1500);
|
||||
// })).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
case Key.I:
|
||||
case Key.K:
|
||||
{
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
await copter.SetChannelsAsync(ch3: 1500);
|
||||
})).ConfigureAwait(false);
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch3: 1500);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
// await Task.WhenAll(copters.Select(async copter =>
|
||||
// {
|
||||
// await copter.SetChannelsAsync(ch3: 1500);
|
||||
// })).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
case Key.J:
|
||||
case Key.L:
|
||||
{
|
||||
var copters = _copterManager.AcceptingControlCopters;
|
||||
await Task.WhenAll(copters.Select(async copter =>
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
// await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360);
|
||||
await copter.SetChannelsAsync(ch4: 1500);
|
||||
})).ConfigureAwait(false);
|
||||
await _commModuleManager.SetChannelsAsync(copters, ch4: 1500);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
// await Task.WhenAll(copters.Select(async copter =>
|
||||
// {
|
||||
// // await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360);
|
||||
// await copter.SetChannelsAsync(ch4: 1500);
|
||||
// })).ConfigureAwait(false);
|
||||
|
||||
break;
|
||||
}
|
||||
case Key.M: // 停止低速下降。
|
||||
|
@ -5,13 +5,86 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Plane.FormationCreator"
|
||||
mc:Ignorable="d"
|
||||
Title="修改参数" Height="238.21" Width="170.881" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
|
||||
Title="修改参数" Height="457.765" Width="669.987" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
|
||||
<Grid Margin="0,0,5,3.5">
|
||||
<Button x:Name="btnModify" Content="修改" HorizontalAlignment="Left" Margin="66,168,0,0" VerticalAlignment="Top" Width="75" Click="btnModify_Click"/>
|
||||
<TextBox x:Name="textParamValue" HorizontalAlignment="Left" Height="23" Margin="21,119,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
|
||||
<TextBox x:Name="textParamName" HorizontalAlignment="Left" Height="23" Margin="21,53,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" RenderTransformOrigin="-0.246,1.213"/>
|
||||
<Label x:Name="label" Content="参数名称" HorizontalAlignment="Left" Margin="21,23,0,0" VerticalAlignment="Top"/>
|
||||
<Label x:Name="label_Copy" Content="参数值" HorizontalAlignment="Left" Margin="21,89,0,0" VerticalAlignment="Top"/>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<WrapPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2" >
|
||||
<Button Content="检测通信" Tag="FS_GCS_ENABLE" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_FS_GCS_ENABLE 0:关闭 1开启"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="返航高度" Tag="RTL_ALT" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_RTL_ALT 单位cm"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="灯光亮度" Tag="NTF_LED_BRIGHT" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_NTF_LED_BRIGHT 1-3"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="GPS类型灯光" Tag="NTF_G_RTKTEST" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_NTF_G_RTKTEST 0:关闭 1:开启"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="气压计GPS类型" Tag="EK2_ALT_GPS" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_EK2_ALT_GPS 1-6"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="最低解锁电压" Tag="ARMING_VOLT_MIN" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_ARMING_VOLT_MIN"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="返航灯光" Tag="NTF_G_RTLOFF" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_NTF_G_RTLOFF"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="航点灯光" Tag="WAYPOINT_GLED" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_WAYPOINT_GLED"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="解锁检查" Tag="ARMING_CHECK" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_ARMING_CHECK 414"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="解锁GPS类型" Tag="ARMING_GPS_LEVEL" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_ARMING_GPS_LEVEL 1-6"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="返航GPS类型" Tag="FS_GPS_RTL" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_FS_GPS_RTL 1-6"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<Button Content="开关灯" Tag="NTF_G_OFF" Click="Modify_Select" Width="130"/>
|
||||
<Label Content="_NTF_G_OFF"/>
|
||||
</StackPanel>
|
||||
|
||||
</WrapPanel>
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Center" Orientation ="Horizontal">
|
||||
<WrapPanel VerticalAlignment="Center" Orientation="Vertical" >
|
||||
<Label x:Name="label" Content="参数名称" Margin="5,0,5,5"/>
|
||||
<TextBox x:Name="textParamName" Width="160" Margin="5"/>
|
||||
<Label x:Name="label_Copy" Content="参数值" Margin="5"/>
|
||||
<TextBox x:Name="textParamValue" Margin="5"/>
|
||||
<Button x:Name="btnModify" Content="修改" Width="100" Margin="10" Click="btnModify_Click"/>
|
||||
</WrapPanel>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -29,5 +29,10 @@ namespace Plane.FormationCreator
|
||||
this.DialogResult = true;
|
||||
|
||||
}
|
||||
|
||||
private void Modify_Select(object sender, RoutedEventArgs e)
|
||||
{
|
||||
textParamName.Text = ((Button)sender).Tag.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _CloseCommand ?? (_CloseCommand = new RelayCommand(() =>
|
||||
{
|
||||
commModule.Close();
|
||||
commModule.CloseConnection();
|
||||
}
|
||||
));
|
||||
}
|
||||
@ -165,6 +165,36 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _QueryAllCopterCommand;
|
||||
public ICommand QueryAllCopterCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _QueryAllCopterCommand ?? (_QueryAllCopterCommand = new RelayCommand(async () =>
|
||||
{
|
||||
if (commModule.CommModuleCopterCount > 0)
|
||||
{
|
||||
short queryCount = 40;
|
||||
|
||||
short begin = 1;
|
||||
while (begin < commModule.CommModuleCopterCount)
|
||||
{
|
||||
short end = (short)(begin + queryCount -1);
|
||||
if (end > commModule.CommModuleCopterCount)
|
||||
end = (short)commModule.CommModuleCopterCount;
|
||||
byte[] beginByte = BitConverter.GetBytes(begin);
|
||||
byte[] endByte = BitConverter.GetBytes(end);
|
||||
byte[] query = beginByte.Concat(endByte).ToArray();
|
||||
await commModule.WriteCommPacketAsync(0, 0x20, query);
|
||||
begin += queryCount;
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _CommDataAsync;
|
||||
public ICommand CommDataAsync
|
||||
{
|
||||
@ -172,135 +202,12 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _CommDataAsync ?? (_CommDataAsync = new RelayCommand(async () =>
|
||||
{
|
||||
await commModule.GenerateDataAsync((short)CopterNum);
|
||||
await commModule.TestLED((short)CopterNum);
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _CommWriteMissionCommand;
|
||||
public ICommand CommWriteMissionCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _CommWriteMissionCommand ?? (_CommWriteMissionCommand = new RelayCommand(async () =>
|
||||
{
|
||||
var _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
|
||||
{
|
||||
Alert.Show("作为参照的原点未设置,无法写入相对位置!", "提示");
|
||||
return;
|
||||
}
|
||||
|
||||
int coptercount = _copterManager.Copters.Count;
|
||||
int taskcount = _flightTaskManager.Tasks.Count;
|
||||
// bool havewritefault = true;
|
||||
if (taskcount < 2) return;
|
||||
|
||||
for (int i = 0; i < coptercount; i++)
|
||||
{
|
||||
|
||||
///写航线开始
|
||||
//var missions = new IMission[taskcount]; //不要起飞任务但增加一个起飞后低空航点,见起飞任务,再增加一个降落低空航点,见降落部分
|
||||
var missions = new List<IMission>();
|
||||
missions.Add(PLCopter.PRE_TAKE_OFF_MISSION);
|
||||
|
||||
int missindex = 0;
|
||||
ICopter copter = _copterManager.Copters[i];
|
||||
//if (copter is PLCopter)
|
||||
{
|
||||
for (int j = 0; j < _flightTaskManager.Tasks.Count; j++)
|
||||
{
|
||||
|
||||
switch (_flightTaskManager.Tasks[j].TaskType)
|
||||
{
|
||||
|
||||
case FlightTaskType.TakeOff:
|
||||
//计算起飞需要的时间,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)
|
||||
);
|
||||
|
||||
//要起飞任务
|
||||
|
||||
break;
|
||||
|
||||
case FlightTaskType.FlyTo:
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
|
||||
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;
|
||||
Lng = 180;
|
||||
}
|
||||
missions.Add(Mission.CreateWaypointMission(
|
||||
//5,//_flightTaskManager.Tasks[j].SingleCopterInfos[i].LoiterTime,
|
||||
//5,// _flightTaskManager.Tasks[j].SingleCopterInfos[i].FlytoTime,
|
||||
_flightTaskManager.Tasks[j].LoiterTime,
|
||||
_flightTaskManager.Tasks[j].FlytoTime,
|
||||
Lat,
|
||||
Lng,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt)
|
||||
);
|
||||
|
||||
break;
|
||||
case FlightTaskType.Loiter:
|
||||
// missions[missindex++] = Mission.CreateWaypointMission(10,10,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
|
||||
// _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng, _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt);
|
||||
break;
|
||||
case FlightTaskType.ReturnToLand:
|
||||
//降落低空航点
|
||||
// missions[missindex++] = Mission.CreateWaypointMission(_flightTaskManager.Tasks[j - 1].SingleCopterInfos[i].TargetLat,
|
||||
// _flightTaskManager.Tasks[j - 1].SingleCopterInfos[i].TargetLng, 3);
|
||||
//返航
|
||||
missions.Add(Mission.CreateReturnToLaunchMission());
|
||||
break;
|
||||
|
||||
case FlightTaskType.Land:
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
|
||||
missions.Add(Mission.CreateLandMission(
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].LandWaitTime)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
bool result = await WriteCommandAsync(copter, missions);
|
||||
//_copterManager.Copters[i].WriteMissionListAsync(missions);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
Message.Show($"飞机:{copter.Name} 任务写入失败!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Message.Show($"飞机:{copter.Name} 任务写入成功!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Alert.Show($"写入完成!");
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private List<IMission> CreateLEDMissions(IEnumerable<LEDInfo> LEDInfos)
|
||||
{
|
||||
List<IMission> missions = new List<IMission>();
|
||||
@ -326,7 +233,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
private async Task WriteIdCommandAsync(int num, short messageType)
|
||||
{
|
||||
await commModule.GeneratePacketAsync((short)num, messageType);
|
||||
await commModule.WriteCommPacketAsync((short)num, messageType);
|
||||
}
|
||||
|
||||
private async Task SendCommandAsync(int Count)
|
||||
@ -360,54 +267,9 @@ namespace Plane.FormationCreator.ViewModels
|
||||
await Task.Delay(10);
|
||||
return true;
|
||||
}
|
||||
private async Task<bool> WriteCommandAsync(ICopter copter, List<IMission> missions)
|
||||
{
|
||||
List<MAVLink.mavlink_mission_item_t> mission_list = new List<MAVLink.mavlink_mission_item_t>();
|
||||
foreach (IMission mission in missions)
|
||||
{
|
||||
var frame = mission.Command == FlightCommand.Waypoint && mission.Sequence == 0 ? MAVLink.MAV_FRAME.GLOBAL : MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT;
|
||||
|
||||
var req = new MAVLink.mavlink_mission_item_t();
|
||||
|
||||
//PLCopter plCopter = (PLCopter)copter;
|
||||
//req.target_system = plCopter._internalCopter.sysid;
|
||||
//req.target_component = plCopter._internalCopter.compid;
|
||||
req.target_system = 1;
|
||||
req.target_component = 1;
|
||||
|
||||
req.command = (byte)mission.Command;
|
||||
|
||||
req.current = 0;
|
||||
req.autocontinue = 1;
|
||||
|
||||
req.frame = (byte)frame;
|
||||
if (mission.Command == FlightCommand.LEDControl)
|
||||
{
|
||||
req.x = mission.R;
|
||||
req.y = mission.G;
|
||||
req.z = mission.B;
|
||||
}
|
||||
else
|
||||
{
|
||||
req.x = (float)mission.Latitude;
|
||||
req.y = (float)mission.Longitude;
|
||||
req.z = mission.Altitude;
|
||||
}
|
||||
|
||||
req.param1 = mission.Param1;
|
||||
req.param2 = mission.Param2;
|
||||
req.param3 = mission.Param3;
|
||||
req.param4 = mission.Param4;
|
||||
|
||||
req.seq = mission.Sequence;
|
||||
mission_list.Add(req);
|
||||
}
|
||||
|
||||
return await commModule.GeneratePacketAsyncNew(short.Parse(copter.Name), (byte)Protocols.MavComm.COMM_DOWNLOAD_MODE, mission_list.ToArray());
|
||||
}
|
||||
|
||||
|
||||
CommModule commModule = new CommModule();
|
||||
CommModuleManager commModule = CommModuleManager.Instance;
|
||||
|
||||
private async Task ConnectAsync()
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ using Plane.Communication;
|
||||
using Microsoft.Win32;
|
||||
using Plane.Util;
|
||||
using System.Windows.Media;
|
||||
using Plane.CommunicationManagement;
|
||||
|
||||
namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
@ -38,6 +39,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
private FormationController _formationController;
|
||||
private CopterManager _copterManager;
|
||||
private CommModuleManager _commModuleManager = CommModuleManager.Instance;
|
||||
|
||||
private ILogger _logger = ServiceLocator.Current.GetInstance<ILogger>();
|
||||
|
||||
@ -77,10 +79,13 @@ namespace Plane.FormationCreator.ViewModels
|
||||
if (Alert.Show("再次确认上锁?请确认所有飞行器都在地面,否则将自由落体", "再次警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
|
||||
== MessageBoxResult.OK)
|
||||
{
|
||||
await _commModuleManager.LockAsync();
|
||||
/*
|
||||
await Task.WhenAll(_copterManager.Copters.Select(async c =>
|
||||
{
|
||||
await c.LockAsync();
|
||||
}));
|
||||
*/
|
||||
}
|
||||
}
|
||||
}));
|
||||
@ -132,6 +137,77 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _DetectionMissionData;
|
||||
public ICommand DetectionMissionData
|
||||
{
|
||||
get
|
||||
{
|
||||
return _DetectionMissionData ?? (_DetectionMissionData = new RelayCommand(async () =>
|
||||
{
|
||||
var missionState = _commModuleManager.MissionWriteState.Where(i => !i.Value.SendAchieved || !i.Value.WriteSucceed);
|
||||
if (missionState.Count() == 0)
|
||||
Message.Show("航点全部写入成功");
|
||||
else
|
||||
{
|
||||
foreach (KeyValuePair<int, CommWriteMissinState> item in missionState)
|
||||
{
|
||||
string msg = $"{item.Key}: 传输:{item.Value.SendAchieved}, 写入:{item.Value.WriteSucceed} ";
|
||||
Message.Show(msg);
|
||||
await Task.Delay(10);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _DetectionReturnData;
|
||||
public ICommand DetectionReturnData
|
||||
{
|
||||
get
|
||||
{
|
||||
return _DetectionReturnData ?? (_DetectionReturnData = new RelayCommand(async () =>
|
||||
{
|
||||
Dictionary<int, List<string>> dic_returnData = new Dictionary<int, List<string>>();
|
||||
await Task.WhenAll(_copterManager.Copters.Select(async c =>
|
||||
{
|
||||
|
||||
string name = c.Name;
|
||||
int return_data = BitConverter.ToInt32(c.Retain, 0);
|
||||
|
||||
lock (locker)
|
||||
{
|
||||
List<string> copterList;
|
||||
if (!dic_returnData.ContainsKey(return_data))
|
||||
{
|
||||
copterList = new List<string>();
|
||||
dic_returnData.Add(return_data, copterList);
|
||||
}
|
||||
else
|
||||
copterList = dic_returnData[return_data];
|
||||
|
||||
copterList.Add(name);
|
||||
}
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
})).ConfigureAwait(false);
|
||||
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
foreach (KeyValuePair<int, List<string>> kv in dic_returnData)
|
||||
{
|
||||
byte[] test = BitConverter.GetBytes(kv.Key);
|
||||
Array.Reverse(test);
|
||||
string data = string.Join(".", test);
|
||||
string copters = string.Join(",", kv.Value.ToArray());
|
||||
Message.Show(string.Format("返回数据{0}:{1}", data, copters));
|
||||
await Task.Delay(5).ConfigureAwait(false);
|
||||
}
|
||||
Message.Show("----统计完成----");
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _AllLandCommand;
|
||||
public ICommand AllLandCommand
|
||||
{
|
||||
@ -139,10 +215,25 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _AllLandCommand ?? (_AllLandCommand = new RelayCommand(async () =>
|
||||
{
|
||||
await _commModuleManager.LandAsync();
|
||||
/*
|
||||
await Task.WhenAll(_copterManager.Copters.Select(async c =>
|
||||
{
|
||||
await c.LandAsync();
|
||||
}));
|
||||
*/
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _LEDFlickerCommand;
|
||||
public ICommand LEDFlickerCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _LEDFlickerCommand ?? (_LEDFlickerCommand = new RelayCommand(() =>
|
||||
{
|
||||
_commModuleManager.LED_FlickerAsync(_copterManager.AcceptingControlCopters);
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -154,6 +245,17 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _MotorTestCommand ?? (_MotorTestCommand = new RelayCommand(async () =>
|
||||
{
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
{
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
await _commModuleManager.MotorTestAsync(i, _copterManager.AcceptingControlCopters);
|
||||
await Task.Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
await Task.WhenAll(_copterManager.Copters.Select(async c =>
|
||||
{
|
||||
for (int i = 1; i <= 4; i++)
|
||||
@ -163,6 +265,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}
|
||||
|
||||
})).ConfigureAwait(false);
|
||||
*/
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -174,16 +277,16 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _GuidAsyncCommand ?? (_GuidAsyncCommand = new RelayCommand(async () =>
|
||||
{
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
await _commModuleManager.TakeOffAsync(1);
|
||||
/*
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(async c =>
|
||||
{
|
||||
await c.GuidAsync();
|
||||
await Task.Delay(100).ConfigureAwait(false);
|
||||
await c.TakeOffAsync(1);
|
||||
}));
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -197,7 +300,13 @@ namespace Plane.FormationCreator.ViewModels
|
||||
return _UnlockAllCommand ?? (_UnlockAllCommand = new RelayCommand(async () =>
|
||||
{
|
||||
// await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.UnlockAsync()));
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
await _commModuleManager.UnlockAsync();
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/*
|
||||
await Task.WhenAll(_copterManager.Copters.Select(async c => {
|
||||
await c.UnlockAsync();
|
||||
//解锁间隔一定要超过1s否则导致飞控以后无法解锁
|
||||
@ -212,20 +321,23 @@ namespace Plane.FormationCreator.ViewModels
|
||||
await Task.Delay(25).ConfigureAwait(false);
|
||||
}
|
||||
}));
|
||||
*/
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private const string NTF_GROUPLED_OFF = "NTF_GLED_OFF";
|
||||
private const string NTF_GROUPLED_OFF = "NTF_G_OFF";
|
||||
private ICommand _LEDOnOffCommand;
|
||||
public ICommand LEDOnOffCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _LEDOnOffCommand ?? (_LEDOnOffCommand = new RelayCommand(async () =>
|
||||
return _LEDOnOffCommand ?? (_LEDOnOffCommand = new RelayCommand<int>(async onOff=>
|
||||
{
|
||||
string paramstr = NTF_GROUPLED_OFF;
|
||||
float paramvalue = 0;
|
||||
float paramvalue = onOff;
|
||||
await _commModuleManager.SetParamAsync(paramstr, paramvalue, _copterManager.AcceptingControlCopters);
|
||||
/*
|
||||
await Task.WhenAll(
|
||||
_copterManager.AcceptingControlCopters.Select(async copter =>
|
||||
{
|
||||
@ -236,6 +348,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select
|
||||
(copter => copter.SetParamAsync(paramstr, newParamvalue)));
|
||||
*/
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -248,7 +361,10 @@ namespace Plane.FormationCreator.ViewModels
|
||||
return _UnlockCommand ?? (_UnlockCommand = new RelayCommand(async () =>
|
||||
{
|
||||
// await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.UnlockAsync()));
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
await _commModuleManager.UnlockAsync(_copterManager.AcceptingControlCopters);
|
||||
|
||||
/*
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select( async c => {
|
||||
await c.UnlockAsync();
|
||||
//解锁间隔一定要超过1s否则导致飞控以后无法解锁
|
||||
@ -263,6 +379,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
await Task.Delay(25).ConfigureAwait(false);
|
||||
}
|
||||
}));
|
||||
*/
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -274,10 +391,14 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _LockCommand ?? (_LockCommand = new RelayCommand(async () =>
|
||||
{
|
||||
if (Alert.Show("您确定要上锁吗?飞行器将无视转速,立即强制停止运转!!!", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
|
||||
== MessageBoxResult.OK)
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
{
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.LockAsync()));
|
||||
if (Alert.Show("您确定要上锁吗?飞行器将无视转速,立即强制停止运转!!!", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
|
||||
== MessageBoxResult.OK)
|
||||
{
|
||||
await _commModuleManager.LockAsync(_copterManager.AcceptingControlCopters);
|
||||
//await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.LockAsync()));
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -302,7 +423,9 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _HoverCommand ?? (_HoverCommand = new RelayCommand(async () =>
|
||||
{
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.HoverAsync()));
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
await _commModuleManager.HoverAsync(_copterManager.AcceptingControlCopters);
|
||||
//await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.HoverAsync()));
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -314,7 +437,9 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _FloatCommand ?? (_FloatCommand = new RelayCommand(async () =>
|
||||
{
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.FloatAsync()));
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
await _commModuleManager.FloatAsync(_copterManager.AcceptingControlCopters);
|
||||
//await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.FloatAsync()));
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -326,7 +451,23 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _ReturnToLaunchCommand ?? (_ReturnToLaunchCommand = new RelayCommand(async () =>
|
||||
{
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.ReturnToLaunchAsync()));
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
await _commModuleManager.ReturnToLaunchAsync(_copterManager.AcceptingControlCopters);
|
||||
//await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.ReturnToLaunchAsync()));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ICommand _GetVersionsCommand;
|
||||
public ICommand GetVersionsCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _GetVersionsCommand ?? (_GetVersionsCommand = new RelayCommand(async () =>
|
||||
{
|
||||
//if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
await _commModuleManager.GetVersionsAsync();
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -390,36 +531,46 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _ParamModify ?? (_ParamModify = new RelayCommand(async () =>
|
||||
{
|
||||
|
||||
var ModifyParamWindow = new Plane.FormationCreator.ModifyParam();
|
||||
if (ModifyParamWindow.ShowDialog() == true)
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
{
|
||||
var ModifyParamWindow = new Plane.FormationCreator.ModifyParam();
|
||||
if (ModifyParamWindow.ShowDialog() == true)
|
||||
{
|
||||
|
||||
string paramstr = ModifyParamWindow.textParamName.Text;
|
||||
float paramvalue = Convert.ToSingle(ModifyParamWindow.textParamValue.Text);
|
||||
string paramstr = ModifyParamWindow.textParamName.Text;
|
||||
float paramvalue = Convert.ToSingle(ModifyParamWindow.textParamValue.Text);
|
||||
int num = 0;
|
||||
if (_copterManager.AcceptingControlCopters.Count() < _copterManager.Copters.Count)
|
||||
num = await _commModuleManager.SetParamAsync(paramstr, paramvalue, _copterManager.AcceptingControlCopters);
|
||||
else if (_copterManager.AcceptingControlCopters.Count() == _copterManager.Copters.Count)
|
||||
num = await _commModuleManager.SetParamAsync(paramstr, paramvalue);
|
||||
Alert.Show($"广播完成! 当前序列号:{num}");
|
||||
/*
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select
|
||||
(copter => copter.SetParamAsync(paramstr, paramvalue)));
|
||||
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select
|
||||
(copter => copter.SetParamAsync(paramstr, paramvalue)));
|
||||
bool ifallok = true;
|
||||
await Task.WhenAll(
|
||||
|
||||
bool ifallok = true;
|
||||
await Task.WhenAll(
|
||||
|
||||
_copterManager.AcceptingControlCopters.Select(async copter =>
|
||||
{
|
||||
float getvaule = await copter.GetParamAsync(paramstr);
|
||||
if (getvaule != paramvalue)
|
||||
_copterManager.AcceptingControlCopters.Select(async copter =>
|
||||
{
|
||||
ifallok = false;
|
||||
Alert.Show(copter.Id + "设置失败,读取的参数是" + getvaule, "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
float getvaule = await copter.GetParamAsync(paramstr);
|
||||
if (getvaule != paramvalue)
|
||||
{
|
||||
ifallok = false;
|
||||
Alert.Show(copter.Id + "设置失败,读取的参数是" + getvaule, "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
));
|
||||
if (ifallok)
|
||||
Alert.Show("所有已选的飞机参数设置完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
Alert.Show("有部分飞机参数设置失败,请检查并再次设置", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
));
|
||||
if (ifallok)
|
||||
Alert.Show("所有已选的飞机参数设置完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
Alert.Show("有部分飞机参数设置失败,请检查并再次设置", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -502,8 +653,6 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
if (!trkthreadrun)
|
||||
{
|
||||
|
||||
|
||||
Rtkport = new SerialPortConnection(RTKcomvalue, 57600) as IConnection;
|
||||
await Rtkport.OpenAsync();
|
||||
if (!Rtkport.IsOpen)
|
||||
@ -537,23 +686,24 @@ namespace Plane.FormationCreator.ViewModels
|
||||
Console.WriteLine("rev:" + (ushort)packet.Length);
|
||||
|
||||
//分发到每个飞机
|
||||
/*
|
||||
foreach (var copter in _copterManager.Copters)
|
||||
{
|
||||
// int iid = Convert.ToInt32(copter.Name);
|
||||
//临时用来区分RTK发送数据
|
||||
//if (iid<50)
|
||||
|
||||
await copter.InjectGpsDataAsync(packet, (ushort)packet.Length);
|
||||
|
||||
}
|
||||
*/
|
||||
await _commModuleManager.InjectGpsDataAsync(packet, (ushort)packet.Length);
|
||||
}
|
||||
|
||||
|
||||
await Task.Delay(200).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
Alert.Show("RTK数据停止发送", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
}
|
||||
else//停止RTK
|
||||
{
|
||||
@ -563,10 +713,6 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
RTKState = "未发送RTK数据";
|
||||
RTKbtntxt = "发送RTK";
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -623,7 +769,11 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _LandCommand ?? (_LandCommand = new RelayCommand(async () =>
|
||||
{
|
||||
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
|
||||
await _commModuleManager.LandAsync(_copterManager.AcceptingControlCopters);
|
||||
/*
|
||||
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.LandAsync()));
|
||||
*/
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -745,6 +895,14 @@ namespace Plane.FormationCreator.ViewModels
|
||||
//循环3次 发送起飞命令 避免通信问题
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
await _commModuleManager.DoMissionStartAsync(utchour,
|
||||
utcminute,
|
||||
utcsecond,
|
||||
_flightTaskManager.OriginLng,
|
||||
_flightTaskManager.OriginLat
|
||||
);
|
||||
|
||||
|
||||
foreach (var vcopter in _copterManager.Copters)
|
||||
{
|
||||
await vcopter.MissionStartAsync(utchour,
|
||||
@ -754,28 +912,116 @@ namespace Plane.FormationCreator.ViewModels
|
||||
_flightTaskManager.OriginLat
|
||||
);
|
||||
}
|
||||
|
||||
await Task.Delay(10).ConfigureAwait(false);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ICommand _MissionPauseCommand;
|
||||
public ICommand MissionPauseCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _MissionPauseCommand ?? (_MissionPauseCommand = new RelayCommand(async () =>
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
await _commModuleManager.DoMissionPauseAsync();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// private ICommand _SetOriginalPointCommand;
|
||||
// public ICommand SetOriginalPointCommand
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _SetOriginalPointCommand ?? (_SetOriginalPointCommand = new RelayCommand(() =>
|
||||
// {
|
||||
// FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
// _flightTaskManager.SetOriginal();
|
||||
// }));
|
||||
// }
|
||||
// }
|
||||
private ICommand _MissionResumeCommand;
|
||||
public ICommand MissionResumeCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _MissionResumeCommand ?? (_MissionResumeCommand = new RelayCommand(async () =>
|
||||
{
|
||||
int utchour = DateTime.UtcNow.AddSeconds(5).Hour;
|
||||
int utcminute = DateTime.UtcNow.AddSeconds(5).Minute;
|
||||
int utcsecond = DateTime.UtcNow.AddSeconds(5).Second;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
await _commModuleManager.DoMissionResumeAsync(
|
||||
utchour,
|
||||
utcminute,
|
||||
utcsecond);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// private ICommand _SetOriginalPointCommand;
|
||||
// public ICommand SetOriginalPointCommand
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return _SetOriginalPointCommand ?? (_SetOriginalPointCommand = new RelayCommand(() =>
|
||||
// {
|
||||
// FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
// _flightTaskManager.SetOriginal();
|
||||
// }));
|
||||
// }
|
||||
// }
|
||||
private ICommand _WriteMissionSingleCommand;
|
||||
public ICommand WriteMissionSingleCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _WriteMissionSingleCommand ?? (_WriteMissionSingleCommand = new RelayCommand(async () =>
|
||||
{
|
||||
var _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
|
||||
{
|
||||
Alert.Show("作为参照的原点未设置,无法写入相对位置!", "提示");
|
||||
return;
|
||||
}
|
||||
int taskcount = _flightTaskManager.Tasks.Count;
|
||||
if (taskcount < 2) return;
|
||||
foreach (var copter in _copterManager.AcceptingControlCopters)
|
||||
{
|
||||
int i = _copterManager.Copters.IndexOf(copter);
|
||||
await CollectMissions(i);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ICommand _WriteMissionFailedCommand;
|
||||
public ICommand WriteMissionFailedCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _WriteMissionFailedCommand ?? (_WriteMissionFailedCommand = new RelayCommand(async () =>
|
||||
{
|
||||
var _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
if (_flightTaskManager.OriginLat == 0 && _flightTaskManager.OriginLng == 0)
|
||||
{
|
||||
Alert.Show("作为参照的原点未设置,无法写入相对位置!", "提示");
|
||||
return;
|
||||
}
|
||||
int coptercount = _copterManager.Copters.Count;
|
||||
int taskcount = _flightTaskManager.Tasks.Count;
|
||||
if (taskcount < 2) return;
|
||||
foreach(KeyValuePair<int, CommWriteMissinState> kv in _commModuleManager.MissionWriteState)
|
||||
{
|
||||
if (!kv.Value.SendAchieved || !kv.Value.WriteSucceed)
|
||||
{
|
||||
var copter = _copterManager.Copters.FirstOrDefault(c => c.Id == kv.Key.ToString());
|
||||
int i = _copterManager.Copters.IndexOf(copter);
|
||||
await CollectMissions(i);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _WriteMissionCommand;
|
||||
public ICommand WriteMissionCommand
|
||||
{
|
||||
@ -792,229 +1038,100 @@ namespace Plane.FormationCreator.ViewModels
|
||||
|
||||
int coptercount = _copterManager.Copters.Count;
|
||||
int taskcount = _flightTaskManager.Tasks.Count;
|
||||
// bool havewritefault = true;
|
||||
if (taskcount < 2) return;
|
||||
|
||||
_commModuleManager.ClearMissionWriteState();
|
||||
for (int i = 0; i < coptercount; i++)
|
||||
{
|
||||
|
||||
///写航线开始
|
||||
//var missions = new IMission[taskcount]; //不要起飞任务但增加一个起飞后低空航点,见起飞任务,再增加一个降落低空航点,见降落部分
|
||||
var missions =new List<IMission>();
|
||||
int missindex = 0;
|
||||
|
||||
for (int j = 0; j < _flightTaskManager.Tasks.Count; j++)
|
||||
{
|
||||
|
||||
switch (_flightTaskManager.Tasks[j].TaskType)
|
||||
{
|
||||
case FlightTaskType.TakeOff:
|
||||
//计算起飞需要的时间,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)
|
||||
);
|
||||
|
||||
//要起飞任务
|
||||
|
||||
break;
|
||||
|
||||
case FlightTaskType.FlyTo:
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
if (_flightTaskManager.Tasks[j].SingleCopterInfos[i].IsChangeSpeed)
|
||||
{
|
||||
missions.Add(Mission.CreateChangeSpeedMission(
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].LevelSpeed,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].UpSpeed,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].DownSpeed)
|
||||
);
|
||||
}
|
||||
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;
|
||||
Lng = 180;
|
||||
}
|
||||
missions.Add(Mission.CreateWaypointMission(
|
||||
//5,//_flightTaskManager.Tasks[j].SingleCopterInfos[i].LoiterTime,
|
||||
//5,// _flightTaskManager.Tasks[j].SingleCopterInfos[i].FlytoTime,
|
||||
_flightTaskManager.Tasks[j].LoiterTime,
|
||||
_flightTaskManager.Tasks[j].FlytoTime,
|
||||
Lat,
|
||||
Lng,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt)
|
||||
);
|
||||
|
||||
break;
|
||||
case FlightTaskType.Loiter:
|
||||
// missions[missindex++] = Mission.CreateWaypointMission(10,10,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
|
||||
// _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng, _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt);
|
||||
break;
|
||||
case FlightTaskType.ReturnToLand:
|
||||
//降落低空航点
|
||||
// missions[missindex++] = Mission.CreateWaypointMission(_flightTaskManager.Tasks[j - 1].SingleCopterInfos[i].TargetLat,
|
||||
// _flightTaskManager.Tasks[j - 1].SingleCopterInfos[i].TargetLng, 3);
|
||||
//返航
|
||||
missions.Add(Mission.CreateReturnToLaunchMission());
|
||||
break;
|
||||
|
||||
case FlightTaskType.Land:
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
|
||||
missions.Add(Mission.CreateLandMission(
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].LandWaitTime)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var result = await _copterManager.Copters[i].WriteMissionListAsync(missions);
|
||||
if (!result)
|
||||
{
|
||||
|
||||
Alert.Show($"飞机:{_copterManager.Copters[i].Name} 任务写入失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
await CollectMissions(i).ConfigureAwait(false);
|
||||
}
|
||||
Alert.Show($"所有任务写入成功!");
|
||||
|
||||
|
||||
// var firstCopter = _copterManager.Copters.First();
|
||||
|
||||
// Test TurnAsync.
|
||||
//var latLng = GeographyUtils.CalcLatLngSomeMetersAway(firstCopter.Latitude, firstCopter.Longitude, 135, 10);
|
||||
//await _formationController.TurnAsync(_copterManager.AcceptingControlCopters, latLng.Item1, latLng.Item2);
|
||||
|
||||
// Test FlyToLatLngAsync.
|
||||
//var copters = _copterManager.AcceptingControlCopters;
|
||||
//var centerLat = copters.Average(c => c.Latitude);
|
||||
//var centerLng = copters.Average(c => c.Longitude);
|
||||
//var latDelta = 10 * GeographyUtils.MetersToLocalLat;
|
||||
//var lngDelta = 10 * GeographyUtils.GetMetersToLocalLon(copters.First().Latitude);
|
||||
//var targetLat = centerLat + latDelta;
|
||||
//var targetLng = centerLng + lngDelta;
|
||||
//await _formationController.FlyToLatLngAsync(copters, targetLat, targetLng);
|
||||
|
||||
// Test FlyInCircleAsync.
|
||||
//await _formationController.FlyInCircleAsync(_copterManager.AcceptingControlCopters, centerDirection: 180, radius: 10, loop: false);
|
||||
|
||||
// Test FlyAroundCenterOfCoptersAsync.
|
||||
//await _formationController.FlyAroundCenterOfCoptersAsync(_copterManager.AcceptingControlCopters);
|
||||
|
||||
// Test FlyToLatLngAsync.
|
||||
//var targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway(firstCopter.Latitude, firstCopter.Longitude, 135, 20);
|
||||
//await _formationController.FlyToLatLngAsync(firstCopter, targetLatLng.Item1, targetLatLng.Item2);
|
||||
|
||||
//firstCopter.LoiterTurns(1, 10);
|
||||
|
||||
//var radius = await firstCopter.GetParamAsync("CIRCLE_RADIUS");
|
||||
|
||||
////await firstCopter.SetParamAsync("CIRCLE_RADIUS", 1500);
|
||||
////var param = await firstCopter.GetParamAsync("CIRCLE_RADIUS");
|
||||
//// Alert.Show($"半径设置成功啦: {param}");
|
||||
|
||||
////await firstCopter.SetParamAsync("CIRCLE_RATE", 30);
|
||||
//var rate = await firstCopter.GetParamAsync("CIRCLE_RATE");
|
||||
|
||||
//Alert.Show($"半径: {radius} 角速度: {rate}");
|
||||
|
||||
//await firstCopter.SetMobileControlAsync(yaw: 90);
|
||||
|
||||
//if (!_listeningMissionItemReceived)
|
||||
//{
|
||||
// firstCopter.MissionItemReceived += (sender, e) => Alert.Show($"{e.Index} {e.Total} {(Protocols.MAVLink.MAV_CMD)e.Details.id}");
|
||||
// _listeningMissionItemReceived = true;
|
||||
//}
|
||||
// await firstCopter.RequestMissionListAsync();
|
||||
|
||||
// var copter = firstCopter;
|
||||
|
||||
///* 写航线 */
|
||||
//// 任务总数。
|
||||
// await copter.SetMissionCountAsync(6).ConfigureAwait(false);
|
||||
//// 起飞前准备。
|
||||
// await copter.WritePreTakeOffMissionAsync().ConfigureAwait(false);
|
||||
//// 起飞。
|
||||
// await copter.WriteTakeOffMissionAsync().ConfigureAwait(false);
|
||||
//// 不断自增的编号。
|
||||
// ushort index = 2;
|
||||
//// 航点。
|
||||
// await copter.WriteWaypointMissionAsync(new EHLocation(copter).AddLatLngAlt(0.001, 0.002, 2), index++).ConfigureAwait(false);
|
||||
//// 航点。
|
||||
// await copter.WriteWaypointMissionAsync(new EHLocation(copter).AddLatLngAlt(0.003, 0.002, 2), index++).ConfigureAwait(false);
|
||||
//// 返航。
|
||||
// await copter.WriteReturnToLaunchMissionAsync(index++).ConfigureAwait(false);
|
||||
//// 降落。
|
||||
// await copter.WriteLandMissionAsync(index++).ConfigureAwait(false);
|
||||
|
||||
|
||||
|
||||
|
||||
///* 读航线 */
|
||||
// 监听“任务项已接收”事件。
|
||||
// (copter as PLCopter).MissionItemReceived += (sender, e) => Alert.Show($"{e.Mission.Sequence} {e.Mission.Latitude} {e.Mission.Command}");
|
||||
// 请求任务列表。
|
||||
// var missions = await copter.RequestMissionListAsync();
|
||||
// Alert.Show(string.Join(Environment.NewLine, missions.Select(m => $"{m.Sequence}\t{m.Command}\t\t{m.Latitude}")));
|
||||
/////////////////////////////////* 读航线结束 */
|
||||
|
||||
|
||||
//ICopter previousCopter = firstCopter;
|
||||
//foreach (var item in _copterManager.Copters.Where(c => c != firstCopter))
|
||||
//{
|
||||
// item.Follow(previousCopter, keepYawDifference: false, keepFacingTarget: false);
|
||||
// previousCopter = item;
|
||||
//}
|
||||
|
||||
//var missions = new Mission[]
|
||||
//{
|
||||
// Mission.CreateWaypointMission(new EHLocation(firstCopter).AddLatLngAlt(0.0001, 0, 10)),
|
||||
// Mission.CreateReturnToLaunchMission(),
|
||||
// Mission.CreateLandMission()
|
||||
//};
|
||||
//var result = await firstCopter.WriteMissionsAsync(missions);
|
||||
//var result2 = await firstCopter.WriteMissionsAsync(missions);
|
||||
//Debug.WriteLine($"{result1} {result2}");
|
||||
|
||||
|
||||
///写航线开始
|
||||
/* var missions = new IMission[]
|
||||
{
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateWaypointMission(23.123, 113.123, 10),
|
||||
Mission.CreateReturnToLaunchMission(),
|
||||
Mission.CreateLandMission()
|
||||
};
|
||||
var result = await firstCopter.WriteMissionListAsync(missions);
|
||||
MessageBox.Show($"The result of WriteMissions: {result}");
|
||||
*/
|
||||
/////////////////写航向结束
|
||||
|
||||
|
||||
Alert.Show($"任务写入完成!请检测失败的飞机");
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 收集航点信息
|
||||
/// </summary>
|
||||
/// <param name="i">copterIndex</param>
|
||||
/// <returns></returns>
|
||||
private async Task CollectMissions(int i)
|
||||
{
|
||||
var missions = new List<IMission>();
|
||||
var _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>();
|
||||
for (int j = 0; j < _flightTaskManager.Tasks.Count; j++)
|
||||
{
|
||||
switch (_flightTaskManager.Tasks[j].TaskType)
|
||||
{
|
||||
case FlightTaskType.TakeOff:
|
||||
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)
|
||||
);
|
||||
break;
|
||||
|
||||
case FlightTaskType.FlyTo:
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
if (_flightTaskManager.Tasks[j].SingleCopterInfos[i].IsChangeSpeed)
|
||||
{
|
||||
missions.Add(Mission.CreateChangeSpeedMission(
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].LevelSpeed,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].UpSpeed,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].DownSpeed)
|
||||
);
|
||||
}
|
||||
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;
|
||||
Lng = 180;
|
||||
}
|
||||
missions.Add(Mission.CreateWaypointMission(
|
||||
_flightTaskManager.Tasks[j].LoiterTime,
|
||||
_flightTaskManager.Tasks[j].FlytoTime,
|
||||
Lat,
|
||||
Lng,
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt)
|
||||
);
|
||||
break;
|
||||
case FlightTaskType.Loiter:
|
||||
break;
|
||||
case FlightTaskType.ReturnToLand:
|
||||
missions.Add(Mission.CreateReturnToLaunchMission());
|
||||
break;
|
||||
|
||||
case FlightTaskType.Land:
|
||||
missions.AddRange(CreateLEDMissions(_flightTaskManager.Tasks[j].SingleCopterInfos[i].LEDInfos));
|
||||
|
||||
missions.Add(Mission.CreateLandMission(
|
||||
_flightTaskManager.Tasks[j].SingleCopterInfos[i].LandWaitTime)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool result = await _commModuleManager.WriteMissionListAsync(short.Parse(_copterManager.Copters[i].Id), missions);
|
||||
//CommWriteMissinState state = new CommWriteMissinState(result);
|
||||
//_commModuleManager.missionWriteState.Add(int.Parse(_copterManager.Copters[i].Id), state);
|
||||
if (!result)
|
||||
{
|
||||
Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输失败!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Message.Show($"飞机:{_copterManager.Copters[i].Id} 通信模块传输完成!");
|
||||
}
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private List<IMission> CreateLEDMissions(IEnumerable<LEDInfo> LEDInfos)
|
||||
{
|
||||
List<IMission> missions = new List<IMission>();
|
||||
|
@ -134,9 +134,9 @@ namespace Plane.FormationCreator.ViewModels
|
||||
var center = _mapManager.Center;
|
||||
string id;
|
||||
|
||||
int colnum = 10; //自动生成列数=4
|
||||
float coldis = 5;//列相距5米
|
||||
float rowdis = 2.5f;//行相距5米
|
||||
int colnum = 20; //自动生成列数=4
|
||||
float coldis = 2.5f;//列相距5米
|
||||
float rowdis = 5f;//行相距5米
|
||||
int currcol = 0; //当前列号
|
||||
int currrow = 0; //当前行
|
||||
Tuple<double, double> colheadLatLng = new Tuple<double, double>(0, 0);
|
||||
@ -210,6 +210,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
return _ClearCoptersCommand ?? (_ClearCoptersCommand = new RelayCommand(async () =>
|
||||
{
|
||||
_flightTaskManager.Pause();
|
||||
foreach (var copter in _copterManager.Copters)
|
||||
{
|
||||
await copter.DisconnectAsync();
|
||||
@ -219,7 +220,7 @@ namespace Plane.FormationCreator.ViewModels
|
||||
_copterManager.CopterStatus.Clear();
|
||||
_mapManager.ClearCopters();
|
||||
_flightTaskManager.ClearTasks();
|
||||
UdpServerConnectionManager.Instance.ClearConnections();
|
||||
//UdpServerConnectionManager.Instance.ClearConnections();
|
||||
_virtualCopterId = 1;
|
||||
_lastVirtualCopterLocation = null;
|
||||
}));
|
||||
|
@ -145,12 +145,13 @@ namespace Plane.FormationCreator.ViewModels
|
||||
get { return _CanModifySingleCopterInfo; }
|
||||
set { Set(nameof(CanModifySingleCopterInfo), ref _CanModifySingleCopterInfo, value); }
|
||||
}
|
||||
private double _Distancevalue;
|
||||
public double Distancevalue
|
||||
{
|
||||
get { return _Distancevalue; }
|
||||
set { Set(nameof(Distancevalue), ref _Distancevalue, value); }
|
||||
}
|
||||
|
||||
// private double _Distancevalue;
|
||||
// public double Distancevalue
|
||||
// {
|
||||
// get { return _Distancevalue; }
|
||||
// set { Set(nameof(Distancevalue), ref _Distancevalue, value); }
|
||||
// }
|
||||
|
||||
|
||||
private float _Modialtvalue;
|
||||
@ -1250,50 +1251,31 @@ public ICommand VerticlAlignmentCommand
|
||||
return _calDistinceCommand ?? (_calDistinceCommand = new RelayCommand<double>(async =>
|
||||
{
|
||||
|
||||
double lng1=0, lat1=0, alt1=0, lng2=0, lat2=0, alt2=0;
|
||||
double distance = 0;
|
||||
double minDistance = double.MaxValue;
|
||||
|
||||
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
|
||||
if (_flightTaskManager.SelectedTask == null) return;
|
||||
|
||||
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
|
||||
var flightTask = _flightTaskManager.SelectedTask;
|
||||
List<ICopter> selectedCopter = new List<ICopter>();
|
||||
selectedCopter.AddRange(_copterManager.AcceptingControlCopters);
|
||||
for (int i = 0; i < selectedCopter.Count; i++)
|
||||
{
|
||||
|
||||
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
|
||||
foreach (var capter in _copterManager.SelectedCopters)
|
||||
var copter1 = selectedCopter[i];
|
||||
var copterInfo1 = _flightTaskManager.SelectedTask.SingleCopterInfos.FirstOrDefault(c =>c.Copter == copter1);
|
||||
|
||||
for (int j = i + 1; j < selectedCopter.Count; j++)
|
||||
{
|
||||
if (capter == selectedCopter)
|
||||
{
|
||||
if (lng1 == 0)
|
||||
{
|
||||
lng1 = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng;
|
||||
lat1 = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
|
||||
alt1 = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetAlt;
|
||||
}
|
||||
else
|
||||
if (lng2 == 0)
|
||||
{
|
||||
lng2 = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLng;
|
||||
lat2 = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
|
||||
alt2 = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetAlt;
|
||||
}
|
||||
else break;
|
||||
var copter2 = selectedCopter[j];
|
||||
var copterInfo2 = _flightTaskManager.SelectedTask.SingleCopterInfos.FirstOrDefault(c => c.Copter == copter2);
|
||||
|
||||
}
|
||||
double distance = GeographyUtils.CalcDistance(
|
||||
copterInfo1.TargetLat, copterInfo1.TargetLng, copterInfo1.TargetAlt,
|
||||
copterInfo2.TargetLat, copterInfo2.TargetLng, copterInfo2.TargetAlt);
|
||||
|
||||
minDistance = Math.Min(minDistance, distance);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if ((lng1 != 0) && (lng2 != 0))
|
||||
{
|
||||
distance = GeographyUtils.CalcDistance(
|
||||
lat1, lng1, alt1,
|
||||
lat2, lng2, alt2);
|
||||
distance = ((double)Math.Round(distance * 100) / 100);
|
||||
|
||||
}
|
||||
Distancevalue = distance;
|
||||
//Distancevalue = minDistance;
|
||||
Message.Show($"最小距离 = {minDistance}");
|
||||
|
||||
}));
|
||||
}
|
||||
@ -1384,7 +1366,6 @@ public ICommand VerticlAlignmentCommand
|
||||
}
|
||||
}
|
||||
|
||||
//缩放
|
||||
private ICommand _BackToPreviousTaskPoint;
|
||||
public ICommand BackToPreviousTaskPoint
|
||||
{
|
||||
|
@ -127,9 +127,8 @@
|
||||
HorizontalAlignment="Center"
|
||||
Grid.Row="2"
|
||||
Grid.ColumnSpan="3">
|
||||
<Button Content="状态查询" Margin="5" Command="{Binding Path=StateInquireCommand}"/>
|
||||
<Button Content="设置20台" Margin="5" Command="{Binding Path=SendCommand}" />
|
||||
<Button Content="写入航点" Margin="5" Command="{Binding Path=CommWriteMissionCommand}" />
|
||||
<Button Content="通信模块状态" Margin="5" Command="{Binding Path=StateInquireCommand}"/>
|
||||
<Button Content="设置总数" Margin="5" Command="{Binding Path=SendCommand}" />
|
||||
<Button Content="切换写航点" Margin="5" Command="{Binding Path=ChangeWriteMissionCommand}" />
|
||||
|
||||
|
||||
@ -141,7 +140,7 @@
|
||||
<TextBox Margin="2,5,5,5" Width="30" Text="{Binding CopterNum}"></TextBox>
|
||||
<Button Content="广播编号" Margin="5,5,0,5" Command="{Binding Path=WriteIdCommand}" />
|
||||
<Button Content="闪灯" Margin="5" Command="{Binding CommDataAsync}"/>
|
||||
|
||||
<Button Content="搜索飞机" Margin="5" Command="{Binding QueryAllCopterCommand}"/>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
@ -17,7 +17,7 @@
|
||||
<Style TargetType="Button"
|
||||
BasedOn="{StaticResource {x:Type Button}}">
|
||||
<Setter Property="Margin"
|
||||
Value="0,0,5,5" />
|
||||
Value="0,0,3,5" />
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
|
||||
@ -34,8 +34,10 @@
|
||||
<WrapPanel>
|
||||
<Button Content="解锁"
|
||||
Command="{Binding UnlockCommand}" />
|
||||
<Button Content="起飞"
|
||||
<Button Content="起飞" Visibility="Collapsed"
|
||||
Command="{Binding TakeOffCommand}" />
|
||||
<Button Content="起飞"
|
||||
Command="{Binding GuidAsyncCommand}" />
|
||||
<Button Content="悬停"
|
||||
Command="{Binding HoverCommand}" />
|
||||
<Button Content="手动"
|
||||
@ -44,7 +46,8 @@
|
||||
Command="{Binding ParamModify}" />
|
||||
<Button Content="参数文件"
|
||||
Command="{Binding LoadParamfile}" />
|
||||
|
||||
<Button Content="版本"
|
||||
Command="{Binding GetVersionsCommand}" />
|
||||
</WrapPanel>
|
||||
<WrapPanel>
|
||||
<Button Content="返航"
|
||||
@ -53,40 +56,55 @@
|
||||
Command="{Binding LandCommand}" />
|
||||
<Button Content="上锁"
|
||||
Command="{Binding LockCommand}" />
|
||||
<Button Content="跳过"
|
||||
<Button Content="跳过" Visibility="Collapsed"
|
||||
Command="{Binding FlagCommand}" />
|
||||
<Button Content="测试"
|
||||
<Button Content="闪灯"
|
||||
Command="{Binding LEDFlickerCommand}" />
|
||||
<Button Content="测试" Visibility="Collapsed"
|
||||
Command="{Binding TestCommand}" />
|
||||
<Button Content="开/关灯"
|
||||
Command="{Binding LEDOnOffCommand}" />
|
||||
<Button Content="开灯"
|
||||
Command="{Binding LEDOnOffCommand}"
|
||||
CommandParameter="0"/>
|
||||
<Button Content="关灯"
|
||||
Command="{Binding LEDOnOffCommand}"
|
||||
CommandParameter="1"/>
|
||||
<Button Content="电机"
|
||||
Command="{Binding MotorTestCommand}" />
|
||||
<Button Content="航点"
|
||||
Command="{Binding WriteMissionSingleCommand}" />
|
||||
<TextBox Width="50"
|
||||
Visibility="Hidden"
|
||||
Visibility="Collapsed"
|
||||
Text="{Binding AltP, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</WrapPanel>
|
||||
<Separator/>
|
||||
<WrapPanel>
|
||||
|
||||
<Button Content="起飞测试"
|
||||
Command="{Binding GuidAsyncCommand}" />
|
||||
<Button Content="全部降落"
|
||||
Command="{Binding AllLandCommand}" />
|
||||
<Button Content="测试电机"
|
||||
Command="{Binding MotorTestCommand}" />
|
||||
<Button Content="全部加锁"
|
||||
Command="{Binding LockAllCommand}" />
|
||||
<Button Content="检测电压"
|
||||
Command="{Binding DetectionVoltage}" />
|
||||
<Button Content="统计返回"
|
||||
Command="{Binding DetectionReturnData}" />
|
||||
<Button Content="统计航点"
|
||||
Command="{Binding DetectionMissionData}" />
|
||||
</WrapPanel>
|
||||
<WrapPanel>
|
||||
<Button Content="写入航点"
|
||||
Command="{Binding WriteMissionCommand}" />
|
||||
|
||||
<Button Content="全部解锁"
|
||||
Command="{Binding UnlockAllCommand}" />
|
||||
<Button Content="开始任务"
|
||||
Command="{Binding MissionStartCommand}" />
|
||||
<Button Content="暂停任务"
|
||||
Command="{Binding MissionPauseCommand}" />
|
||||
<Button Content="继续任务"
|
||||
Command="{Binding MissionResumeCommand}" />
|
||||
</WrapPanel>
|
||||
|
||||
<WrapPanel>
|
||||
<Button Content="航点续写"
|
||||
Command="{Binding WriteMissionFailedCommand}" />
|
||||
<TextBox
|
||||
Grid.Column="1"
|
||||
Width="55"
|
||||
@ -94,6 +112,7 @@
|
||||
HorizontalContentAlignment="Right"
|
||||
Text="{Binding RTKcomvalue, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
|
||||
<Button Content="{Binding Path=RTKbtntxt}"
|
||||
|
||||
Command="{Binding SendRTKCommand}" />
|
||||
|
@ -50,7 +50,7 @@
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="已连接:" />
|
||||
<ContentPresenter Content="{Binding IsConnected, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" />
|
||||
<ContentPresenter Content="{Binding CommModuleConnected, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="已解锁:" />
|
||||
@ -92,7 +92,18 @@
|
||||
<TextBlock Text="锁定类型:" />
|
||||
<TextBlock Text="{Binding GpsFixType}" />
|
||||
</StackPanel>
|
||||
<!--
|
||||
<StackPanel>
|
||||
<TextBlock Text="返回数据:" />
|
||||
<TextBlock Text="{Binding Retain[3]}" />
|
||||
<TextBlock Text="." />
|
||||
<TextBlock Text="{Binding Retain[2]}" />
|
||||
<TextBlock Text="." />
|
||||
<TextBlock Text="{Binding Retain[1]}" />
|
||||
<TextBlock Text="." />
|
||||
<TextBlock Text="{Binding Retain[0]}" />
|
||||
|
||||
</StackPanel>
|
||||
<!--
|
||||
<StackPanel>
|
||||
<TextBlock Text="固件版本:" />
|
||||
<TextBlock Text="{Binding FirmwareVersionText}" />
|
||||
@ -139,7 +150,7 @@
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="状态:" />
|
||||
<TextBlock Text="{Binding Path=State}" />
|
||||
<TextBlock Text="{Binding Path=CommModuleMode}" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="纬度:" />
|
||||
|
@ -34,7 +34,7 @@
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox Width="20"
|
||||
IsChecked="{Binding IsConnected, Mode=OneWay}"
|
||||
IsChecked="{Binding CommModuleConnected, Mode=OneWay}"
|
||||
IsEnabled="False"/>
|
||||
<Rectangle Width="15"
|
||||
Height="15"
|
||||
|
@ -38,13 +38,6 @@ namespace Plane.FormationCreator.Views
|
||||
{
|
||||
_copterManager.RaiseSelectedCoptersChanged(e.AddedItems.Cast<ICopter>(), e.RemovedItems.Cast<ICopter>());
|
||||
};
|
||||
lvwDrones.KeyDown += (sender, e) =>
|
||||
{
|
||||
if (e.IsDown)
|
||||
{
|
||||
//e.can
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
|
||||
|
@ -82,6 +82,7 @@ namespace Plane.FormationCreator.Views
|
||||
{
|
||||
var copterDrawing = item.Value;
|
||||
copterDrawing.SetTaskEffect(_flightTaskManager.SelectedTaskIndex);
|
||||
copterDrawing.ResetRoute(_flightTaskManager.SelectedTaskIndex);
|
||||
}
|
||||
break;
|
||||
case nameof(FlightTaskManager.RightSelectedTaskIndex): // 单击右键触发
|
||||
@ -197,10 +198,11 @@ namespace Plane.FormationCreator.Views
|
||||
if (rectangle != null && map.Children.Contains(rectangle))
|
||||
{
|
||||
map.Children.Remove(rectangle);
|
||||
if (_flightTaskManager.SelectedTask != null)
|
||||
_copterManager.Select(null);
|
||||
if (_flightTaskManager.SelectedTask != null && _flightTaskManager.SelectedTask.TaskType != FlightTaskType.TakeOff)
|
||||
{
|
||||
_copterManager.shiftkeydown = true;
|
||||
_copterManager.Select(null);
|
||||
|
||||
foreach (FlightTaskSingleCopterInfo taskCopterInfo in _flightTaskManager.SelectedTask.SingleCopterInfos)
|
||||
{
|
||||
Location seekLocation = new Location(taskCopterInfo.TargetLat, taskCopterInfo.TargetLng);
|
||||
|
@ -187,10 +187,10 @@ namespace Plane.FormationCreator.Views
|
||||
this.Route.Stroke = _brush;
|
||||
this.Route.StrokeThickness = 2.0;
|
||||
//显示计划航线
|
||||
|
||||
|
||||
// _map.Children.Add(this.Route);
|
||||
|
||||
|
||||
|
||||
|
||||
this.LastLocation = location;
|
||||
|
||||
@ -244,7 +244,6 @@ namespace Plane.FormationCreator.Views
|
||||
if (locationUpdated)
|
||||
{
|
||||
Track.Locations.Add(location);
|
||||
this.Route.Locations[0] = location;
|
||||
MapLayer.SetPosition(Dot.Parent, location);
|
||||
this.LastLocation = location;
|
||||
}
|
||||
@ -273,9 +272,6 @@ namespace Plane.FormationCreator.Views
|
||||
|
||||
SetEffect(_copterManager.SelectedCopters.Contains(Copter));
|
||||
|
||||
// Add route point.
|
||||
Route.Locations.Add(location);
|
||||
|
||||
// Register event handlers.
|
||||
RegisterEventHandlersForDraggingWaypoint(shapesContainer, taskIndex: Waypoints.Count);
|
||||
|
||||
@ -311,9 +307,9 @@ namespace Plane.FormationCreator.Views
|
||||
|
||||
var center = _map.ViewportPointToLocation(pos);
|
||||
|
||||
var routePoint = this.Route.Locations[0];
|
||||
routePoint.Latitude = center.Latitude;
|
||||
routePoint.Longitude = center.Longitude;
|
||||
// var routePoint = this.Route.Locations[0];
|
||||
// routePoint.Latitude = center.Latitude;
|
||||
// routePoint.Longitude = center.Longitude;
|
||||
|
||||
var fc = Copter as FakeCopter;
|
||||
fc.SetProperties(
|
||||
@ -394,9 +390,9 @@ namespace Plane.FormationCreator.Views
|
||||
|
||||
}
|
||||
|
||||
var routePoint = this.Route.Locations[taskIndex];
|
||||
var routePoint = this.Route.Locations[1];
|
||||
var leftTopPos = new Point(eventPos.X - wpOffsetX, eventPos.Y - wpOffsetY);
|
||||
//var newRoutePoint = new Point(leftTopPos.X + WAYPOINT_RADIUS, leftTopPos.Y + WAYPOINT_RADIUS);
|
||||
var newRoutePoint = new Point(leftTopPos.X + WAYPOINT_RADIUS, leftTopPos.Y + WAYPOINT_RADIUS);
|
||||
routePoint.Latitude = _map.ViewportPointToLocation(leftTopPos).Latitude;
|
||||
routePoint.Longitude = _map.ViewportPointToLocation(leftTopPos).Longitude;
|
||||
MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos));
|
||||
@ -425,10 +421,10 @@ namespace Plane.FormationCreator.Views
|
||||
var centerPos = _map.LocationToViewportPoint(centerLocation);
|
||||
var leftTopPos = new Point(centerPos.X, centerPos.Y);
|
||||
MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos));
|
||||
var routePoint = Route.Locations[taskIndex];
|
||||
routePoint.Latitude = info.TargetLat;
|
||||
routePoint.Longitude = info.TargetLng;
|
||||
routePoint.Altitude = info.TargetAlt;
|
||||
var routePoint = Route.Locations[1];
|
||||
routePoint.Latitude = info.TargetLat;
|
||||
routePoint.Longitude = info.TargetLng;
|
||||
routePoint.Altitude = info.TargetAlt;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -455,7 +451,11 @@ namespace Plane.FormationCreator.Views
|
||||
{
|
||||
|
||||
if (showroute ?? false )
|
||||
_map.Children.Add(this.Route);
|
||||
{
|
||||
_map.Children.Add(this.Route);
|
||||
MapLayer.SetZIndex(this.Route, 99);
|
||||
}
|
||||
|
||||
else
|
||||
_map.Children.Remove(this.Route);
|
||||
}
|
||||
@ -498,6 +498,24 @@ namespace Plane.FormationCreator.Views
|
||||
*/
|
||||
}
|
||||
|
||||
public void ResetRoute(int taskIndex)
|
||||
{
|
||||
var wpIndex = taskIndex - 1; // Waypoints 中没有起飞点。
|
||||
Route.Locations.Clear();
|
||||
if (wpIndex >= 0 && wpIndex < Waypoints.Count)
|
||||
{
|
||||
var info1 = _flightTaskManager.Tasks[wpIndex].SingleCopterInfos.Find(i => i.Copter == this.Copter);
|
||||
var info2 = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.Find(i => i.Copter == this.Copter);
|
||||
|
||||
Location loc1 = new Location(info1.TargetLat, info1.TargetLng);
|
||||
Location loc2 = new Location(info2.TargetLat, info2.TargetLng);
|
||||
Route.Locations.Add(loc1);
|
||||
Route.Locations.Add(loc2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void SetTaskEffect(int taskIndex)
|
||||
{
|
||||
var wpIndex = taskIndex - 1; // Waypoints 中没有起飞点。
|
||||
@ -526,10 +544,13 @@ namespace Plane.FormationCreator.Views
|
||||
wp.Visibility = Visibility.Hidden;
|
||||
//Route.Visibility = Visibility.Hidden;
|
||||
//Route.Children.RemoveAt(1);
|
||||
//Route.Locations.RemoveAt(taskIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
wp.Visibility = Visibility.Visible;
|
||||
var info = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.Find(i => i.Copter == this.Copter);
|
||||
//Route.Locations.Insert(taskIndex, new Location(info.TargetLat, info.TargetLng));
|
||||
//Route.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
|
@ -129,16 +129,11 @@
|
||||
Text="100"
|
||||
VerticalContentAlignment="Center" />
|
||||
<TextBlock Text="%" Margin="0, 10, 5, 0"/>
|
||||
<Button Content="计算距离"
|
||||
<Button Content="最小距离"
|
||||
Margin="0,5,5,0"
|
||||
Command="{Binding calDistinceCommand}"/>
|
||||
|
||||
<TextBox Grid.Column="1"
|
||||
Width="35"
|
||||
Margin="0, 5, 5, 0"
|
||||
HorizontalContentAlignment="Right"
|
||||
Text="{Binding Distancevalue, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<TextBlock Text="米" Margin="0, 10, 5, 0"/>
|
||||
|
||||
<Button Content="前一高度"
|
||||
Margin="0,5,5,0"
|
||||
Command="{Binding PrealtCommand}" />
|
||||
|
@ -117,7 +117,7 @@
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Height="100" Background="#FF2D2D2D">
|
||||
<StackPanel Height="100" Background="#FF2D2D2D" >
|
||||
|
||||
<TabControl
|
||||
DataContext="{Binding FlightTaskManager.SelectedTask}"
|
||||
@ -149,10 +149,12 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="飞行时间: " />
|
||||
<TextBox Grid.Column="1" Margin="2"
|
||||
Text="{Binding FlytoTime, UpdateSourceTrigger=PropertyChanged}" />
|
||||
MaxLength="4"
|
||||
Text="{Binding FlytoTime, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<TextBlock Grid.Row="1" Text="悬停时间: " />
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Margin="2"
|
||||
Text="{Binding LoiterTime, UpdateSourceTrigger=PropertyChanged}" />
|
||||
MaxLength="4"
|
||||
Text="{Binding LoiterTime, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
@ -165,9 +167,7 @@
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="等待时间: " />
|
||||
<TextBox Grid.Column="1" Margin="2"
|
||||
Text="{Binding LandWaitTime, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
|
@ -109,5 +109,16 @@ namespace Plane.FormationCreator.Views
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
// TextBox textbox = sender as TextBox;
|
||||
// int value = 0;
|
||||
// if (int.TryParse(textbox.Text, out value))
|
||||
// {
|
||||
// if (value > 4095)
|
||||
// textbox.Text = "4095";
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user