将Src0918的部分功能移植进来,还有倒计时,任务启动检查灯没有移植

1.shift多选航点
2.任务整体移动
This commit is contained in:
panxu 2018-04-30 19:41:13 +08:00
parent 074c5bdedf
commit f31f08e530
11 changed files with 299 additions and 92 deletions

View File

@ -113,19 +113,27 @@ namespace Plane.FormationCreator
*/
MainWindow = new MainWindow();
MainWindow.Show();
TcpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
if (!TcpServerConnectionManager.Instance.StartListening())
try
{
Alert.Show("网络连接不正常,无法启动监听。");
TcpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
if (!TcpServerConnectionManager.Instance.StartListening())
{
Alert.Show("网络连接不正常,无法连接飞机。");
return;
}
UdpServerConnectionManager.Instance.ExceptionThrown += (sender, e1) =>
{
_logger.Log(e1.Exception);
};
UdpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
UdpServerConnectionManager.Instance.StartReceiving();
}
catch (Exception ex)
{
Alert.Show("网络连接不正常,无法连接飞机。");
return;
}
UdpServerConnectionManager.Instance.ExceptionThrown += (sender, e1) =>
{
_logger.Log(e1.Exception);
};
UdpServerConnectionManager.Instance.ConnectionEstablished += ConnectionManager_ConnectionEstablished;
UdpServerConnectionManager.Instance.StartReceiving();
}
private void Copter_TextReceived(object sender, MessageCreatedEventArgs e)
{

View File

@ -69,7 +69,8 @@ namespace Plane.FormationCreator
}
set
{
_config.Center = $"{value.Lat},{value.Lng}";
if (_config != null)
_config.Center = $"{value.Lat},{value.Lng}";
}
}
@ -89,7 +90,8 @@ namespace Plane.FormationCreator
}
set
{
_config.ZoomLevel = value;
if (_config != null)
_config.ZoomLevel = value;
}
}
@ -99,7 +101,8 @@ namespace Plane.FormationCreator
{
Directory.CreateDirectory(_dirPath);
}
File.WriteAllText(_filePath, JsonConvert.SerializeObject(_config));
if (_config != null)
File.WriteAllText(_filePath, JsonConvert.SerializeObject(_config));
}
}
}

View File

@ -86,7 +86,7 @@ namespace Plane.FormationCreator.Formation
// }
//}
public bool shiftkeydown;
public IEnumerable<ICopter> SelectedCopters { get { return _selectedCoptersGetter().Cast<ICopter>(); } }
/// <summary>

View File

