加入飞行任务时间和悬停时间保存到航点文件

加入从文件读取的设置
灯光控制改到设置按钮里面,还没有做
This commit is contained in:
panxu 2018-05-24 11:57:23 +08:00
parent 475993d357
commit bc8373363d
5 changed files with 74 additions and 23 deletions

View File

@ -262,7 +262,7 @@ namespace Plane.FormationCreator.Formation
coptindex++; coptindex++;
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, targetLatLng.Item1, targetLatLng.Item2, preSingleCopterInfo.TargetAlt, true); var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, targetLatLng.Item1, targetLatLng.Item2, preSingleCopterInfo.TargetAlt, 10,10);
newSingleCopterInfo.TargetHeading = lastSingleCopterInfo.TargetHeading; newSingleCopterInfo.TargetHeading = lastSingleCopterInfo.TargetHeading;
newSingleCopterInfo.CenterDirectionDeg = lastSingleCopterInfo.TargetHeading; newSingleCopterInfo.CenterDirectionDeg = lastSingleCopterInfo.TargetHeading;
newTask.SingleCopterInfos.Add(newSingleCopterInfo); newTask.SingleCopterInfos.Add(newSingleCopterInfo);
@ -380,13 +380,19 @@ namespace Plane.FormationCreator.Formation
{ {
var singleCopterInfoObj = singleCopterInfos[i]; var singleCopterInfoObj = singleCopterInfos[i];
tagalt = (float)singleCopterInfoObj.targetAlt; tagalt = (float)singleCopterInfoObj.targetAlt;
newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, new LatLng((double)singleCopterInfoObj.latOffset, (double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt, (bool)singleCopterInfoObj.showLED); newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(
copter, new LatLng((double)singleCopterInfoObj.latOffset,
(double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt,
(int)singleCopterInfoObj.flytoTime,
(int)singleCopterInfoObj.loiterTime);
} }
else else
{ {
//实际飞机比保存的任务计划的飞机多,多的飞机设置默认航点
newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask
(copter, (double)copter.Latitude, (double)copter.Longitude, tagalt, (bool)false); (copter, (double)copter.Latitude, (double)copter.Longitude, tagalt, 10,10
);
} }
newTask.SingleCopterInfos.Add(newSingleCopterInfo); newTask.SingleCopterInfos.Add(newSingleCopterInfo);
@ -519,6 +525,7 @@ namespace Plane.FormationCreator.Formation
SelectedTaskIndex = Tasks.Count - 1; SelectedTaskIndex = Tasks.Count - 1;
} }
//导出任务
public string ExportTasks() public string ExportTasks()
{ {
// For reference. // For reference.
@ -635,7 +642,9 @@ namespace Plane.FormationCreator.Formation
latOffset = offset.Lat, latOffset = offset.Lat,
lngOffset = offset.Lng, lngOffset = offset.Lng,
targetAlt = info.TargetAlt, targetAlt = info.TargetAlt,
showLED = info.FlytoShowLED showLED = info.FlytoShowLED,
flytoTime = info.FlytoTime,
loiterTime = info.LoiterTime
}; };
}) })
}; };
@ -735,6 +744,7 @@ namespace Plane.FormationCreator.Formation
} }
//导入任务,可设置导入哪些步骤
public void ImportTasksindex(string tasksText,int startindex,int endindex) public void ImportTasksindex(string tasksText,int startindex,int endindex)
{ {
dynamic tasks = JsonConvert.DeserializeObject(tasksText); dynamic tasks = JsonConvert.DeserializeObject(tasksText);
@ -781,7 +791,7 @@ namespace Plane.FormationCreator.Formation
i++; i++;
} }
} }
// 导入任务
public void ImportTasks(string tasksText) public void ImportTasks(string tasksText)
{ {
dynamic tasks = JsonConvert.DeserializeObject(tasksText); dynamic tasks = JsonConvert.DeserializeObject(tasksText);

View File

@ -1,35 +1,38 @@
using Plane.Copters; using GalaSoft.MvvmLight.Command;
using Plane.Copters;
using Plane.Windows.Messages;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
namespace Plane.FormationCreator.Formation namespace Plane.FormationCreator.Formation
{ {
public partial class FlightTaskSingleCopterInfo public partial class FlightTaskSingleCopterInfo
{ {
public static FlightTaskSingleCopterInfo CreateForFlyToTask(ICopter copter, double targetLat, double targetLng, float targetAlt,bool showLED) public static FlightTaskSingleCopterInfo CreateForFlyToTask(ICopter copter, double targetLat, double targetLng, float targetAlt,int flytoTime,int loiterTime)
{ {
var info = new FlightTaskSingleCopterInfo(copter) var info = new FlightTaskSingleCopterInfo(copter)
{ {
TargetLat = targetLat, TargetLat = targetLat,
TargetLng = targetLng, TargetLng = targetLng,
TargetAlt = targetAlt, TargetAlt = targetAlt,
FlytoShowLED= showLED, FlytoTime= flytoTime,
// FlytoTime= flytoTime, LoiterTime = loiterTime
// LoiterTime = loiterTime
}; };
return info; return info;
} }
public static FlightTaskSingleCopterInfo CreateForFlyToTask(ICopter copter, LatLng latLngOffset, float targetAlt, bool showLED) public static FlightTaskSingleCopterInfo CreateForFlyToTask(ICopter copter, LatLng latLngOffset, float targetAlt, int flytoTime, int loiterTime)
{ {
var info = new FlightTaskSingleCopterInfo(copter) var info = new FlightTaskSingleCopterInfo(copter)
{ {
LatLngOffset = latLngOffset, LatLngOffset = latLngOffset,
TargetAlt = targetAlt, TargetAlt = targetAlt,
FlytoShowLED = showLED FlytoTime = flytoTime,
LoiterTime = loiterTime
}; };
return info; return info;
} }
@ -52,7 +55,18 @@ namespace Plane.FormationCreator.Formation
get { return _LoiterTime; } get { return _LoiterTime; }
set { Set(nameof(LoiterTime), ref _LoiterTime, value); } set { Set(nameof(LoiterTime), ref _LoiterTime, value); }
} }
//设置飞机航点中灯光
private ICommand _ModiFlytoLEDCommand;
public ICommand ModiFlytoLEDCommand
{
get
{
return _ModiFlytoLEDCommand ?? (_ModiFlytoLEDCommand = new RelayCommand<double>(async =>
{
Alert.Show("sfsdf");
}));
}
}
} }
} }

