Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 1 | #ifndef FRC971_ZEROING_ZEROING_H_ |
| 2 | #define FRC971_ZEROING_ZEROING_H_ |
| 3 | |
Philipp Schrader | 41d8291 | 2015-02-15 03:44:23 +0000 | [diff] [blame] | 4 | #include <cstdint> |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 5 | #include <vector> |
Philipp Schrader | 41d8291 | 2015-02-15 03:44:23 +0000 | [diff] [blame] | 6 | |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 7 | #include "frc971/control_loops/control_loops.q.h" |
| 8 | #include "frc971/constants.h" |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 9 | |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 10 | // TODO(pschrader): Flag an error if encoder index pulse is not n revolutions |
| 11 | // away from the last one (i.e. got extra counts from noise, etc..) |
| 12 | // |
| 13 | // TODO(pschrader): Flag error if the pot disagrees too much with the encoder |
| 14 | // after being zeroed. |
| 15 | // |
| 16 | // TODO(pschrader): Watch the offset over long periods of time and flag if it |
| 17 | // gets too far away from the initial value. |
| 18 | |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 19 | namespace frc971 { |
| 20 | namespace zeroing { |
| 21 | |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 22 | class ZeroingEstimator { |
| 23 | public: |
| 24 | virtual ~ZeroingEstimator(){} |
| 25 | |
| 26 | // Returns true if the logic considers the corresponding mechanism to be |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 27 | // zeroed. |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 28 | virtual bool zeroed() const = 0; |
| 29 | |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 30 | // Returns the estimated position of the corresponding mechanism. |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 31 | virtual double offset() const = 0; |
| 32 | |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 33 | // Returns true if there has been an error. |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 34 | virtual bool error() const = 0; |
| 35 | }; |
| 36 | |
Brian Silverman | ab0b677 | 2017-02-05 16:16:21 -0800 | [diff] [blame] | 37 | // Estimates the position with an incremental encoder with an index pulse and a |
| 38 | // potentiometer. |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 39 | class PotAndIndexPulseZeroingEstimator : public ZeroingEstimator { |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 40 | public: |
Brian Silverman | ab0b677 | 2017-02-05 16:16:21 -0800 | [diff] [blame] | 41 | using Position = PotAndIndexPosition; |
| 42 | using ZeroingConstants = constants::PotAndIndexPulseZeroingConstants; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 43 | using State = EstimatorState; |
Brian Silverman | ab0b677 | 2017-02-05 16:16:21 -0800 | [diff] [blame] | 44 | |
Campbell Crowley | 36e93e9 | 2017-12-23 14:21:43 -0800 | [diff] [blame] | 45 | explicit PotAndIndexPulseZeroingEstimator( |
Tyler Chatow | f8f0311 | 2017-02-05 14:31:34 -0800 | [diff] [blame] | 46 | const constants::PotAndIndexPulseZeroingConstants &constants); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 47 | |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 48 | // Update the internal logic with the next sensor values. |
| 49 | void UpdateEstimate(const PotAndIndexPosition &info); |
| 50 | |
| 51 | // Reset the internal logic so it needs to be re-zeroed. |
| 52 | void Reset(); |
| 53 | |
Philipp Schrader | 53f4b6d | 2015-02-15 22:32:08 +0000 | [diff] [blame] | 54 | // Manually trigger an internal error. This is used for testing the error |
| 55 | // logic. |
| 56 | void TriggerError(); |
| 57 | |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 58 | bool error() const override { return error_; } |
Philipp Schrader | 53f4b6d | 2015-02-15 22:32:08 +0000 | [diff] [blame] | 59 | |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 60 | bool zeroed() const override { return zeroed_; } |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 61 | |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 62 | double offset() const override { return offset_; } |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 63 | |
| 64 | // Returns a number between 0 and 1 that represents the percentage of the |
| 65 | // samples being used in the moving average filter. A value of 0.0 means that |
| 66 | // no samples are being used. A value of 1.0 means that the filter is using |
| 67 | // as many samples as it has room for. For example, after a Reset() this |
| 68 | // value returns 0.0. As more samples get added with UpdateEstimate(...) the |
| 69 | // return value starts increasing to 1.0. |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 70 | double offset_ratio_ready() const { |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 71 | return start_pos_samples_.size() / |
| 72 | static_cast<double>(constants_.average_filter_size); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Austin Schuh | 7485dbb | 2016-02-08 00:21:58 -0800 | [diff] [blame] | 75 | // Returns true if the sample buffer is full. |
| 76 | bool offset_ready() const { |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 77 | return start_pos_samples_.size() == constants_.average_filter_size; |
Austin Schuh | 7485dbb | 2016-02-08 00:21:58 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Brian Silverman | 4f2e2ce | 2017-02-19 17:49:47 -0800 | [diff] [blame] | 80 | // Returns information about our current state. |
| 81 | State GetEstimatorState() const; |
| 82 | |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 83 | private: |
Philipp Schrader | e828be7 | 2015-02-15 07:07:37 +0000 | [diff] [blame] | 84 | // This function calculates the start position given the internal state and |
| 85 | // the provided `latched_encoder' value. |
| 86 | double CalculateStartPosition(double start_average, |
| 87 | double latched_encoder) const; |
| 88 | |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 89 | // The zeroing constants used to describe the configuration of the system. |
| 90 | const constants::PotAndIndexPulseZeroingConstants constants_; |
| 91 | |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 92 | // The estimated position. |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 93 | double position_; |
Austin Schuh | be133ed | 2016-03-11 21:23:34 -0800 | [diff] [blame] | 94 | // The unzeroed filtered position. |
| 95 | double filtered_position_ = 0.0; |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 96 | // The next position in 'start_pos_samples_' to be used to store the next |
| 97 | // sample. |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 98 | int samples_idx_; |
| 99 | // Last 'max_sample_count_' samples for start positions. |
| 100 | std::vector<double> start_pos_samples_; |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 101 | // The estimated starting position of the mechanism. We also call this the |
| 102 | // 'offset' in some contexts. |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 103 | double offset_; |
Philipp Schrader | 41d8291 | 2015-02-15 03:44:23 +0000 | [diff] [blame] | 104 | // Flag for triggering logic that takes note of the current index pulse count |
Philipp Schrader | e828be7 | 2015-02-15 07:07:37 +0000 | [diff] [blame] | 105 | // after a reset. See `last_used_index_pulse_count_'. |
Philipp Schrader | 41d8291 | 2015-02-15 03:44:23 +0000 | [diff] [blame] | 106 | bool wait_for_index_pulse_; |
| 107 | // After a reset we keep track of the index pulse count with this. Only after |
| 108 | // the index pulse count changes (i.e. increments at least once or wraps |
Philipp Schrader | e828be7 | 2015-02-15 07:07:37 +0000 | [diff] [blame] | 109 | // around) will we consider the mechanism zeroed. We also use this to store |
| 110 | // the most recent `PotAndIndexPosition::index_pulses' value when the start |
| 111 | // position was calculated. It helps us calculate the start position only on |
| 112 | // index pulses to reject corrupted intermediate data. |
| 113 | uint32_t last_used_index_pulse_count_; |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 114 | // Marker to track whether we're fully zeroed yet or not. |
| 115 | bool zeroed_; |
Philipp Schrader | 53f4b6d | 2015-02-15 22:32:08 +0000 | [diff] [blame] | 116 | // Marker to track whether an error has occurred. This gets reset to false |
| 117 | // whenever Reset() is called. |
| 118 | bool error_; |
Adam Snaider | 3cd11c5 | 2015-02-16 02:16:09 +0000 | [diff] [blame] | 119 | // Stores the position "start_pos" variable the first time the program |
| 120 | // is zeroed. |
| 121 | double first_start_pos_; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Campbell Crowley | 36e93e9 | 2017-12-23 14:21:43 -0800 | [diff] [blame] | 124 | // Estimates the position with an incremental encoder and a hall effect sensor. |
Austin Schuh | 5593403 | 2017-03-11 12:45:27 -0800 | [diff] [blame] | 125 | class HallEffectAndPositionZeroingEstimator : public ZeroingEstimator { |
| 126 | public: |
| 127 | using Position = HallEffectAndPosition; |
| 128 | using ZeroingConstants = constants::HallEffectZeroingConstants; |
| 129 | using State = HallEffectAndPositionEstimatorState; |
| 130 | |
| 131 | explicit HallEffectAndPositionZeroingEstimator(const ZeroingConstants &constants); |
| 132 | |
| 133 | // Update the internal logic with the next sensor values. |
| 134 | void UpdateEstimate(const Position &info); |
| 135 | |
| 136 | // Reset the internal logic so it needs to be re-zeroed. |
| 137 | void Reset(); |
| 138 | |
| 139 | // Manually trigger an internal error. This is used for testing the error |
| 140 | // logic. |
| 141 | void TriggerError(); |
| 142 | |
| 143 | bool error() const override { return error_; } |
| 144 | |
| 145 | bool zeroed() const override { return zeroed_; } |
| 146 | |
| 147 | double offset() const override { return offset_; } |
| 148 | |
| 149 | // Returns information about our current state. |
| 150 | State GetEstimatorState() const; |
| 151 | |
| 152 | private: |
| 153 | // Sets the minimum and maximum posedge position values. |
| 154 | void StoreEncoderMaxAndMin(const HallEffectAndPosition &info); |
| 155 | |
| 156 | // The zeroing constants used to describe the configuration of the system. |
| 157 | const ZeroingConstants constants_; |
| 158 | |
| 159 | // The estimated state of the hall effect. |
| 160 | double current_ = 0.0; |
| 161 | // The estimated position. |
| 162 | double position_ = 0.0; |
| 163 | // The smallest and largest positions of the last set of encoder positions |
| 164 | // while the hall effect was low. |
| 165 | double min_low_position_; |
| 166 | double max_low_position_; |
| 167 | // If we've seen the hall effect high for enough times without going low, then |
| 168 | // we can be sure it isn't a false positive. |
| 169 | bool high_long_enough_; |
| 170 | size_t cycles_high_; |
| 171 | |
| 172 | bool last_hall_ = false; |
| 173 | |
| 174 | // The estimated starting position of the mechanism. We also call this the |
| 175 | // 'offset' in some contexts. |
| 176 | double offset_; |
| 177 | // Flag for triggering logic that takes note of the current posedge count |
| 178 | // after a reset. See `last_used_posedge_count_'. |
| 179 | bool initialized_; |
| 180 | // After a reset we keep track of the posedge count with this. Only after the |
| 181 | // posedge count changes (i.e. increments at least once or wraps around) will |
| 182 | // we consider the mechanism zeroed. We also use this to store the most recent |
| 183 | // `HallEffectAndPosition::posedge_count' value when the start position |
| 184 | // was calculated. It helps us calculate the start position only on posedges |
| 185 | // to reject corrupted intermediate data. |
| 186 | int32_t last_used_posedge_count_; |
| 187 | // Marker to track whether we're fully zeroed yet or not. |
| 188 | bool zeroed_; |
| 189 | // Marker to track whether an error has occurred. This gets reset to false |
| 190 | // whenever Reset() is called. |
| 191 | bool error_ = false; |
| 192 | // Stores the position "start_pos" variable the first time the program |
| 193 | // is zeroed. |
| 194 | double first_start_pos_; |
| 195 | }; |
| 196 | |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 197 | // Estimates the position with an absolute encoder which also reports |
| 198 | // incremental counts, and a potentiometer. |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 199 | class PotAndAbsEncoderZeroingEstimator : public ZeroingEstimator { |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 200 | public: |
| 201 | using Position = PotAndAbsolutePosition; |
| 202 | using ZeroingConstants = constants::PotAndAbsoluteEncoderZeroingConstants; |
| 203 | using State = AbsoluteEstimatorState; |
| 204 | |
Campbell Crowley | 36e93e9 | 2017-12-23 14:21:43 -0800 | [diff] [blame] | 205 | explicit PotAndAbsEncoderZeroingEstimator( |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 206 | const constants::PotAndAbsoluteEncoderZeroingConstants &constants); |
| 207 | |
| 208 | // Resets the internal logic so it needs to be re-zeroed. |
| 209 | void Reset(); |
| 210 | |
| 211 | // Updates the sensor values for the zeroing logic. |
| 212 | void UpdateEstimate(const PotAndAbsolutePosition &info); |
| 213 | |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 214 | bool zeroed() const override { return zeroed_; } |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 215 | |
Neil Balch | 1049be9 | 2017-02-15 23:20:49 -0800 | [diff] [blame] | 216 | double offset() const override { return offset_; } |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 217 | |
Neil Balch | 16275e3 | 2017-02-18 16:38:45 -0800 | [diff] [blame] | 218 | bool error() const override { return error_; } |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 219 | |
| 220 | // Returns true if the sample buffer is full. |
| 221 | bool offset_ready() const { |
| 222 | return relative_to_absolute_offset_samples_.size() == |
| 223 | constants_.average_filter_size && |
| 224 | offset_samples_.size() == constants_.average_filter_size; |
| 225 | } |
| 226 | |
Brian Silverman | 4f2e2ce | 2017-02-19 17:49:47 -0800 | [diff] [blame] | 227 | // Returns information about our current state. |
| 228 | State GetEstimatorState() const; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 229 | |
| 230 | private: |
| 231 | // The zeroing constants used to describe the configuration of the system. |
| 232 | const constants::PotAndAbsoluteEncoderZeroingConstants constants_; |
Brian Silverman | a10d20a | 2017-02-19 14:28:53 -0800 | [diff] [blame] | 233 | |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 234 | // True if the mechanism is zeroed. |
| 235 | bool zeroed_; |
Brian Silverman | a10d20a | 2017-02-19 14:28:53 -0800 | [diff] [blame] | 236 | // Marker to track whether an error has occurred. |
| 237 | bool error_; |
| 238 | // The first valid offset we recorded. This is only set after zeroed_ first |
| 239 | // changes to true. |
| 240 | double first_offset_; |
| 241 | |
Austin Schuh | 0e1c2c6 | 2017-02-21 02:03:25 -0800 | [diff] [blame] | 242 | // The filtered absolute encoder. This is used in the status for calibration. |
| 243 | double filtered_absolute_encoder_ = 0.0; |
| 244 | |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 245 | // Samples of the offset needed to line the relative encoder up with the |
| 246 | // absolute encoder. |
| 247 | ::std::vector<double> relative_to_absolute_offset_samples_; |
| 248 | // Offset between the Pot and Relative encoder position. |
| 249 | ::std::vector<double> offset_samples_; |
Diana Vandenberg | 8fea6ea | 2017-02-18 17:24:45 -0800 | [diff] [blame] | 250 | // Last moving_buffer_size position samples to be used to determine if the |
| 251 | // robot is moving. |
| 252 | ::std::vector<PotAndAbsolutePosition> buffered_samples_; |
| 253 | // Pointer to front of the buffered samples. |
| 254 | int buffered_samples_idx_ = 0; |
| 255 | // Estimated offset between the pot and relative encoder. |
| 256 | double pot_relative_encoder_offset_ = 0; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 257 | // Estimated start position of the mechanism |
Diana Vandenberg | 8fea6ea | 2017-02-18 17:24:45 -0800 | [diff] [blame] | 258 | double offset_ = 0; |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 259 | // The next position in 'relative_to_absolute_offset_samples_' and |
| 260 | // 'encoder_samples_' to be used to store the next sample. |
Austin Schuh | ddd08f8 | 2018-03-02 20:05:29 -0800 | [diff] [blame] | 261 | int samples_idx_ = 0; |
| 262 | |
| 263 | size_t nan_samples_ = 0; |
Brian Silverman | a10d20a | 2017-02-19 14:28:53 -0800 | [diff] [blame] | 264 | |
Austin Schuh | 5f01f15 | 2017-02-11 21:34:08 -0800 | [diff] [blame] | 265 | // The unzeroed filtered position. |
| 266 | double filtered_position_ = 0.0; |
| 267 | // The filtered position. |
| 268 | double position_ = 0.0; |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 269 | }; |
| 270 | |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 271 | |
| 272 | // Zeros by seeing all the index pulses in the range of motion of the mechanism |
| 273 | // and using that to figure out which index pulse is which. |
| 274 | class PulseIndexZeroingEstimator : public ZeroingEstimator { |
| 275 | public: |
| 276 | using Position = IndexPosition; |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 277 | using ZeroingConstants = constants::EncoderPlusIndexZeroingConstants; |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 278 | using State = IndexEstimatorState; |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 279 | |
Campbell Crowley | 36e93e9 | 2017-12-23 14:21:43 -0800 | [diff] [blame] | 280 | explicit PulseIndexZeroingEstimator(const ZeroingConstants &constants) |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 281 | : constants_(constants) { |
| 282 | Reset(); |
| 283 | } |
| 284 | |
| 285 | // Resets the internal logic so it needs to be re-zeroed. |
| 286 | void Reset(); |
| 287 | |
| 288 | bool zeroed() const override { return zeroed_; } |
| 289 | |
Austin Schuh | 6a90cd9 | 2017-02-19 20:55:33 -0800 | [diff] [blame] | 290 | // It's as ready as it'll ever be... |
| 291 | bool offset_ready() const { return true; } |
| 292 | |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 293 | double offset() const override { return offset_; } |
| 294 | |
| 295 | bool error() const override { return error_; } |
| 296 | |
| 297 | // Updates the internal logic with the next sensor values. |
| 298 | void UpdateEstimate(const IndexPosition &info); |
| 299 | |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 300 | // Returns information about our current state. |
| 301 | State GetEstimatorState() const; |
| 302 | |
Austin Schuh | d93160a | 2017-03-05 01:00:54 -0800 | [diff] [blame] | 303 | void TriggerError() { error_ = true; } |
| 304 | |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 305 | private: |
| 306 | // Returns the current real position using the relative encoder offset. |
| 307 | double CalculateCurrentPosition(const IndexPosition &info); |
| 308 | |
| 309 | // Sets the minimum and maximum index pulse position values. |
| 310 | void StoreIndexPulseMaxAndMin(const IndexPosition &info); |
| 311 | |
| 312 | // Returns the number of index pulses we should have seen so far. |
Brian Silverman | f37839c | 2017-02-19 18:07:15 -0800 | [diff] [blame] | 313 | int IndexPulseCount() const; |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 314 | |
| 315 | // Contains the physical constants describing the system. |
Philipp Schrader | 3f5b618 | 2017-03-25 22:36:37 +0000 | [diff] [blame] | 316 | const ZeroingConstants constants_; |
Isaac Wilcove | 0851ffd | 2017-02-16 04:13:14 +0000 | [diff] [blame] | 317 | |
| 318 | // The smallest position of all the index pulses. |
| 319 | double min_index_position_; |
| 320 | // The largest position of all the index pulses. |
| 321 | double max_index_position_; |
| 322 | |
| 323 | // The estimated starting position of the mechanism. |
| 324 | double offset_; |
| 325 | // After a reset we keep track of the index pulse count with this. Only after |
| 326 | // the index pulse count changes (i.e. increments at least once or wraps |
| 327 | // around) will we consider the mechanism zeroed. We also use this to store |
| 328 | // the most recent `PotAndIndexPosition::index_pulses' value when the start |
| 329 | // position was calculated. It helps us calculate the start position only on |
| 330 | // index pulses to reject corrupted intermediate data. |
| 331 | uint32_t last_used_index_pulse_count_; |
| 332 | |
| 333 | // True if we are fully zeroed. |
| 334 | bool zeroed_; |
| 335 | // Marker to track whether an error has occurred. |
| 336 | bool error_; |
| 337 | |
| 338 | // The estimated position. |
| 339 | double position_; |
| 340 | }; |
| 341 | |
Adam Snaider | b411925 | 2015-02-15 01:30:57 +0000 | [diff] [blame] | 342 | } // namespace zeroing |
| 343 | } // namespace frc971 |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 344 | |
| 345 | #endif // FRC971_ZEROING_ZEROING_H_ |