blob: 6256fe742317ce5ea2b49c0ec4f689892e70e4fa [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
6namespace frc971 {
7namespace zeroing {
8namespace testing {
9
10class RelativeEncoderZeroingTest : public ZeroingTest {
11 protected:
12 void MoveTo(PositionSensorSimulator *simulator,
13 RelativeEncoderZeroingEstimator *estimator, double new_position) {
14 simulator->MoveTo(new_position);
15 FBB fbb;
16 estimator->UpdateEstimate(
17 *simulator->FillSensorValues<RelativePosition>(&fbb));
18 }
19};
20
21TEST_F(RelativeEncoderZeroingTest, TestRelativeEncoderZeroingWithoutMovement) {
22 PositionSensorSimulator sim(1.0);
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080023 RelativeEncoderZeroingEstimator estimator{
24 constants::RelativeEncoderZeroingConstants{}};
Brian Silvermana57b7012020-03-11 20:19:23 -070025
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