Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 1 | namespace frc971; |
Brian Silverman | e0a9546 | 2014-02-17 00:41:09 -0800 | [diff] [blame] | 2 | |
Philipp Schrader | fd6335e | 2017-02-04 01:26:40 +0000 | [diff] [blame] | 3 | // Represents all of the data for a single indexed encoder. In other words, |
| 4 | // just a relative encoder with an index pulse. |
| 5 | // The units on all of the positions are the same. |
| 6 | // All encoder values are relative to where the encoder was at some arbitrary |
| 7 | // point in time. All potentiometer values are relative to some arbitrary 0 |
| 8 | // position which varies with each robot. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 9 | table IndexPosition { |
Philipp Schrader | fd6335e | 2017-02-04 01:26:40 +0000 | [diff] [blame] | 10 | // Current position read from the encoder. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 11 | encoder:double; |
Philipp Schrader | fd6335e | 2017-02-04 01:26:40 +0000 | [diff] [blame] | 12 | // Position from the encoder latched at the last index pulse. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 13 | latched_encoder:double; |
Philipp Schrader | fd6335e | 2017-02-04 01:26:40 +0000 | [diff] [blame] | 14 | // How many index pulses we've seen since startup. Starts at 0. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 15 | index_pulses:uint; |
| 16 | } |
Philipp Schrader | fd6335e | 2017-02-04 01:26:40 +0000 | [diff] [blame] | 17 | |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 18 | // Represents all of the data for a single potentiometer and indexed encoder |
| 19 | // pair. |
| 20 | // The units on all of the positions are the same. |
| 21 | // All encoder values are relative to where the encoder was at some arbitrary |
| 22 | // point in time. All potentiometer values are relative to some arbitrary 0 |
| 23 | // position which varies with each robot. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 24 | table PotAndIndexPosition { |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 25 | // Current position read from the encoder. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 26 | encoder:double; |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 27 | // Current position read from the potentiometer. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 28 | pot:double; |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 29 | |
| 30 | // Position from the encoder latched at the last index pulse. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 31 | latched_encoder:double; |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 32 | // Position from the potentiometer latched at the last index pulse. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 33 | latched_pot:double; |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 34 | |
| 35 | // How many index pulses we've seen since startup. Starts at 0. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 36 | index_pulses:uint; |
| 37 | } |
Brian Silverman | 5b433df | 2014-02-17 11:57:37 -0800 | [diff] [blame] | 38 | |
Diana Vandenberg | abb3d19 | 2017-01-28 16:19:43 -0800 | [diff] [blame] | 39 | // Represents all of the data for a single potentiometer with an absolute and |
| 40 | // relative encoder pair. |
| 41 | // The units on all of the positions are the same. |
| 42 | // The relative encoder values are relative to where the encoder was at some |
| 43 | // arbitrary point in time. All potentiometer values are relative to some |
| 44 | // arbitrary 0 position which varies with each robot. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 45 | table PotAndAbsolutePosition { |
Diana Vandenberg | abb3d19 | 2017-01-28 16:19:43 -0800 | [diff] [blame] | 46 | // Current position read from each encoder. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 47 | encoder:double; |
| 48 | absolute_encoder:double; |
Diana Vandenberg | abb3d19 | 2017-01-28 16:19:43 -0800 | [diff] [blame] | 49 | |
| 50 | // Current position read from the potentiometer. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 51 | pot:double; |
| 52 | } |
Diana Vandenberg | abb3d19 | 2017-01-28 16:19:43 -0800 | [diff] [blame] | 53 | |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 54 | // Represents all of the data for an absolute and relative encoder pair. |
| 55 | // The units on all of the positions are the same. |
| 56 | // The relative encoder values are relative to where the encoder was at some |
| 57 | // arbitrary point in time. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 58 | table AbsolutePosition { |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 59 | // Current position read from each encoder. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 60 | encoder:double; |
| 61 | absolute_encoder:double; |
| 62 | } |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 63 | |
Daniel Petti | ab27423 | 2015-02-16 19:15:34 -0800 | [diff] [blame] | 64 | // The internal state of a zeroing estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 65 | table EstimatorState { |
Daniel Petti | ab27423 | 2015-02-16 19:15:34 -0800 | [diff] [blame] | 66 | // If true, there has been a fatal error for the estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 67 | error:bool; |
Daniel Petti | ab27423 | 2015-02-16 19:15:34 -0800 | [diff] [blame] | 68 | // If the joint has seen an index pulse and is zeroed. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 69 | zeroed:bool; |
Daniel Petti | ab27423 | 2015-02-16 19:15:34 -0800 | [diff] [blame] | 70 | // The estimated position of the joint. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 71 | position:double; |
Austin Schuh | be133ed | 2016-03-11 21:23:34 -0800 | [diff] [blame] | 72 | |
| 73 | // The estimated position not using the index pulse. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 74 | pot_position:double; |
| 75 | } |
Daniel Petti | ab27423 | 2015-02-16 19:15:34 -0800 | [diff] [blame] | 76 | |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 77 | // The internal state of a zeroing estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 78 | table PotAndAbsoluteEncoderEstimatorState { |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 79 | // If true, there has been a fatal error for the estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 80 | error:bool; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 81 | // If the joint has seen an index pulse and is zeroed. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 82 | zeroed:bool; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 83 | // The estimated position of the joint. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 84 | position:double; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 85 | |
| 86 | // The estimated position not using the index pulse. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 87 | pot_position:double; |
Austin Schuh | 0e1c2c6 | 2017-02-21 02:03:25 -0800 | [diff] [blame] | 88 | |
| 89 | // The estimated absolute position of the encoder. This is filtered, so it |
| 90 | // can be easily used when zeroing. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 91 | absolute_position:double; |
| 92 | } |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 93 | |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 94 | // The internal state of a zeroing estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 95 | table AbsoluteEncoderEstimatorState { |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 96 | // If true, there has been a fatal error for the estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 97 | error:bool; |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 98 | // If the joint has seen an index pulse and is zeroed. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 99 | zeroed:bool; |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 100 | // The estimated position of the joint. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 101 | position:double; |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 102 | |
| 103 | // The estimated absolute position of the encoder. This is filtered, so it |
| 104 | // can be easily used when zeroing. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 105 | absolute_position:double; |
| 106 | } |
Austin Schuh | d82068e | 2019-01-26 20:05:42 -0800 | [diff] [blame] | 107 | |
| 108 | // The internal state of a zeroing estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 109 | table IndexEstimatorState { |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 110 | // If true, there has been a fatal error for the estimator. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 111 | error:bool; |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 112 | // If the joint has seen an index pulse and is zeroed. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 113 | zeroed:bool; |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 114 | // The estimated position of the joint. This is just the position relative to |
| 115 | // where we started if we're not zeroed yet. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 116 | position:double; |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 117 | |
| 118 | // The positions of the extreme index pulses we've seen. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 119 | min_index_position:double; |
| 120 | max_index_position:double; |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 121 | // The number of index pulses we've seen. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 122 | index_pulses_seen:int; |
| 123 | } |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 124 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 125 | table HallEffectAndPositionEstimatorState { |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 126 | // If error. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 127 | error:bool; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 128 | // If we've found a positive edge while moving backwards and is zeroed. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 129 | zeroed:bool; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 130 | // Encoder angle relative to where we started. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 131 | encoder:double; |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 132 | // The positions of the extreme posedges we've seen. |
| 133 | // If we've gotten enough samples where the hall effect is high before can be |
| 134 | // certain it is not a false positive. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 135 | high_long_enough:bool; |
| 136 | offset:double; |
| 137 | } |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 138 | |
Brian Silverman | 0a7f606 | 2015-01-24 17:41:33 -0500 | [diff] [blame] | 139 | // A left/right pair of PotAndIndexPositions. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 140 | table PotAndIndexPair { |
| 141 | left:PotAndIndexPosition; |
| 142 | right:PotAndIndexPosition; |
| 143 | } |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 144 | |
| 145 | // Records edges captured on a single hall effect sensor. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 146 | table HallEffectStruct { |
| 147 | current:bool; |
| 148 | posedge_count:int; |
| 149 | negedge_count:int; |
| 150 | posedge_value:double; |
| 151 | negedge_value:double; |
| 152 | } |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 153 | |
Austin Schuh | f380a3f | 2017-03-04 22:31:47 -0800 | [diff] [blame] | 154 | // Records the hall effect sensor and encoder values. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 155 | table HallEffectAndPosition { |
Austin Schuh | f380a3f | 2017-03-04 22:31:47 -0800 | [diff] [blame] | 156 | // The current hall effect state. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 157 | current:bool; |
Austin Schuh | f380a3f | 2017-03-04 22:31:47 -0800 | [diff] [blame] | 158 | // The current encoder position. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 159 | encoder:double; |
Austin Schuh | f380a3f | 2017-03-04 22:31:47 -0800 | [diff] [blame] | 160 | // The number of positive and negative edges we've seen on the hall effect |
| 161 | // sensor. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 162 | posedge_count:int; |
| 163 | negedge_count:int; |
Austin Schuh | f380a3f | 2017-03-04 22:31:47 -0800 | [diff] [blame] | 164 | // The values corresponding to the last hall effect sensor reading. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 165 | posedge_value:double; |
| 166 | negedge_value:double; |
| 167 | } |
Austin Schuh | f380a3f | 2017-03-04 22:31:47 -0800 | [diff] [blame] | 168 | |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 169 | // Records the positions for a mechanism with edge-capturing sensors on it. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 170 | table HallEventPositions { |
| 171 | current:double; |
| 172 | posedge:double; |
| 173 | negedge:double; |
| 174 | } |
Brian Silverman | 17f503e | 2015-08-02 18:17:18 -0700 | [diff] [blame] | 175 | |
| 176 | // Records edges captured on a single hall effect sensor. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 177 | table PosedgeOnlyCountedHallEffectStruct { |
| 178 | current:bool; |
| 179 | posedge_count:int; |
| 180 | negedge_count:int; |
| 181 | posedge_value:double; |
| 182 | } |
Austin Schuh | edbb64f | 2016-03-19 01:18:09 -0700 | [diff] [blame] | 183 | |
| 184 | // Parameters for the motion profiles. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 185 | table ProfileParameters { |
Austin Schuh | edbb64f | 2016-03-19 01:18:09 -0700 | [diff] [blame] | 186 | // Maximum velocity for the profile. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 187 | max_velocity:float; |
Austin Schuh | edbb64f | 2016-03-19 01:18:09 -0700 | [diff] [blame] | 188 | // Maximum acceleration for the profile. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 189 | max_acceleration:float; |
| 190 | } |
| 191 | |
| 192 | enum ConstraintType : byte { |
| 193 | CONSTRAINT_TYPE_UNDEFINED, |
| 194 | LONGITUDINAL_ACCELERATION, |
| 195 | LATERAL_ACCELERATION, |
| 196 | VOLTAGE, |
| 197 | VELOCITY, |
| 198 | } |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 199 | |
| 200 | // Definition of a constraint on a trajectory |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 201 | table Constraint { |
| 202 | constraint_type:ConstraintType; |
| 203 | |
| 204 | value:float; |
| 205 | |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 206 | // start and end distance are only checked for velocity limits. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 207 | start_distance:float; |
| 208 | end_distance:float; |
| 209 | } |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 210 | |
| 211 | // Parameters for computing a trajectory using a chain of splines and |
| 212 | // constraints. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 213 | table MultiSpline { |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 214 | // Number of splines. The spline point arrays will be expected to have |
| 215 | // 6 + 5 * (n - 1) points in them. The endpoints are shared between |
| 216 | // neighboring splines. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 217 | spline_count:byte; |
| 218 | // Maximum of 36 spline points (7 splines). |
| 219 | spline_x:[float]; |
| 220 | spline_y:[float]; |
Alex Perry | 731b460 | 2019-02-02 22:13:01 -0800 | [diff] [blame] | 221 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 222 | // Maximum of 6 constraints; |
| 223 | constraints:[Constraint]; |
| 224 | } |