mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[commands] Fix PIDSubsystem setSetpoint behavior (#4759)
No longer stores a temporary setpoint in PIDSubsystem, instead immediately sending to PIDController. This fixes an issue where the setpoint didn't take effect until the Subsystem Periodic method ran, and could cause commands to finish early if they were scheduled after the subsystem periodic method ran because it used the old setpoint.
This commit is contained in:
@@ -18,8 +18,6 @@ public abstract class PIDSubsystem extends SubsystemBase {
|
||||
protected final PIDController m_controller;
|
||||
protected boolean m_enabled;
|
||||
|
||||
private double m_setpoint;
|
||||
|
||||
/**
|
||||
* Creates a new PIDSubsystem.
|
||||
*
|
||||
@@ -27,8 +25,8 @@ public abstract class PIDSubsystem extends SubsystemBase {
|
||||
* @param initialPosition the initial setpoint of the subsystem
|
||||
*/
|
||||
public PIDSubsystem(PIDController controller, double initialPosition) {
|
||||
setSetpoint(initialPosition);
|
||||
m_controller = requireNonNullParam(controller, "controller", "PIDSubsystem");
|
||||
setSetpoint(initialPosition);
|
||||
addChild("PID Controller", m_controller);
|
||||
}
|
||||
|
||||
@@ -44,7 +42,7 @@ public abstract class PIDSubsystem extends SubsystemBase {
|
||||
@Override
|
||||
public void periodic() {
|
||||
if (m_enabled) {
|
||||
useOutput(m_controller.calculate(getMeasurement(), m_setpoint), m_setpoint);
|
||||
useOutput(m_controller.calculate(getMeasurement()), getSetpoint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +56,7 @@ public abstract class PIDSubsystem extends SubsystemBase {
|
||||
* @param setpoint the setpoint for the subsystem
|
||||
*/
|
||||
public void setSetpoint(double setpoint) {
|
||||
m_setpoint = setpoint;
|
||||
m_controller.setSetpoint(setpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +65,7 @@ public abstract class PIDSubsystem extends SubsystemBase {
|
||||
* @return The current setpoint
|
||||
*/
|
||||
public double getSetpoint() {
|
||||
return m_setpoint;
|
||||
return m_controller.getSetpoint();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user