[wpimath] Fix PID atSetpoint to not return true prematurely (#4906)

Wait until setpoint and measurement have been set.
This commit is contained in:
sciencewhiz
2023-01-13 22:26:30 -08:00
committed by GitHub
parent e5a6197633
commit 1e05b21ab5
5 changed files with 21 additions and 11 deletions

View File

@@ -13,16 +13,14 @@ TEST(PIDToleranceTest, InitialTolerance) {
frc2::PIDController controller{0.5, 0.0, 0.0};
controller.EnableContinuousInput(-kRange / 2, kRange / 2);
EXPECT_TRUE(controller.AtSetpoint());
EXPECT_FALSE(controller.AtSetpoint());
}
TEST(PIDToleranceTest, AbsoluteTolerance) {
frc2::PIDController controller{0.5, 0.0, 0.0};
controller.EnableContinuousInput(-kRange / 2, kRange / 2);
EXPECT_TRUE(controller.AtSetpoint())
<< "Error was not in tolerance when it should have been. Error was "
<< controller.GetPositionError();
EXPECT_FALSE(controller.AtSetpoint());
controller.SetTolerance(kTolerance);
controller.SetSetpoint(kSetpoint);