blob: 89ee9daf58ed42f73394fd70d619bdb8d797fc07 [file] [log] [blame]
Adam Snaiderc4b3c192015-02-01 01:30:39 +00001#ifndef FRC971_ZEROING_ZEROING_H_
2#define FRC971_ZEROING_ZEROING_H_
3
4#include <vector>
5#include "frc971/zeroing/zeroing_queue.q.h"
Austin Schuh703b8d42015-02-01 14:56:34 -08006#include "frc971/control_loops/control_loops.q.h"
7#include "frc971/constants.h"
Adam Snaiderc4b3c192015-02-01 01:30:39 +00008
9namespace frc971 {
10namespace zeroing {
11
12// Estimates the position with encoder,
13// the pot and the indices.
14class ZeroingEstimator {
15 public:
16 ZeroingEstimator(double index_difference, size_t max_sample_count);
Austin Schuh703b8d42015-02-01 14:56:34 -080017 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 Snaiderc4b3c192015-02-01 01:30:39 +000027 private:
Austin Schuh703b8d42015-02-01 14:56:34 -080028 void DoInit(double index_difference, size_t max_sample_count);
29
30 double offset_ = 0.0;
31 bool zeroed_ = false;
Adam Snaiderc4b3c192015-02-01 01:30:39 +000032 // 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_