blob: 50eb7a92b4ae842d2bc678be63ffeed7d267a132 [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 Silvermana280ae02013-10-28 18:21:15 -07006// <stdint.h> must be #included by the containing file.
Brian Silvermanf92396c2013-09-12 20:13:13 -07007// In the gyro board code, fill_packet.h #includes this file.
8// In the fitpc code, frc971/input/gyro_board_data.h #includes this file.
9
10#pragma pack(push, 1)
Brian Silverman49876942013-10-11 17:50:26 -070011// Be careful with declaration order in here. ARM doesn't like unaligned
12// accesses!
Brian Silvermanf92396c2013-09-12 20:13:13 -070013struct DATA_STRUCT_NAME {
14 int64_t gyro_angle;
15
Brian Silvermana280ae02013-10-28 18:21:15 -070016 // In units of 100,000 counts/second.
17 uint64_t timestamp;
18
Brian Silvermanf92396c2013-09-12 20:13:13 -070019 union {
20 struct {
Brian Silverman89e86362013-10-30 17:50:50 -070021 // This is the USB frame number for this data. It gets incremented on
22 // every packet sent.
23 // Negative numbers mean that the gyro board has no idea what the right
24 // answer is.
25 // This value going down at all indicates that the code on the gyro board
26 // dealing with it reset.
27 int32_t frame_number;
Brian Silvermana280ae02013-10-28 18:21:15 -070028
Brian Silverman28d97782013-10-31 17:33:52 -070029 // Checksum of this file calculated with sum(1).
30 // The gyro board sets this and then the fitpc checks it to make sure that
31 // they're both using the same version of this file.
32 uint16_t checksum;
33
Brian Silvermanf92396c2013-09-12 20:13:13 -070034 // Which robot (+version) the gyro board is sending out data for.
35 // We should keep this in the same place for all gyro board software
36 // versions so that the fitpc can detect when it's reading from a gyro
Brian Silverman74acd622013-10-26 14:47:14 -070037 // board set up for a different robot (or version) than it is.
38 // The numbers listed below each robot are the values that have been used
39 // for it.
40 //
41 // 2013 competition/practice robot
42 // 0
43 // 2 added battery measurement + drivetrain analog hall effects
44 // 2013 3rd robot
45 // 1
Brian Silvermanf92396c2013-09-12 20:13:13 -070046 uint8_t robot_id;
47 // This information should also be kept in the same place from year to
48 // year so that the fitpc code can record the dip switch values when it
49 // detects the wrong robot id to make debugging easier.
50 union {
51 struct {
52 uint8_t dip_switch0 : 1;
53 uint8_t dip_switch1 : 1;
54 uint8_t dip_switch2 : 1;
55 uint8_t dip_switch3 : 1;
56 };
Brian Silvermana280ae02013-10-28 18:21:15 -070057 uint8_t dip_switches;
58 };
59 struct {
60 // If the current gyro_angle has been not updated because of a bad
61 // reading from the sensor.
62 uint8_t old_gyro_reading : 1;
63 // If we're not going to get any more good gyro_angles.
64 uint8_t bad_gyro : 1;
Brian Silverman89e86362013-10-30 17:50:50 -070065
66 // We're not sure what frame number this packet was sent in.
67 uint8_t unknown_frame : 1;
Brian Silvermanf92396c2013-09-12 20:13:13 -070068 };
69 };
Brian Silverman28d97782013-10-31 17:33:52 -070070 struct {
71 uint64_t header0, header1;
72 };
Brian Silvermanf92396c2013-09-12 20:13:13 -070073 };
74
Brian Silvermana280ae02013-10-28 18:21:15 -070075 // We are 64-bit aligned at this point.
Brian Silverman70478d12013-10-11 17:54:58 -070076
Brian Silvermanf92396c2013-09-12 20:13:13 -070077 union {
78 struct {
Brian Silvermanf92396c2013-09-12 20:13:13 -070079 int32_t left_drive;
80 int32_t right_drive;
81 int32_t shooter_angle;
82 int32_t shooter;
83 int32_t indexer;
84 int32_t wrist;
85
86 int32_t capture_top_rise;
87 int32_t capture_top_fall;
88 int32_t capture_bottom_fall_delay;
89 int32_t capture_wrist_rise;
90 int32_t capture_shooter_angle_rise;
91
Brian Silverman74acd622013-10-26 14:47:14 -070092 uint16_t battery_voltage;
93 uint16_t left_drive_hall;
94 uint16_t right_drive_hall;
95
Brian Silvermanf92396c2013-09-12 20:13:13 -070096 int8_t top_rise_count;
97
98 int8_t top_fall_count;
99
100 int8_t bottom_rise_count;
101
102 int8_t bottom_fall_delay_count;
103 int8_t bottom_fall_count;
104
105 int8_t wrist_rise_count;
106
107 int8_t shooter_angle_rise_count;
Brian Silverman74acd622013-10-26 14:47:14 -0700108
109 struct {
110 uint8_t wrist_hall_effect : 1;
111 uint8_t angle_adjust_bottom_hall_effect : 1;
112 uint8_t top_disc : 1;
113 uint8_t bottom_disc : 1;
114 uint8_t loader_top : 1;
115 uint8_t loader_bottom : 1;
116 };
Brian Silvermanf92396c2013-09-12 20:13:13 -0700117 } main;
118
119 struct {
120 union {
121 struct {
122 };
123 uint16_t booleans;
124 };
125 } bot3;
126 };
127};
128#pragma pack(pop)
Brian Silverman466d6692013-09-13 14:16:36 -0700129
Brian Silverman2d21bb22013-10-25 15:52:42 -0700130// This is how big the isochronous packets that we're going to send are.
131// This number is more painful to change than the actual size of the struct
132// because the code on both ends has to agree on this (or at least that's what
133// Brian found empirically 2013-10-24).
134#define DATA_STRUCT_SEND_SIZE 128
135
Brian Silverman466d6692013-09-13 14:16:36 -0700136#ifdef __cplusplus
137// TODO(brians): Consider using C1X's _Static_assert once we have a compiler
138// (GCC 4.6) + flags that support it.
Brian Silverman2d21bb22013-10-25 15:52:42 -0700139static_assert(sizeof(DATA_STRUCT_NAME) <= DATA_STRUCT_SEND_SIZE,
Brian Silverman1e869f32013-10-25 18:00:20 -0700140 "The sensor data structure is too big.");
Brian Silverman466d6692013-09-13 14:16:36 -0700141#endif // defined(__cplusplus)