blob: 8c069b9eb89f6f3e4610217138a7aa091170eaa2 [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
Brian Silverman74acd622013-10-26 14:47:14 -070020 // board set up for a different robot (or version) than it is.
21 // The numbers listed below each robot are the values that have been used
22 // for it.
23 //
24 // 2013 competition/practice robot
25 // 0
26 // 2 added battery measurement + drivetrain analog hall effects
27 // 2013 3rd robot
28 // 1
Brian Silvermanf92396c2013-09-12 20:13:13 -070029 uint8_t robot_id;
30 // This information should also be kept in the same place from year to
31 // year so that the fitpc code can record the dip switch values when it
32 // detects the wrong robot id to make debugging easier.
33 union {
34 struct {
35 uint8_t dip_switch0 : 1;
36 uint8_t dip_switch1 : 1;
37 uint8_t dip_switch2 : 1;
38 uint8_t dip_switch3 : 1;
Brian Silverman49876942013-10-11 17:50:26 -070039 // If the current gyro_angle has been not updated because of a bad
40 // reading from the sensor.
41 uint8_t old_gyro_reading : 1;
42 // If we're not going to get any more good gyro_angles.
43 uint8_t bad_gyro : 1;
Brian Silvermanf92396c2013-09-12 20:13:13 -070044 };
Brian Silverman49876942013-10-11 17:50:26 -070045 uint8_t base_status;
Brian Silvermanf92396c2013-09-12 20:13:13 -070046 };
47 };
Brian Silverman74acd622013-10-26 14:47:14 -070048 uint32_t header;
Brian Silvermanf92396c2013-09-12 20:13:13 -070049 };
50
Brian Silverman74acd622013-10-26 14:47:14 -070051 // This is a counter that gets incremented with each packet sent.
52 uint32_t sequence;
53
54 // We are 64-bit aligned at this point if it matters for anything other than
55 // the gyro angle.
Brian Silverman70478d12013-10-11 17:54:58 -070056
Brian Silvermanf92396c2013-09-12 20:13:13 -070057 union {
58 struct {
Brian Silvermanf92396c2013-09-12 20:13:13 -070059 int32_t left_drive;
60 int32_t right_drive;
61 int32_t shooter_angle;
62 int32_t shooter;
63 int32_t indexer;
64 int32_t wrist;
65
66 int32_t capture_top_rise;
67 int32_t capture_top_fall;
68 int32_t capture_bottom_fall_delay;
69 int32_t capture_wrist_rise;
70 int32_t capture_shooter_angle_rise;
71
Brian Silverman74acd622013-10-26 14:47:14 -070072 uint16_t battery_voltage;
73 uint16_t left_drive_hall;
74 uint16_t right_drive_hall;
75
Brian Silvermanf92396c2013-09-12 20:13:13 -070076 int8_t top_rise_count;
77
78 int8_t top_fall_count;
79
80 int8_t bottom_rise_count;
81
82 int8_t bottom_fall_delay_count;
83 int8_t bottom_fall_count;
84
85 int8_t wrist_rise_count;
86
87 int8_t shooter_angle_rise_count;
Brian Silverman74acd622013-10-26 14:47:14 -070088
89 struct {
90 uint8_t wrist_hall_effect : 1;
91 uint8_t angle_adjust_bottom_hall_effect : 1;
92 uint8_t top_disc : 1;
93 uint8_t bottom_disc : 1;
94 uint8_t loader_top : 1;
95 uint8_t loader_bottom : 1;
96 };
Brian Silvermanf92396c2013-09-12 20:13:13 -070097 } main;
98
99 struct {
100 union {
101 struct {
102 };
103 uint16_t booleans;
104 };
105 } bot3;
106 };
107};
108#pragma pack(pop)
Brian Silverman466d6692013-09-13 14:16:36 -0700109
Brian Silverman2d21bb22013-10-25 15:52:42 -0700110// This is how big the isochronous packets that we're going to send are.
111// This number is more painful to change than the actual size of the struct
112// because the code on both ends has to agree on this (or at least that's what
113// Brian found empirically 2013-10-24).
114#define DATA_STRUCT_SEND_SIZE 128
115
Brian Silverman466d6692013-09-13 14:16:36 -0700116#ifdef __cplusplus
117// TODO(brians): Consider using C1X's _Static_assert once we have a compiler
118// (GCC 4.6) + flags that support it.
Brian Silverman2d21bb22013-10-25 15:52:42 -0700119static_assert(sizeof(DATA_STRUCT_NAME) <= DATA_STRUCT_SEND_SIZE,
Brian Silverman1e869f32013-10-25 18:00:20 -0700120 "The sensor data structure is too big.");
Brian Silverman466d6692013-09-13 14:16:36 -0700121#endif // defined(__cplusplus)