[FlightTaskManager.cs]让新任务高度等于前一任务高度

[ControlPanelViewModel.cs]解锁测试尽量和实际起飞操作一致
This commit is contained in:
pxzleo 2017-04-13 08:07:43 +08:00
parent 17c717db9e
commit bdad49ce6d
2 changed files with 91 additions and 10 deletions

View File

@ -227,9 +227,11 @@ namespace Plane.FormationCreator.Formation
Tuple<double, double> colLatLng = new Tuple<double, double>(0, 0);
Tuple<double, double> targetLatLng = new Tuple<double, double>(0, 0);
FlightTaskSingleCopterInfo lastSingleCopterInfo = null;
FlightTaskSingleCopterInfo preSingleCopterInfo = null;
foreach (var copter in copters)
{
preSingleCopterInfo = lastTask.SingleCopterInfos.Find(info => info.Copter == copter);
if (coptindex == 0)
{
lastSingleCopterInfo = lastTask.SingleCopterInfos.Find(info => info.Copter == copter);
@ -252,7 +254,7 @@ namespace Plane.FormationCreator.Formation
coptindex++;
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, targetLatLng.Item1, targetLatLng.Item2, lastSingleCopterInfo.TargetAlt, true);
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, targetLatLng.Item1, targetLatLng.Item2, preSingleCopterInfo.TargetAlt, true);
newSingleCopterInfo.TargetHeading = lastSingleCopterInfo.TargetHeading;
newSingleCopterInfo.CenterDirectionDeg = lastSingleCopterInfo.TargetHeading;
newTask.SingleCopterInfos.Add(newSingleCopterInfo);
@ -289,6 +291,7 @@ namespace Plane.FormationCreator.Formation
public void ForceNextTasks()
{
Pause();
//起飞任务需要跳过
if (CurrentRunningTaskIndex == 0)
CurrentRunningTaskIndex++;
CurrentRunningTaskIndex++;

View File

@ -251,6 +251,62 @@ namespace Plane.FormationCreator.ViewModels
}
}
private async Task UnlockTestSingleCopterAsync(ICopter SingleCopter)
{
await SingleCopter.UnlockAsync();
await Task.Delay(25).ConfigureAwait(false);
for (int i = 0; !SingleCopter.IsUnlocked; i++)
{
//5秒内每1000毫秒尝试解锁一次
//解锁间隔一定要超过1s否则导致飞控以后无法解锁
if (i > 200)
return; //无法解锁后面不用执行了
if (i % (1000 / 25) == 1000 / 25 - 1)
{
await SingleCopter.UnlockAsync(); // 每 1000 毫秒重试一次。
}
await Task.Delay(25).ConfigureAwait(false);
}
await Task.Delay(1000);
if (SingleCopter.IsUnlocked)
{
await SingleCopter.SetShowLEDAsync(true);
await Task.Delay(50);
await SingleCopter.SetShowLEDAsync(true);
}
await Task.Delay(5000);
await SingleCopter.LockAsync();
await Task.Delay(25).ConfigureAwait(false);
for (int i = 0; SingleCopter.IsUnlocked; i++)
{
//5秒内每1000毫秒尝试解锁一次
//解锁间隔一定要超过1s否则导致飞控以后无法解锁
if (i > 200)
return; //无法解锁后面不用执行了
if (i % (1000 / 25) == 1000 / 25 - 1)
{
await SingleCopter.LockAsync(); // 每 1000 毫秒重试一次。
}
await Task.Delay(25).ConfigureAwait(false);
}
await Task.Delay(1000);
if (!SingleCopter.IsUnlocked)
{
await SingleCopter.SetShowLEDAsync(false);
await Task.Delay(50);
await SingleCopter.SetShowLEDAsync(false);
}
}
private ICommand _TestCommand;
public ICommand TestCommand
{
@ -259,24 +315,46 @@ namespace Plane.FormationCreator.ViewModels
return _TestCommand ?? (_TestCommand = new RelayCommand(async () =>
{
foreach (var vcopter in _copterManager.Copters)
{
await vcopter.UnlockAsync();
Message.Show("解锁测试--开始");
int i = 0;
var tasksUnlockTest = new Task[_copterManager.Copters.Count];
foreach (var vcopter in _copterManager.Copters)
{
tasksUnlockTest[i++] = UnlockTestSingleCopterAsync(vcopter);
//i++;
}
await Task.WhenAll(tasksUnlockTest).ConfigureAwait(false);
Message.Show("解锁测试--完成!");
return;
foreach (var vcopter in _copterManager.Copters)
{
await vcopter.UnlockAsync();
}
await Task.Delay(1000);
foreach (var vcopter in _copterManager.Copters)
{
if (vcopter.IsUnlocked)
await vcopter.SetShowLEDAsync(true);
await vcopter.SetShowLEDAsync(true);
}
await Task.Delay(5000);
await Task.Delay(5000);
foreach (var vcopter in _copterManager.Copters)
{
await vcopter.LockAsync();
await vcopter.SetShowLEDAsync(false);
foreach (var vcopter in _copterManager.Copters)
{
await vcopter.LockAsync();
await vcopter.SetShowLEDAsync(false);
}