Brian Silverman | a57b701 | 2020-03-11 20:19:23 -0700 | [diff] [blame] | 1 | #include "frc971/zeroing/zeroing.h" |
Brian Silverman | a57b701 | 2020-03-11 20:19:23 -0700 | [diff] [blame] | 2 | #include "frc971/zeroing/zeroing_test.h" |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 3 | #include "gtest/gtest.h" |
Brian Silverman | a57b701 | 2020-03-11 20:19:23 -0700 | [diff] [blame] | 4 | |
| 5 | namespace frc971 { |
| 6 | namespace zeroing { |
| 7 | namespace testing { |
| 8 | |
| 9 | class RelativeEncoderZeroingTest : public ZeroingTest { |
| 10 | protected: |
| 11 | void MoveTo(PositionSensorSimulator *simulator, |
| 12 | RelativeEncoderZeroingEstimator *estimator, double new_position) { |
| 13 | simulator->MoveTo(new_position); |
| 14 | FBB fbb; |
| 15 | estimator->UpdateEstimate( |
| 16 | *simulator->FillSensorValues<RelativePosition>(&fbb)); |
| 17 | } |
| 18 | }; |
| 19 | |
| 20 | TEST_F(RelativeEncoderZeroingTest, TestRelativeEncoderZeroingWithoutMovement) { |
| 21 | PositionSensorSimulator sim(1.0); |
Siddhant Kanwar | 0e37f59 | 2022-02-21 19:26:50 -0800 | [diff] [blame^] | 22 | RelativeEncoderZeroingEstimator estimator{ |
| 23 | constants::RelativeEncoderZeroingConstants{}}; |
Brian Silverman | a57b701 | 2020-03-11 20:19:23 -0700 | [diff] [blame] | 24 | |
| 25 | sim.InitializeRelativeEncoder(); |
| 26 | |
| 27 | ASSERT_TRUE(estimator.zeroed()); |
| 28 | ASSERT_TRUE(estimator.offset_ready()); |
| 29 | EXPECT_DOUBLE_EQ(estimator.offset(), 0.0); |
| 30 | EXPECT_DOUBLE_EQ(GetEstimatorPosition(&estimator), 0.0); |
| 31 | |
| 32 | MoveTo(&sim, &estimator, 0.1); |
| 33 | |
| 34 | EXPECT_DOUBLE_EQ(GetEstimatorPosition(&estimator), 0.1); |
| 35 | } |
| 36 | |
| 37 | } // namespace testing |
| 38 | } // namespace zeroing |
| 39 | } // namespace frc971 |