Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 1 | // 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 Silverman | 3c52c13 | 2013-10-11 21:36:59 -0700 | [diff] [blame] | 4 | // This means that it can not #include anything else because it (sometimes) gets |
| 5 | // #included inside a namespace. |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame^] | 6 | // <stdint.h> must be #included by the containing file. |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 7 | // 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 Silverman | 4987694 | 2013-10-11 17:50:26 -0700 | [diff] [blame] | 11 | // Be careful with declaration order in here. ARM doesn't like unaligned |
| 12 | // accesses! |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 13 | struct DATA_STRUCT_NAME { |
| 14 | int64_t gyro_angle; |
| 15 | |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame^] | 16 | // In units of 100,000 counts/second. |
| 17 | uint64_t timestamp; |
| 18 | |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 19 | union { |
| 20 | struct { |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame^] | 21 | // This is a counter that gets incremented with each packet sent. |
| 22 | uint32_t sequence; |
| 23 | |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 24 | // Which robot (+version) the gyro board is sending out data for. |
| 25 | // We should keep this in the same place for all gyro board software |
| 26 | // versions so that the fitpc can detect when it's reading from a gyro |
Brian Silverman | 74acd62 | 2013-10-26 14:47:14 -0700 | [diff] [blame] | 27 | // board set up for a different robot (or version) than it is. |
| 28 | // The numbers listed below each robot are the values that have been used |
| 29 | // for it. |
| 30 | // |
| 31 | // 2013 competition/practice robot |
| 32 | // 0 |
| 33 | // 2 added battery measurement + drivetrain analog hall effects |
| 34 | // 2013 3rd robot |
| 35 | // 1 |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 36 | uint8_t robot_id; |
| 37 | // This information should also be kept in the same place from year to |
| 38 | // year so that the fitpc code can record the dip switch values when it |
| 39 | // detects the wrong robot id to make debugging easier. |
| 40 | union { |
| 41 | struct { |
| 42 | uint8_t dip_switch0 : 1; |
| 43 | uint8_t dip_switch1 : 1; |
| 44 | uint8_t dip_switch2 : 1; |
| 45 | uint8_t dip_switch3 : 1; |
| 46 | }; |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame^] | 47 | uint8_t dip_switches; |
| 48 | }; |
| 49 | struct { |
| 50 | // If the current gyro_angle has been not updated because of a bad |
| 51 | // reading from the sensor. |
| 52 | uint8_t old_gyro_reading : 1; |
| 53 | // If we're not going to get any more good gyro_angles. |
| 54 | uint8_t bad_gyro : 1; |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 55 | }; |
| 56 | }; |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame^] | 57 | uint64_t header; |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame^] | 60 | // We are 64-bit aligned at this point. |
Brian Silverman | 70478d1 | 2013-10-11 17:54:58 -0700 | [diff] [blame] | 61 | |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 62 | union { |
| 63 | struct { |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 64 | int32_t left_drive; |
| 65 | int32_t right_drive; |
| 66 | int32_t shooter_angle; |
| 67 | int32_t shooter; |
| 68 | int32_t indexer; |
| 69 | int32_t wrist; |
| 70 | |
| 71 | int32_t capture_top_rise; |
| 72 | int32_t capture_top_fall; |
| 73 | int32_t capture_bottom_fall_delay; |
| 74 | int32_t capture_wrist_rise; |
| 75 | int32_t capture_shooter_angle_rise; |
| 76 | |
Brian Silverman | 74acd62 | 2013-10-26 14:47:14 -0700 | [diff] [blame] | 77 | uint16_t battery_voltage; |
| 78 | uint16_t left_drive_hall; |
| 79 | uint16_t right_drive_hall; |
| 80 | |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 81 | int8_t top_rise_count; |
| 82 | |
| 83 | int8_t top_fall_count; |
| 84 | |
| 85 | int8_t bottom_rise_count; |
| 86 | |
| 87 | int8_t bottom_fall_delay_count; |
| 88 | int8_t bottom_fall_count; |
| 89 | |
| 90 | int8_t wrist_rise_count; |
| 91 | |
| 92 | int8_t shooter_angle_rise_count; |
Brian Silverman | 74acd62 | 2013-10-26 14:47:14 -0700 | [diff] [blame] | 93 | |
| 94 | struct { |
| 95 | uint8_t wrist_hall_effect : 1; |
| 96 | uint8_t angle_adjust_bottom_hall_effect : 1; |
| 97 | uint8_t top_disc : 1; |
| 98 | uint8_t bottom_disc : 1; |
| 99 | uint8_t loader_top : 1; |
| 100 | uint8_t loader_bottom : 1; |
| 101 | }; |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 102 | } main; |
| 103 | |
| 104 | struct { |
| 105 | union { |
| 106 | struct { |
| 107 | }; |
| 108 | uint16_t booleans; |
| 109 | }; |
| 110 | } bot3; |
| 111 | }; |
| 112 | }; |
| 113 | #pragma pack(pop) |
Brian Silverman | 466d669 | 2013-09-13 14:16:36 -0700 | [diff] [blame] | 114 | |
Brian Silverman | 2d21bb2 | 2013-10-25 15:52:42 -0700 | [diff] [blame] | 115 | // This is how big the isochronous packets that we're going to send are. |
| 116 | // This number is more painful to change than the actual size of the struct |
| 117 | // because the code on both ends has to agree on this (or at least that's what |
| 118 | // Brian found empirically 2013-10-24). |
| 119 | #define DATA_STRUCT_SEND_SIZE 128 |
| 120 | |
Brian Silverman | 466d669 | 2013-09-13 14:16:36 -0700 | [diff] [blame] | 121 | #ifdef __cplusplus |
| 122 | // TODO(brians): Consider using C1X's _Static_assert once we have a compiler |
| 123 | // (GCC 4.6) + flags that support it. |
Brian Silverman | 2d21bb2 | 2013-10-25 15:52:42 -0700 | [diff] [blame] | 124 | static_assert(sizeof(DATA_STRUCT_NAME) <= DATA_STRUCT_SEND_SIZE, |
Brian Silverman | 1e869f3 | 2013-10-25 18:00:20 -0700 | [diff] [blame] | 125 | "The sensor data structure is too big."); |
Brian Silverman | 466d669 | 2013-09-13 14:16:36 -0700 | [diff] [blame] | 126 | #endif // defined(__cplusplus) |