forked from CPL/Simulator
Update
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.Drawing;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DroneClient
|
||||
@ -8,8 +9,11 @@ namespace DroneClient
|
||||
|
||||
public float AccX, AccY, AccZ;
|
||||
public float GyrX, GyrY, GyrZ;
|
||||
public uint TimeAcc, TimeGyr;
|
||||
|
||||
public float PosX, PosY;
|
||||
public float LaserRange;
|
||||
public uint TimeRange;
|
||||
|
||||
public float MotorUL, MotorUR, MotorDL, MotorDR;
|
||||
|
||||
@ -70,22 +74,44 @@ namespace DroneClient
|
||||
return getBytes(mot4);
|
||||
}
|
||||
|
||||
private byte[]? RecvDataIMU(byte[] data)
|
||||
private byte[]? RecvDataAcc(byte[] data)
|
||||
{
|
||||
DroneData.DataIMU imu = (DroneData.DataIMU)fromBytes(data, typeof(DroneData.DataIMU));
|
||||
DroneData.DataAcc imu = (DroneData.DataAcc)fromBytes(data, typeof(DroneData.DataAcc));
|
||||
|
||||
AccX = imu.Acc.X; AccY = imu.Acc.Y; AccZ = imu.Acc.Z;
|
||||
GyrX = imu.Gyr.X; GyrY = imu.Gyr.Y; GyrZ = imu.Gyr.Z;
|
||||
|
||||
TimeAcc= imu.Time;
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
private byte[]? RecvDataPos(byte[] data)
|
||||
private byte[]? RecvDataGyr(byte[] data)
|
||||
{
|
||||
DroneData.DataPos pos = (DroneData.DataPos)fromBytes(data, typeof(DroneData.DataPos));
|
||||
DroneData.DataGyr imu = (DroneData.DataGyr)fromBytes(data, typeof(DroneData.DataGyr));
|
||||
|
||||
GyrX = imu.Gyr.X; GyrY = imu.Gyr.Y; GyrZ = imu.Gyr.Z;
|
||||
|
||||
TimeGyr = imu.Time;
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
private byte[]? RecvDataRange(byte[] data)
|
||||
{
|
||||
DroneData.DataRange pos = (DroneData.DataRange)fromBytes(data, typeof(DroneData.DataRange));
|
||||
|
||||
LaserRange = pos.LiDAR;
|
||||
|
||||
TimeRange = pos.Time;
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
private byte[]? RecvDataLocal(byte[] data)
|
||||
{
|
||||
DroneData.DataLocal pos = (DroneData.DataLocal)fromBytes(data, typeof(DroneData.DataLocal));
|
||||
|
||||
PosX = pos.Local.X; PosY = pos.Local.Y;
|
||||
LaserRange = pos.LiDAR;
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
@ -96,7 +122,7 @@ namespace DroneClient
|
||||
|
||||
switch (head.Type)
|
||||
{
|
||||
case DroneData.DataType.DataIMU:
|
||||
case DroneData.DataType.DataAcc:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
@ -108,11 +134,11 @@ namespace DroneClient
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
return RecvDataIMU(body);
|
||||
return RecvDataAcc(body);
|
||||
}
|
||||
}
|
||||
|
||||
case DroneData.DataType.DataPos:
|
||||
case DroneData.DataType.DataGyr:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
@ -124,7 +150,39 @@ namespace DroneClient
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
return RecvDataPos(body);
|
||||
return RecvDataGyr(body);
|
||||
}
|
||||
}
|
||||
|
||||
case DroneData.DataType.DataRange:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
// Запрос данных
|
||||
// ... //
|
||||
//
|
||||
return zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
return RecvDataRange(body);
|
||||
}
|
||||
}
|
||||
|
||||
case DroneData.DataType.DataLocal:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
// Запрос данных
|
||||
// ... //
|
||||
//
|
||||
return zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
return RecvDataLocal(body);
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,24 +251,46 @@ namespace DroneClient
|
||||
|
||||
public byte[] SendReqest()
|
||||
{
|
||||
DroneData.DataHead imu = new DroneData.DataHead();
|
||||
imu.Size = DroneData.DataHead.StrLen;
|
||||
imu.Mode = DroneData.DataMode.Request;
|
||||
imu.Type = DroneData.DataType.DataIMU;
|
||||
DroneData.DataHead acc = new DroneData.DataHead();
|
||||
acc.Size = DroneData.DataHead.StrLen;
|
||||
acc.Mode = DroneData.DataMode.Request;
|
||||
acc.Type = DroneData.DataType.DataAcc;
|
||||
|
||||
DroneData.DataHead pos = new DroneData.DataHead();
|
||||
pos.Size = DroneData.DataHead.StrLen;
|
||||
pos.Mode = DroneData.DataMode.Request;
|
||||
pos.Type = DroneData.DataType.DataPos;
|
||||
DroneData.DataHead gyr = new DroneData.DataHead();
|
||||
gyr.Size = DroneData.DataHead.StrLen;
|
||||
gyr.Mode = DroneData.DataMode.Request;
|
||||
gyr.Type = DroneData.DataType.DataGyr;
|
||||
|
||||
byte[] si = getBytes(imu);
|
||||
byte[] sp = getBytes(pos);
|
||||
byte[] sm = SendDataMotor4();
|
||||
DroneData.DataHead range = new DroneData.DataHead();
|
||||
range.Size = DroneData.DataHead.StrLen;
|
||||
range.Mode = DroneData.DataMode.Request;
|
||||
range.Type = DroneData.DataType.DataRange;
|
||||
|
||||
byte[] send = new byte[si.Length + sp.Length + sm.Length];
|
||||
si.CopyTo(send, 0);
|
||||
sp.CopyTo(send, si.Length);
|
||||
sm.CopyTo(send, si.Length + sp.Length);
|
||||
DroneData.DataHead local = new DroneData.DataHead();
|
||||
local.Size = DroneData.DataHead.StrLen;
|
||||
local.Mode = DroneData.DataMode.Request;
|
||||
local.Type = DroneData.DataType.DataLocal;
|
||||
|
||||
List<byte[]> list = new List<byte[]>();
|
||||
|
||||
list.Add(getBytes(acc));
|
||||
list.Add(getBytes(gyr));
|
||||
list.Add(getBytes(range));
|
||||
list.Add(getBytes(local));
|
||||
list.Add(SendDataMotor4());
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (byte[] d in list) count += d.Length;
|
||||
|
||||
byte[] send = new byte[count];
|
||||
|
||||
count = 0;
|
||||
foreach (byte[] d in list)
|
||||
{
|
||||
d.CopyTo(send, count);
|
||||
count += d.Length;
|
||||
}
|
||||
|
||||
return send;
|
||||
}
|
||||
|
@ -8,11 +8,11 @@ namespace DroneData
|
||||
};
|
||||
|
||||
public enum DataType : ushort
|
||||
{
|
||||
{
|
||||
None = 0, Head = 1,
|
||||
|
||||
// Output
|
||||
DataIMU = 1001, DataPos = 1002,
|
||||
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005,
|
||||
|
||||
// Input
|
||||
DataMotor4 = 2001, DataMotor6 = 2002
|
||||
@ -25,32 +25,66 @@ namespace DroneData
|
||||
public DataMode Mode;
|
||||
public DataType Type;
|
||||
|
||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataHead));
|
||||
}
|
||||
|
||||
public struct XYZ { public float X, Y, Z; }
|
||||
|
||||
public struct DataIMU
|
||||
public struct DataAcc
|
||||
{
|
||||
public DataHead Head;
|
||||
public XYZ Acc, Gyr, Mag;
|
||||
public XYZ Acc;
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataIMU));
|
||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataAcc));
|
||||
}
|
||||
|
||||
public struct DataPos
|
||||
public struct DataGyr
|
||||
{
|
||||
public DataHead Head;
|
||||
public XYZ Gyr;
|
||||
|
||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataGyr));
|
||||
}
|
||||
|
||||
public struct DataMag
|
||||
{
|
||||
public DataHead Head;
|
||||
public XYZ Mag;
|
||||
|
||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMag));
|
||||
}
|
||||
|
||||
public struct DataLocal
|
||||
{
|
||||
public DataHead Head;
|
||||
public XYZ Local; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
||||
}
|
||||
|
||||
public struct DataRange
|
||||
{
|
||||
public DataHead Head;
|
||||
public float LiDAR; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataPos));
|
||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataRange));
|
||||
}
|
||||
|
||||
public struct DataMotor4
|
||||
{
|
||||
public DataHead Head;
|
||||
public ulong Count;
|
||||
public float UL, UR, DL, DR;
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor4));
|
||||
@ -59,7 +93,6 @@ namespace DroneData
|
||||
public struct DataMotor6
|
||||
{
|
||||
public DataHead Head;
|
||||
public ulong Count;
|
||||
public float UL, UR, LL, RR, DL, DR;
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor6));
|
||||
|
43
DroneClient/FormMain.Designer.cs
generated
43
DroneClient/FormMain.Designer.cs
generated
@ -65,6 +65,9 @@
|
||||
label_Pow = new Label();
|
||||
button_ML = new Button();
|
||||
button_MR = new Button();
|
||||
label_time_acc = new Label();
|
||||
label_time_range = new Label();
|
||||
label_time_gyr = new Label();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Server_Port).BeginInit();
|
||||
groupBox2.SuspendLayout();
|
||||
@ -156,6 +159,7 @@
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(label_time_acc);
|
||||
groupBox2.Controls.Add(label_Acc_Z);
|
||||
groupBox2.Controls.Add(label7);
|
||||
groupBox2.Controls.Add(label_Acc_Y);
|
||||
@ -164,7 +168,7 @@
|
||||
groupBox2.Controls.Add(label1);
|
||||
groupBox2.Location = new Point(6, 86);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(78, 100);
|
||||
groupBox2.Size = new Size(78, 118);
|
||||
groupBox2.TabIndex = 5;
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "Acc";
|
||||
@ -216,6 +220,7 @@
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
groupBox3.Controls.Add(label_time_gyr);
|
||||
groupBox3.Controls.Add(label_Gyr_Z);
|
||||
groupBox3.Controls.Add(label9);
|
||||
groupBox3.Controls.Add(label_Gyr_Y);
|
||||
@ -224,7 +229,7 @@
|
||||
groupBox3.Controls.Add(label13);
|
||||
groupBox3.Location = new Point(95, 86);
|
||||
groupBox3.Name = "groupBox3";
|
||||
groupBox3.Size = new Size(78, 100);
|
||||
groupBox3.Size = new Size(78, 118);
|
||||
groupBox3.TabIndex = 6;
|
||||
groupBox3.TabStop = false;
|
||||
groupBox3.Text = "Gyr";
|
||||
@ -285,6 +290,7 @@
|
||||
//
|
||||
// groupBox4
|
||||
//
|
||||
groupBox4.Controls.Add(label_time_range);
|
||||
groupBox4.Controls.Add(label_Pos_L);
|
||||
groupBox4.Controls.Add(label6);
|
||||
groupBox4.Controls.Add(label_Pos_Y);
|
||||
@ -293,7 +299,7 @@
|
||||
groupBox4.Controls.Add(label14);
|
||||
groupBox4.Location = new Point(188, 86);
|
||||
groupBox4.Name = "groupBox4";
|
||||
groupBox4.Size = new Size(78, 100);
|
||||
groupBox4.Size = new Size(78, 118);
|
||||
groupBox4.TabIndex = 7;
|
||||
groupBox4.TabStop = false;
|
||||
groupBox4.Text = "Pos";
|
||||
@ -437,6 +443,33 @@
|
||||
button_MR.MouseDown += button_UU_MouseDown;
|
||||
button_MR.MouseUp += button_UU_MouseUp;
|
||||
//
|
||||
// label_time_acc
|
||||
//
|
||||
label_time_acc.AutoSize = true;
|
||||
label_time_acc.Location = new Point(6, 100);
|
||||
label_time_acc.Name = "label_time_acc";
|
||||
label_time_acc.Size = new Size(13, 15);
|
||||
label_time_acc.TabIndex = 25;
|
||||
label_time_acc.Text = "0";
|
||||
//
|
||||
// label_time_range
|
||||
//
|
||||
label_time_range.AutoSize = true;
|
||||
label_time_range.Location = new Point(6, 100);
|
||||
label_time_range.Name = "label_time_range";
|
||||
label_time_range.Size = new Size(13, 15);
|
||||
label_time_range.TabIndex = 27;
|
||||
label_time_range.Text = "0";
|
||||
//
|
||||
// label_time_gyr
|
||||
//
|
||||
label_time_gyr.AutoSize = true;
|
||||
label_time_gyr.Location = new Point(3, 100);
|
||||
label_time_gyr.Name = "label_time_gyr";
|
||||
label_time_gyr.Size = new Size(13, 15);
|
||||
label_time_gyr.TabIndex = 26;
|
||||
label_time_gyr.Text = "0";
|
||||
//
|
||||
// Form_Main
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -509,5 +542,9 @@
|
||||
private Label label_Pow;
|
||||
private Button button_ML;
|
||||
private Button button_MR;
|
||||
private Label label4;
|
||||
private Label label_time_acc;
|
||||
private Label label_time_range;
|
||||
private Label label_time_gyr;
|
||||
}
|
||||
}
|
||||
|
@ -95,14 +95,20 @@ namespace DroneSimulator
|
||||
label_Acc_Y.Text = dataDrone.AccY.ToString();
|
||||
label_Acc_Z.Text = dataDrone.AccZ.ToString();
|
||||
|
||||
label_time_acc.Text = dataDrone.TimeAcc.ToString();
|
||||
|
||||
label_Gyr_X.Text = dataDrone.GyrX.ToString();
|
||||
label_Gyr_Y.Text = dataDrone.GyrY.ToString();
|
||||
label_Gyr_Z.Text = dataDrone.GyrZ.ToString();
|
||||
|
||||
label_time_gyr.Text = dataDrone.TimeGyr.ToString();
|
||||
|
||||
label_Pos_X.Text = dataDrone.PosX.ToString();
|
||||
label_Pos_Y.Text = dataDrone.PosY.ToString();
|
||||
label_Pos_L.Text = dataDrone.LaserRange.ToString();
|
||||
|
||||
label_time_range.Text = dataDrone.TimeRange.ToString();
|
||||
|
||||
netClient.SendData(dataDrone.SendReqest());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user