修改一些小问题

[App.xaml.cs]修复Checkbox无法显示对勾
[FlightTaskManager.cs]增加选中闪烁,悬停机头控制
[FlightTask_LoiterTime.cs]改变机头方向和灯的闪烁方式
[FlightTask_TakeOff.cs] 解锁起飞开始亮灯(暂时没启用)
[MainWindow.xaml.cs]增加C按键控制灯开关,机头转向采用以前的方法
[ModifyTaskView.xaml]增加机头方向设置显示
This commit is contained in:
pxzleo 2017-03-10 19:58:18 +08:00
parent 57ff775913
commit 517146971f
6 changed files with 169 additions and 16 deletions

View File

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

View File

@ -47,6 +47,7 @@ namespace Plane.FormationCreator.Formation
}
}
}
selectedCopter.SetShowLEDFlashAsync(1, 100);
};
TaskAdded += (sender, e) =>
@ -349,6 +350,7 @@ 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 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);

View File

@ -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,11 +148,23 @@ namespace Plane.FormationCreator.Formation
public async Task RunLoiterTimeTaskAsync()
{
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();
@ -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);
}

View File

@ -143,6 +143,7 @@ namespace Plane.FormationCreator.Formation
{
return;
}
//await copter.SetShowLEDAsync(true);
await copter.UnlockAsync();
for (int i = 0; !copter.IsUnlocked; i++)
{

View File

@ -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;
@ -291,6 +311,7 @@ namespace Plane.FormationCreator
// await copter.SetMobileControlAsync(yaw: (copter.Yaw + (e.Key == Key.J ? -10 : 10)) % 360);
await copter.SetChannelsAsync(ch4: 1500);
})).ConfigureAwait(false);
break;
}
case Key.M: // 停止低速下降。

View File

@ -266,17 +266,18 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="悬停时间: " />
<TextBlock Text="悬停时间:(秒) " />
<TextBox Grid.Column="1"
Text="{Binding LoiterTimeAttr, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="闪烁: " />
<TextBlock Grid.Row="1" Grid.Column="0" Text="闪烁:(次数) " />
<Grid Grid.Row="1" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition />
@ -307,6 +308,20 @@
</Grid>
<TextBox Grid.Row="3" Grid.ColumnSpan="2" IsReadOnly="True" Text="{Binding flashCopterNameArray, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="机头方向: " />
<Grid Grid.Row="4" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<CheckBox Grid.Row="0" Grid.Column="0"
IsChecked="{Binding ChangeYaw, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="1" Grid.Row="0"
Text="{Binding HeadYaw, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</Grid>
</Grid>
</Grid>