Remove percent tolerance from PID controller

It breaks the unit system badly; the tolerance member variable has
different units depending on percent vs absolute. Absolute tolerance is
a lot more natural than percent tolerance anyway.
This commit is contained in:
Tyler Veness
2019-08-25 13:01:51 -07:00
committed by Peter Johnson
parent 0ca8d667d2
commit ff8b8f0a8a
29 changed files with 121 additions and 507 deletions

View File

@@ -18,7 +18,7 @@ ShooterSubsystem::ShooterSubsystem()
m_shooterMotor(kShooterMotorPort),
m_feederMotor(kFeederMotorPort),
m_shooterEncoder(kEncoderPorts[0], kEncoderPorts[1]) {
m_controller.SetAbsoluteTolerance(kShooterToleranceRPS);
m_controller.SetTolerance(kShooterToleranceRPS);
m_shooterEncoder.SetDistancePerPulse(kEncoderDistancePerPulse);
}

View File

@@ -18,7 +18,7 @@ DriveStraight::DriveStraight(double distance, DriveTrain* drivetrain)
[this](double output) { m_drivetrain->Drive(output, output); },
{drivetrain}),
m_drivetrain(drivetrain) {
m_controller.SetAbsoluteTolerance(0.01);
m_controller.SetTolerance(0.01);
}
// Called just before this Command runs the first time

View File

@@ -18,7 +18,7 @@ SetDistanceToBox::SetDistanceToBox(double distance, DriveTrain* drivetrain)
[this](double output) { m_drivetrain->Drive(output, output); },
{drivetrain}),
m_drivetrain(drivetrain) {
m_controller.SetAbsoluteTolerance(0.01);
m_controller.SetTolerance(0.01);
}
// Called just before this Command runs the first time

View File

@@ -16,7 +16,7 @@ Elevator::Elevator()
#ifdef SIMULATION // Check for simulation and update PID values
GetPIDController()->SetPID(kP_simulation, kI_simulation, 0, 0);
#endif
m_controller.SetAbsoluteTolerance(0.005);
m_controller.SetTolerance(0.005);
SetName("Elevator");
// Let's show everything on the LiveWindow

View File

@@ -14,7 +14,7 @@ Wrist::Wrist() : frc2::PIDSubsystem(frc2::PIDController(kP_real, 0, 0)) {
#ifdef SIMULATION // Check for simulation and update PID values
GetPIDController()->SetPID(kP_simulation, 0, 0, 0);
#endif
m_controller.SetAbsoluteTolerance(2.5);
m_controller.SetTolerance(2.5);
SetName("Wrist");
// Let's show everything on the LiveWindow

View File

@@ -26,8 +26,7 @@ TurnToAngle::TurnToAngle(double targetAngleDegrees, DriveSubsystem* drive)
// Set the controller tolerance - the delta tolerance ensures the robot is
// stationary at the setpoint before it is considered as having reached the
// reference
m_controller.SetAbsoluteTolerance(kTurnToleranceDeg,
kTurnRateToleranceDegPerS);
m_controller.SetTolerance(kTurnToleranceDeg, kTurnRateToleranceDegPerS);
AddRequirements({drive});
}

View File

@@ -20,8 +20,6 @@
*/
class Robot : public frc::TimedRobot {
public:
void RobotInit() override { m_pidController.SetInputRange(0, 5); }
void TeleopPeriodic() override {
// When the button is pressed once, the selected elevator setpoint is
// incremented.

View File

@@ -22,10 +22,6 @@ class Robot : public frc::TimedRobot {
* ultrasonic sensor.
*/
void TeleopInit() override {
// Set expected range to 0-24 inches; e.g. at 24 inches from object go full
// forward, at 0 inches from object go full backward.
m_pidController.SetInputRange(0, 24 * kValueToInches);
// Set setpoint of the PID Controller
m_pidController.SetSetpoint(kHoldDistance * kValueToInches);
}