blob: 4470476755e3e1586b1b0509d9150e76fcf2c0b2 [file] [log] [blame]
Brian Silvermanf92396c2013-09-12 20:13:13 -07001// This isn't really a header file. It's designed to be #included directly into
2// other code (possibly in a namespace or whatever), so it doesn't have include
3// guards.
Brian Silverman3c52c132013-10-11 21:36:59 -07004// This means that it can not #include anything else because it (sometimes) gets
5// #included inside a namespace.
Brian Silvermanf92396c2013-09-12 20:13:13 -07006// In the gyro board code, fill_packet.h #includes this file.
7// In the fitpc code, frc971/input/gyro_board_data.h #includes this file.
8
9#pragma pack(push, 1)
Brian Silverman49876942013-10-11 17:50:26 -070010// Be careful with declaration order in here. ARM doesn't like unaligned
11// accesses!
Brian Silvermanf92396c2013-09-12 20:13:13 -070012struct DATA_STRUCT_NAME {
13 int64_t gyro_angle;
14
15 union {
16 struct {
17 // Which robot (+version) the gyro board is sending out data for.
18 // We should keep this in the same place for all gyro board software
19 // versions so that the fitpc can detect when it's reading from a gyro
20 // board set up for a different robot than it is.
21 // 0 = 2013 competition/practice robot
22 // 1 = 2013 3rd robot
23 uint8_t robot_id;
24 // This information should also be kept in the same place from year to
25 // year so that the fitpc code can record the dip switch values when it
26 // detects the wrong robot id to make debugging easier.
27 union {
28 struct {
29 uint8_t dip_switch0 : 1;
30 uint8_t dip_switch1 : 1;
31 uint8_t dip_switch2 : 1;
32 uint8_t dip_switch3 : 1;
Brian Silverman49876942013-10-11 17:50:26 -070033 // If the current gyro_angle has been not updated because of a bad
34 // reading from the sensor.
35 uint8_t old_gyro_reading : 1;
36 // If we're not going to get any more good gyro_angles.
37 uint8_t bad_gyro : 1;
Brian Silvermanf92396c2013-09-12 20:13:13 -070038 };
Brian Silverman49876942013-10-11 17:50:26 -070039 uint8_t base_status;
Brian Silvermanf92396c2013-09-12 20:13:13 -070040 };
41 };
42 uint16_t header;
43 };
44
Brian Silverman70478d12013-10-11 17:54:58 -070045 // This is a counter that gets incremented with each packet sent (and wraps
46 // around when it reaches 255).
47 uint8_t sequence;
48
Brian Silvermanf92396c2013-09-12 20:13:13 -070049 union {
50 struct {
51 union {
52 struct {
53 uint8_t wrist_hall_effect : 1;
54 uint8_t angle_adjust_bottom_hall_effect : 1;
55 uint8_t top_disc : 1;
56 uint8_t bottom_disc : 1;
Brian Silverman1623c332013-10-01 18:05:16 -070057 uint8_t loader_top : 1;
58 uint8_t loader_bottom : 1;
Brian Silvermanf92396c2013-09-12 20:13:13 -070059 };
60 uint16_t booleans;
61 };
62 int32_t left_drive;
63 int32_t right_drive;
64 int32_t shooter_angle;
65 int32_t shooter;
66 int32_t indexer;
67 int32_t wrist;
68
69 int32_t capture_top_rise;
70 int32_t capture_top_fall;
71 int32_t capture_bottom_fall_delay;
72 int32_t capture_wrist_rise;
73 int32_t capture_shooter_angle_rise;
74
75 int8_t top_rise_count;
76
77 int8_t top_fall_count;
78
79 int8_t bottom_rise_count;
80
81 int8_t bottom_fall_delay_count;
82 int8_t bottom_fall_count;
83
84 int8_t wrist_rise_count;
85
86 int8_t shooter_angle_rise_count;
87 } main;
88
89 struct {
90 union {
91 struct {
92 };
93 uint16_t booleans;
94 };
95 } bot3;
96 };
97};
98#pragma pack(pop)
Brian Silverman466d6692013-09-13 14:16:36 -070099
Brian Silverman2d21bb22013-10-25 15:52:42 -0700100// This is how big the isochronous packets that we're going to send are.
101// This number is more painful to change than the actual size of the struct
102// because the code on both ends has to agree on this (or at least that's what
103// Brian found empirically 2013-10-24).
104#define DATA_STRUCT_SEND_SIZE 128
105
Brian Silverman466d6692013-09-13 14:16:36 -0700106#ifdef __cplusplus
107// TODO(brians): Consider using C1X's _Static_assert once we have a compiler
108// (GCC 4.6) + flags that support it.
Brian Silverman2d21bb22013-10-25 15:52:42 -0700109static_assert(sizeof(DATA_STRUCT_NAME) <= DATA_STRUCT_SEND_SIZE,
110 "We only have room for " STRINGIFY(DATA_STRUCT_SEND_SIZE)
111 " bytes in the USB packet.");
Brian Silverman466d6692013-09-13 14:16:36 -0700112#endif // defined(__cplusplus)