主要修改取消UDPserver 更换通信模块的通信

最小距离的修改
无悬停的快速航点模拟
时间长度的限定 如flyto的时间限定为4095
计划路线的修改:只显示当前航点的路线
飞控版本检测
航点失败续写和航点单写
This commit is contained in:
zxd 2018-08-23 22:30:56 +08:00
parent c6de7dc49e
commit 6ade842b38
23 changed files with 901 additions and 629 deletions

View File

@ -18,6 +18,7 @@ using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Plane.CommunicationManagement;
namespace Plane.FormationCreator namespace Plane.FormationCreator
{ {
@ -128,15 +129,22 @@ namespace Plane.FormationCreator
} }
*/ */
/*
UdpServerConnectionManager.Instance.ExceptionThrown += (sender, e1) => UdpServerConnectionManager.Instance.ExceptionThrown += (sender, e1) =>
{ {
_logger.Log(e1.Exception); _logger.Log(e1.Exception);
}; };
UdpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished; UdpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
UdpServerConnectionManager.Instance.StartReceiving(); UdpServerConnectionManager.Instance.StartReceiving();
*/
CommModuleManager.Instance.CommunicationReceived += CommtionReceivedCopterInfo;
CommModuleManager.Instance.CommunicationCopterDisconnect += CommCopterDisconnect;
CommModuleManager.Instance.CommunicationConnected += CommCopterconnected;
CommModuleManager.Instance.Connect();
//CommModuleManager.Instance.test();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -144,6 +152,14 @@ namespace Plane.FormationCreator
return; return;
} }
} }
protected override void OnExit(ExitEventArgs e)
{
CommModuleManager.Instance.CloseConnection();
base.OnExit(e);
}
private void Copter_TextReceived(object sender, MessageCreatedEventArgs e) private void Copter_TextReceived(object sender, MessageCreatedEventArgs e)
{ {
_logger.Log(e.Message ); _logger.Log(e.Message );
@ -164,14 +180,10 @@ namespace Plane.FormationCreator
Name = ip.Substring(ip.LastIndexOf('.') + 1) Name = ip.Substring(ip.LastIndexOf('.') + 1)
}; };
int _index; int _index;
_index=copters.AddCopter(copter); _index=copters.AddCopter(copter);
copterStatus.Insert(_index,false); copterStatus.Insert(_index,false);
copter.TextReceived += Copter_TextReceived; copter.TextReceived += Copter_TextReceived;
})); }));
} }
else else
@ -185,5 +197,81 @@ namespace Plane.FormationCreator
{ {
await AddOrUpdateCopter(e.RemoteAddress, e.Connection); 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;
}
}
}
} }
} }

View File

@ -30,7 +30,8 @@ namespace Plane.FormationCreator.Formation
bool isInsret = false; bool isInsret = false;
for (int i = 0; i < this.Count; i++) 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); InsertItem(i, entityObject);
isInsret = true; isInsret = true;
@ -62,6 +63,7 @@ namespace Plane.FormationCreator.Formation
{ {
Task.WhenAll(Copters.Select(c => c.DisconnectAsync())); Task.WhenAll(Copters.Select(c => c.DisconnectAsync()));
}; };
} }

View File

