53 char buf[MAX_BUF_LEN+1];
56 double GpsOrin[3]={0};
60 int SelfCheckMainState=0;
61 int SelfCheckSubState=0;
68 uint64_t m_start_time = 0;
75 double m_global_pos[3] = {0};
76 double m_ang_euler[3] = {0};
77 double m_local_pos[3] = {0};
78 double m_local_vel[3] = {0};
79 double m_battery_info = 100;
82 m_cmd.ioSilInts[0] = 5;
83 m_send_ue.checksum = 1234567894;
92 int recvlen=udp.RecvNoblock(buf,RecvIP,RecvPort,MAX_BUF_LEN);
95 if (udp.needFilter && (RecvIP != TargetIP)){
103 onUdpMessage((uint8_t*)buf, recvlen);
112 void onUdpMessage(uint8_t *buf,
int recvlen){
115 unpackStruct(buf, m_recv);
116 for (
int i = 0; i < 3; i++){
117 m_global_pos[i] = m_recv.ioSilFloats[i];
118 m_ang_euler[i] = m_recv.ioSilFloats[i+3];
119 m_local_pos[i] = m_recv.ioSilFloats[i+6];
120 m_local_vel[i] = m_recv.ioSilFloats[i+9];
122 m_battery_info = m_recv.ioSilFloats[12];
128 unpackStruct(buf, m_recv_ue);
129 for (
int i = 0; i < 3; i++){
130 m_global_pos[i] = m_recv_ue.PosE[i];
131 m_ang_euler[i] = m_recv_ue.AngEuler[i];
132 m_local_pos[i] = m_recv_ue.PosE[i];
133 m_local_vel[i] = m_recv_ue.VelE[i];
142 length = packStruct(m_cmd, (uint8_t*)buf);
145 length = packStruct(m_send_ue, (uint8_t*)buf);
150 udp.SendTo((
const char *)buf,length,TargetIP,TargetPort);
155 void setBit(
int &num,
int n) {
163 void SendSetAction(
int mode)
165 m_cmd.ioSilInts[1] = 0;
166 setBit(m_cmd.ioSilInts[1], 0);
167 setBit(m_cmd.ioSilInts[1], 5);
168 m_cmd.ioSilInts[2] = mode;
172 void SendMove(
float vx,
float vy,
float yaw_rate)
174 m_cmd.ioSilInts[1] = 0;
175 setBit(m_cmd.ioSilInts[1], 0);
176 setBit(m_cmd.ioSilInts[1], 19);
177 m_cmd.ioSilFloats[3] = vx;
178 m_cmd.ioSilFloats[4] = vy;
179 m_cmd.ioSilFloats[14] = yaw_rate;
183 bool isBitTrue(uint32_t value,
int bitIndex) {
184 return (value & (1U << bitIndex)) != 0;
188 void SendMavlinkReal(
double **u,
double t){
190 int cmdBitmap = (int)*u[1];
191 int typeMask = (int)*u[2];
193 if (isBitTrue(cmdBitmap, 0)){
194 if (isBitTrue(cmdBitmap, 5)){
196 SendSetAction(typeMask);
199 if (isBitTrue(cmdBitmap, 19)){
201 SendMove((
float)*u[11], (
float)*u[12], (
float)*u[22]);
205 void SendUECtrl(
double **u,
double t){
206 int cmdBitmap = (int)*u[1];
207 int typeMask = (int)*u[2];
208 m_send_ue.runnedTime = t;
209 for (
int i=0; i< 16; i++)
210 m_send_ue.ExtToUE4[i] = 0;
211 if (isBitTrue(cmdBitmap, 0)){
212 if (isBitTrue(cmdBitmap, 5)){
213 m_send_ue.ExtToUE4[0] = 2;
214 m_send_ue.ExtToUE4[1] = typeMask;
218 if (isBitTrue(cmdBitmap, 19)){
219 m_send_ue.ExtToUE4[0] = 26112;
220 m_send_ue.ExtToUE4[8] = -*u[22];
221 m_send_ue.ExtToUE4[9] = *u[11];
222 m_send_ue.ExtToUE4[10] = -*u[12];
223 m_send_ue.ExtToUE4[14] = 2;