Basic_Frame_TypeC_2023_Omni
Loading...
Searching...
No Matches
subsystems_types.h
1
2// TODO: Rename to .hpp
3#ifndef __SUBSYSTEMS_TYPES_H
4#define __SUBSYSTEMS_TYPES_H
5
6#include <array>
7#include "attitude_types.h"
8#include "motor_types.h"
9#include "subsystems_defines.h"
10#include "uarm_os.hpp"
11#include "uarm_types.hpp"
12
13/* =========================================================================
14 * MOTOR TYPES
15 * ====================================================================== */
16/*
17 * @brief Structure for all motors installed
18 * @Note first 4 motors will use 0x200
19 * motor_data[0]: chassis 3508
20 * motor_data[1]: chassis 3508
21 * motor_data[2]: chassis 3508
22 * motor_data[3]: chassis 3508
23 * motor_data[4]: gimbal 6020 pitch
24 * motor_data[5]: gimbal 6020 yaw
25 * motor_data[6]: magazine 2006
26 * */
27
31
32typedef enum {
33 // DJI CHASSIS
34 CHASSIS_WHEEL1 = 0x201,
35 CHASSIS_WHEEL2 = 0x202,
36 CHASSIS_WHEEL3 = 0x203,
37 CHASSIS_WHEEL4 = 0x204,
38
39 // SWERVE
40 SWERVE_STEER_MOTOR1 = 0x141,
41 SWERVE_STEER_MOTOR2 = 0x142,
42 SWERVE_STEER_MOTOR3 = 0x143,
43 SWERVE_STEER_MOTOR4 = 0x144,
44
45 // SHOOT
46 SHOOT_LEFT_FRIC = 0x201,
47 SHOOT_RIGHT_FRIC = 0x202,
48 SHOOT_LOADER = 0x207,
49
50 // GIMBAL
51 GIMBAL_YAW = 0x205,
52 GIMBAL_PITCH = 0x206,
53} Motor_CAN_ID_t;
54
55typedef enum {
56 DJI_CHASSIS,
57 SWERVE,
58 SWERVE_ZERO,
59 DJI_GIMBAL,
60 MOTORS_NONE,
61} Motor_Config_t;
62
63typedef enum { DJI, LK, UNKNOWN_MOTOR } Motor_Brand_t;
64
65typedef struct {
66 // feedback_id is the same as stdid used to send commands to LK motors.
67 uint32_t feedback_id;
68 int32_t tx_data;
69 Motor_Brand_t brand;
71
72typedef struct {
73 Generic_Motor_t motors[MAX_MOTOR_COUNT];
74 Motor_Config_t config;
76
77/*
78 * @brief Structure for all motors installed
79 * @Note first 4 motors will use 0x200
80 * motor_data[0]: chassis 3508/shoot fric left 3508
81 * motor_data[1]: chassis 3508/shoot fric right 3508
82 * motor_data[2]: chassis 3508/shoot magazine 3508
83 * motor_data[3]: chassis 3508
84 * motor_data[4]: gimbal 6020 pitch
85 * motor_data[5]: gimbal 6020 yaw
86 * motor_data[6]: magazine 2006
87 * */
88
89/* =========================================================================
90 * IMU TYPES
91 * ====================================================================== */
92typedef enum { NORMAL = 1, ABNORMAL } IMU_temp_status;
93
94typedef enum {
95 GAM_MODE = 0, // 9 axis imu
96 GA_MODE // 6 axis mpu
97} IMU_mode_t;
98
99typedef struct {
100 float temp;
101 float prev_temp;
102 uint32_t sample_time;
103
104 IMU_temp_status temp_status;
105 IMU_mode_t imu_mode;
106 AhrsSensor_t ahrs_sensor; //for ahrs sensor - processed data
107} IMU_t;
108
109/* =========================================================================
110 * MESSAGE CENTER TYPES
111 * ====================================================================== */
112typedef enum Topic_Name_t {
113 MOTOR_SET = 100,
114 MOTOR_READ,
115 MOTOR_IN,
116 COMM_OUT,
117 COMM_IN,
118 IMU_READINGS,
119 // IMU_READY,
120 UI_SEND,
121 REF_INFO,
122 PLAYER_COMMANDS,
123 RC_INFO,
124 RC_RAW,
125
126 UC_PACK_IN,
127 UC_PACK_OUT,
128 AUTO_AIM,
129 UART_OUT,
130 GIMBAL_REL_ANGLES,
131
132 // Referee System
133 REFEREE_IN,
134 REFEREE_OUT,
135 COMMAND_GIMBAL,
136 COMMAND_CHASSIS,
137 COMMAND_SHOOT,
138} Topic_Name_t;
139
140// TODO: Find better solution to defining a testable QueueHandle_t.
141#ifdef GTEST
142typedef uint8_t* QueueHandle_t;
143#endif
144
145typedef struct Topic_Handle_t {
146 Topic_Name_t name;
147 uint8_t item_size;
148 uint8_t queue_length;
149 QueueHandle_t queue_handle;
151
152typedef struct {
153 uint32_t topic_name;
154 uint8_t data[8];
156
157typedef struct {
158 /*
159 * modes[0] - BoardMode_t
160 * modes[1] - BoardActMode_t
161 * modes[2] - ShootActMode_t
162 */
163 uint8_t modes[3];
164
165 /*
166 * channels[0-3] - Have info from RC on Chassis.
167 * channels[0-1] - Have info from Chassis on Gimbal.
168 * Gimbal is not given channels[2] and channels[3] because it does not need channels[0] and
169 * channels[1] for calculations. This allows RC info to be transmitted in one CAN frame (8 bytes).
170 */
171 int16_t channels[4];
173
174typedef struct {
175 int32_t motor_can_volts[MAX_MOTOR_COUNT];
176 Motor_CAN_ID_t can_ids[MAX_MOTOR_COUNT];
178
179typedef struct {
180 uint8_t feedback[MAX_MOTOR_COUNT][8];
181 Motor_CAN_ID_t can_ids[MAX_MOTOR_COUNT];
183
184typedef struct {
185 float v_perp;
186 float v_parallel;
187 float wz;
188 uint16_t command_bits; // TODO: Implement and remove RC_INFO.
190
191typedef struct {
192 float yaw;
193 float pitch;
194 uint32_t command_bits; // TODO: Implement and remove AUTO_AIM topic.
196
197typedef struct {
198 uint32_t command_bits;
199 uint32_t extra_bits;
201
202typedef struct {
203 uint8_t robot_id;
204 uint8_t robot_level;
205 uint16_t shoot_barrel_cooling_rate;
206 uint16_t shoot_barrel_heat_limit;
207 uint16_t chassis_power_limit;
209
210/* =========================================================================
211 * DEBUG TYPES
212 * ====================================================================== */
213typedef enum { GIMBAL_BOARD = 1, CHASSIS_BOARD = 2 } BoardStatus_t;
214
215typedef enum {
216 BLUE,
217 RED,
218 GREEN,
219} Board_LED_t;
220
221typedef enum {
222 ON,
223 OFF,
224} Board_LED_State_t;
225
226/* =========================================================================
227 * EVENT CENTER TYPES
228 * ====================================================================== */
229// There is a maximum of 24 bits for our configuration for one event group.
230// The other 8 bits are reserved for other use.
231typedef enum Event_t { IMU_READY = 1 << 0 } Event_t;
232
233typedef uint32_t UARM_Events_t;
234
235typedef enum Task_Sync_t {
236 TS_CHASSIS = 1 << 1,
237 TS_GIMBAL = 1 << 2,
238 TS_SHOOT = 1 << 3,
239 TS_COMM = 1 << 4,
240 TS_CONTROL = 1 << 5,
241 TS_IMU = 1 << 6,
242 TS_PC_UART = 1 << 7,
243 TS_REFEREE = 1 << 8,
244 TS_TIMER = 1 << 9,
245 TS_WATCHDOG = 1 << 10,
246} Task_Sync_t;
247
248typedef enum Sync_Event_t {
249 None,
250} Sync_Event_t;
251
252/* =========================================================================
253 * REFEREE UI TYPES
254 * ====================================================================== */
255typedef enum { FIGURE_ID = 0, INFO_ID = 1, NUMBER_ID = 2 } referee_name_type_t;
256
257typedef enum { UNKOWN = 0, RED_TEAM, BLUE_TEAM } robot_color_t;
258
259/* used id define */
260typedef enum {
261 IDLE_ID = 0x0000,
262 GAME_STAT_ID = 0x0001,
263 GAME_RESULT_ID = 0x0002,
264 GMAE_HP_ID = 0x0003,
265 ROBOT_STAT_ID = 0x0201,
266 POWER_HEAT_ID = 0x0202,
267 SHOOT_ID = 0x0207,
268
269 // Drawing UI interaction
270 INTERA_UI_ID = 0x0301,
271 INTERA_USER_DATA_ID = 0x0302,
272} referee_id_t;
273
274typedef struct __attribute__((__packed__)) {
275 uint8_t winner;
276} game_result_t;
277
278/* define user structure here */
279/* copy those from DJI referee manual */
280typedef struct __attribute__((__packed__)) //0x0001
281{
282 uint8_t game_type : 4;
283 uint8_t game_progress : 4;
284 uint16_t stage_remain_time;
285 uint64_t SyncTimeStamp;
286} game_status_t;
287
288typedef struct __attribute__((__packed__)) //0x0003
289{
290 uint16_t red_1_robot_HP;
291 uint16_t red_2_robot_HP;
292 uint16_t red_3_robot_HP;
293 uint16_t red_4_robot_HP;
294 uint16_t red_5_robot_HP;
295 uint16_t red_7_robot_HP;
296 uint16_t red_outpost_HP;
297 uint16_t red_base_HP;
298 uint16_t blue_1_robot_HP;
299 uint16_t blue_2_robot_HP;
300 uint16_t blue_3_robot_HP;
301 uint16_t blue_4_robot_HP;
302 uint16_t blue_5_robot_HP;
303 uint16_t blue_7_robot_HP;
304 uint16_t blue_outpost_HP;
305 uint16_t blue_base_HP;
306} game_robot_HP_t;
307
308typedef struct __attribute__((__packed__)) //0x0201
309{
310 uint8_t robot_id;
311 uint8_t robot_level;
312 uint16_t current_HP;
313 uint16_t maximum_HP;
314 uint16_t shooter_barrel_cooling_value;
315 uint16_t shooter_barrel_heat_limit;
316 uint16_t chassis_power_limit;
317 uint8_t power_management_gimbal_output : 1;
318 uint8_t power_management_chassis_output : 1;
319 uint8_t power_management_shooter_output : 1;
320} robot_status_t;
321
322typedef struct //0x0202
323{
324 uint16_t chassis_voltage;
325 uint16_t chassis_current;
326 float chassis_power;
327 uint16_t buffer_energy;
328 uint16_t shooter_17mm_1_barrel_heat;
329 uint16_t shooter_17mm_2_barrel_heat;
330 uint16_t shooter_42mm_barrel_heat;
332
333typedef struct __attribute__((__packed__)) //0x0207
334{
335 uint8_t bullet_type;
336 uint8_t shooter_number;
337 uint8_t launching_frequency;
338 float initial_speed;
339} shoot_data_t;
340
341/* For drawing the UI on the client */
342typedef struct __attribute__((__packed__)) //0x0301
343{
344 uint16_t data_cmd_id;
345 uint16_t sender_id;
346 uint16_t receiver_id;
347 uint8_t user_data[113]; //max length 113
348} robot_interaction_data_t;
349
350// Sub commands for UI interactions
351typedef struct __attribute__((__packed__)) //0x0100
352{
353 uint8_t delete_type;
354 uint8_t layer;
355} interaction_layer_delete_t;
356
357typedef struct __attribute__((__packed__)) //0x0101
358{
359 uint8_t figure_name[3];
360 uint32_t operate_tpye : 3;
361 uint32_t figure_tpye : 3;
362 uint32_t layer : 4;
363 uint32_t color : 4;
364 uint32_t details_a : 9;
365 uint32_t details_b : 9;
366 uint32_t width : 10;
367 uint32_t start_x : 11;
368 uint32_t start_y : 11;
369 uint32_t details_c : 10;
370 uint32_t details_d : 11;
371 uint32_t details_e : 11;
372} interaction_figure_t;
373
374typedef struct __attribute__((__packed__)) //0x0102
375{
376 interaction_figure_t interaction_figure[2];
377} interaction_figure_2_t;
378
379typedef struct __attribute__((__packed__)) //0x0103
380{
381 interaction_figure_t interaction_figure[5];
382} interaction_figure_5_t;
383
384typedef struct __attribute__((__packed__)) //0x0104
385{
386 interaction_figure_t interaction_figure[7];
387} interaction_figure_7_t;
388
389typedef struct __attribute__((__packed__)) //0x0110
390{
391 interaction_figure_t figure_data_struct;
392 uint8_t data[30];
393} ext_client_custom_character_t;
394
395typedef struct __attribute__((__packed__)) //0x0302
396{
397 uint8_t data[30]; // max 30
398} custom_robot_data_t;
399
400/* main referee system struct */
401typedef struct __attribute__((__packed__)) {
402 uint8_t sof; //0xA5
403 uint16_t data_length;
404 uint8_t seq;
405 uint8_t crc8;
406} frame_header_t;
407
408// TODO: Re-enable later.
409typedef enum {
410 UI_TYPE_IDLE_ID = 0,
411 /* General UI */
412 UI_ROBOT_VAILD_INFO,
413 UI_ROBOT_ACT_MODE,
414 UI_ROBOT_LEVEL,
415 UI_SUPCAP_PERCENT,
416
417 /* Infantry only */
418 UI_INFANTRY_MARK,
419
420 /* Hero only */
421 UI_HERO_MARK,
422} referee_ui_type_t;
423
424typedef enum {
425 UI_IDLE_ID = 0x0000, // No interaction
426 // Sub cmd id
427 SUB_UI_LAYER_DEL_ID = 0x0100,
428 SUB_UI_DRAW_1_ID = 0x0101,
429 SUB_UI_DRAW_2_ID = 0x0102,
430 SUB_UI_DRAW_5_ID = 0x0103,
431 SUB_UI_DRAW_7_ID = 0x0104,
432 SUB_UI_EXT_CUSTOM_ID = 0x0110
433} ref_ui_id_t;
434
435typedef struct {
436 uint32_t act_mode;
437 uint32_t level;
438 uint32_t super_cap_percent;
440
441typedef struct {
442 robot_interaction_data_t ui_intrect_data;
443 robot_interaction_data_t ui_intrect_data_info;
444 interaction_layer_delete_t ui_del_fig_data;
445 interaction_figure_t ui_figure_data;
446 interaction_figure_2_t ui_figure_draw_2_data;
447 interaction_figure_5_t ui_figure_draw_5_data;
448 interaction_figure_7_t ui_draw_marks_data;
449 interaction_figure_7_t ui_draw_info_data;
450 ext_client_custom_character_t ui_custom_data;
451
452 uint8_t first_drawing_flag;
453 uint8_t first_drawing_flag_info; // For infantry marks
454 uint8_t cur_sending_count;
455 referee_ui_type_t cur_sending_id;
456 ref_ui_info_t ui_info;
457 uint8_t pack_seq;
459
460/* =========================================================================
461 * RC COMM TYPES
462 * ====================================================================== */
463constexpr uint32_t DBUS_BUFFER_LENGTH = 18;
464constexpr uint16_t CHANNEL_CENTER = 1024;
465constexpr uint16_t MOUSE_MAX_SPEED = 15000;
466constexpr uint16_t MAX_CHANNEL_VALUE = 660;
467
468using Buffer = std::array<uint8_t, DBUS_BUFFER_LENGTH>;
469
470enum class EKeyStatus {
471 RELEASED = 0, // key released
472 RELEASED_TO_PRESS, // key just pressed, rising edge
473 PRESSED_TO_RELEASE, // key just released, falling edge
474 PRESSED // key pressed
475};
476
477enum class ESwitchState {
478 UNKNOWN = 0,
479 UP = 1,
480 MID = 3,
481 DOWN = 2,
482};
483
484enum class EKeyBitIndex {
485 W = 0x01 << 0, // Also used for mouse clicks.
486 S = 0x01 << 1,
487 A = 0x01 << 2,
488 D = 0x01 << 3,
489 SHIFT = 0x01 << 4,
490 CTRL = 0x01 << 5,
491 Q = 0x01 << 6,
492 E = 0x01 << 7,
493 R = 0x01 << 8,
494 F = 0x01 << 9,
495 G = 0x01 << 10,
496 Z = 0x01 << 11,
497 X = 0x01 << 12,
498 C = 0x01 << 13,
499 V = 0x01 << 14,
500 B = 0x01 << 15,
501};
502
504 int16_t ch0;
505 int16_t ch1;
506 int16_t ch2;
507 int16_t ch3;
508 ESwitchState s1;
509 ESwitchState s2;
510 int16_t wheel;
511};
512
513/* pc mode */
514struct KeyObject {
515 EKeyStatus status;
516 EKeyStatus pre_status;
517 uint8_t status_count;
518};
519
520struct Keyboard {
521 KeyObject W;
522 KeyObject A;
523 KeyObject S;
524 KeyObject D;
525 KeyObject Q;
526 KeyObject E;
527 KeyObject R;
528 KeyObject V;
529 KeyObject Ctrl;
530 KeyObject F;
531 KeyObject Shift;
532 KeyObject G;
533 KeyObject C;
534 KeyObject B;
535
536 uint16_t key_buffer; // used to grab current key info
537};
538
539struct Mouse {
540 int16_t x;
541 int16_t y;
542 int16_t z;
543 uint8_t click_l;
544 uint8_t click_r;
545 KeyObject left_click;
546 KeyObject right_click;
547};
548
549struct PC {
550 Mouse mouse;
551 Keyboard keyboard;
552};
553
554/* =========================================================================
555 * AMMO LID TYPES
556 * ====================================================================== */
557enum class EAmmoLidStatus {
558 OPEN,
559 CLOSED,
560};
561
562/* =========================================================================
563 * PC COMM TYPES
564 * ====================================================================== */
565// PACK STRUCTS
566// upper computer -> MCU
567typedef struct {
568 uint8_t target_num;
569 uint8_t should_shoot;
570 float delta_yaw;
571 float delta_pitch;
573
574typedef struct {
575 uint8_t control_code;
576 uint32_t sequence_number;
577 uint32_t acknowledge;
579
580// MCU -> upper computer
581typedef struct {
582 uint8_t robot_color; // 0: red, 1: blue
583
584 // imu data
585 float pitch;
586 float yaw;
587 float accel_x;
588 float accel_y;
589
590 float wheel_rpm[4]; // from chassis wheels
592
593// OTHER STRUCTS
594typedef union pack_checksum {
595 uint32_t as_integer;
596 uint8_t as_bytes[PACK_TRAILER_SIZE];
597} UC_Checksum_t;
598
599typedef struct {
600 uint8_t header_id;
601 uint8_t header_size;
602 uint8_t data_size;
603 uint8_t trailer_size;
605
606#endif
Definition attitude_types.h:9
Definition subsystems_types.h:152
Definition subsystems_types.h:184
Definition subsystems_types.h:503
Definition subsystems_types.h:65
Definition subsystems_types.h:191
Definition subsystems_types.h:99
Definition subsystems_types.h:514
Definition subsystems_types.h:520
Definition subsystems_types.h:179
Definition subsystems_types.h:174
Definition subsystems_types.h:539
Definition subsystems_types.h:549
Definition subsystems_types.h:599
Definition subsystems_types.h:157
Definition subsystems_types.h:441
Definition subsystems_types.h:202
Definition subsystems_types.h:197
Definition subsystems_types.h:72
Definition subsystems_types.h:145
Definition subsystems_types.h:567
Definition subsystems_types.h:581
Definition subsystems_types.h:574
Definition subsystems_types.h:323
Definition subsystems_types.h:435
Definition subsystems_types.h:594