mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib] PIDController: Recompute the error in AtSetpoint() (#2822)
This makes AtSetpoint() return false after the setpoint is changed with SetSetpoint(). Closes #2821. Co-authored-by: Prateek Machiraju <prateek.machiraju@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2014-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2014-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -23,9 +23,17 @@ 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();
|
||||
|
||||
controller.SetTolerance(kTolerance);
|
||||
controller.SetSetpoint(kSetpoint);
|
||||
|
||||
EXPECT_FALSE(controller.AtSetpoint())
|
||||
<< "Error was in tolerance when it should not have been. Error was "
|
||||
<< controller.GetPositionError();
|
||||
|
||||
controller.Calculate(0.0);
|
||||
|
||||
EXPECT_FALSE(controller.AtSetpoint())
|
||||
|
||||
Reference in New Issue
Block a user