blob: a29ba4bf3321a8d6be15fc8b9b1b69bc9a627770 [file] [log] [blame]
Brian Silvermana57b7012020-03-11 20:19:23 -07001#include "frc971/zeroing/zeroing.h"
Brian Silvermana57b7012020-03-11 20:19:23 -07002#include "frc971/zeroing/zeroing_test.h"
Siddhant Kanwar0e37f592022-02-21 19:26:50 -08003#include "gtest/gtest.h"
Brian Silvermana57b7012020-03-11 20:19:23 -07004
5namespace frc971 {
6namespace zeroing {
7namespace testing {
8
9class 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
20TEST_F(RelativeEncoderZeroingTest, TestRelativeEncoderZeroingWithoutMovement) {
21 PositionSensorSimulator sim(1.0);
Siddhant Kanwar0e37f592022-02-21 19:26:50 -080022 RelativeEncoderZeroingEstimator estimator{
23 constants::RelativeEncoderZeroingConstants{}};
Brian Silvermana57b7012020-03-11 20:19:23 -070024
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