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