mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
committed by
Peter Johnson
parent
0ca8d667d2
commit
ff8b8f0a8a
@@ -37,7 +37,7 @@ public class ShooterSubsystem extends PIDSubsystem {
|
||||
*/
|
||||
public ShooterSubsystem() {
|
||||
super(new PIDController(kP, kI, kD));
|
||||
getController().setAbsoluteTolerance(kShooterToleranceRPS);
|
||||
getController().setTolerance(kShooterToleranceRPS);
|
||||
m_shooterEncoder.setDistancePerPulse(kEncoderDistancePerPulse);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DriveStraight extends PIDCommand {
|
||||
m_drivetrain = drivetrain;
|
||||
addRequirements(m_drivetrain);
|
||||
|
||||
getController().setAbsoluteTolerance(0.01);
|
||||
getController().setTolerance(0.01);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
|
||||
@@ -35,7 +35,7 @@ public class SetDistanceToBox extends PIDCommand {
|
||||
m_drivetrain = drivetrain;
|
||||
addRequirements(m_drivetrain);
|
||||
|
||||
getController().setAbsoluteTolerance(0.01);
|
||||
getController().setTolerance(0.01);
|
||||
}
|
||||
|
||||
// Called just before this Command runs the first time
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Elevator extends PIDSubsystem {
|
||||
if (Robot.isSimulation()) { // Check for simulation and update PID values
|
||||
getController().setPID(kP_simulation, kI_simulation, 0);
|
||||
}
|
||||
getController().setAbsoluteTolerance(0.005);
|
||||
getController().setTolerance(0.005);
|
||||
|
||||
m_motor = new Victor(5);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Wrist extends PIDSubsystem {
|
||||
if (Robot.isSimulation()) { // Check for simulation and update PID values
|
||||
getController().setPID(kP_simulation, 0, 0);
|
||||
}
|
||||
getController().setAbsoluteTolerance(2.5);
|
||||
getController().setTolerance(2.5);
|
||||
|
||||
m_motor = new Victor(6);
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TurnToAngle extends PIDCommand {
|
||||
getController().enableContinuousInput(-180, 180);
|
||||
// Set the controller tolerance - the delta tolerance ensures the robot is stationary at the
|
||||
// setpoint before it is considered as having reached the reference
|
||||
getController().setAbsoluteTolerance(kTurnToleranceDeg, kTurnRateToleranceDegPerS);
|
||||
getController().setTolerance(kTurnToleranceDeg, kTurnRateToleranceDegPerS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,7 +50,6 @@ public class Robot extends TimedRobot {
|
||||
m_joystick = new Joystick(kJoystickChannel);
|
||||
|
||||
m_pidController = new PIDController(kP, kI, kD);
|
||||
m_pidController.setInputRange(0, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,9 +21,6 @@ public class Robot extends TimedRobot {
|
||||
// distance in inches the robot wants to stay from an object
|
||||
private static final double kHoldDistance = 12.0;
|
||||
|
||||
// maximum distance in inches we expect the robot to see
|
||||
private static final double kMaxDistance = 24.0;
|
||||
|
||||
// factor to convert sensor values to a distance in inches
|
||||
private static final double kValueToInches = 0.125;
|
||||
|
||||
@@ -46,13 +43,6 @@ public class Robot extends TimedRobot {
|
||||
new PWMVictorSPX(kRightMotorPort));
|
||||
private final PIDController m_pidController = new PIDController(kP, kI, kD);
|
||||
|
||||
@Override
|
||||
public void robotInit() {
|
||||
// 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, kMaxDistance * kValueToInches);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleopInit() {
|
||||
// Set setpoint of the pid controller
|
||||
|
||||
Reference in New Issue
Block a user