blob: 975084a63f13a90c4ab69f6a2eaaddb08beafe64 [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
16 union {
17 struct {
Brian Silverman441d55c2013-10-31 19:27:23 -070018 // This is the USB frame number for this data. It (theoretically) gets
19 // incremented on every packet sent, but the gyro board will deal with it
20 // correctly if it misses a frame or whatever by tracking the frame
21 // numbers sent out by the host.
Brian Silverman89e86362013-10-30 17:50:50 -070022 // Negative numbers mean that the gyro board has no idea what the right
23 // answer is.
24 // This value going down at all indicates that the code on the gyro board
25 // dealing with it reset.
Brian Silverman441d55c2013-10-31 19:27:23 -070026 //
27 // The USB 2.0 standard says that timing of frames is 1.000ms +- 500ns.
28 // Testing with a fitpc and gyro board on 2013-10-30 by Brian gave 10us
29 // (the resolution of the timer on the gyro board that was used) of drift
30 // every 90-130 frames (~100ns per frame) and no jitter (and the timer on
31 // the gyro board isn't necessarily that good). This is plenty accurate
32 // for what we need for timing, so this number is what the code uses to do
33 // all timing calculations.
Brian Silverman89e86362013-10-30 17:50:50 -070034 int32_t frame_number;
Brian Silvermana280ae02013-10-28 18:21:15 -070035
Brian Silverman28d97782013-10-31 17:33:52 -070036 // Checksum of this file calculated with sum(1).
37 // The gyro board sets this and then the fitpc checks it to make sure that
38 // they're both using the same version of this file.
39 uint16_t checksum;
40
Brian Silvermanf92396c2013-09-12 20:13:13 -070041 // Which robot (+version) the gyro board is sending out data for.
42 // We should keep this in the same place for all gyro board software
43 // versions so that the fitpc can detect when it's reading from a gyro
Brian Silverman74acd622013-10-26 14:47:14 -070044 // board set up for a different robot (or version) than it is.
45 // The numbers listed below each robot are the values that have been used
46 // for it.
47 //
48 // 2013 competition/practice robot
49 // 0
50 // 2 added battery measurement + drivetrain analog hall effects
51 // 2013 3rd robot
52 // 1
Brian Silvermanf92396c2013-09-12 20:13:13 -070053 uint8_t robot_id;
54 // This information should also be kept in the same place from year to
55 // year so that the fitpc code can record the dip switch values when it
56 // detects the wrong robot id to make debugging easier.
57 union {
58 struct {
59 uint8_t dip_switch0 : 1;
60 uint8_t dip_switch1 : 1;
61 uint8_t dip_switch2 : 1;
62 uint8_t dip_switch3 : 1;
63 };
Brian Silvermana280ae02013-10-28 18:21:15 -070064 uint8_t dip_switches;
65 };
66 struct {
67 // If the current gyro_angle has been not updated because of a bad
68 // reading from the sensor.
69 uint8_t old_gyro_reading : 1;
70 // If we're not going to get any more good gyro_angles.
71 uint8_t bad_gyro : 1;
Brian Silverman89e86362013-10-30 17:50:50 -070072
73 // We're not sure what frame number this packet was sent in.
74 uint8_t unknown_frame : 1;
Brian Silvermanf92396c2013-09-12 20:13:13 -070075 };
76 };
Brian Silverman28d97782013-10-31 17:33:52 -070077 struct {
78 uint64_t header0, header1;
79 };
Brian Silvermanf92396c2013-09-12 20:13:13 -070080 };
81
Brian Silvermana280ae02013-10-28 18:21:15 -070082 // We are 64-bit aligned at this point.
Brian Silverman70478d12013-10-11 17:54:58 -070083
Brian Silvermanf92396c2013-09-12 20:13:13 -070084 union {
85 struct {
Brian Silvermanf92396c2013-09-12 20:13:13 -070086 int32_t left_drive;
87 int32_t right_drive;
88 int32_t shooter_angle;
89 int32_t shooter;
90 int32_t indexer;
91 int32_t wrist;
92
93 int32_t capture_top_rise;
94 int32_t capture_top_fall;
95 int32_t capture_bottom_fall_delay;
96 int32_t capture_wrist_rise;
97 int32_t capture_shooter_angle_rise;
98
Brian Silverman74acd622013-10-26 14:47:14 -070099 uint16_t battery_voltage;
100 uint16_t left_drive_hall;
101 uint16_t right_drive_hall;
102
Brian Silvermanf92396c2013-09-12 20:13:13 -0700103 int8_t top_rise_count;
104
105 int8_t top_fall_count;
106
107 int8_t bottom_rise_count;
108
109 int8_t bottom_fall_delay_count;
110 int8_t bottom_fall_count;
111
112 int8_t wrist_rise_count;
113
114 int8_t shooter_angle_rise_count;
Brian Silverman74acd622013-10-26 14:47:14 -0700115
116 struct {
117 uint8_t wrist_hall_effect : 1;
118 uint8_t angle_adjust_bottom_hall_effect : 1;
119 uint8_t top_disc : 1;
120 uint8_t bottom_disc : 1;
121 uint8_t loader_top : 1;
122 uint8_t loader_bottom : 1;
123 };
Brian Silvermanf92396c2013-09-12 20:13:13 -0700124 } main;
125
126 struct {
127 union {
128 struct {
129 };
130 uint16_t booleans;
131 };
132 } bot3;
133 };
134};
135#pragma pack(pop)
Brian Silverman466d6692013-09-13 14:16:36 -0700136
Brian Silverman2d21bb22013-10-25 15:52:42 -0700137// This is how big the isochronous packets that we're going to send are.
138// This number is more painful to change than the actual size of the struct
139// because the code on both ends has to agree on this (or at least that's what
140// Brian found empirically 2013-10-24).
141#define DATA_STRUCT_SEND_SIZE 128
142
Brian Silverman466d6692013-09-13 14:16:36 -0700143#ifdef __cplusplus
144// TODO(brians): Consider using C1X's _Static_assert once we have a compiler
145// (GCC 4.6) + flags that support it.
Brian Silverman2d21bb22013-10-25 15:52:42 -0700146static_assert(sizeof(DATA_STRUCT_NAME) <= DATA_STRUCT_SEND_SIZE,
Brian Silverman1e869f32013-10-25 18:00:20 -0700147 "The sensor data structure is too big.");
Brian Silverman466d6692013-09-13 14:16:36 -0700148#endif // defined(__cplusplus)