View File

@ -152,6 +152,7 @@
<Compile Include="ViewModels\MainViewModel.cs" /> <Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="ViewModels\MapViewModel.cs" /> <Compile Include="ViewModels\MapViewModel.cs" />
<Compile Include="ViewModels\ModifyTaskViewModel.cs" /> <Compile Include="ViewModels\ModifyTaskViewModel.cs" />
<Compile Include="ViewModels\ModiLEDModel.cs" />
<Compile Include="ViewModels\TaskBarViewModel.cs" /> <Compile Include="ViewModels\TaskBarViewModel.cs" />
<Compile Include="Views\ControlPanelView.xaml.cs"> <Compile Include="Views\ControlPanelView.xaml.cs">
<DependentUpon>ControlPanelView.xaml</DependentUpon> <DependentUpon>ControlPanelView.xaml</DependentUpon>
@ -172,6 +173,9 @@
<Compile Include="Views\ModifyTaskView.xaml.cs"> <Compile Include="Views\ModifyTaskView.xaml.cs">
<DependentUpon>ModifyTaskView.xaml</DependentUpon> <DependentUpon>ModifyTaskView.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\ModiLEDWindow.xaml.cs">
<DependentUpon>ModiLEDWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\TaskBarView.xaml.cs"> <Compile Include="Views\TaskBarView.xaml.cs">
<DependentUpon>TaskBarView.xaml</DependentUpon> <DependentUpon>TaskBarView.xaml</DependentUpon>
</Compile> </Compile>
@ -275,6 +279,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\ModiLEDWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\TaskBarView.xaml"> <Page Include="Views\TaskBarView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -205,6 +205,7 @@ namespace Plane.FormationCreator.ViewModels
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select await Task.WhenAll(_copterManager.AcceptingControlCopters.Select
(copter => copter.SetParamAsync(name, value))); (copter => copter.SetParamAsync(name, value)));
/*
await Task.WhenAll( await Task.WhenAll(
_copterManager.AcceptingControlCopters.Select(async copter => _copterManager.AcceptingControlCopters.Select(async copter =>
@ -218,6 +219,7 @@ namespace Plane.FormationCreator.ViewModels
} }
)); ));
*/
} }
@ -606,7 +608,7 @@ namespace Plane.FormationCreator.ViewModels
var _flightTaskManager = _taskmodimodel.FlightTaskManager; var _flightTaskManager = _taskmodimodel.FlightTaskManager;
int coptercount = _copterManager.Copters.Count; int coptercount = _copterManager.Copters.Count;
int taskcount = _flightTaskManager.Tasks.Count; int taskcount = _flightTaskManager.Tasks.Count;
bool havewritefault = true; // bool havewritefault = true;
if (taskcount < 2) return; if (taskcount < 2) return;
for (int i = 0; i < coptercount; i++) for (int i = 0; i < coptercount; i++)
@ -622,15 +624,24 @@ namespace Plane.FormationCreator.ViewModels
switch (_flightTaskManager.Tasks[j].TaskType) switch (_flightTaskManager.Tasks[j].TaskType)
{ {
case FlightTaskType.TakeOff: case FlightTaskType.TakeOff:
//计算起飞需要的时间,5秒是上升加速和最后稳定时间
missions[missindex++] = Mission.CreateTakeoffMission(2,5,_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat, int takeofftime = (int)(_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetAlt / 2.5 + 5);
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng, _flightTaskManager.Tasks[j+1].SingleCopterInfos[i].TargetAlt); missions[missindex++] = Mission.CreateTakeoffMission(1,
takeofftime,
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLat,
_flightTaskManager.Tasks[j + 1].SingleCopterInfos[i].TargetLng,
_flightTaskManager.Tasks[j+1].SingleCopterInfos[i].TargetAlt);
//要起飞任务 //要起飞任务
break; break;
case FlightTaskType.FlyTo: case FlightTaskType.FlyTo:
missions[missindex++] = Mission.CreateWaypointMission(5,15,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng, _flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt); missions[missindex++] = Mission.CreateWaypointMission(
5,//_flightTaskManager.Tasks[j].SingleCopterInfos[i].LoiterTime,
20,// _flightTaskManager.Tasks[j].SingleCopterInfos[i].FlytoTime,
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLng,
_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetAlt);
break; break;
case FlightTaskType.Loiter: case FlightTaskType.Loiter:
// missions[missindex++] = Mission.CreateWaypointMission(10,10,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat, // missions[missindex++] = Mission.CreateWaypointMission(10,10,_flightTaskManager.Tasks[j].SingleCopterInfos[i].TargetLat,

View File

@ -206,7 +206,8 @@
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="0"> <Grid Grid.Row="0" DataContext="{Binding ModifyingSingleCopterInfo}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition /> <RowDefinition />
@ -219,19 +220,26 @@
<TextBlock Grid.Row="0" Text="飞行时间: " /> <TextBlock Grid.Row="0" Text="飞行时间: " />
<TextBox Grid.Column="1" <TextBox Grid.Column="1"
Margin="0,5,10,0" Margin="0,5,10,0"
Text="{Binding FlytoTime, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding FlytoTime, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="1" Text="悬停时间: " /> <TextBlock Grid.Row="1" Text="悬停时间: " />
<TextBox Grid.Row="1" Grid.Column="1" <TextBox Grid.Row="1" Grid.Column="1"
Margin="0,5,10,0" Margin="0,5,10,0"
Text="{Binding LoiterTime, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding LoiterTime, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="2" Text="灯光控制: " /> <TextBlock Grid.Row="2" Text="灯光控制: " />
<CheckBox Grid.Row="2" Grid.Column="1"
DataContext="{Binding ModifyingSingleCopterInfo}" <Button Content="设置"
IsChecked="{Binding FlytoShowLED}" /> Grid.Row="2" Grid.Column="1"
Margin="0,5,5,0"
Command="{Binding ModiFlytoLEDCommand}" />
</Grid> </Grid>