diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs
index d089e63..f8b5748 100644
--- a/Plane.FormationCreator/App.xaml.cs
+++ b/Plane.FormationCreator/App.xaml.cs
@@ -80,7 +80,7 @@ namespace Plane.FormationCreator
base.OnStartup(e);
var md = Resources.MergedDictionaries;
- md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") });
+ // md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml") });
md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml") });
md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml") });
md.Add(new ResourceDictionary { Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml") });
diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs
index 07b8ea3..7420df7 100644
--- a/Plane.FormationCreator/Formation/FlightTaskManager.cs
+++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs
@@ -47,6 +47,7 @@ namespace Plane.FormationCreator.Formation
}
}
}
+ selectedCopter.SetShowLEDFlashAsync(1, 100);
};
TaskAdded += (sender, e) =>
@@ -348,7 +349,8 @@ namespace Plane.FormationCreator.Formation
// added by ZJF
private void RestoreLoiterTimeTask(float LoiteTimeTmp, bool flashCheck, float flashCheckPeriod,
- bool oneByOneCheck, float oneByOneCheckPeriod, string flashNameArray, string flashIndexArray,
+ bool oneByOneCheck, float oneByOneCheckPeriod, string flashNameArray, string flashIndexArray,
+ bool ChangeYaw, float HeadYaw,
dynamic singleCopterInfos)
{
var copters = _copterManager.Copters;
@@ -366,6 +368,9 @@ namespace Plane.FormationCreator.Formation
loiterTimeTask.oneByOnePeriodAttr = oneByOneCheckPeriod;
loiterTimeTask.flashCopterNameArray = flashNameArray;
loiterTimeTask.flashCopterIndexArray = flashIndexArray;
+ loiterTimeTask.ChangeYaw = ChangeYaw;
+ loiterTimeTask.HeadYaw = HeadYaw;
+
// foreach (var copter in copters)
for (int i=0; i < copters.Count && i < singleCopterInfos.Count; i++)
{
@@ -523,6 +528,10 @@ namespace Plane.FormationCreator.Formation
oneByOneCheckPeriod = task.oneByOnePeriodAttr,
flashNameArray = task.flashCopterNameArray,
flashIndexArray = task.flashCopterIndexArray,
+ ChangeYaw = task.ChangeYaw,
+ HeadYaw = task.HeadYaw,
+
+
singleCopterInfos = task.SingleCopterInfos.Select(info =>
{
var offset = info.LatLngOffset;
@@ -607,7 +616,8 @@ namespace Plane.FormationCreator.Formation
case FlightTaskType.Loiter:
RestoreLoiterTimeTask( (float)task.loiterTimeAttr, (bool)task.flashCheck, (float)task.flashCheckPeriod,
(bool)task.oneByOneCheck, (float)task.oneByOneCheckPeriod, (string)task.flashNameArray,
- (string)task.flashIndexArray, task.singleCopterInfos);
+ (string)task.flashIndexArray, (bool)task.ChangeYaw, (float)task.HeadYaw, task.singleCopterInfos);
+
break;
case FlightTaskType.SimpleCircle:
RestoreSimpleCircleTask(task.singleCopterInfos);
diff --git a/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs b/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs
index 15e0ba5..7721501 100644
--- a/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs
+++ b/Plane.FormationCreator/Formation/FlightTask_LoiterTime.cs
@@ -18,6 +18,33 @@ namespace Plane.FormationCreator.Formation
}
}
+
+
+
+ // 改变机头
+ private bool _ChangeYaw = false;
+ public bool ChangeYaw
+ {
+ get { return _ChangeYaw; }
+ set
+ {
+ Set(nameof(ChangeYaw), ref _ChangeYaw, value);
+ }
+ }
+
+ // 机头方向0为北,顺时针360
+ private float _HeadYaw = 1.0f;
+ public float HeadYaw
+ {
+ get { return _HeadYaw; }
+ set
+ {
+ Set(nameof(HeadYaw), ref _HeadYaw, value);
+ }
+ }
+
+
+
// LED灯闪烁
private bool _flashAttr = false;
public bool flashAttr
@@ -121,12 +148,24 @@ namespace Plane.FormationCreator.Formation
public async Task RunLoiterTimeTaskAsync()
{
- // 判断flashPeriodAttr, oneByOnePeriodAttr的值,执行不同的闪烁模式
- // 当flashPeriodAttr小于10,正常闪烁,即没有预制闪烁模式
- // 当flashPeriodAttr大于等于10,小于20,执行预制闪烁模式
- // 当flashPeriodAttr大于等于20, 改变飞控闪烁模式,以oneByOnePeriodAttr作为周期值
- if ((flashPeriodAttr >= 10.0f) && (flashPeriodAttr < 20.0f))
+ if (ChangeYaw)
+ {
+ await Task.WhenAll(SingleCopterInfos.Select(info => SetCopterYawAsync(info,HeadYaw)));
+ }
+
+
+
+
+
+
+
+
+ // 判断flashPeriodAttr, oneByOnePeriodAttr的值,执行不同的闪烁模式
+ // 当flashPeriodAttr小于10,正常闪烁,即没有预制闪烁模式
+ // 当flashPeriodAttr大于等于10,小于20,执行预制闪烁模式
+ // 当flashPeriodAttr大于等于20, 改变飞控闪烁模式,以oneByOnePeriodAttr作为周期值
+ if ((flashPeriodAttr >= 10.0f) && (flashPeriodAttr < 20.0f))
{
await LEDFlashPlanAsync();
return;
@@ -258,11 +297,58 @@ namespace Plane.FormationCreator.Formation
}
await Task.WhenAll(tasks_selected).ConfigureAwait(false);
}
+ private async Task SetCopterYawAsync(FlightTaskSingleCopterInfo info, float headyaw)
+ {
+ var copter = info.Copter;
+ // await Task.Delay(200).ConfigureAwait(false);
+
+ var tasks = new Task[1];
+ tasks[0] = Task.Run(async () =>
+ {
+ try
+ {
+ await copter.SetMobileControlAsync(yaw: headyaw);
+
+ while (!copter.ArrivedHeading((short)headyaw))
+ {
+ if (_flightTaskManager.IsPaused == true)
+ {
+ await info.Copter.HoverAsync();
+ return;
+ }
+ await Task.Delay(25).ConfigureAwait(false);
+ }
+ }
+ catch (TimeoutException ex)
+ {
+ _logger.Log($"SetYAWtimeout, {ex.Message}, CopterId: {copter.Id}。");
+ }
+ });
+ await Task.WhenAll(tasks).ConfigureAwait(false);
+ }
private async Task LEDParaModifySingleCopterAsync(FlightTaskSingleCopterInfo info, float count)
{
var copter = info.Copter;
-
+
+ var tasks = new Task[1];
+ tasks[0] = Task.Run(async () =>
+ {
+ try
+ {
+ if (count == 1.0)
+ await copter.SetShowLEDAsync(true);
+ else
+ await copter.SetShowLEDAsync(false);
+ //await copter.SetParamAsync("NTF_SHOWLED", count, 5000);
+ }
+ catch (TimeoutException ex)
+ {
+ _logger.Log($"SetShowLEDAsync 超时, {ex.Message}, CopterId: {copter.Id}。");
+ }
+ });
+
+ /*
var tasks = new Task[2];
tasks[0] = Task.Run(async () =>
{
@@ -286,6 +372,7 @@ namespace Plane.FormationCreator.Formation
_logger.Log($"NOTI_ARMLED 超时, {ex.Message}, CopterId: {copter.Id}。");
}
});
+ */
await Task.WhenAll(tasks).ConfigureAwait(false);
}
@@ -296,11 +383,29 @@ namespace Plane.FormationCreator.Formation
{
var copter = info.Copter;
// float gpsLed = await c.GetParamAsync("NOTI_GPSLED");
- float ledControl = 0.0f;
+
+ /*
+ float ledControl = 0.0f; //关灯
if (isOn)
{
- ledControl = 1.0f;
+ ledControl = 1.0f; //长亮
}
+ */
+ var tasks = new Task[1];
+ tasks[0] = Task.Run(async () =>
+ {
+ try
+ {
+ await copter.SetShowLEDAsync(isOn);
+ // await copter.SetParamAsync("NTF_SHOWLED", ledControl, 5000);
+ }
+ catch (TimeoutException ex)
+ {
+ _logger.Log($"SetShowLED 超时, {ex.Message}, CopterId: {copter.Id}。");
+ }
+ });
+
+ /*
var tasks = new Task[2];
tasks[0] = Task.Run(async () =>
{
@@ -324,6 +429,7 @@ namespace Plane.FormationCreator.Formation
_logger.Log($"NOTI_ARMLED 超时, {ex.Message}, CopterId: {copter.Id}。");
}
});
+ */
await Task.WhenAll(tasks).ConfigureAwait(false);
}
diff --git a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs
index 0d2ba85..98ad9f5 100644
--- a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs
+++ b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs
@@ -143,6 +143,7 @@ namespace Plane.FormationCreator.Formation
{
return;
}
+ //await copter.SetShowLEDAsync(true);
await copter.UnlockAsync();
for (int i = 0; !copter.IsUnlocked; i++)
{
diff --git a/Plane.FormationCreator/MainWindow.xaml.cs b/Plane.FormationCreator/MainWindow.xaml.cs
index a8678ec..1bc63cf 100644
--- a/Plane.FormationCreator/MainWindow.xaml.cs
+++ b/Plane.FormationCreator/MainWindow.xaml.cs
@@ -101,8 +101,23 @@ namespace Plane.FormationCreator
if (e.OriginalSource is TextBox || e.OriginalSource is PasswordBox) return;
var isInFastMode = AppEx.Current.IsInFastMode;
+ bool isledon;
switch (e.Key)
{
+ //开关SHOWLED
+ case Key.C:
+ {
+
+ var copters = _copterManager.AcceptingControlCopters;
+ await Task.WhenAll(copters.Select(async copter =>
+ {
+ isledon = await copter.GetShowLEDAsync();
+ await copter.SetShowLEDAsync(!isledon);
+ })).ConfigureAwait(false);
+
+ break;
+ }
+ //俯仰控制
case Key.W:
case Key.S:
{
@@ -120,6 +135,7 @@ namespace Plane.FormationCreator
})).ConfigureAwait(false);
break;
}
+ //横滚控制
case Key.A:
case Key.D:
{
@@ -137,6 +153,7 @@ namespace Plane.FormationCreator
})).ConfigureAwait(false);
break;
}
+ //高度控制
case Key.I:
case Key.K:
{
@@ -154,13 +171,14 @@ namespace Plane.FormationCreator
})).ConfigureAwait(false);
break;
}
+ //航向控制
case Key.J:
case Key.L:
{
var copters = _copterManager.AcceptingControlCopters;
await Task.WhenAll(copters.Select(async copter =>
{
- //await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 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);
})).ConfigureAwait(false);
break;
@@ -196,6 +214,7 @@ namespace Plane.FormationCreator
}
break;
}
+ //设置6通道
case Key.P:
{
var copters = _copterManager.AcceptingControlCopters;
@@ -219,6 +238,7 @@ namespace Plane.FormationCreator
})).ConfigureAwait(false);
break;
}
+ //设置7通道
case Key.O:
{
var copters = _copterManager.AcceptingControlCopters;
@@ -288,9 +308,10 @@ namespace Plane.FormationCreator
var copters = _copterManager.AcceptingControlCopters;
await Task.WhenAll(copters.Select(async copter =>
{
- //await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360);
+ // await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360);
await copter.SetChannelsAsync(ch4: 1500);
})).ConfigureAwait(false);
+
break;
}
case Key.M: // 停止低速下降。
diff --git a/Plane.FormationCreator/Views/ModifyTaskView.xaml b/Plane.FormationCreator/Views/ModifyTaskView.xaml
index 952ef55..a8f9b40 100644
--- a/Plane.FormationCreator/Views/ModifyTaskView.xaml
+++ b/Plane.FormationCreator/Views/ModifyTaskView.xaml
@@ -99,7 +99,7 @@
-
+
-
+
-
+
@@ -307,6 +308,20 @@
+
+
+
+
+
+
+
+
+
+
+
+