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 | |
| 4 | #include <vector> |
| 5 | #include "frc971/zeroing/zeroing_queue.q.h" |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 6 | #include "frc971/control_loops/control_loops.q.h" |
| 7 | #include "frc971/constants.h" |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 8 | |
| 9 | namespace frc971 { |
| 10 | namespace zeroing { |
| 11 | |
| 12 | // Estimates the position with encoder, |
| 13 | // the pot and the indices. |
| 14 | class ZeroingEstimator { |
| 15 | public: |
| 16 | ZeroingEstimator(double index_difference, size_t max_sample_count); |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 17 | ZeroingEstimator(const constants::Values::ZeroingConstants &constants); |
| 18 | void UpdateEstimate(const PotAndIndexPosition &info); |
| 19 | void UpdateEstimate(const ZeroingInfo &info); |
| 20 | |
| 21 | double offset() const { return offset_; } |
| 22 | bool zeroed() const { return zeroed_; } |
| 23 | double offset_ratio_ready() const { |
| 24 | return start_pos_samples_.size() / static_cast<double>(max_sample_count_); |
| 25 | } |
| 26 | |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 27 | private: |
Austin Schuh | 703b8d4 | 2015-02-01 14:56:34 -0800 | [diff] [blame] | 28 | void DoInit(double index_difference, size_t max_sample_count); |
| 29 | |
| 30 | double offset_ = 0.0; |
| 31 | bool zeroed_ = false; |
Adam Snaider | c4b3c19 | 2015-02-01 01:30:39 +0000 | [diff] [blame] | 32 | // The distance between two consecutive index positions. |
| 33 | double index_diff_; |
| 34 | // The next position in 'start_pos_samples_' to be used to store the |
| 35 | // next sample. |
| 36 | int samples_idx_; |
| 37 | // Last 'max_sample_count_' samples for start positions. |
| 38 | std::vector<double> start_pos_samples_; |
| 39 | // The number of the last samples of start position to consider |
| 40 | // in the estimation. |
| 41 | size_t max_sample_count_; |
| 42 | }; |
| 43 | |
| 44 | } // namespace zeroing |
| 45 | } // namespace frc971 |
| 46 | |
| 47 | #endif // FRC971_ZEROING_ZEROING_H_ |