Package org.chsrobotics.lib.controllers
Class ComposedFeedbackController
java.lang.Object
org.chsrobotics.lib.controllers.ComposedFeedbackController
- All Implemented Interfaces:
FeedbackController
A controller made of a sum of filters, each multiplied by a constant gain. Instead of the input
value, the error between the setpoint and input is what is given to the filters.
For example, this can easily be turned into a simple PID controller by constructing as follows:
new ComposedController(Map.of(new NullFilter(), kP, new IntegratingFilter(window), kI,
new DifferentiatingFilter(), kD))
-
Field Summary
Fields inherited from interface org.chsrobotics.lib.controllers.FeedbackController
defaultPositionErrorToleranceProportion, defaultVelocityErrorToleranceProportion -
Constructor Summary
ConstructorsConstructorDescriptionComposedFeedbackController(List<Filter> filters) Constructs a ComposedController.ComposedFeedbackController(Map<Filter, Double> values) Constructs a ComposedController. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the controller has reached the setpoint with minimal velocity.doublecalculate(double measurement) Returns an output from the controller with the default robot loop time.doublecalculate(double measurement, double dtSeconds) Returns an output from the controller with a given dt.doubleReturns the last output of the controller without updating with a new value.doubleReturns the current setpoint (target) of the controller.voidreset()Resets the controller.voidsetSetpoint(double value) Sets the setpoint (target) of the controller.voidsetSetpointTolerance(double positionErrorProportion, double velocityErrorProportion) Sets the maximum error of both position and velocity allowed foratSetpoint()to return true.
-
Constructor Details
-
ComposedFeedbackController
Constructs a ComposedController.- Parameters:
filters- A list of filters to combine into the controller.
-
ComposedFeedbackController
Constructs a ComposedController.- Parameters:
values- A map of filters to their gains.
-
-
Method Details
-
reset
public void reset()Description copied from interface:FeedbackControllerResets the controller.- Specified by:
resetin interfaceFeedbackController
-
setSetpoint
public void setSetpoint(double value) Description copied from interface:FeedbackControllerSets the setpoint (target) of the controller.- Specified by:
setSetpointin interfaceFeedbackController- Parameters:
value- The new target of the controller.
-
getSetpoint
public double getSetpoint()Description copied from interface:FeedbackControllerReturns the current setpoint (target) of the controller.- Specified by:
getSetpointin interfaceFeedbackController- Returns:
- The current setpoint.
-
calculate
public double calculate(double measurement) Description copied from interface:FeedbackControllerReturns an output from the controller with the default robot loop time.This must be called at a rate of once every robot loop to be consistent.
- Specified by:
calculatein interfaceFeedbackController- Parameters:
measurement- The value of the measured feedback.- Returns:
- The output of the controller.
-
calculate
public double calculate(double measurement, double dtSeconds) Description copied from interface:FeedbackControllerReturns an output from the controller with a given dt.- Specified by:
calculatein interfaceFeedbackController- Parameters:
measurement- The value of the measured feedback.dtSeconds- The time, in seconds, since the last update of this controller.- Returns:
- The output of the controller.
-
getCurrentValue
public double getCurrentValue()Description copied from interface:FeedbackControllerReturns the last output of the controller without updating with a new value.- Specified by:
getCurrentValuein interfaceFeedbackController- Returns:
- The last ouptut of the controller.
-
setSetpointTolerance
public void setSetpointTolerance(double positionErrorProportion, double velocityErrorProportion) Description copied from interface:FeedbackControllerSets the maximum error of both position and velocity allowed foratSetpoint()to return true.- Specified by:
setSetpointTolerancein interfaceFeedbackController- Parameters:
positionErrorProportion- The maximum allowed position error, as a proportion of the setpoint.velocityErrorProportion- The maximum allowed absolute velocity per second, as a proportion of the setpoint / second.
-
atSetpoint
public boolean atSetpoint()Description copied from interface:FeedbackControllerReturns whether the controller has reached the setpoint with minimal velocity.- Specified by:
atSetpointin interfaceFeedbackController- Returns:
- Whether the controller is within the minimum position and velocity errors.
-