diff --git a/Plane.FormationCreator/App.xaml.cs b/Plane.FormationCreator/App.xaml.cs
index 63bd207..c558e60 100644
--- a/Plane.FormationCreator/App.xaml.cs
+++ b/Plane.FormationCreator/App.xaml.cs
@@ -19,6 +19,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Plane.CommunicationManagement;
+using Plane.FormationCreator.Util;
namespace Plane.FormationCreator
{
@@ -68,6 +69,8 @@ namespace Plane.FormationCreator
};
//new Test().Prepare().Run();
+
+ VersionControl.GetVersionFromIni();
}
private ILogger _logger;
diff --git a/Plane.FormationCreator/Formation/FlightTaskManager.cs b/Plane.FormationCreator/Formation/FlightTaskManager.cs
index 85f7866..e82b101 100644
--- a/Plane.FormationCreator/Formation/FlightTaskManager.cs
+++ b/Plane.FormationCreator/Formation/FlightTaskManager.cs
@@ -374,8 +374,8 @@ namespace Plane.FormationCreator.Formation
CurrentRunningTask = null;
//起飞任务需要跳过
- if (CurrentRunningTaskIndex == 0)
- CurrentRunningTaskIndex++;
+// if (CurrentRunningTaskIndex == 0)
+// CurrentRunningTaskIndex++;
CurrentRunningTaskIndex++;
await RunTaskAsync();
}
@@ -572,6 +572,7 @@ namespace Plane.FormationCreator.Formation
{
var singleCopterInfoObj = singleCopterInfos[i];
takeOffTask.SingleCopterInfos[i].TakeOffWaitTime = (ushort)singleCopterInfoObj.waitTime;
+ //Message.Show(((ushort)singleCopterInfoObj.waitTime).ToString());
}
}
diff --git a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs
index 14ebc27..84be95e 100644
--- a/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs
+++ b/Plane.FormationCreator/Formation/FlightTaskSingleCopterInfo_Land.cs
@@ -19,7 +19,7 @@ namespace Plane.FormationCreator.Formation
return info;
}
- private ushort _LandWaitTime = 5;
+ private ushort _LandWaitTime = 1;
public ushort LandWaitTime
{
get { return _LandWaitTime; }
diff --git a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs
index f20fbbe..0f44e08 100644
--- a/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs
+++ b/Plane.FormationCreator/Formation/FlightTask_TakeOff.cs
@@ -76,7 +76,15 @@ namespace Plane.FormationCreator.Formation
var tasksTakeOff = new Task[infos.Count];
for (int i = 0; i < infos.Count; i++)
{
- tasksTakeOff[i] = NewSingleRunTaskOffTaskAsunc(infos[i]);
+ //tasksTakeOff[i] = NewSingleRunTaskOffTaskAsunc(infos[i]);
+
+
+ tasksTakeOff[i] = await Task.Factory.StartNew(async () =>
+ {
+ var internalInfo = infos[i];
+
+ await NewSingleRunTaskOffTaskAsunc(internalInfo);
+ });
}
await Task.WhenAll(tasksTakeOff).ConfigureAwait(false);
//await Task.Delay(100);
@@ -90,31 +98,24 @@ namespace Plane.FormationCreator.Formation
int copterIndex = SingleCopterInfos.IndexOf(info);
var copter = info.Copter;
-
- await copter.UnlockAsync();
- for (int i = 0; !copter.IsUnlocked; i++)
- {
- //8秒内每1000毫秒尝试解锁一次
- //解锁间隔一定要超过1s否则导致飞控以后无法解锁
-
- if (i > 320)
- return; //无法解锁后面不用执行了
- if (i % (1000 / 25) == 1000 / 25 - 1)
- {
- await copter.UnlockAsync(); // 每 1000 毫秒重试一次。
- }
-
- await Task.Delay(25).ConfigureAwait(false);
- }
//等待起飞时间
- while (ts.TotalMilliseconds < info.TakeOffWaitTime * 1000)
+ Windows.Messages.Message.Show($"{copter.Name}:等待起飞 = {info.TakeOffWaitTime}");
+ while ((int)ts.TotalMilliseconds < (int)info.TakeOffWaitTime * 1000)
{
+ if (_flightTaskManager.IsPaused == true)
+ {
+ await info.Copter.HoverAsync();
+ return;
+ }
await Task.Delay(100);
dtNow = DateTime.Now;
- ts = dtNow - dtLastTime;
+ ts = dtNow - dtLastTime;
}
+ //虚拟飞机5秒后不起飞会自动上锁
+ await copter.UnlockAsync();
+
for (int i = 0; i < 5; i++) // added by ZJF
{
await copter.TakeOffAsync();
@@ -124,6 +125,9 @@ namespace Plane.FormationCreator.Formation
var copterNextTask = _flightTaskManager.Tasks[TaskIndex + 1].SingleCopterInfos[copterIndex];
float takeOffAlt = copterNextTask.TargetAlt;
+ info.TargetLat = info.Copter.Latitude;
+ info.TargetLng = info.Copter.Longitude;
+
for (int j = 0; j < 3; j++)
{
await info.Copter.FlyToAsync(info.TargetLat, info.TargetLng, takeOffAlt);
@@ -133,8 +137,16 @@ namespace Plane.FormationCreator.Formation
dtNow = DateTime.Now;
ts = dtNow - dtLastTime;
FlightTask task = _flightTaskManager.CurrentRunningTask;
+
+ Windows.Messages.Message.Show($"{copter.Name}:等待到达飞行时间 = {task.TakeOffTime}");
while (ts.TotalMilliseconds < task.TakeOffTime * 1000)
{
+ if (_flightTaskManager.IsPaused == true)
+ {
+ //Windows.Messages.Message.Show($"{copter.Name}:悬停");
+ await info.Copter.HoverAsync();
+ return;
+ }
await Task.Delay(100).ConfigureAwait(false);
dtNow = DateTime.Now;
ts = dtNow - dtLastTime;
diff --git a/Plane.FormationCreator/Formation/View3DManager.cs b/Plane.FormationCreator/Formation/View3DManager.cs
new file mode 100644
index 0000000..41d6dbf
--- /dev/null
+++ b/Plane.FormationCreator/Formation/View3DManager.cs
@@ -0,0 +1,19 @@
+using Plane.FormationCreator.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Plane.FormationCreator.Formation
+{
+ public class View3DManager
+ {
+ public View3DViewModel _view3DViewModel { get; set; }
+
+ public void ClearCopters()
+ {
+ this._view3DViewModel.Clear3DCopters();
+ }
+ }
+}
diff --git a/Plane.FormationCreator/ModifyParam.xaml b/Plane.FormationCreator/ModifyParam.xaml
index c10bb94..6b7bed8 100644
--- a/Plane.FormationCreator/ModifyParam.xaml
+++ b/Plane.FormationCreator/ModifyParam.xaml
@@ -12,75 +12,80 @@
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
+
diff --git a/Plane.FormationCreator/ModifyParam.xaml.cs b/Plane.FormationCreator/ModifyParam.xaml.cs
index c519d9e..eb5b9d2 100644
--- a/Plane.FormationCreator/ModifyParam.xaml.cs
+++ b/Plane.FormationCreator/ModifyParam.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using Plane.FormationCreator.Util;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -19,20 +20,33 @@ namespace Plane.FormationCreator
///
public partial class ModifyParam : Window
{
+ public bool LoadParam = false;
public ModifyParam()
{
InitializeComponent();
+ if (!VersionControl.IsFullVersion)
+ {
+ hide_panel.Visibility = Visibility.Collapsed;
+ textParamName.IsReadOnly = true;
+ btnLoad.Visibility = Visibility.Collapsed;
+ }
}
private void btnModify_Click(object sender, RoutedEventArgs e)
{
+ LoadParam = false;
this.DialogResult = true;
-
}
private void Modify_Select(object sender, RoutedEventArgs e)
{
textParamName.Text = ((Button)sender).Tag.ToString();
}
+
+ private void btnLoad_Click(object sender, RoutedEventArgs e)
+ {
+ LoadParam = true;
+ this.DialogResult = true;
+ }
}
}
diff --git a/Plane.FormationCreator/Plane.FormationCreator.csproj b/Plane.FormationCreator/Plane.FormationCreator.csproj
index 846e7bc..a4b7fcb 100644
--- a/Plane.FormationCreator/Plane.FormationCreator.csproj
+++ b/Plane.FormationCreator/Plane.FormationCreator.csproj
@@ -191,6 +191,7 @@
+
diff --git a/Plane.FormationCreator/Util/VersionControl.cs b/Plane.FormationCreator/Util/VersionControl.cs
new file mode 100644
index 0000000..0c14d19
--- /dev/null
+++ b/Plane.FormationCreator/Util/VersionControl.cs
@@ -0,0 +1,25 @@
+using Plane.Windows.IniHelper;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Plane.FormationCreator.Util
+{
+ public static class VersionControl
+ {
+ public static int Version = 0;
+ public static bool IsFullVersion = false;
+
+ public static void GetVersionFromIni()
+ {
+ IniFiles iniFiles = new IniFiles();
+ string readvalue = iniFiles.IniReadvalue("Version", "Version");
+ int intTemp;
+ if (readvalue != "" && int.TryParse(readvalue, out intTemp))
+ Version = int.Parse(readvalue);
+ IsFullVersion = Version == 255;
+ }
+ }
+}
diff --git a/Plane.FormationCreator/ViewModels/CalibrationViewModel.cs b/Plane.FormationCreator/ViewModels/CalibrationViewModel.cs
new file mode 100644
index 0000000..dab88f9
--- /dev/null
+++ b/Plane.FormationCreator/ViewModels/CalibrationViewModel.cs
@@ -0,0 +1,224 @@
+using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.Command;
+using Microsoft.Practices.ServiceLocation;
+using Plane.CommunicationManagement;
+using Plane.CopterManagement;
+using Plane.Copters;
+using Plane.FormationCreator.Formation;
+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.ViewModels
+{
+ public class CalibrationViewModel : ViewModelBase
+ {
+ CommModuleManager commModule = CommModuleManager.Instance;
+
+ private CopterManager _copterManager = ServiceLocator.Current.GetInstance();
+
+ private string _AccelerometerTips;
+ public string AccelerometerTips
+ {
+ get
+ {
+ switch (AccelerometerState)
+ {
+ case AccelerometerStates.Idle:
+ _AccelerometerTips = "点击“开始校准”后,开始校准加速计";
+ break;
+ case AccelerometerStates.Front:
+ _AccelerometerTips = "亮紫色: 飞机水平放置(Front)";
+ break;
+ case AccelerometerStates.Left:
+ _AccelerometerTips = "亮黄色:飞机左侧接触地面竖立放置(Left)";
+ break;
+ case AccelerometerStates.Right:
+ _AccelerometerTips = "亮青色:飞机右侧接触地面竖立放置(Right)";
+ break;
+ case AccelerometerStates.Down:
+ _AccelerometerTips = "紫色:飞机机头向下接触地面竖立放置(Down)";
+ break;
+ case AccelerometerStates.Up:
+ _AccelerometerTips = "黄色:飞机机尾向下接触地面竖立放置(Up)";
+ break;
+ case AccelerometerStates.Back:
+ _AccelerometerTips = "青色:飞机翻过来水平放置(Back)";
+ break;
+ }
+ return _AccelerometerTips;
+ }
+ }
+
+ private string _AccelerometerBtnText = "开始校准";
+ public string AccelerometerBtnText
+ {
+ get
+ {
+ switch (AccelerometerState)
+ {
+ case AccelerometerStates.Idle:
+ _AccelerometerBtnText = "开始校准";
+ break;
+ default:
+ _AccelerometerBtnText = "完成";
+ break;
+ }
+ return _AccelerometerBtnText;
+ }
+ }
+
+ //校准加速计的状态
+ public enum AccelerometerStates
+ {
+ Idle = 0,
+ Front = 1,
+ Left = 2,
+ Right = 3,
+ Down = 4,
+ Up = 5,
+ Back = 6
+ }
+
+ private AccelerometerStates _AccelerometerState = AccelerometerStates.Idle;
+ public AccelerometerStates AccelerometerState
+ {
+ get { return _AccelerometerState; }
+ set
+ {
+ Set(nameof(AccelerometerState), ref _AccelerometerState, value);
+ RaisePropertyChanged(nameof(AccelerometerBtnText));
+ RaisePropertyChanged(nameof(AccelerometerTips));
+ }
+ }
+
+
+ private ICommand _CalibrationAccelerometerCommand;
+ public ICommand CalibrationAccelerometerCommand
+ {
+ get
+ {
+ return _CalibrationAccelerometerCommand ?? (_CalibrationAccelerometerCommand = new RelayCommand(async () =>
+ {
+ ICopter copter = _copterManager.SelectedCopters.FirstOrDefault();
+ short copterId = short.Parse(copter.Name);
+
+ switch (AccelerometerState)
+ {
+ case AccelerometerStates.Idle:
+ await commModule.DoStartPreflightCompassAsync(copterId);
+ break;
+ default:
+ await commModule.DoNextPreflightCompassAsync(copterId);
+ break;
+ }
+ if (AccelerometerState == AccelerometerStates.Back)
+ {
+ Alert.Show("校准结束,请检测灯光后重启飞机!\r\n 绿色:校准成功 红色:校准失败");
+ AccelerometerState = AccelerometerStates.Idle;
+ }
+ else
+ {
+ AccelerometerState = (AccelerometerStates)((int)AccelerometerState + 1);
+ }
+ }));
+ }
+ }
+
+
+ private int _CompassPercent;
+ public int CompassPercent
+ {
+ get { return _CompassPercent; }
+ set
+ {
+ Set(nameof(CompassPercent), ref _CompassPercent, value);
+ }
+ }
+
+ public bool IsCalibration { get; set; }
+ ///
+ /// 校准指南针
+ ///
+ private ICommand _CalibrationCompassCommand;
+ public ICommand CalibrationCompassCommand
+ {
+ get
+ {
+ return _CalibrationCompassCommand ?? (_CalibrationCompassCommand = new RelayCommand(async () =>
+ {
+ if (IsCalibration || _copterManager.SelectedCopters.Count() != 1) return;
+
+ ICopter copter = _copterManager.SelectedCopters.FirstOrDefault();
+
+ short copterId = short.Parse(copter.Name);
+ Message.Show("开始校准指南针:" + copter.Name);
+ //for (int i = 0; i < 3; i++)
+ //{
+ await commModule.DoCalibrationCompassAsync(copterId);
+ await Task.Delay(50).ConfigureAwait(false);
+ //}
+
+ IsCalibration = true;
+ CompassPercent = 0;
+ int State = 0; //4:成功 5失败 todo 改为枚举
+
+
+ while (IsCalibration && CompassPercent <= 100)
+ {
+ //两个255的时候表示 当前预留字节代表的意思是校准
+ if (copter.Retain[2] == 255 && copter.Retain[3] == 255)
+ {
+ CompassPercent = copter.Retain[0];
+ State = copter.Retain[1];
+ if (State == 4 || State == 5)
+ break;
+ }
+
+ await Task.Delay(100);
+ }
+
+ switch (State)
+ {
+ case 4:
+ Alert.Show($"校准成功,请重新上电{copterId}号", "指南针");
+ break;
+ case 5:
+ Alert.Show("校准失败", "指南针");
+ break;
+ default:
+ break;
+ }
+
+ IsCalibration = false;
+
+ }));
+ }
+ }
+
+ private ICommand _CancelCalibrationCompassCommand;
+ public ICommand CancelCalibrationCompassCommand
+ {
+ get
+ {
+ return _CancelCalibrationCompassCommand ?? (_CancelCalibrationCompassCommand = new RelayCommand(async () =>
+ {
+ if (_copterManager.SelectedCopters.Count() != 1) return;
+
+ ICopter copter = _copterManager.SelectedCopters.FirstOrDefault();
+
+ short copterId = short.Parse(copter.Name);
+ await commModule.DoCancelCalibrationCompassAsync(copterId);
+ IsCalibration = false;
+ Alert.Show("放弃校准", "指南针");
+ }));
+ }
+ }
+ }
+
+
+}
diff --git a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
index 1eed30d..dea2564 100644
--- a/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/ControlPanelViewModel.cs
@@ -596,15 +596,27 @@ namespace Plane.FormationCreator.ViewModels
var ModifyParamWindow = new Plane.FormationCreator.ModifyParam();
if (ModifyParamWindow.ShowDialog() == true)
{
-
+ bool isLoadParam = ModifyParamWindow.LoadParam;
string paramstr = ModifyParamWindow.textParamName.Text;
- float paramvalue = Convert.ToSingle(ModifyParamWindow.textParamValue.Text);
- int num = 0;
- if (_copterManager.AcceptingControlCopters.Count() < _copterManager.Copters.Count)
- num = await _commModuleManager.SetParamAsync(paramstr, paramvalue, _copterManager.AcceptingControlCopters);
- else if (_copterManager.AcceptingControlCopters.Count() == _copterManager.Copters.Count)
- num = await _commModuleManager.SetParamAsync(paramstr, paramvalue);
- Alert.Show($"广播完成! 当前序列号:{num}");
+
+ if(!isLoadParam)
+ {
+ float paramvalue = Convert.ToSingle(ModifyParamWindow.textParamValue.Text);
+ int num = 0;
+ if (_copterManager.AcceptingControlCopters.Count() < _copterManager.Copters.Count)
+ num = await _commModuleManager.SetParamAsync(paramstr, paramvalue, _copterManager.AcceptingControlCopters);
+ else if (_copterManager.AcceptingControlCopters.Count() == _copterManager.Copters.Count)
+ num = await _commModuleManager.SetParamAsync(paramstr, paramvalue);
+ Alert.Show($"广播完成! 当前序列号:{num}");
+ }
+ else
+ {
+ if (_copterManager.AcceptingControlCopters.Count() < _copterManager.Copters.Count)
+ await _commModuleManager.ReadParamAsnyc(paramstr, _copterManager.AcceptingControlCopters);
+ else if (_copterManager.AcceptingControlCopters.Count() == _copterManager.Copters.Count)
+ await _commModuleManager.ReadParamAsnyc(paramstr);
+ }
+
/*
await Task.WhenAll(_copterManager.AcceptingControlCopters.Select
(copter => copter.SetParamAsync(paramstr, paramvalue)));
diff --git a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs
index ebe127f..508cecb 100644
--- a/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs
+++ b/Plane.FormationCreator/ViewModels/ModifyTaskViewModel.cs
@@ -381,7 +381,7 @@ namespace Plane.FormationCreator.ViewModels
double minlat = 0;
double avgl = 0;
- /*
+
if (_copterManager.SelectedCopters.Count() > 2)
{
List selectTaskInfos = new List();
@@ -401,8 +401,8 @@ namespace Plane.FormationCreator.ViewModels
selectTaskInfos[i].TargetLat = minlat + i * tlat;
}
}
- */
-
+
+ /*
if (Alert.Show("本操作将导致飞机位置重新排列,编号最小的飞机在最上边,您确定要继续吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
== MessageBoxResult.OK)
{
@@ -464,6 +464,7 @@ namespace Plane.FormationCreator.ViewModels
// await Task.Delay(100); // 如果不等待一段时间,很可能会再触发 DataStreamReceived 事件导致飞行器重新出现在地图上。
}
}
+ */
}));
}
}
diff --git a/Plane.FormationCreator/Views/CalibrationWindow.xaml b/Plane.FormationCreator/Views/CalibrationWindow.xaml
new file mode 100644
index 0000000..540cf5e
--- /dev/null
+++ b/Plane.FormationCreator/Views/CalibrationWindow.xaml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Plane.FormationCreator/Views/CalibrationWindow.xaml.cs b/Plane.FormationCreator/Views/CalibrationWindow.xaml.cs
new file mode 100644
index 0000000..f943a0d
--- /dev/null
+++ b/Plane.FormationCreator/Views/CalibrationWindow.xaml.cs
@@ -0,0 +1,36 @@
+using Microsoft.Practices.ServiceLocation;
+using Plane.FormationCreator.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace Plane.FormationCreator.Views
+{
+ ///
+ /// CalibrationWindow.xaml 的交互逻辑
+ ///
+ public partial class CalibrationWindow : Window
+ {
+ public CalibrationWindow()
+ {
+ InitializeComponent();
+ CalibrationViewModel calibrationViewModel = ServiceLocator.Current.GetInstance();
+ calibrationViewModel.AccelerometerState = CalibrationViewModel.AccelerometerStates.Idle;
+ this.DataContext = calibrationViewModel;
+
+
+ }
+
+
+ }
+}
diff --git a/Plane.FormationCreator/Views/ConnectWindow.xaml b/Plane.FormationCreator/Views/ConnectWindow.xaml
index dd3cbb8..3ad72fa 100644
--- a/Plane.FormationCreator/Views/ConnectWindow.xaml
+++ b/Plane.FormationCreator/Views/ConnectWindow.xaml
@@ -8,8 +8,8 @@
xmlns:ec="clr-namespace:Plane.Windows.Controls;assembly=Plane.Windows"
mc:Ignorable="d"
Title="连接"
- Width="429.175"
- Height="570.371"
+ Width="432.175"
+ Height="300.371"
WindowStartupLocation="CenterScreen"
FontFamily="Microsoft YaHei"
@@ -111,7 +111,7 @@
IsProcessing="{Binding IsProcessing}"
Command="{Binding Path=ConnectCommand}"
CommandParameter="SerialPort" />
-
+