@ -10,6 +10,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Plane.CommunicationManagement;
namespace Plane.FormationCreator.Formation namespace Plane.FormationCreator.Formation
{ {
@ -17,7 +18,7 @@ namespace Plane.FormationCreator.Formation
{ {
public FlightTaskManager(CopterManager copterManager) public FlightTaskManager(CopterManager copterManager)
{ {
_copterManager = copterManager; _copterManager = copterManager;
//AddTakeOffTask(_copterManager.Copters); //AddTakeOffTask(_copterManager.Copters);
@ -29,10 +30,16 @@ namespace Plane.FormationCreator.Formation
_copterManager.SelectedCoptersChanged += (sender, e) => _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(); copter.LEDAsync();
} }
*/
// TODO: 林俊清, 20150803, 处理选中多个飞行器的情况。 // TODO: 林俊清, 20150803, 处理选中多个飞行器的情况。
if (_copterManager.SelectedCopters.Count() > 1) if (_copterManager.SelectedCopters.Count() > 1)
{ {
@ -54,8 +61,8 @@ namespace Plane.FormationCreator.Formation
if (selectedCopter!=null) if (selectedCopter!=null)
selectedCopter.SetShowLEDFlashAsync(1, 100); selectedCopter.SetShowLEDFlashAsync(1, 100);
if (selectedCopter != null) //if (selectedCopter != null)
selectedCopter.LEDAsync(); //selectedCopter.LEDAsync();
}; };
TaskAdded += (sender, e) => TaskAdded += (sender, e) =>
@ -220,9 +227,9 @@ namespace Plane.FormationCreator.Formation
var newTask = new FlightTask(FlightTaskType.FlyTo); var newTask = new FlightTask(FlightTaskType.FlyTo);
int coptindex = 0; int coptindex = 0;
int colnum = 10; //自动生成列数=4 int colnum = 20; //自动生成列数=4
float coldis = 5f;//列相距5米 float coldis = 2.5f;//列相距5米
float rowdis = 2.5f;//行相距5米 float rowdis = 5f;//行相距5米
float matrixdis = 20; //生成方阵距离30米 float matrixdis = 20; //生成方阵距离30米
@ -510,7 +517,7 @@ namespace Plane.FormationCreator.Formation
SelectedTaskIndex = Tasks.Count - 1; SelectedTaskIndex = Tasks.Count - 1;
} }
private void RestoreTakeOffTask(int takeOffTime, dynamic singleCopterInfos) private void RestoreTakeOffTask(byte takeOffTime, dynamic singleCopterInfos)
{ {
var copters = _copterManager.Copters; var copters = _copterManager.Copters;
if (copters == null || !copters.Any()) return; if (copters == null || !copters.Any()) return;
@ -522,7 +529,7 @@ namespace Plane.FormationCreator.Formation
for (int i = 0; i < copters.Count; i++) for (int i = 0; i < copters.Count; i++)
{ {
var singleCopterInfoObj = singleCopterInfos[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); RestoreSimpleCircleTask(task.singleCopterInfos);
break; break;
case FlightTaskType.ReturnToLand: 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; break;
} }
} }
@ -1035,7 +1045,7 @@ namespace Plane.FormationCreator.Formation
case FlightTaskType.TakeOff: case FlightTaskType.TakeOff:
// AddTakeOffTask(copters); // added by ZJF // AddTakeOffTask(copters); // added by ZJF
TakeOffNumAttr = task.takeoffnumber; TakeOffNumAttr = task.takeoffnumber;
RestoreTakeOffTask((int)task.takeoffTime, task.singleCopterInfos); RestoreTakeOffTask((byte)task.takeoffTime, task.singleCopterInfos);
break; break;
case FlightTaskType.FlyTo: case FlightTaskType.FlyTo:
RestoreFlyToTask((bool)task.staggerRoutes, (int)task.flytoTime, (int)task.loiterTime, task.singleCopterInfos); RestoreFlyToTask((bool)task.staggerRoutes, (int)task.flytoTime, (int)task.loiterTime, task.singleCopterInfos);

View File

@ -22,15 +22,15 @@ namespace Plane.FormationCreator.Formation
{ {
var info = new FlightTaskSingleCopterInfo(copter) var info = new FlightTaskSingleCopterInfo(copter)
{ {
TakeOffWaitTime = waitTime TakeOffWaitTime = (ushort)waitTime
}; };
return info; return info;
} }
//起飞等待时间 //起飞等待时间
private int _TakeOffWaitTime = 1; private ushort _TakeOffWaitTime = 1;
public int TakeOffWaitTime public ushort TakeOffWaitTime
{ {
get { return _TakeOffWaitTime; } get { return _TakeOffWaitTime; }
set { Set(nameof(TakeOffWaitTime), ref _TakeOffWaitTime, value); } set { Set(nameof(TakeOffWaitTime), ref _TakeOffWaitTime, value); }

View File

@ -25,18 +25,27 @@ namespace Plane.FormationCreator.Formation
public int FlytoTime public int FlytoTime
{ {
get { return _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; private int _LoiterTime = 10;
public int LoiterTime public int LoiterTime
{ {
get { return _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; private bool _VerticalLift = false;
public bool VerticalLift // 垂直升降标志位,后面需要加入即使拖动地图上的飞机,也不会变化经纬度. added by ZJF public bool VerticalLift // 垂直升降标志位,后面需要加入即使拖动地图上的飞机,也不会变化经纬度. added by ZJF
{ {
@ -106,6 +115,7 @@ namespace Plane.FormationCreator.Formation
} }
private int RuningTaskRemaining = 0;
private async Task FlyToTaskFlySingleCopterAsync(FlightTaskSingleCopterInfo info) private async Task FlyToTaskFlySingleCopterAsync(FlightTaskSingleCopterInfo info)
{ {
@ -114,11 +124,12 @@ namespace Plane.FormationCreator.Formation
TimeSpan ts = dtNow - dtLastTime; TimeSpan ts = dtNow - dtLastTime;
FlightTask task = _flightTaskManager.CurrentRunningTask; FlightTask task = _flightTaskManager.CurrentRunningTask;
int flyToTime = task.FlytoTime; int flyToTime = task.FlytoTime * 1000;
int loiterTime = task.LoiterTime; int loiterTime = task.LoiterTime * 1000;
int taskIndex = _flightTaskManager.CurrentRunningTaskIndex; int taskIndex = _flightTaskManager.CurrentRunningTaskIndex;
int copterIndex = SingleCopterInfos.IndexOf(info); int copterIndex = SingleCopterInfos.IndexOf(info);
// 当该飞机被标记时,悬停并跳过飞行任务 // 当该飞机被标记时,悬停并跳过飞行任务
if ((bool)_copterManager.CopterStatus[copterIndex]) if ((bool)_copterManager.CopterStatus[copterIndex])
{ {
@ -150,10 +161,24 @@ namespace Plane.FormationCreator.Formation
int sendFlyToTimes = 0; int sendFlyToTimes = 0;
//while (!info.Copter.ArrivedTarget(info.TargetLat, info.TargetLng, info.TargetAlt)) //按航点飞 所有Copter到达目标点开始飞下个航点 //第0个任务为takeoff
while (ts.TotalMilliseconds < (flyToTime + loiterTime) * 1000) //按时间轴飞:当前任务时间到达后自动飞往下个航点 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) if (_flightTaskManager.IsPaused == true)
{ {
await info.Copter.HoverAsync(); await info.Copter.HoverAsync();

View File

@ -24,8 +24,8 @@ namespace Plane.FormationCreator.Formation
} }
//起飞到第一个航点高度的飞行时间 //起飞到第一个航点高度的飞行时间
private int _TakeOffTime = 10; private byte _TakeOffTime = 10;
public int TakeOffTime public byte TakeOffTime
{ {
get { return _TakeOffTime; } get { return _TakeOffTime; }
set { Set(nameof(TakeOffTime), ref _TakeOffTime, value); } set { Set(nameof(TakeOffTime), ref _TakeOffTime, value); }

View File

@ -20,6 +20,7 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using Plane.CommunicationManagement;
namespace Plane.FormationCreator namespace Plane.FormationCreator
{ {
@ -40,7 +41,7 @@ namespace Plane.FormationCreator
// //App.Current.Shutdown(); // //App.Current.Shutdown();
//} //}
} }
private CommModuleManager _commModuleManager = CommModuleManager.Instance;
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>(); private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private FlightTaskManager _flightTaskManager= ServiceLocator.Current.GetInstance<FlightTaskManager>(); private FlightTaskManager _flightTaskManager= ServiceLocator.Current.GetInstance<FlightTaskManager>();
private void ShowConnectDialog(ConnectWindow loginWindow = null) private void ShowConnectDialog(ConnectWindow loginWindow = null)
@ -162,17 +163,26 @@ namespace Plane.FormationCreator
var copters = _copterManager.AcceptingControlCopters; var copters = _copterManager.AcceptingControlCopters;
await Task.WhenAll(copters.Select(async copter => if (isInFastMode)
{ {
if (isInFastMode) await _commModuleManager.SetChannelsAsync(copters, ch2: e.Key == Key.W ? (ushort)1100 : (ushort)1900);
{ }
await copter.SetChannelsAsync(ch2: e.Key == Key.W ? (ushort)1100 : (ushort)1900); else
} {
else await _commModuleManager.SetChannelsAsync(copters, ch2: e.Key == Key.W ? (ushort)1350 : (ushort)1650);
{ }
await copter.SetChannelsAsync(ch2: e.Key == Key.W ? (ushort)1350 : (ushort)1650);
} // await Task.WhenAll(copters.Select(async copter =>
})).ConfigureAwait(false); // {
// 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; break;
} }
//横滚控制 //横滚控制
@ -226,17 +236,25 @@ namespace Plane.FormationCreator
var copters = _copterManager.AcceptingControlCopters; var copters = _copterManager.AcceptingControlCopters;
await Task.WhenAll(copters.Select(async copter => if (isInFastMode)
{ {
if (isInFastMode) await _commModuleManager.SetChannelsAsync(copters, ch1: e.Key == Key.A ? (ushort)1100 : (ushort)1900);
{ }
await copter.SetChannelsAsync(ch1: e.Key == Key.A ? (ushort)1100 : (ushort)1900); else
} {
else await _commModuleManager.SetChannelsAsync(copters, ch1: e.Key == Key.A ? (ushort)1350 : (ushort)1650);
{ }
await copter.SetChannelsAsync(ch1: e.Key == Key.A ? (ushort)1350 : (ushort)1650); // await Task.WhenAll(copters.Select(async copter =>
} // {
})).ConfigureAwait(false); // 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; break;
} }
//高度控制 //高度控制
@ -244,6 +262,15 @@ namespace Plane.FormationCreator
case Key.K: case Key.K:
{ {
var copters = _copterManager.AcceptingControlCopters; 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 => await Task.WhenAll(copters.Select(async copter =>
{ {
if (isInFastMode) if (isInFastMode)
@ -255,6 +282,8 @@ namespace Plane.FormationCreator
await copter.SetChannelsAsync(ch3: e.Key == Key.K ? (ushort)1350 : (ushort)1650); await copter.SetChannelsAsync(ch3: e.Key == Key.K ? (ushort)1350 : (ushort)1650);
} }
})).ConfigureAwait(false); })).ConfigureAwait(false);
*/
break; break;
} }
//航向控制 //航向控制
@ -262,11 +291,14 @@ namespace Plane.FormationCreator
case Key.L: case Key.L:
{ {
var copters = _copterManager.AcceptingControlCopters; 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 Task.WhenAll(copters.Select(async copter =>
{ {
//await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -20 : 20)) % 360); //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); await copter.SetChannelsAsync(ch4: e.Key == Key.J ? (ushort)1200 : (ushort)1800);
})).ConfigureAwait(false); })).ConfigureAwait(false);
*/
break; break;
} }
case Key.M: // 低速下降。 case Key.M: // 低速下降。
@ -368,42 +400,67 @@ namespace Plane.FormationCreator
case Key.S: case Key.S:
{ {
var copters = _copterManager.AcceptingControlCopters; var copters = _copterManager.AcceptingControlCopters;
await Task.WhenAll(copters.Select(async copter => for (int i = 0; i < 3; i++)
{ {
await copter.SetChannelsAsync(ch2: 1500); await _commModuleManager.SetChannelsAsync(copters, ch2: 1500);
})).ConfigureAwait(false); await Task.Delay(100);
}
// await Task.WhenAll(copters.Select(async copter =>
// {
// await copter.SetChannelsAsync(ch2: 1500);
// })).ConfigureAwait(false);
break; break;
} }
case Key.A: case Key.A:
case Key.D: case Key.D:
{ {
var copters = _copterManager.AcceptingControlCopters; var copters = _copterManager.AcceptingControlCopters;
await Task.WhenAll(copters.Select(async copter => for (int i = 0; i < 3; i++)
{ {
await copter.SetChannelsAsync(ch1: 1500); await _commModuleManager.SetChannelsAsync(copters, ch1: 1500);
})).ConfigureAwait(false); await Task.Delay(100);
}
// await Task.WhenAll(copters.Select(async copter =>
// {
// await copter.SetChannelsAsync(ch1: 1500);
// })).ConfigureAwait(false);
break; break;
} }
case Key.I: case Key.I:
case Key.K: case Key.K:
{ {
var copters = _copterManager.AcceptingControlCopters; var copters = _copterManager.AcceptingControlCopters;
await Task.WhenAll(copters.Select(async copter => for (int i = 0; i < 3; i++)
{ {
await copter.SetChannelsAsync(ch3: 1500); await _commModuleManager.SetChannelsAsync(copters, ch3: 1500);
})).ConfigureAwait(false); await Task.Delay(100);
}
// await Task.WhenAll(copters.Select(async copter =>
// {
// await copter.SetChannelsAsync(ch3: 1500);
// })).ConfigureAwait(false);
break; break;
} }
case Key.J: case Key.J:
case Key.L: case Key.L:
{ {
var copters = _copterManager.AcceptingControlCopters; 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 _commModuleManager.SetChannelsAsync(copters, ch4: 1500);
await copter.SetChannelsAsync(ch4: 1500); await Task.Delay(100);
})).ConfigureAwait(false); }
// 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; break;
} }
case Key.M: // 停止低速下降。 case Key.M: // 停止低速下降。

View File

@ -5,13 +5,86 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Plane.FormationCreator" xmlns:local="clr-namespace:Plane.FormationCreator"
mc:Ignorable="d" 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"> <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"/> <Grid.ColumnDefinitions>
<TextBox x:Name="textParamValue" HorizontalAlignment="Left" Height="23" Margin="21,119,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/> <ColumnDefinition/>
<TextBox x:Name="textParamName" HorizontalAlignment="Left" Height="23" Margin="21,53,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" RenderTransformOrigin="-0.246,1.213"/> <ColumnDefinition/>
<Label x:Name="label" Content="参数名称" HorizontalAlignment="Left" Margin="21,23,0,0" VerticalAlignment="Top"/> </Grid.ColumnDefinitions>
<Label x:Name="label_Copy" Content="参数值" HorizontalAlignment="Left" Margin="21,89,0,0" VerticalAlignment="Top"/> <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> </Grid>
</Window> </Window>

View File

@ -29,5 +29,10 @@ namespace Plane.FormationCreator
this.DialogResult = true; this.DialogResult = true;
} }
private void Modify_Select(object sender, RoutedEventArgs e)
{
textParamName.Text = ((Button)sender).Tag.ToString();
}
} }
} }

