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 | |
| 16 | union { |
| 17 | struct { |
Brian Silverman | 441d55c | 2013-10-31 19:27:23 -0700 | [diff] [blame^] | 18 | // 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 Silverman | 89e8636 | 2013-10-30 17:50:50 -0700 | [diff] [blame] | 22 | // 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 Silverman | 441d55c | 2013-10-31 19:27:23 -0700 | [diff] [blame^] | 26 | // |
| 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 Silverman | 89e8636 | 2013-10-30 17:50:50 -0700 | [diff] [blame] | 34 | int32_t frame_number; |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame] | 35 | |
Brian Silverman | 28d9778 | 2013-10-31 17:33:52 -0700 | [diff] [blame] | 36 | // 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 Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 41 | // 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 Silverman | 74acd62 | 2013-10-26 14:47:14 -0700 | [diff] [blame] | 44 | // 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 Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 53 | 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 Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame] | 64 | 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 Silverman | 89e8636 | 2013-10-30 17:50:50 -0700 | [diff] [blame] | 72 | |
| 73 | // We're not sure what frame number this packet was sent in. |
| 74 | uint8_t unknown_frame : 1; |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 75 | }; |
| 76 | }; |
Brian Silverman | 28d9778 | 2013-10-31 17:33:52 -0700 | [diff] [blame] | 77 | struct { |
| 78 | uint64_t header0, header1; |
| 79 | }; |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Brian Silverman | a280ae0 | 2013-10-28 18:21:15 -0700 | [diff] [blame] | 82 | // We are 64-bit aligned at this point. |
Brian Silverman | 70478d1 | 2013-10-11 17:54:58 -0700 | [diff] [blame] | 83 | |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 84 | union { |
| 85 | struct { |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 86 | 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 Silverman | 74acd62 | 2013-10-26 14:47:14 -0700 | [diff] [blame] | 99 | uint16_t battery_voltage; |
| 100 | uint16_t left_drive_hall; |
| 101 | uint16_t right_drive_hall; |
| 102 | |
Brian Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 103 | 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 Silverman | 74acd62 | 2013-10-26 14:47:14 -0700 | [diff] [blame] | 115 | |
| 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 Silverman | f92396c | 2013-09-12 20:13:13 -0700 | [diff] [blame] | 124 | } main; |
| 125 | |
| 126 | struct { |
| 127 | union { |
| 128 | struct { |
| 129 | }; |
| 130 | uint16_t booleans; |
| 131 | }; |
| 132 | } bot3; |
| 133 | }; |
| 134 | }; |
| 135 | #pragma pack(pop) |
Brian Silverman | 466d669 | 2013-09-13 14:16:36 -0700 | [diff] [blame] | 136 | |
Brian Silverman | 2d21bb2 | 2013-10-25 15:52:42 -0700 | [diff] [blame] | 137 | // 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 Silverman | 466d669 | 2013-09-13 14:16:36 -0700 | [diff] [blame] | 143 | #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 Silverman | 2d21bb2 | 2013-10-25 15:52:42 -0700 | [diff] [blame] | 146 | static_assert(sizeof(DATA_STRUCT_NAME) <= DATA_STRUCT_SEND_SIZE, |
Brian Silverman | 1e869f3 | 2013-10-25 18:00:20 -0700 | [diff] [blame] | 147 | "The sensor data structure is too big."); |
Brian Silverman | 466d669 | 2013-09-13 14:16:36 -0700 | [diff] [blame] | 148 | #endif // defined(__cplusplus) |