@ -62,8 +62,6 @@ namespace Plane.FormationCreator.Formation
public static bool ArrivedTarget(this ICopter copter, double targetLat, double targetLng, float targetAlt)
{
// return copter.DistanceTo(targetLat, targetLng, targetAlt) < 0.6; //到达航点精度
if (copter.GpsFixType == GpsFixType.RTKFIXED)
return copter.DistanceTo(targetLat, targetLng, targetAlt) < RTKArrivedDis; //RTK到达航点精度0.6米
else

View File

@ -224,7 +224,7 @@ namespace Plane.FormationCreator.Formation
var newTask = new FlightTask(FlightTaskType.FlyTo);
int coptindex = 0;
int colnum = 4; //自动生成列数=4
int colnum = 5; //自动生成列数=4
float coldis = 5;//列相距5米
float rowdis = 5;//行相距5米
float matrixdis = 20; //生成方阵距离30米
@ -363,6 +363,7 @@ namespace Plane.FormationCreator.Formation
public void RestoreFlyToTask(bool staggerRoutes, dynamic singleCopterInfos)
{
var copters = _copterManager.Copters;
float tagalt = 15;
if (!copters.Any()) return;
AppEx.Current.AppMode = AppMode.ModifyingTask;
var lastTask = Tasks.LastOrDefault();
@ -371,11 +372,23 @@ namespace Plane.FormationCreator.Formation
var center = nullableCenter.Value;
var newTask = new FlightTask(FlightTaskType.FlyTo) { StaggerRoutes = staggerRoutes };
// TODO: 林俊清, 20150801, 处理实际飞行器数目与记录中数目不一致的情况。
for (int i = 0; i < copters.Count && i < singleCopterInfos.Count; i++)
for (int i = 0; i < copters.Count; i++)
{
var copter = copters[i];
var singleCopterInfoObj = singleCopterInfos[i];
var newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask(copter, new LatLng((double)singleCopterInfoObj.latOffset, (double)singleCopterInfoObj.lngOffset), (float)singleCopterInfoObj.targetAlt,(bool)singleCopterInfoObj.showLED);
FlightTaskSingleCopterInfo newSingleCopterInfo;
if (i < singleCopterInfos.Count)
{
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);
}
else
{
newSingleCopterInfo = FlightTaskSingleCopterInfo.CreateForFlyToTask
(copter, (double)copter.Latitude, (double)copter.Longitude, tagalt, (bool)false);
}
newTask.SingleCopterInfos.Add(newSingleCopterInfo);
}
Tasks.Add(newTask);
@ -493,7 +506,7 @@ namespace Plane.FormationCreator.Formation
loiterTimeTask.HeadYaw = HeadYaw;
// foreach (var copter in copters)
for (int i=0; i < copters.Count && i < singleCopterInfos.Count; i++)
for (int i = 0; i < copters.Count; i++)
{
var copter = copters[i];
var singleCopterInfoObj = singleCopterInfos[i];

View File

@ -107,7 +107,9 @@ namespace Plane.FormationCreator
case Key.LeftShift:
{
var copters = _copterManager.AcceptingControlCopters;
Shiftkeydown = true;
_copterManager.shiftkeydown = true;
break;
}
//开关SHOWLED
@ -359,6 +361,7 @@ namespace Plane.FormationCreator
case Key.LeftShift:
{
Shiftkeydown = false;
_copterManager.shiftkeydown = false;
break;
}
case Key.W:

View File

@ -54,7 +54,7 @@ namespace Plane.FormationCreator.ViewModels
var center = _mapManager.Center;
string id;
int colnum = 4; //自动生成列数=4
int colnum = 5; //自动生成列数=4
float coldis = 3;//列相距5米
float rowdis = 3;//行相距5米
int currcol = 0; //当前列号

View File

@ -175,6 +175,12 @@ namespace Plane.FormationCreator.ViewModels
set { Set(nameof(txtendindex), ref _txtendindex, value); }
}
private float _directionvalue = 0;
public float directionvalue
{
get { return _directionvalue; }
set { Set(nameof(directionvalue), ref _directionvalue, value); }
}
@ -263,7 +269,57 @@ namespace Plane.FormationCreator.ViewModels
}
}
//调整所有任务经度
private ICommand _ModiAllPosCommand;
public ICommand ModiAllPosCommand
{
get
{
return _ModiAllPosCommand ?? (_ModiAllPosCommand = new RelayCommand<double>(async =>
{
if (_flightTaskManager.Tasks.Count < 2) return;
float lowalt = 200;
int _startindex = 0;
int _endindex = _flightTaskManager.Tasks.Count - 1;
int lowtask = 0;
int lowCopter = 0;
if ((txtStarindex != 0) && (txtendindex != 0))
{
_startindex = txtStarindex;
_endindex = txtendindex;
}
for (int i = _startindex; i <= _endindex; i++)
{
if ((_flightTaskManager.Tasks[i].TaskType == FlightTaskType.TakeOff) ||
(_flightTaskManager.Tasks[i].TaskType == FlightTaskType.ReturnToLand))
continue;
for (int j = 0; j < _flightTaskManager.Tasks[i].SingleCopterInfos.Count; j++)
{
Tuple<double, double> targetLatLng = new Tuple<double, double>(0, 0);
targetLatLng = GeographyUtils.CalcLatLngSomeMetersAway2D(
_flightTaskManager.Tasks[i].SingleCopterInfos[j].TargetLat,
_flightTaskManager.Tasks[i].SingleCopterInfos[j].TargetLng,
directionvalue,
Modialtvalue
);
_flightTaskManager.Tasks[i].SingleCopterInfos[j].TargetLat = targetLatLng.Item1;
_flightTaskManager.Tasks[i].SingleCopterInfos[j].TargetLng = targetLatLng.Item2;
}
}
Alert.Show("指定步骤任务位置已向" + directionvalue + "度改变" + Modialtvalue + "米,注意是否有障碍物!");
}));
}
}
private ICommand _LevelAverageCommand;
@ -366,56 +422,59 @@ namespace Plane.FormationCreator.ViewModels
//////////////////////
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
bool copterisselect;
int selectednumber = _copterManager.SelectedCopters.Count() - 1;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
if (_flightTaskManager.SelectedTask != null)
{
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
bool copterisselect;
int selectednumber = _copterManager.SelectedCopters.Count() - 1;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
if (capter == selectedCopter)
copterisselect = true;
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
}
if (copterisselect)
{
tlat = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
if (minlat == 0)
minlat = tlat;
if (tlat > maxlat)
maxlat = tlat;
else if (tlat < minlat)
minlat = tlat;
}
}
if (copterisselect)
avgl = (maxlat - minlat) / selectednumber;
int coptnum = 0;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
tlat = _flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat;
if (minlat == 0)
minlat = tlat;
if (tlat > maxlat)
maxlat = tlat;
else if (tlat < minlat)
minlat = tlat;
}
if (copterisselect)
{
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat = maxlat - avgl * coptnum;
coptnum++;
}
}
///////////////////////
// await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
avgl = (maxlat - minlat) / selectednumber;
int coptnum = 0;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
foreach (var capter in _copterManager.SelectedCopters)
{
if (capter == selectedCopter)
copterisselect = true;
}
if (copterisselect)
{
_flightTaskManager.SelectedTask.SingleCopterInfos[i].TargetLat = maxlat - avgl * coptnum;
coptnum++;
}
}
///////////////////////
// await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
}));
}
@ -437,7 +496,9 @@ namespace Plane.FormationCreator.ViewModels
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
bool copterisselect;
if (_flightTaskManager.SelectedTask != null)
{
bool copterisselect;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
copterisselect = false;
@ -477,10 +538,33 @@ namespace Plane.FormationCreator.ViewModels
}
}
}
else
//调整飞机
{
//模拟飞机才能调整
if (selectedCopter is FakeCopter)
{
foreach (var capter in _copterManager.SelectedCopters)
{
tlat = capter.Latitude;
if (tlat > maxlat)
maxlat = tlat;
}
foreach (var capter in _copterManager.SelectedCopters)
{
var copterfk = (FakeCopter)capter;
copterfk.SetProperties(
latitude: maxlat,
longitude: copterfk.Longitude);
}
}
}
//await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}));
@ -505,7 +589,9 @@ public ICommand VerticlAlignmentCommand
double tlng = 0;
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
bool copterisselect;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
if (_flightTaskManager.SelectedTask != null)
{
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
copterisselect = false;
selectedCopter = _flightTaskManager.SelectedTask.SingleCopterInfos[i].Copter;
@ -544,11 +630,37 @@ public ICommand VerticlAlignmentCommand
}
}
//await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}));
//await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
//await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
else
//调整飞机
{
//模拟飞机才能调整
if (selectedCopter is FakeCopter)
{
foreach (var capter in _copterManager.SelectedCopters)
{
tlng = capter.Longitude;
if (tlng > maxlng)
maxlng = tlng;
}
foreach (var capter in _copterManager.SelectedCopters)
{
var copterfk = (FakeCopter)capter;
copterfk.SetProperties(
latitude: copterfk.Latitude,
longitude: maxlng);
}
}
}
}));
}
}
@ -623,6 +735,8 @@ public ICommand VerticlAlignmentCommand
double centlng = 0;
double centlat = 0;
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
if (_flightTaskManager.SelectedTask != null)
{
bool copterisselect;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
@ -685,6 +799,56 @@ public ICommand VerticlAlignmentCommand
////
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
else
//调整飞机
{
//模拟飞机才能调整
if (selectedCopter is FakeCopter)
{
foreach (var capter in _copterManager.SelectedCopters)
{
lngsum += capter.Longitude;
latsum += capter.Latitude;
selectcount++;
}
//计算旋转中心
if (selectcount > 0)
{
centlng = lngsum / selectcount;
centlat = latsum / selectcount;
}
else return;
foreach (var capter in _copterManager.SelectedCopters)
{
double lpDistance = CalculationLogLatDistance.GetDistanceOne(centlng, centlat,
capter.Longitude,
capter.Latitude);
CalculationLogLatDistance.MyLatLng mypos1, mypos2;
mypos1 = new CalculationLogLatDistance.MyLatLng(centlng, centlat);
mypos2 = new CalculationLogLatDistance.MyLatLng(
capter.Longitude
, capter.Latitude);
double lpAzimuth = CalculationLogLatDistance.getAngle(mypos1, mypos2);
double lng2 = 0;
double lat2 = 0;
CalculationLogLatDistance.ConvertDistanceToLogLat(centlng, centlat, lpDistance,
lpAzimuth + (double)RotateLine, out lng2, out lat2);
var copterfk = (FakeCopter)capter;
copterfk.SetProperties(
latitude: lat2,
longitude: lng2);
}
}
}
}));
}
}
@ -791,6 +955,8 @@ public ICommand VerticlAlignmentCommand
double centlat = 0;
double centalt = 0;
var selectedCopter = _copterManager.SelectedCopters.FirstOrDefault();
if (_flightTaskManager.SelectedTask != null)
{
bool copterisselect;
for (int i = 0; i < _flightTaskManager.SelectedTask.SingleCopterInfos.Count; i++)
{
@ -888,7 +1054,7 @@ public ICommand VerticlAlignmentCommand
await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
}));
}
}

