-
Notifications
You must be signed in to change notification settings - Fork 347
/
infantry_info.h
453 lines (404 loc) · 12.3 KB
/
infantry_info.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/****************************************************************************
* Copyright (C) 2018 RoboMaster.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************/
#ifndef MODULES_DRIVER_SERIAL_INFANTRY_INFO_H
#define MODULES_DRIVER_SERIAL_INFANTRY_INFO_H
#include <stdio.h>
#include <stdint.h>
namespace rrts {
namespace driver {
namespace serial {
#define UP_REG_ID 0xA0
#define DN_REG_ID 0xA5
#define HEADER_LEN sizeof(FrameHeader)
#define CMD_LEN 2
#define CRC_LEN 2
#define PROTOCAL_FRAME_MAX_SIZE 200
#define UART_BUFF_SIZE 2000
#define PACK_MAX_SIZE 200
#define COMPRESS_TIME 1
/**
* @brief command id
*/
typedef enum {
GAME_INFO_ID = 0x0001,
REAL_BLOOD_DATA_ID = 0x0002,
REAL_SHOOT_DATA_ID = 0x0003,
REAL_RFID_DATA_ID = 0x0005,
GAME_RESULT_ID = 0x0006,
GAIN_BUFF_ID = 0x0007,
CHASSIS_DATA_ID = 0x0010,
GIMBAL_DATA_ID = 0x0011,
SHOOT_TASK_DATA_ID = 0x0012,
INFANTRY_ERR_ID = 0x0013,
CONFIG_RESPONSE_ID = 0x0014,
CALI_RESPONSE_ID = 0x0015,
REMOTE_CTRL_INFO_ID = 0x0016,
BOTTOM_VERSION_ID = 0x0017,
CHASSIS_CTRL_ID = 0x00A0,
GIMBAL_CTRL_ID = 0x00A1,
SHOOT_CTRL_ID = 0x00A2,
ERROR_LEVEL_ID = 0x00A3,
INFANTRY_STRUCT_ID = 0x00A4,
CALI_GIMBAL_ID = 0x00A5,
CLIENT_SHOW_ID = 0x0100,
USER_TO_SERVER_ID = 0x0101,
SERVER_TO_USER_ID = 0x0102,
} CommandID;
/* enumeration type data */
typedef enum {
STEP_HEADER_SOF = 0,
STEP_LENGTH_LOW = 1,
STEP_LENGTH_HIGH = 2,
STEP_FRAME_SEQ = 3,
STEP_HEADER_CRC8 = 4,
STEP_DATA_CRC16 = 5,
} UnpackStep;
typedef enum {
DEVICE_NORMAL = 0,
ERROR_EXIST = 1,
UNKNOWN_STATE = 2,
} BottomError;
typedef enum {
BOTTOM_DEVICE_NORMAL = 0,
GIMBAL_GYRO_OFFLINE = 1,
CHASSIS_GYRO_OFFLINE = 2,
CHASSIS_M1_OFFLINE = 3,
CHASSIS_M2_OFFLINE = 4,
CHASSIS_M3_OFFLINE = 5,
CHASSIS_M4_OFFLINE = 6,
REMOTE_CTRL_OFFLINE = 7,
JUDGE_SYS_OFFLINE = 8,
GIMBAL_YAW_OFFLINE = 9,
GIMBAL_PIT_OFFLINE = 10,
TRIGGER_MOTO_OFFLINE = 11,
BULLET_JAM = 12,
CHASSIS_CONFIG_ERR = 13,
GIMBAL_CONFIG_ERR = 14,
ERROR_LIST_LENGTH = 15,
} ErrorID;
typedef enum {
GLOBAL_NORMAL = 0,
SOFTWARE_WARNING = 1,
SOFTWARE_ERROR = 2,
SOFTWARE_FATAL_ERROR = 3,
GIMBAL_ERROR = 4,
CHASSIS_ERROR = 5,
HARAWARE_ERROR = 6,
} ErrorLevel;
typedef enum {
NO_CONFIG = 0,
DEFAULT_CONFIG = 1,
CUSTOM_CONFIG = 3,
} StructConfig;
typedef enum {
GIMBAL_RELAX = 0,
GIMBAL_INIT = 1,
GIMBAL_NO_ARTI_INPUT = 2,
GIMBAL_FOLLOW_ZGYRO = 3,
GIMBAL_TRACK_ARMOR = 4,
GIMBAL_PATROL_MODE = 5,
GIMBAL_SHOOT_BUFF = 6,
GIMBAL_POSITION_MODE = 7,
} GimbalMode;
typedef enum {
CHASSIS_RELAX = 0,
CHASSIS_STOP = 1,
MANUAL_SEPARATE_GIMBAL = 2,
MANUAL_FOLLOW_GIMBAL = 3,
DODGE_MODE = 4,
AUTO_SEPARATE_GIMBAL = 5,
AUTO_FOLLOW_GIMBAL = 6,
} ChassisMode;
typedef enum {
SHOT_DISABLE = 0,
REMOTE_CTRL_SHOT = 1,
KEYBOARD_CTRL_SHOT = 2,
SEMIAUTO_CTRL_SHOT = 3,
AUTO_CTRL_SHOT = 4,
} ShootMode;
/**
* @brief frame header structure definition
*/
typedef struct {
uint8_t sof;
uint16_t data_length;
uint8_t seq;
uint8_t crc8;
} __attribute__((packed)) FrameHeader;
/********************** the judgement system from bottom main control **********************/
/**
* @brief GPS state structures definition
*/
typedef struct {
uint8_t valid_flag;
float x;
float y;
float z;
float yaw;
} __attribute__((packed)) Position;
/**
* @brief game information structures definition(0x0001)
*/
typedef struct {
uint16_t stage_remain_time;
uint8_t game_process;
/* current race stage
0 not start
1 preparation stage
2 self-check stage
3 5 seconds count down
4 fighting stage
5 result computing stage */
uint8_t reserved;
uint16_t remain_hp;
uint16_t max_hp;
Position position;
} __attribute__((packed)) GameInfo;
/**
* @brief real time blood volume change data(0x0002)
*/
typedef struct {
uint8_t armor_type:4;
/* 0-3bits: the attacked armor id:
0x00: 0 front
0x01: 1 left
0x02: 2 behind
0x03: 3 right
others reserved*/
uint8_t hurt_type:4;
/* 4-7bits: blood volume change type
0x00: armor attacked
0x01: module offline
0x02: bullet over speed
0x03: bullet over frequency */
} __attribute__((packed)) HurtData;
/**
* @brief real time shooting data(0x0003)
*/
typedef struct {
uint8_t reserved1;
uint8_t bullet_freq;
float bullet_speed;
float reserved2;
} __attribute__((packed)) ShootData;
/**
* @brief rfid detect data(0x0005)
*/
typedef struct {
uint8_t card_type;
uint8_t card_idx;
} __attribute__((packed)) RfidData;
/**
* @brief game result data(0x0006)
*/
typedef struct {
uint8_t winner;
} __attribute__((packed)) GameResult;
/**
* @brief the data of get field buff(0x0007)
*/
typedef struct {
uint8_t buff_type;
uint8_t buff_addition;
} __attribute__((packed)) GameBuff;
/**
* @brief student custom data(0x0100)
*/
typedef struct {
float data1;
float data2;
float data3;
} __attribute__((packed)) ClientData;
/**
* @brief student custom data(0x0101)
*/
typedef struct {
uint8_t data[64];
} __attribute__((packed)) UserToServer;
/**
* @brief student custom data(0x0102)
*/
typedef struct {
uint8_t data[32];
} __attribute__((packed)) ServerToUser;
/********************** the infantry information from bottom main control **********************/
/**
* @brief chassis information(0x0010)
*/
typedef struct {
uint8_t ctrl_mode; /* chassis control mode */
float gyro_palstance; /* chassis palstance(degree/s) from gyroscope */
float gyro_angle; /* chassis angle(degree) relative to ground from gyroscope */
float ecd_palstance; /* chassis palstance(degree/s) from chassis motor encoder calculated */
float ecd_angle; /* chassis angle(degree) relative to ground from chassis motor encoder calculated */
int16_t x_speed; /* chassis x-axis move speed(mm/s) from chassis motor encoder calculated */
int16_t y_speed; /* chassis y-axis move speed(mm/s) from chassis motor encoder calculated */
int32_t x_position; /* chassis x-axis position(mm) relative to the starting point */
int32_t y_position; /* chassis y-axis position(mm) relative to the starting point */
} __attribute__((packed)) ChassisInfo;
/**
* @brief gimbal information(0x0011)
*/
typedef struct {
uint8_t ctrl_mode; /* gimbal control mode */
float pit_relative_angle; /* pitch angle(degree) relative to the gimbal center */
float yaw_relative_angle; /* yaw angle(degree) relative to the gimbal center */
float pit_absolute_angle; /* pitch angle(degree) relative to ground */
float yaw_absolute_angle; /* yaw angle(degree) relative to ground */
float pit_palstance; /* pitch axis palstance(degree/s) */
float yaw_palstance; /* yaw axis palstance(degree/s) */
} __attribute__((packed)) GimbalInfo;
/**
* @brief shoot information(0x0012)
*/
typedef struct {
int16_t remain_bullet; /* the member of remain bullets */
int16_t sent_bullet; /* the member of bullets that have been sent */
uint8_t fric_wheel_run; /* friction run or not */
} __attribute__((packed)) ShootInfo;
/**
* @brief infantry error information(0x0013)
*/
typedef struct {
BottomError err_sta; /* bottom error state */
BottomError err[ERROR_LIST_LENGTH]; /* device error list */
} __attribute__((packed)) InfantryError;
/**
* @brief infantry structure config response(0x0014)
*/
typedef struct {
StructConfig chassis_config;
StructConfig gimbal_config;
} __attribute__((packed)) ConfigMessage;
/**
* @brief gimbal calibrate response(0x0015)
*/
typedef struct {
uint8_t type; //0x01 success 0x00 fault
int16_t yaw_offset;
int16_t pitch_offset;
} __attribute__((packed)) CalibrateResponse;
/**
* @brief remote control information(0x0016)
*/
typedef struct {
/* rocker channel information */
int16_t ch1;
int16_t ch2;
int16_t ch3;
int16_t ch4;
/* left and right lever information */
uint8_t sw1;
uint8_t sw2;
/* Mouse movement and button information */
struct {
int16_t x;
int16_t y;
int16_t z;
uint8_t l;
uint8_t r;
} __attribute__((packed)) Mouse;
/* keyboard key information */
union {
uint16_t key_code;
struct {
uint16_t W:1;
uint16_t S:1;
uint16_t A:1;
uint16_t D:1;
uint16_t SHIFT:1;
uint16_t CTRL:1;
uint16_t Q:1;
uint16_t E:1;
uint16_t R:1;
uint16_t F:1;
uint16_t G:1;
uint16_t Z:1;
uint16_t X:1;
uint16_t C:1;
uint16_t V:1;
uint16_t B:1;
} __attribute__((packed)) Bit;
} __attribute__((packed)) Keyboard;
} __attribute__((packed)) RcInfo;
/**
* @brief bottom software version information(0x0017)
*/
typedef struct {
uint8_t num[4];
} __attribute__((packed)) VersionInfo;
/************************ the control information from computer ************************/
typedef struct {
int16_t x_offset; /* offset(mm) relative to the x-axis of the chassis center */
int16_t y_offset; /* offset(mm) relative to the y-axis of the chassis center */
float w_speed; /* rotation speed(degree/s) of chassis */
} __attribute__((packed)) ChassisRotate;
/**
* @brief chassis control information(0x00A0)
*/
typedef struct {
uint8_t ctrl_mode; /* chassis control mode */
int16_t x_speed; /* x-axis move speed(mm/s) of chassis */
int16_t y_speed; /* y-axis move speed(mm/s) of chassis */
ChassisRotate w_info; /* rotation control of chassis */
} __attribute__((packed)) ChassisControl;
/**
* @brief gimbal control information(0x00A1)
*/
typedef struct {
uint8_t ctrl_mode; /* gimbal control mode */
float pit_ref; /* gimbal pitch reference angle(degree) */
float yaw_ref; /* gimbal yaw reference angle(degree) */
uint8_t visual_valid; /* visual information valid or not */
} __attribute__((packed)) GimbalControl;
/**
* @brief shoot control information(0x00A2)
*/
typedef struct {
uint8_t shoot_cmd; /* single shoot command */
uint8_t c_shoot_cmd; /* continuous shoot command */
uint8_t fric_wheel_run; /* friction run or not */
uint8_t fric_wheel_spd; /* fricrion wheel speed */
} __attribute__((packed)) ShootControl;
/**
* @brief robot system error level(0x00A3)
*/
typedef struct {
ErrorLevel err_level; /* the error level is included in ErrorLevel enumeration */
} __attribute__((packed)) GlobalErrorLevel;
/**
* @brief infantry structure configuration information(0x00A4)
*/
typedef struct {
StructConfig chassis_config; /* chassis structure config state */
uint16_t wheel_perimeter; /* the perimeter(mm) of wheel */
uint16_t wheel_track; /* wheel track distance(mm) */
uint16_t wheel_base; /* wheelbase distance(mm) */
StructConfig gimbal_config; /* gimbal structure config state */
int16_t gimbal_x_offset; /* gimbal offset(mm) relative to the x-axis of the chassis center */
int16_t gimbal_y_offset; /* gimbal offset(mm) relative to the y-axis of the chassis center */
} __attribute__((packed)) InfantryStructure;
/**
* @brief gimbal calibrate command(0x00A5)
*/
typedef struct {
uint8_t type; /* 0x01 calibrate gimbal center, 0x02 calibrate camera */
} __attribute__((packed)) CalibrateCommand;
} //namespace serial
} //namespace driver
} //namespace rrts
#endif //MODULES_DRIVER_SERIAL_INFANTRY_INFO_H