blob: fd86fb33ff1a1b533e414461f8b15882792907a1 [file] [log] [blame]
Brian Silvermana57b7012020-03-11 20:19:23 -07001#include "frc971/zeroing/zeroing.h"
2
3#include "gtest/gtest.h"
4
5#include "frc971/zeroing/zeroing_test.h"
6
7namespace frc971 {
8namespace zeroing {
9namespace testing {
10
11class 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
22TEST_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