blob: 28fe97880460b495b17eddef4d43c56cea3eb8aa [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "gtest/gtest.h"
2
Brian Silvermana57b7012020-03-11 20:19:23 -07003#include "frc971/zeroing/zeroing.h"
Brian Silvermana57b7012020-03-11 20:19:23 -07004#include "frc971/zeroing/zeroing_test.h"
5
Stephan Pleinesf63bde82024-01-13 15:59:33 -08006namespace frc971::zeroing::testing {
Brian Silvermana57b7012020-03-11 20:19:23 -07007
8class 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
19TEST_F(RelativeEncoderZeroingTest, TestRelativeEncoderZeroingWithoutMovement) {
20 PositionSensorSimulator sim(1.0);
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080021 RelativeEncoderZeroingEstimator estimator{
22 constants::RelativeEncoderZeroingConstants{}};
Brian Silvermana57b7012020-03-11 20:19:23 -070023
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 Pleinesf63bde82024-01-13 15:59:33 -080036} // namespace frc971::zeroing::testing