加入RTK支持
[Extensions.cs] 修改//到达航点精度0.6米////最近碰撞检测距离2米 (飞机飞控中飞行速度改为200/秒) [ControlPanelViewModel.cs] 读取基站数据并发送 [ControlPanelView.xaml]加入rtk发送按钮
This commit is contained in:
parent
70e70e182c
commit
d81d8f30ea
@ -54,8 +54,8 @@ namespace Plane.FormationCreator.Formation
|
||||
|
||||
public static bool ArrivedTarget(this ICopter copter, double targetLat, double targetLng, float targetAlt)
|
||||
{
|
||||
return copter.DistanceTo(targetLat, targetLng, targetAlt) < 2;
|
||||
// return copter.DistanceTo(targetLat, targetLng, targetAlt) < 1.5;
|
||||
// return copter.DistanceTo(targetLat, targetLng, targetAlt) < 2;
|
||||
return copter.DistanceTo(targetLat, targetLng, targetAlt) < 0.6; //到达航点精度
|
||||
// return copter.DistanceTo(targetLat, targetLng, targetAlt) < 2; // added by ZJF
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ namespace Plane.FormationCreator.Formation
|
||||
|
||||
public static bool IsTooCloseTo(this ICopter copter, ICopter copter2)
|
||||
{
|
||||
return copter.DistanceTo(copter2) < 2;
|
||||
return copter.DistanceTo(copter2) < 0.5; //最近距离2米
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,19 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Plane.Communication;
|
||||
|
||||
namespace Plane.FormationCreator.ViewModels
|
||||
{
|
||||
public class ControlPanelViewModel : ViewModelBase
|
||||
{
|
||||
// serialport
|
||||
internal static IConnection Rtkport ;
|
||||
private static System.Threading.Thread thrtk;
|
||||
private static bool trkthreadrun = false;
|
||||
|
||||
|
||||
|
||||
public ControlPanelViewModel(FormationController formationController, CopterManager copterManager)
|
||||
{
|
||||
_formationController = formationController;
|
||||
@ -127,6 +135,156 @@ namespace Plane.FormationCreator.ViewModels
|
||||
}));
|
||||
}
|
||||
}
|
||||
private string _RTKcomvalue = "COM3";
|
||||
public string RTKcomvalue
|
||||
{
|
||||
get { return _RTKcomvalue; }
|
||||
set { Set(nameof(RTKcomvalue), ref _RTKcomvalue, value); }
|
||||
}
|
||||
|
||||
//RTK收发线程
|
||||
private static void mainloop()
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private async Task<byte[]> ReadRTKPacketAsync()
|
||||
{
|
||||
if (!Rtkport.IsOpen)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// limit to 110 byte packets
|
||||
byte[] buffer = new byte[180];
|
||||
int length = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (Rtkport.BytesToRead() > 0)//while (Rtkport.BytesToRead() > 0)
|
||||
|
||||
|
||||
{
|
||||
int read = await Rtkport.ReadAsync(buffer, 0, Math.Min(buffer.Length, Rtkport.BytesToRead()));
|
||||
|
||||
// sendData(buffer, (byte)read);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
if (await Rtkport.ReadAsync(buffer, 0, 1) == 0)
|
||||
{
|
||||
// 做简单数据解析,得到协议类型,后续数据长度等
|
||||
}
|
||||
//根据数据长度读取实际数据
|
||||
if (await Rtkport.ReadAsync(buffer, 1, 1) == 0)
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return buffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private ICommand _SendRTKCommand;
|
||||
public ICommand SendRTKCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return _SendRTKCommand ?? (_SendRTKCommand = new RelayCommand(async () =>
|
||||
{
|
||||
Rtkport = new SerialPortConnection(RTKcomvalue,57600) as IConnection;
|
||||
await Rtkport.OpenAsync();
|
||||
if (!Rtkport.IsOpen)
|
||||
{
|
||||
Alert.Show("无法打开" + RTKcomvalue , "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
trkthreadrun = true; //开始运行后台任务
|
||||
/* //线程方式后台运行rtk转发任务
|
||||
thrtk = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop))
|
||||
{
|
||||
IsBackground = true,
|
||||
Name = "injectgps"
|
||||
};
|
||||
thrtk.Start();
|
||||
*/
|
||||
//后台任务方式运行rtk转发任务
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
//读取RTK数据循环
|
||||
while (trkthreadrun)
|
||||
{
|
||||
//读入RTK数据
|
||||
var packet = await ReadRTKPacketAsync().ConfigureAwait(false);
|
||||
//分发到每个飞机
|
||||
foreach (var copter in _copterManager.Copters)
|
||||
{
|
||||
await copter.InjectGpsDataAsync(packet, (ushort)packet.Length);
|
||||
}
|
||||
|
||||
|
||||
await Task.Delay(200).ConfigureAwait(false);
|
||||
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
/*
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (!Rtkport.IsOpen)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// var packet = await ReadRTKPacketAsync().ConfigureAwait(false);
|
||||
|
||||
while (trkthreadrun)
|
||||
{
|
||||
|
||||
await ReadRTKPacketAsync();
|
||||
|
||||
// if (await Rtkport.ReadAsync(buffer, 0, Math.Min(buffer.Length, 110)) > 0)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});*/
|
||||
|
||||
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private ICommand _LandCommand;
|
||||
public ICommand LandCommand
|
||||
|
@ -59,6 +59,19 @@
|
||||
Text="{Binding AltP, UpdateSourceTrigger=PropertyChanged}" />
|
||||
</WrapPanel>
|
||||
|
||||
<WrapPanel>
|
||||
<TextBox
|
||||
Grid.Column="1"
|
||||
Width="55"
|
||||
Margin="5, 5, 5, 5"
|
||||
HorizontalContentAlignment="Right"
|
||||
Text="{Binding RTKcomvalue, UpdateSourceTrigger=PropertyChanged}"
|
||||
/>
|
||||
<Button Content="发送RTK"
|
||||
Command="{Binding SendRTKCommand}" />
|
||||
</WrapPanel>
|
||||
|
||||
|
||||
<!--// 林俊清, 20150920, 目前不再使用 FormationController,删除相关按钮。
|
||||
<StackPanel Visibility="{Binding Source={x:Static fc:AppEx.Current}, Path=AppMode, Converter={StaticResource AppModeToVisibilityConverter}, ConverterParameter=ControlPanelView_Formation}">
|
||||
<TextBlock Text="任务" />
|
||||
|
Loading…
Reference in New Issue
Block a user