去掉飞行时间,飞行距离,姿态计算和更新,提高效率

碰撞检测改为异步提示,检测间隔缩小为50ms
修改任务无法停止的bug
不多次发送目标航点
地图上选中变为红色
地图中间加入十字标记,用于精确确定添加飞机位置
This commit is contained in:
xu 2020-01-28 22:47:49 +08:00
parent c0fa7d8ddb
commit 7ea00c6855
6 changed files with 60 additions and 22 deletions

View File

@ -449,15 +449,19 @@ namespace Plane.FormationCreator.Formation
public async void ResetTasks()
{
var copters = _copterManager.Copters;
Pause();
//等待暂停或2s超时(80*25ms)
int k = 0;
while ((TaskState != TasksStatus.Paused) || (k > 80))
{
await Task.Delay(25).ConfigureAwait(false);
k++;
}
if (TaskState == TasksStatus.Running)
{
Pause();
//等待暂停或2s超时(80*25ms)
int k = 0;
while ((TaskState != TasksStatus.Paused) || (k > 80))
{
await Task.Delay(25).ConfigureAwait(false);
k++;
}
}
CurrentRunningTaskIndex = 0;
if (CurrentRunningTask != null)
@ -1954,11 +1958,41 @@ namespace Plane.FormationCreator.Formation
#endregion Run and pause.
Dictionary<int, string> AvoidCrashLog = new Dictionary<int, string >();
private async void StartAvoidingCrash()
{
await Task.Factory.StartNew(AvoidCrashtoshow);
await Task.Factory.StartNew(LoopToAvoidCrash);
}
private async void AvoidCrashtoshow()
{
while (IsPaused == false)
{
try
{
foreach (KeyValuePair<int, string> kv in AvoidCrashLog)
{
string moveCopterNum = kv.Value;
int destNum = kv.Key;
Message.Show(moveCopterNum);
}
AvoidCrashLog.Clear();
}
catch // 林俊清, 20151102, 通常是“集合已修改”异常。
{
}
finally
{
await Task.Delay(100).ConfigureAwait(false);
}
}
}
private async void LoopToAvoidCrash()
{
while (IsPaused == false)
@ -1977,7 +2011,9 @@ namespace Plane.FormationCreator.Formation
{
if (copter != anotherCopter && copter.IsTooCloseTo(anotherCopter, out distance))
{
Message.Show($"{copter.Name} 与 {anotherCopter.Name} 距离过近,间距{distance}米。");
//防止卡顿
AvoidCrashLog.Add(1, $"{copter.Name} 与 {anotherCopter.Name} 距离过近,间距{distance}米。");
// Message.Show($"{copter.Name} 与 {anotherCopter.Name} 距离过近,间距{distance}米。");
}
}
}
@ -1989,7 +2025,7 @@ namespace Plane.FormationCreator.Formation
}
finally
{
await Task.Delay(100).ConfigureAwait(false);
await Task.Delay(50).ConfigureAwait(false);
}
}
}

View File

@ -162,8 +162,8 @@ namespace Plane.FormationCreator.Formation
}
//发送目标航点1次
await info.Copter.FlyToAsync(targetLat, targetLng, info.TargetAlt);
await Task.Delay(10).ConfigureAwait(false);
await info.Copter.FlyToAsync(targetLat, targetLng, info.TargetAlt);
// await Task.Delay(10).ConfigureAwait(false);
dtNow = DateTime.Now;
ts = dtNow - dtLastTime;
@ -233,7 +233,7 @@ namespace Plane.FormationCreator.Formation
}
/*
if (ts.TotalMilliseconds / 10 > sendFlyToTimes) // 每500ms发送一遍指点坐标
{
sendFlyToTimes++;
@ -245,6 +245,7 @@ namespace Plane.FormationCreator.Formation
//dtLastTime = dtNow;
}
*/
// 当该飞机被标记时,悬停并跳过飞行任务
if ((bool)_copterManager.CopterStatus[copterIndex])
{

View File

@ -128,11 +128,11 @@ namespace Plane.FormationCreator.Formation
info.TargetLat = info.Copter.Latitude;
info.TargetLng = info.Copter.Longitude;
for (int j = 0; j < 3; j++)
{
// for (int j = 0; j < 3; j++)
// {
await info.Copter.FlyToAsync(info.TargetLat, info.TargetLng, takeOffAlt);
await Task.Delay(10).ConfigureAwait(false);
}
// await Task.Delay(10).ConfigureAwait(false);
// }
//解锁起飞用暗紫色
info.Copter.LEDColor = "FF00FF";

View File

@ -229,7 +229,7 @@ namespace Plane.FormationCreator.ViewModels
LatLng? colLatLng = new LatLng(center.Lat, center.Lng); ;
LatLng? colLatLng = new LatLng(center.Lat, center.Lng);
for (int i = 0; i < addcount; ++i, ++_virtualCopterId)
{

View File

@ -50,7 +50,7 @@ namespace Plane.FormationCreator.Views
gmap.MinZoom = 2; //最小缩放
gmap.MaxZoom = 30; //最大缩放
gmap.Zoom = 19; //当前缩放
gmap.ShowCenter = false; //不显示中心十字点
gmap.ShowCenter = true; //不显示中心十字点
gmap.DragButton = MouseButton.Middle; //左键拖拽地图
gmap.Position = new LatLng(40.07734857737275, 116.34323845862502).ToGCJ02();
@ -60,6 +60,7 @@ namespace Plane.FormationCreator.Views
_flightTaskManager.TaskAdded += FlightTaskManager_TaskAdded;
_flightTaskManager.OnOriginalSet += FlightTaskManager_SetOriginal;
/*
Task.Factory.StartNew(async () =>
{
int delay = 500;
@ -73,7 +74,7 @@ namespace Plane.FormationCreator.Views
await Task.Delay(delay);
}
});
*/
_copterManager.SelectedCoptersChanged += (sender, e) =>
{
//if (AppEx.Instance.CurrentMode.IsForTasks())

View File

@ -64,7 +64,7 @@ namespace Plane.FormationCreator.Views
selectMarkup.Height = 7;
selectMarkup.HorizontalAlignment = HorizontalAlignment.Left;
selectMarkup.VerticalAlignment = VerticalAlignment.Top;
selectMarkup.Fill = new SolidColorBrush(Colors.Black);
selectMarkup.Fill = new SolidColorBrush(Colors.Red); //选中做红色标记
}
Rectangle selectMarkup = new Rectangle();