View File

@ -112,7 +112,7 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _CloseCommand ?? (_CloseCommand = new RelayCommand(() => 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; private ICommand _CommDataAsync;
public ICommand CommDataAsync public ICommand CommDataAsync
{ {
@ -172,135 +202,12 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _CommDataAsync ?? (_CommDataAsync = new RelayCommand(async () => 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) private List<IMission> CreateLEDMissions(IEnumerable<LEDInfo> LEDInfos)
{ {
List<IMission> missions = new List<IMission>(); List<IMission> missions = new List<IMission>();
@ -326,7 +233,7 @@ namespace Plane.FormationCreator.ViewModels
private async Task WriteIdCommandAsync(int num, short messageType) 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) private async Task SendCommandAsync(int Count)
@ -360,54 +267,9 @@ namespace Plane.FormationCreator.ViewModels
await Task.Delay(10); await Task.Delay(10);
return true; 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() private async Task ConnectAsync()
{ {

View File

@ -18,6 +18,7 @@ using Plane.Communication;
using Microsoft.Win32; using Microsoft.Win32;
using Plane.Util; using Plane.Util;
using System.Windows.Media; using System.Windows.Media;
using Plane.CommunicationManagement;
namespace Plane.FormationCreator.ViewModels namespace Plane.FormationCreator.ViewModels
{ {
@ -38,6 +39,7 @@ namespace Plane.FormationCreator.ViewModels
private FormationController _formationController; private FormationController _formationController;
private CopterManager _copterManager; private CopterManager _copterManager;
private CommModuleManager _commModuleManager = CommModuleManager.Instance;
private ILogger _logger = ServiceLocator.Current.GetInstance<ILogger>(); private ILogger _logger = ServiceLocator.Current.GetInstance<ILogger>();
@ -77,10 +79,13 @@ namespace Plane.FormationCreator.ViewModels
if (Alert.Show("再次确认上锁?请确认所有飞行器都在地面,否则将自由落体", "再次警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning) if (Alert.Show("再次确认上锁?请确认所有飞行器都在地面,否则将自由落体", "再次警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
== MessageBoxResult.OK) == MessageBoxResult.OK)
{ {
await _commModuleManager.LockAsync();
/*
await Task.WhenAll(_copterManager.Copters.Select(async c => await Task.WhenAll(_copterManager.Copters.Select(async c =>
{ {
await c.LockAsync(); 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; private ICommand _AllLandCommand;
public ICommand AllLandCommand public ICommand AllLandCommand
{ {
@ -139,10 +215,25 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _AllLandCommand ?? (_AllLandCommand = new RelayCommand(async () => return _AllLandCommand ?? (_AllLandCommand = new RelayCommand(async () =>
{ {
await _commModuleManager.LandAsync();
/*
await Task.WhenAll(_copterManager.Copters.Select(async c => await Task.WhenAll(_copterManager.Copters.Select(async c =>
{ {
await c.LandAsync(); 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 () => 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 => await Task.WhenAll(_copterManager.Copters.Select(async c =>
{ {
for (int i = 1; i <= 4; i++) for (int i = 1; i <= 4; i++)
@ -163,6 +265,7 @@ namespace Plane.FormationCreator.ViewModels
} }
})).ConfigureAwait(false); })).ConfigureAwait(false);
*/
})); }));
} }
} }
@ -174,16 +277,16 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _GuidAsyncCommand ?? (_GuidAsyncCommand = new RelayCommand(async () => 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 Task.WhenAll(_copterManager.AcceptingControlCopters.Select(async c =>
{ {
await c.GuidAsync(); await c.GuidAsync();
await Task.Delay(100).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false);
await c.TakeOffAsync(1); await c.TakeOffAsync(1);
})); }));
*/
})); }));
} }
} }
@ -197,7 +300,13 @@ namespace Plane.FormationCreator.ViewModels
return _UnlockAllCommand ?? (_UnlockAllCommand = new RelayCommand(async () => return _UnlockAllCommand ?? (_UnlockAllCommand = new RelayCommand(async () =>
{ {
// await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.UnlockAsync())); // 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 Task.WhenAll(_copterManager.Copters.Select(async c => {
await c.UnlockAsync(); await c.UnlockAsync();
//解锁间隔一定要超过1s否则导致飞控以后无法解锁 //解锁间隔一定要超过1s否则导致飞控以后无法解锁
@ -212,20 +321,23 @@ namespace Plane.FormationCreator.ViewModels
await Task.Delay(25).ConfigureAwait(false); 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; private ICommand _LEDOnOffCommand;
public ICommand LEDOnOffCommand public ICommand LEDOnOffCommand
{ {
get get
{ {
return _LEDOnOffCommand ?? (_LEDOnOffCommand = new RelayCommand(async () => return _LEDOnOffCommand ?? (_LEDOnOffCommand = new RelayCommand<int>(async onOff=>
{ {
string paramstr = NTF_GROUPLED_OFF; string paramstr = NTF_GROUPLED_OFF;
float paramvalue = 0; float paramvalue = onOff;
await _commModuleManager.SetParamAsync(paramstr, paramvalue, _copterManager.AcceptingControlCopters);
/*
await Task.WhenAll( await Task.WhenAll(
_copterManager.AcceptingControlCopters.Select(async copter => _copterManager.AcceptingControlCopters.Select(async copter =>
{ {
@ -236,6 +348,7 @@ namespace Plane.FormationCreator.ViewModels
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select await Task.WhenAll(_copterManager.AcceptingControlCopters.Select
(copter => copter.SetParamAsync(paramstr, newParamvalue))); (copter => copter.SetParamAsync(paramstr, newParamvalue)));
*/
})); }));
} }
} }
@ -248,7 +361,10 @@ namespace Plane.FormationCreator.ViewModels
return _UnlockCommand ?? (_UnlockCommand = new RelayCommand(async () => return _UnlockCommand ?? (_UnlockCommand = new RelayCommand(async () =>
{ {
// await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.UnlockAsync())); // 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 Task.WhenAll(_copterManager.AcceptingControlCopters.Select( async c => {
await c.UnlockAsync(); await c.UnlockAsync();
//解锁间隔一定要超过1s否则导致飞控以后无法解锁 //解锁间隔一定要超过1s否则导致飞控以后无法解锁
@ -263,6 +379,7 @@ namespace Plane.FormationCreator.ViewModels
await Task.Delay(25).ConfigureAwait(false); await Task.Delay(25).ConfigureAwait(false);
} }
})); }));
*/
})); }));
} }
} }
@ -274,10 +391,14 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _LockCommand ?? (_LockCommand = new RelayCommand(async () => return _LockCommand ?? (_LockCommand = new RelayCommand(async () =>
{ {
if (Alert.Show("您确定要上锁吗?飞行器将无视转速,立即强制停止运转!!!", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning) if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
== MessageBoxResult.OK)
{ {
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 () => 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 () => 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 () => 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 () => return _ParamModify ?? (_ParamModify = new RelayCommand(async () =>
{ {
if (_copterManager.AcceptingControlCopters != null && _copterManager.AcceptingControlCopters.Count() > 0)
var ModifyParamWindow = new Plane.FormationCreator.ModifyParam();
if (ModifyParamWindow.ShowDialog() == true)
{ {
var ModifyParamWindow = new Plane.FormationCreator.ModifyParam();
if (ModifyParamWindow.ShowDialog() == true)
{
string paramstr = ModifyParamWindow.textParamName.Text; string paramstr = ModifyParamWindow.textParamName.Text;
float paramvalue = Convert.ToSingle(ModifyParamWindow.textParamValue.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 bool ifallok = true;
(copter => copter.SetParamAsync(paramstr, paramvalue))); await Task.WhenAll(
bool ifallok = true; _copterManager.AcceptingControlCopters.Select(async copter =>
await Task.WhenAll(
_copterManager.AcceptingControlCopters.Select(async copter =>
{
float getvaule = await copter.GetParamAsync(paramstr);
if (getvaule != paramvalue)
{ {
ifallok = false; float getvaule = await copter.GetParamAsync(paramstr);
Alert.Show(copter.Id + "设置失败,读取的参数是" + getvaule, "提示", MessageBoxButton.OK, MessageBoxImage.Information); if (getvaule != paramvalue)
{
ifallok = false;
Alert.Show(copter.Id + "设置失败,读取的参数是" + getvaule, "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
} }
}
)); ));
if (ifallok) if (ifallok)
Alert.Show("所有已选的飞机参数设置完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information); Alert.Show("所有已选的飞机参数设置完成", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
else else
Alert.Show("有部分飞机参数设置失败,请检查并再次设置", "提示", MessageBoxButton.OK, MessageBoxImage.Information); Alert.Show("有部分飞机参数设置失败,请检查并再次设置", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
*/
}
} }
})); }));
} }
@ -502,8 +653,6 @@ namespace Plane.FormationCreator.ViewModels
{ {
if (!trkthreadrun) if (!trkthreadrun)
{ {
Rtkport = new SerialPortConnection(RTKcomvalue, 57600) as IConnection; Rtkport = new SerialPortConnection(RTKcomvalue, 57600) as IConnection;
await Rtkport.OpenAsync(); await Rtkport.OpenAsync();
if (!Rtkport.IsOpen) if (!Rtkport.IsOpen)
@ -537,23 +686,24 @@ namespace Plane.FormationCreator.ViewModels
Console.WriteLine("rev:" + (ushort)packet.Length); Console.WriteLine("rev:" + (ushort)packet.Length);
//分发到每个飞机 //分发到每个飞机
/*
foreach (var copter in _copterManager.Copters) foreach (var copter in _copterManager.Copters)
{ {
// int iid = Convert.ToInt32(copter.Name); // int iid = Convert.ToInt32(copter.Name);
//临时用来区分RTK发送数据 //临时用来区分RTK发送数据
//if (iid<50) //if (iid<50)
await copter.InjectGpsDataAsync(packet, (ushort)packet.Length); await copter.InjectGpsDataAsync(packet, (ushort)packet.Length);
} }
*/
await _commModuleManager.InjectGpsDataAsync(packet, (ushort)packet.Length);
} }
await Task.Delay(200).ConfigureAwait(false); await Task.Delay(200).ConfigureAwait(false);
} }
}).ConfigureAwait(false); }).ConfigureAwait(false);
Alert.Show("RTK数据停止发送", "提示", MessageBoxButton.OK, MessageBoxImage.Information); Alert.Show("RTK数据停止发送", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
} }
else//停止RTK else//停止RTK
{ {
@ -563,10 +713,6 @@ namespace Plane.FormationCreator.ViewModels
RTKState = "未发送RTK数据"; RTKState = "未发送RTK数据";
RTKbtntxt = "发送RTK"; RTKbtntxt = "发送RTK";
} }
@ -623,7 +769,11 @@ namespace Plane.FormationCreator.ViewModels
{ {
return _LandCommand ?? (_LandCommand = new RelayCommand(async () => 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())); await Task.WhenAll(_copterManager.AcceptingControlCopters.Select(copter => copter.LandAsync()));
*/
})); }));
} }
} }
@ -745,6 +895,14 @@ namespace Plane.FormationCreator.ViewModels
//循环3次 发送起飞命令 避免通信问题 //循环3次 发送起飞命令 避免通信问题
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
await _commModuleManager.DoMissionStartAsync(utchour,
utcminute,
utcsecond,
_flightTaskManager.OriginLng,
_flightTaskManager.OriginLat
);
foreach (var vcopter in _copterManager.Copters) foreach (var vcopter in _copterManager.Copters)
{ {
await vcopter.MissionStartAsync(utchour, await vcopter.MissionStartAsync(utchour,
@ -754,28 +912,116 @@ namespace Plane.FormationCreator.ViewModels
_flightTaskManager.OriginLat _flightTaskManager.OriginLat
); );
} }
await Task.Delay(10).ConfigureAwait(false); 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; private ICommand _MissionResumeCommand;
// public ICommand SetOriginalPointCommand public ICommand MissionResumeCommand
// { {
// get get
// { {
// return _SetOriginalPointCommand ?? (_SetOriginalPointCommand = new RelayCommand(() => return _MissionResumeCommand ?? (_MissionResumeCommand = new RelayCommand(async () =>
// { {
// FlightTaskManager _flightTaskManager = ServiceLocator.Current.GetInstance<FlightTaskManager>(); int utchour = DateTime.UtcNow.AddSeconds(5).Hour;
// _flightTaskManager.SetOriginal(); 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; private ICommand _WriteMissionCommand;
public ICommand WriteMissionCommand public ICommand WriteMissionCommand
{ {
@ -792,229 +1038,100 @@ namespace Plane.FormationCreator.ViewModels
int coptercount = _copterManager.Copters.Count; int coptercount = _copterManager.Copters.Count;
int taskcount = _flightTaskManager.Tasks.Count; int taskcount = _flightTaskManager.Tasks.Count;
// bool havewritefault = true;
if (taskcount < 2) return; if (taskcount < 2) return;
_commModuleManager.ClearMissionWriteState();
for (int i = 0; i < coptercount; i++) for (int i = 0; i < coptercount; i++)
{ {
///写航线开始 ///写航线开始
//var missions = new IMission[taskcount]; //不要起飞任务但增加一个起飞后低空航点,见起飞任务,再增加一个降落低空航点,见降落部分 await CollectMissions(i).ConfigureAwait(false);
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;
}
} }
Alert.Show($"所有任务写入成功!"); 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}");
*/
/////////////////写航向结束
})); }));
} }
} }
/// <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) private List<IMission> CreateLEDMissions(IEnumerable<LEDInfo> LEDInfos)
{ {
List<IMission> missions = new List<IMission>(); List<IMission> missions = new List<IMission>();

View File

@ -134,9 +134,9 @@ namespace Plane.FormationCreator.ViewModels
var center = _mapManager.Center; var center = _mapManager.Center;
string id; string id;
int colnum = 10; //自动生成列数=4 int colnum = 20; //自动生成列数=4
float coldis = 5;//列相距5米 float coldis = 2.5f;//列相距5米
float rowdis = 2.5f;//行相距5米 float rowdis = 5f;//行相距5米
int currcol = 0; //当前列号 int currcol = 0; //当前列号
int currrow = 0; //当前行 int currrow = 0; //当前行
Tuple<double, double> colheadLatLng = new Tuple<double, double>(0, 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 () => return _ClearCoptersCommand ?? (_ClearCoptersCommand = new RelayCommand(async () =>
{ {
_flightTaskManager.Pause();
foreach (var copter in _copterManager.Copters) foreach (var copter in _copterManager.Copters)
{ {
await copter.DisconnectAsync(); await copter.DisconnectAsync();
@ -219,7 +220,7 @@ namespace Plane.FormationCreator.ViewModels
_copterManager.CopterStatus.Clear(); _copterManager.CopterStatus.Clear();
_mapManager.ClearCopters(); _mapManager.ClearCopters();
_flightTaskManager.ClearTasks(); _flightTaskManager.ClearTasks();
UdpServerConnectionManager.Instance.ClearConnections(); //UdpServerConnectionManager.Instance.ClearConnections();
_virtualCopterId = 1; _virtualCopterId = 1;
_lastVirtualCopterLocation = null; _lastVirtualCopterLocation = null;
})); }));

View File

@ -145,12 +145,13 @@ namespace Plane.FormationCreator.ViewModels
get { return _CanModifySingleCopterInfo; } get { return _CanModifySingleCopterInfo; }
set { Set(nameof(CanModifySingleCopterInfo), ref _CanModifySingleCopterInfo, value); } set { Set(nameof(CanModifySingleCopterInfo), ref _CanModifySingleCopterInfo, value); }
} }
private double _Distancevalue;
public double Distancevalue // private double _Distancevalue;
{ // public double Distancevalue
get { return _Distancevalue; } // {
set { Set(nameof(Distancevalue), ref _Distancevalue, value); } // get { return _Distancevalue; }
} // set { Set(nameof(Distancevalue), ref _Distancevalue, value); }
// }
private float _Modialtvalue; private float _Modialtvalue;
@ -1250,50 +1251,31 @@ public ICommand VerticlAlignmentCommand
return _calDistinceCommand ?? (_calDistinceCommand = new RelayCommand<double>(async => return _calDistinceCommand ?? (_calDistinceCommand = new RelayCommand<double>(async =>
{ {
double lng1=0, lat1=0, alt1=0, lng2=0, lat2=0, alt2=0; double minDistance = double.MaxValue;
double distance = 0;
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault(); var flightTask = _flightTaskManager.SelectedTask;
if (_flightTaskManager.SelectedTask == null) return; List<ICopter> selectedCopter = new List<ICopter>();
selectedCopter.AddRange(_copterManager.AcceptingControlCopters);
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++) for (int i = 0; i < selectedCopter.Count; i++)
{ {
var copter1 = selectedCopter[i];
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter; var copterInfo1 = _flightTaskManager.SelectedTask.SingleCopterInfos.FirstOrDefault(c =>c.Copter == copter1);
foreach (var capter in _copterManager.SelectedCopters)
for (int j = i + 1; j < selectedCopter.Count; j++)
{ {
if (capter == selectedCopter) var copter2 = selectedCopter[j];
{ var copterInfo2 = _flightTaskManager.SelectedTask.SingleCopterInfos.FirstOrDefault(c => c.Copter == copter2);
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;
} 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 = minDistance;
Distancevalue = distance; Message.Show($"最小距离 = {minDistance}");
})); }));
} }
@ -1384,7 +1366,6 @@ public ICommand VerticlAlignmentCommand
} }
} }
//缩放
private ICommand _BackToPreviousTaskPoint; private ICommand _BackToPreviousTaskPoint;
public ICommand BackToPreviousTaskPoint public ICommand BackToPreviousTaskPoint
{ {

View File

@ -127,9 +127,8 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
Grid.Row="2" Grid.Row="2"
Grid.ColumnSpan="3"> Grid.ColumnSpan="3">
<Button Content="状态查询" Margin="5" Command="{Binding Path=StateInquireCommand}"/> <Button Content="通信模块状态" Margin="5" Command="{Binding Path=StateInquireCommand}"/>
<Button Content="设置20台" Margin="5" Command="{Binding Path=SendCommand}" /> <Button Content="设置总数" Margin="5" Command="{Binding Path=SendCommand}" />
<Button Content="写入航点" Margin="5" Command="{Binding Path=CommWriteMissionCommand}" />
<Button Content="切换写航点" Margin="5" Command="{Binding Path=ChangeWriteMissionCommand}" /> <Button Content="切换写航点" Margin="5" Command="{Binding Path=ChangeWriteMissionCommand}" />
@ -141,7 +140,7 @@
<TextBox Margin="2,5,5,5" Width="30" Text="{Binding CopterNum}"></TextBox> <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,5,0,5" Command="{Binding Path=WriteIdCommand}" />
<Button Content="闪灯" Margin="5" Command="{Binding CommDataAsync}"/> <Button Content="闪灯" Margin="5" Command="{Binding CommDataAsync}"/>
<Button Content="搜索飞机" Margin="5" Command="{Binding QueryAllCopterCommand}"/>
</StackPanel> </StackPanel>
</Grid> </Grid>

View File

@ -17,7 +17,7 @@
<Style TargetType="Button" <Style TargetType="Button"
BasedOn="{StaticResource {x:Type Button}}"> BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Margin" <Setter Property="Margin"
Value="0,0,5,5" /> Value="0,0,3,5" />
</Style> </Style>
</StackPanel.Resources> </StackPanel.Resources>
@ -34,8 +34,10 @@
<WrapPanel> <WrapPanel>
<Button Content="解锁" <Button Content="解锁"
Command="{Binding UnlockCommand}" /> Command="{Binding UnlockCommand}" />
<Button Content="起飞" <Button Content="起飞" Visibility="Collapsed"
Command="{Binding TakeOffCommand}" /> Command="{Binding TakeOffCommand}" />
<Button Content="起飞"
Command="{Binding GuidAsyncCommand}" />
<Button Content="悬停" <Button Content="悬停"
Command="{Binding HoverCommand}" /> Command="{Binding HoverCommand}" />
<Button Content="手动" <Button Content="手动"
@ -44,7 +46,8 @@
Command="{Binding ParamModify}" /> Command="{Binding ParamModify}" />
<Button Content="参数文件" <Button Content="参数文件"
Command="{Binding LoadParamfile}" /> Command="{Binding LoadParamfile}" />
<Button Content="版本"
Command="{Binding GetVersionsCommand}" />
</WrapPanel> </WrapPanel>
<WrapPanel> <WrapPanel>
<Button Content="返航" <Button Content="返航"
@ -53,40 +56,55 @@
Command="{Binding LandCommand}" /> Command="{Binding LandCommand}" />
<Button Content="上锁" <Button Content="上锁"
Command="{Binding LockCommand}" /> Command="{Binding LockCommand}" />
<Button Content="跳过" <Button Content="跳过" Visibility="Collapsed"
Command="{Binding FlagCommand}" /> Command="{Binding FlagCommand}" />
<Button Content="测试" <Button Content="闪灯"
Command="{Binding LEDFlickerCommand}" />
<Button Content="测试" Visibility="Collapsed"
Command="{Binding TestCommand}" /> Command="{Binding TestCommand}" />
<Button Content="开/关灯" <Button Content="开灯"
Command="{Binding LEDOnOffCommand}" /> 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" <TextBox Width="50"
Visibility="Hidden" Visibility="Collapsed"
Text="{Binding AltP, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding AltP, UpdateSourceTrigger=PropertyChanged}" />
</WrapPanel> </WrapPanel>
<Separator/>
<WrapPanel> <WrapPanel>
<Button Content="起飞测试"
Command="{Binding GuidAsyncCommand}" />
<Button Content="全部降落" <Button Content="全部降落"
Command="{Binding AllLandCommand}" /> Command="{Binding AllLandCommand}" />
<Button Content="测试电机"
Command="{Binding MotorTestCommand}" />
<Button Content="全部加锁" <Button Content="全部加锁"
Command="{Binding LockAllCommand}" /> Command="{Binding LockAllCommand}" />
<Button Content="检测电压" <Button Content="检测电压"
Command="{Binding DetectionVoltage}" /> Command="{Binding DetectionVoltage}" />
<Button Content="统计返回"
Command="{Binding DetectionReturnData}" />
<Button Content="统计航点"
Command="{Binding DetectionMissionData}" />
</WrapPanel> </WrapPanel>
<WrapPanel> <WrapPanel>
<Button Content="写入航点" <Button Content="写入航点"
Command="{Binding WriteMissionCommand}" /> Command="{Binding WriteMissionCommand}" />
<Button Content="全部解锁" <Button Content="全部解锁"
Command="{Binding UnlockAllCommand}" /> Command="{Binding UnlockAllCommand}" />
<Button Content="开始任务" <Button Content="开始任务"
Command="{Binding MissionStartCommand}" /> Command="{Binding MissionStartCommand}" />
<Button Content="暂停任务"
Command="{Binding MissionPauseCommand}" />
<Button Content="继续任务"
Command="{Binding MissionResumeCommand}" />
</WrapPanel> </WrapPanel>
<WrapPanel> <WrapPanel>
<Button Content="航点续写"
Command="{Binding WriteMissionFailedCommand}" />
<TextBox <TextBox
Grid.Column="1" Grid.Column="1"
Width="55" Width="55"
@ -94,6 +112,7 @@
HorizontalContentAlignment="Right" HorizontalContentAlignment="Right"
Text="{Binding RTKcomvalue, UpdateSourceTrigger=PropertyChanged}" Text="{Binding RTKcomvalue, UpdateSourceTrigger=PropertyChanged}"
/> />
<Button Content="{Binding Path=RTKbtntxt}" <Button Content="{Binding Path=RTKbtntxt}"
Command="{Binding SendRTKCommand}" /> Command="{Binding SendRTKCommand}" />

View File

@ -50,7 +50,7 @@
</StackPanel> </StackPanel>
<StackPanel> <StackPanel>
<TextBlock Text="已连接:" /> <TextBlock Text="已连接:" />
<ContentPresenter Content="{Binding IsConnected, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" /> <ContentPresenter Content="{Binding CommModuleConnected, Converter={StaticResource CheckSignConverter}, Mode=OneWay}" />
</StackPanel> </StackPanel>
<StackPanel> <StackPanel>
<TextBlock Text="已解锁:" /> <TextBlock Text="已解锁:" />
@ -92,7 +92,18 @@
<TextBlock Text="锁定类型:" /> <TextBlock Text="锁定类型:" />
<TextBlock Text="{Binding GpsFixType}" /> <TextBlock Text="{Binding GpsFixType}" />
</StackPanel> </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> <StackPanel>
<TextBlock Text="固件版本:" /> <TextBlock Text="固件版本:" />
<TextBlock Text="{Binding FirmwareVersionText}" /> <TextBlock Text="{Binding FirmwareVersionText}" />
@ -139,7 +150,7 @@
</StackPanel> </StackPanel>
<StackPanel> <StackPanel>
<TextBlock Text="状态:" /> <TextBlock Text="状态:" />
<TextBlock Text="{Binding Path=State}" /> <TextBlock Text="{Binding Path=CommModuleMode}" />
</StackPanel> </StackPanel>
<StackPanel> <StackPanel>
<TextBlock Text="纬度:" /> <TextBlock Text="纬度:" />

View File

@ -34,7 +34,7 @@
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<CheckBox Width="20" <CheckBox Width="20"
IsChecked="{Binding IsConnected, Mode=OneWay}" IsChecked="{Binding CommModuleConnected, Mode=OneWay}"
IsEnabled="False"/> IsEnabled="False"/>
<Rectangle Width="15" <Rectangle Width="15"
Height="15" Height="15"

View File

@ -38,13 +38,6 @@ namespace Plane.FormationCreator.Views
{ {
_copterManager.RaiseSelectedCoptersChanged(e.AddedItems.Cast<ICopter>(), e.RemovedItems.Cast<ICopter>()); _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>(); private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();

View File

@ -82,6 +82,7 @@ namespace Plane.FormationCreator.Views
{ {
var copterDrawing = item.Value; var copterDrawing = item.Value;
copterDrawing.SetTaskEffect(_flightTaskManager.SelectedTaskIndex); copterDrawing.SetTaskEffect(_flightTaskManager.SelectedTaskIndex);
copterDrawing.ResetRoute(_flightTaskManager.SelectedTaskIndex);
} }
break; break;
case nameof(FlightTaskManager.RightSelectedTaskIndex): // 单击右键触发 case nameof(FlightTaskManager.RightSelectedTaskIndex): // 单击右键触发
@ -197,10 +198,11 @@ namespace Plane.FormationCreator.Views
if (rectangle != null && map.Children.Contains(rectangle)) if (rectangle != null && map.Children.Contains(rectangle))
{ {
map.Children.Remove(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.shiftkeydown = true;
_copterManager.Select(null);
foreach (FlightTaskSingleCopterInfo taskCopterInfo in _flightTaskManager.SelectedTask.SingleCopterInfos) foreach (FlightTaskSingleCopterInfo taskCopterInfo in _flightTaskManager.SelectedTask.SingleCopterInfos)
{ {
Location seekLocation = new Location(taskCopterInfo.TargetLat, taskCopterInfo.TargetLng); Location seekLocation = new Location(taskCopterInfo.TargetLat, taskCopterInfo.TargetLng);

View File

@ -187,10 +187,10 @@ namespace Plane.FormationCreator.Views
this.Route.Stroke = _brush; this.Route.Stroke = _brush;
this.Route.StrokeThickness = 2.0; this.Route.StrokeThickness = 2.0;
//显示计划航线 //显示计划航线
// _map.Children.Add(this.Route); // _map.Children.Add(this.Route);
this.LastLocation = location; this.LastLocation = location;
@ -244,7 +244,6 @@ namespace Plane.FormationCreator.Views
if (locationUpdated) if (locationUpdated)
{ {
Track.Locations.Add(location); Track.Locations.Add(location);
this.Route.Locations[0] = location;
MapLayer.SetPosition(Dot.Parent, location); MapLayer.SetPosition(Dot.Parent, location);
this.LastLocation = location; this.LastLocation = location;
} }
@ -273,9 +272,6 @@ namespace Plane.FormationCreator.Views
SetEffect(_copterManager.SelectedCopters.Contains(Copter)); SetEffect(_copterManager.SelectedCopters.Contains(Copter));
// Add route point.
Route.Locations.Add(location);
// Register event handlers. // Register event handlers.
RegisterEventHandlersForDraggingWaypoint(shapesContainer, taskIndex: Waypoints.Count); RegisterEventHandlersForDraggingWaypoint(shapesContainer, taskIndex: Waypoints.Count);
@ -311,9 +307,9 @@ namespace Plane.FormationCreator.Views
var center = _map.ViewportPointToLocation(pos); var center = _map.ViewportPointToLocation(pos);
var routePoint = this.Route.Locations[0]; // var routePoint = this.Route.Locations[0];
routePoint.Latitude = center.Latitude; // routePoint.Latitude = center.Latitude;
routePoint.Longitude = center.Longitude; // routePoint.Longitude = center.Longitude;
var fc = Copter as FakeCopter; var fc = Copter as FakeCopter;
fc.SetProperties( 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 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.Latitude = _map.ViewportPointToLocation(leftTopPos).Latitude;
routePoint.Longitude = _map.ViewportPointToLocation(leftTopPos).Longitude; routePoint.Longitude = _map.ViewportPointToLocation(leftTopPos).Longitude;
MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos)); MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos));
@ -425,10 +421,10 @@ namespace Plane.FormationCreator.Views
var centerPos = _map.LocationToViewportPoint(centerLocation); var centerPos = _map.LocationToViewportPoint(centerLocation);
var leftTopPos = new Point(centerPos.X, centerPos.Y); var leftTopPos = new Point(centerPos.X, centerPos.Y);
MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos)); MapLayer.SetPosition(wp, _map.ViewportPointToLocation(leftTopPos));
var routePoint = Route.Locations[taskIndex]; var routePoint = Route.Locations[1];
routePoint.Latitude = info.TargetLat; routePoint.Latitude = info.TargetLat;
routePoint.Longitude = info.TargetLng; routePoint.Longitude = info.TargetLng;
routePoint.Altitude = info.TargetAlt; routePoint.Altitude = info.TargetAlt;
} }
break; break;
} }
@ -455,7 +451,11 @@ namespace Plane.FormationCreator.Views
{ {
if (showroute ?? false ) if (showroute ?? false )
_map.Children.Add(this.Route); {
_map.Children.Add(this.Route);
MapLayer.SetZIndex(this.Route, 99);
}
else else
_map.Children.Remove(this.Route); _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) public void SetTaskEffect(int taskIndex)
{ {
var wpIndex = taskIndex - 1; // Waypoints 中没有起飞点。 var wpIndex = taskIndex - 1; // Waypoints 中没有起飞点。
@ -526,10 +544,13 @@ namespace Plane.FormationCreator.Views
wp.Visibility = Visibility.Hidden; wp.Visibility = Visibility.Hidden;
//Route.Visibility = Visibility.Hidden; //Route.Visibility = Visibility.Hidden;
//Route.Children.RemoveAt(1); //Route.Children.RemoveAt(1);
//Route.Locations.RemoveAt(taskIndex);
} }
else else
{ {
wp.Visibility = Visibility.Visible; 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; //Route.Visibility = Visibility.Visible;
} }

View File

@ -129,16 +129,11 @@
Text="100" Text="100"
VerticalContentAlignment="Center" /> VerticalContentAlignment="Center" />
<TextBlock Text="%" Margin="0, 10, 5, 0"/> <TextBlock Text="%" Margin="0, 10, 5, 0"/>
<Button Content="计算距离" <Button Content="最小距离"
Margin="0,5,5,0" Margin="0,5,5,0"
Command="{Binding calDistinceCommand}"/> 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="前一高度" <Button Content="前一高度"
Margin="0,5,5,0" Margin="0,5,5,0"
Command="{Binding PrealtCommand}" /> Command="{Binding PrealtCommand}" />

View File

@ -117,7 +117,7 @@
<RowDefinition/> <RowDefinition/>
<RowDefinition/> <RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Height="100" Background="#FF2D2D2D"> <StackPanel Height="100" Background="#FF2D2D2D" >
<TabControl <TabControl
DataContext="{Binding FlightTaskManager.SelectedTask}" DataContext="{Binding FlightTaskManager.SelectedTask}"
@ -149,10 +149,12 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="飞行时间: " /> <TextBlock Grid.Row="0" Text="飞行时间: " />
<TextBox Grid.Column="1" Margin="2" <TextBox Grid.Column="1" Margin="2"
Text="{Binding FlytoTime, UpdateSourceTrigger=PropertyChanged}" /> MaxLength="4"
Text="{Binding FlytoTime, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="1" Text="悬停时间: " /> <TextBlock Grid.Row="1" Text="悬停时间: " />
<TextBox Grid.Row="1" Grid.Column="1" Margin="2" <TextBox Grid.Row="1" Grid.Column="1" Margin="2"
Text="{Binding LoiterTime, UpdateSourceTrigger=PropertyChanged}" /> MaxLength="4"
Text="{Binding LoiterTime, UpdateSourceTrigger=PropertyChanged}" />
</Grid> </Grid>
</TabItem> </TabItem>
@ -165,9 +167,7 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Text="等待时间: " />
<TextBox Grid.Column="1" Margin="2"
Text="{Binding LandWaitTime, UpdateSourceTrigger=PropertyChanged}" />
</Grid> </Grid>
</TabItem> </TabItem>

View File

@ -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";
// }
}
} }
} }