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

加入从文件读取的设置
灯光控制改到设置按钮里面,还没有做
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++;
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.CenterDirectionDeg = lastSingleCopterInfo.TargetHeading;
newTask.SingleCopterInfos.Add(newSingleCopterInfo);
@ -380,13 +380,19 @@ namespace Plane.FormationCreator.Formation
{
var singleCopterInfoObj = singleCopterInfos[i];
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
{
//实际飞机比保存的任务计划的飞机多,多的飞机设置默认航点
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);
@ -519,6 +525,7 @@ namespace Plane.FormationCreator.Formation
SelectedTaskIndex = Tasks.Count - 1;
}
//导出任务
public string ExportTasks()
{
// For reference.
@ -635,7 +642,9 @@ namespace Plane.FormationCreator.Formation
latOffset = offset.Lat,
lngOffset = offset.Lng,
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)
{
dynamic tasks = JsonConvert.DeserializeObject(tasksText);
@ -781,7 +791,7 @@ namespace Plane.FormationCreator.Formation
i++;
}
}
// 导入任务
public void ImportTasks(string 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Plane.FormationCreator.Formation
{
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)
{
TargetLat = targetLat,
TargetLng = targetLng,
TargetAlt = targetAlt,
FlytoShowLED= showLED,
// FlytoTime= flytoTime,
// LoiterTime = loiterTime
FlytoTime= flytoTime,
LoiterTime = loiterTime
};
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)
{
LatLngOffset = latLngOffset,
TargetAlt = targetAlt,
FlytoShowLED = showLED
FlytoTime = flytoTime,
LoiterTime = loiterTime
};
return info;
}
@ -52,7 +55,18 @@ namespace Plane.FormationCreator.Formation
get { return _LoiterTime; }
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\MapViewModel.cs" />
<Compile Include="ViewModels\ModifyTaskViewModel.cs" />
<Compile Include="ViewModels\ModiLEDModel.cs" />
<Compile Include="ViewModels\TaskBarViewModel.cs" />
<Compile Include="Views\ControlPanelView.xaml.cs">
<DependentUpon>ControlPanelView.xaml</DependentUpon>
@ -172,6 +173,9 @@
<Compile Include="Views\ModifyTaskView.xaml.cs">
<DependentUpon>ModifyTaskView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ModiLEDWindow.xaml.cs">
<DependentUpon>ModiLEDWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\TaskBarView.xaml.cs">
<DependentUpon>TaskBarView.xaml</DependentUpon>
</Compile>
@ -275,6 +279,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ModiLEDWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\TaskBarView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

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

View File

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