Package edu.wpi.first.math.controller
Class ElevatorFeedforward
java.lang.Object
edu.wpi.first.math.controller.ElevatorFeedforward
- All Implemented Interfaces:
ProtobufSerializable,StructSerializable,WPISerializable
A helper class that computes feedforward outputs for a simple elevator (modeled as a motor acting
against the force of gravity).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ElevatorFeedforwardProtoElevatorFeedforward protobuf for serialization.static final ElevatorFeedforwardStructElevatorFeedforward struct for serialization. -
Constructor Summary
ConstructorsConstructorDescriptionElevatorFeedforward(double ks, double kg, double kv) Creates a new ElevatorFeedforward with the specified gains.ElevatorFeedforward(double ks, double kg, double kv, double ka) Creates a new ElevatorFeedforward with the specified gains.ElevatorFeedforward(double ks, double kg, double kv, double ka, double dtSeconds) Creates a new ElevatorFeedforward with the specified gains and period. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculate(double velocity) Calculates the feedforward from the gains and velocity setpoint assuming continuous control (acceleration is assumed to be zero).doublecalculate(double velocity, double acceleration) Deprecated, for removal: This API element is subject to removal in a future version.doublecalculateWithVelocities(double currentVelocity, double nextVelocity) Calculates the feedforward from the gains and setpoints assuming discrete control.doublegetDt()Returns the period in seconds.doublegetKa()Returns the acceleration gain in V/(m/s²).doublegetKg()Returns the gravity gain in volts.doublegetKs()Returns the static gain in volts.doublegetKv()Returns the velocity gain in V/(m/s).doublemaxAchievableAcceleration(double maxVoltage, double velocity) Calculates the maximum achievable acceleration given a maximum voltage supply and a velocity.doublemaxAchievableVelocity(double maxVoltage, double acceleration) Calculates the maximum achievable velocity given a maximum voltage supply and an acceleration.doubleminAchievableAcceleration(double maxVoltage, double velocity) Calculates the minimum achievable acceleration given a maximum voltage supply and a velocity.doubleminAchievableVelocity(double maxVoltage, double acceleration) Calculates the minimum achievable velocity given a maximum voltage supply and an acceleration.voidsetKa(double ka) Sets the acceleration gain.voidsetKg(double kg) Sets the gravity gain.voidsetKs(double ks) Sets the static gain.voidsetKv(double kv) Sets the velocity gain.
-
Field Details
-
struct
ElevatorFeedforward struct for serialization. -
proto
ElevatorFeedforward protobuf for serialization.
-
-
Constructor Details
-
ElevatorFeedforward
Creates a new ElevatorFeedforward with the specified gains and period.- Parameters:
ks- The static gain in volts.kg- The gravity gain in volts.kv- The velocity gain in V/(m/s).ka- The acceleration gain in V/(m/s²).dtSeconds- The period in seconds.- Throws:
IllegalArgumentException- for kv < zero.IllegalArgumentException- for ka < zero.IllegalArgumentException- for period ≤ zero.
-
ElevatorFeedforward
Creates a new ElevatorFeedforward with the specified gains. The period is defaulted to 20 ms.- Parameters:
ks- The static gain in volts.kg- The gravity gain in volts.kv- The velocity gain in V/(m/s).ka- The acceleration gain in V/(m/s²).- Throws:
IllegalArgumentException- for kv < zero.IllegalArgumentException- for ka < zero.
-
ElevatorFeedforward
Creates a new ElevatorFeedforward with the specified gains. Acceleration gain is defaulted to zero. The period is defaulted to 20 ms.- Parameters:
ks- The static gain in volts.kg- The gravity gain in volts.kv- The velocity gain in V/(m/s).- Throws:
IllegalArgumentException- for kv < zero.
-
-
Method Details
-
setKs
Sets the static gain.- Parameters:
ks- The static gain in volts.
-
setKg
Sets the gravity gain.- Parameters:
kg- The gravity gain in volts.
-
setKv
Sets the velocity gain.- Parameters:
kv- The velocity gain in V/(m/s).
-
setKa
Sets the acceleration gain.- Parameters:
ka- The acceleration gain in V/(m/s²).
-
getKs
Returns the static gain in volts.- Returns:
- The static gain in volts.
-
getKg
Returns the gravity gain in volts.- Returns:
- The gravity gain in volts.
-
getKv
Returns the velocity gain in V/(m/s).- Returns:
- The velocity gain.
-
getKa
Returns the acceleration gain in V/(m/s²).- Returns:
- The acceleration gain.
-
getDt
Returns the period in seconds.- Returns:
- The period in seconds.
-
calculate
@Deprecated(forRemoval=true, since="2025") public double calculate(double velocity, double acceleration) Deprecated, for removal: This API element is subject to removal in a future version.Calculates the feedforward from the gains and setpoints assuming continuous control.- Parameters:
velocity- The velocity setpoint.acceleration- The acceleration setpoint.- Returns:
- The computed feedforward.
-
calculate
Calculates the feedforward from the gains and velocity setpoint assuming continuous control (acceleration is assumed to be zero).- Parameters:
velocity- The velocity setpoint.- Returns:
- The computed feedforward.
-
calculateWithVelocities
Calculates the feedforward from the gains and setpoints assuming discrete control.Note this method is inaccurate when the velocity crosses 0.
- Parameters:
currentVelocity- The current velocity setpoint in meters per second.nextVelocity- The next velocity setpoint in meters per second.- Returns:
- The computed feedforward in volts.
-
maxAchievableVelocity
Calculates the maximum achievable velocity given a maximum voltage supply and an acceleration. Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the acceleration constraint, and this will give you a simultaneously-achievable velocity constraint.- Parameters:
maxVoltage- The maximum voltage that can be supplied to the elevator, in volts.acceleration- The acceleration of the elevator, in (m/s²).- Returns:
- The maximum possible velocity in (m/s) at the given acceleration.
-
minAchievableVelocity
Calculates the minimum achievable velocity given a maximum voltage supply and an acceleration. Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the acceleration constraint, and this will give you a simultaneously-achievable velocity constraint.- Parameters:
maxVoltage- The maximum voltage that can be supplied to the elevator, in volts.acceleration- The acceleration of the elevator, in (m/s²).- Returns:
- The maximum possible velocity in (m/s) at the given acceleration.
-
maxAchievableAcceleration
Calculates the maximum achievable acceleration given a maximum voltage supply and a velocity. Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the velocity constraint, and this will give you a simultaneously-achievable acceleration constraint.- Parameters:
maxVoltage- The maximum voltage that can be supplied to the elevator, in volts.velocity- The velocity of the elevator, in (m/s)- Returns:
- The maximum possible acceleration in (m/s²) at the given velocity.
-
minAchievableAcceleration
Calculates the minimum achievable acceleration given a maximum voltage supply and a velocity. Useful for ensuring that velocity and acceleration constraints for a trapezoidal profile are simultaneously achievable - enter the velocity constraint, and this will give you a simultaneously-achievable acceleration constraint.- Parameters:
maxVoltage- The maximum voltage that can be supplied to the elevator, in volts.velocity- The velocity of the elevator, in (m/s)- Returns:
- The maximum possible acceleration in (m/s²) at the given velocity.
-