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