View File

@ -32,7 +32,7 @@ namespace Plane.FormationCreator.Views
_copterManager.SetSelectionDelegates(
() => lvwDrones.SelectedItems,
copter => lvwDrones.SelectedItem = copter
SelectitemMessage
);
lvwDrones.SelectionChanged += (sender, e) =>
{
@ -41,5 +41,14 @@ namespace Plane.FormationCreator.Views
}
private CopterManager _copterManager = ServiceLocator.Current.GetInstance<CopterManager>();
private void SelectitemMessage(ICopter copter)
{
if (!_copterManager.shiftkeydown)
lvwDrones.SelectedItem = copter;
else
lvwDrones.SelectedItems.Add(copter);
}
}
}

View File

@ -336,6 +336,7 @@ namespace Plane.FormationCreator.Views
private void RegisterEventHandlersForTaskInfo(Ellipse wp, int taskIndex)
{
var info = _flightTaskManager.Tasks[taskIndex].SingleCopterInfos.FirstOrDefault(i => i.Copter == this.Copter);
if (info == null) return;
info.PropertyChanged += (sender, e) =>
{
switch (e.PropertyName)

View File

@ -71,18 +71,18 @@
Margin="0,5,5,0"
Command="{Binding VerticlRotateCommand}"
CommandParameter="{Binding ElementName=txtAlignmentLine, Path=Text}"/>
<TextBox x:Name="txtAlignmentLine"
Width="45"
Margin="0,5,5,0"
Text="0"
VerticalContentAlignment="Center" />
<TextBlock Text="度" Margin="0, 10, 5, 0"/>
<Button Content="任务整体旋转"
<Button Content="整体旋转"
Margin="0,5,5,0"
Command="{Binding TaskRotateCommand}"
CommandParameter="{Binding ElementName=txtAlignmentLine, Path=Text}"/>
<TextBox x:Name="txtAlignmentLine"
Width="35"
Margin="0,5,5,0"
Text="0"
VerticalContentAlignment="Center" />
<TextBlock Text="度" Margin="0, 10, 5, 0"/>
</StackPanel>
@ -96,7 +96,7 @@
CommandParameter="{Binding ElementName=txtScaleVale, Path=Text}"/>
<TextBox x:Name="txtScaleVale"
Width="40"
Width="35"
Margin="0,5,5,0"
Text="100"
VerticalContentAlignment="Center" />
@ -109,29 +109,27 @@
<TextBox
Grid.Column="1"
Width="40"
Width="35"
Margin="0, 5, 5, 0"
HorizontalContentAlignment="Right"
Text="{Binding Distancevalue, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBlock Text="米" Margin="0, 10, 5, 0"/>
</StackPanel>
<StackPanel>
<Button Content="自动高度"
Margin="0,5,5,0"
Command="{Binding AutoaltCommand}" />
<Button Content="前一高度"
Margin="0,5,5,0"
Command="{Binding PrealtCommand}" />
<Button Content="修改任务高度"
</StackPanel>
<StackPanel>
<Button Content="整体提高"
Margin="0,5,5,0"
Command="{Binding ModiAltCommand}"
/>
<Button Content="整体移动"
Margin="0,5,5,0"
Command="{Binding ModiAllPosCommand}" />
<TextBox
Grid.Column="1"
Width="40"
@ -139,8 +137,16 @@
HorizontalContentAlignment="Right"
Text="{Binding Modialtvalue, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBlock Text="米" Margin="0, 10, 5, 0"/>
<TextBlock Text="米 方向" Margin="0, 10, 5, 0"/>
<TextBox
Grid.Column="1"
Width="35"
Margin="0, 5, 5, 0"
HorizontalContentAlignment="Right"
Text="{Binding directionvalue, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBlock Text="度" Margin="0, 10, 5, 0"/>
</StackPanel>