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