Clean up PIDCommand (#2010)

PIDCommand uses a function based (callback) model, so functions designed for use in derived classes are of limited utility.
This commit is contained in:
Oblarg
2019-11-01 16:11:55 -04:00
committed by Peter Johnson
parent 9ebd23d61e
commit c5186d8159
6 changed files with 11 additions and 150 deletions

View File

@@ -72,12 +72,13 @@ public class PIDCommand extends CommandBase {
@Override
public void execute() {
useOutput(m_controller.calculate(getMeasurement(), getSetpoint()));
m_useOutput.accept(m_controller.calculate(m_measurement.getAsDouble(),
m_setpoint.getAsDouble()));
}
@Override
public void end(boolean interrupted) {
useOutput(0);
m_useOutput.accept(0);
}
/**
@@ -88,31 +89,4 @@ public class PIDCommand extends CommandBase {
public PIDController getController() {
return m_controller;
}
/**
* Gets the setpoint for the controller. Wraps the passed-in function for readability.
*
* @return The setpoint for the controller
*/
private double getSetpoint() {
return m_setpoint.getAsDouble();
}
/**
* Gets the measurement of the process variable. Wraps the passed-in function for readability.
*
* @return The measurement of the process variable
*/
private double getMeasurement() {
return m_measurement.getAsDouble();
}
/**
* Uses the output of the controller. Wraps the passed-in function for readability.
*
* @param output The output value to use
*/
private void useOutput(double output) {
m_useOutput.accept(output);
}
}

View File

@@ -118,12 +118,13 @@ public class ProfiledPIDCommand extends CommandBase {
@Override
public void execute() {
useOutput(m_controller.calculate(getMeasurement(), getGoal()), m_controller.getSetpoint());
m_useOutput.accept(m_controller.calculate(m_measurement.getAsDouble(), m_goal.get()),
m_controller.getSetpoint());
}
@Override
public void end(boolean interrupted) {
useOutput(0, new State());
m_useOutput.accept(0., new State());
}
/**
@@ -134,31 +135,4 @@ public class ProfiledPIDCommand extends CommandBase {
public ProfiledPIDController getController() {
return m_controller;
}
/**
* Gets the goal for the controller. Wraps the passed-in function for readability.
*
* @return The goal for the controller
*/
private State getGoal() {
return m_goal.get();
}
/**
* Gets the measurement of the process variable. Wraps the passed-in function for readability.
*
* @return The measurement of the process variable
*/
private double getMeasurement() {
return m_measurement.getAsDouble();
}
/**
* Uses the output of the controller. Wraps the passed-in function for readability.
*
* @param output The output value to use
*/
private void useOutput(double output, State state) {
m_useOutput.accept(output, state);
}
}