Class ArmFeedforward
java.lang.Object
org.wpilib.math.controller.ArmFeedforward
- All Implemented Interfaces:
ProtobufSerializable, StructSerializable, WPISerializable
A helper class that computes feedforward outputs for a simple arm (modeled as a motor acting
against the force of gravity on a beam suspended at an angle).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ArmFeedforwardProtoArm feedforward protobuf for serialization.static final ArmFeedforwardStructArm feedforward struct for serialization. -
Constructor Summary
ConstructorsConstructorDescriptionArmFeedforward(double ks, double kg, double kv) Creates a new ArmFeedforward with the specified gains.ArmFeedforward(double ks, double kg, double kv, double ka) Creates a new ArmFeedforward with the specified gains.ArmFeedforward(double ks, double kg, double kv, double ka, double dt) Creates a new ArmFeedforward with the specified gains and period. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculate(double position, double velocity) Calculates the feedforward from the gains and velocity reference assuming continuous control (acceleration is assumed to be zero).doublecalculate(double currentAngle, double currentVelocity, double nextVelocity) Calculates the feedforward from the gains and references assuming continuous control.doublegetDt()Returns the period in seconds.doublegetKa()Returns the acceleration gain in V/(rad/s²).doublegetKg()Returns the gravity gain in volts.doublegetKs()Returns the static gain in volts.doublegetKv()Returns the velocity gain in V/(rad/s).doublemaxAchievableAcceleration(double maxVoltage, double angle, double velocity) Calculates the maximum achievable acceleration given a maximum voltage supply, a position, and a velocity.doublemaxAchievableVelocity(double maxVoltage, double angle, double acceleration) Calculates the maximum achievable velocity given a maximum voltage supply, a position, and an acceleration.doubleminAchievableAcceleration(double maxVoltage, double angle, double velocity) Calculates the minimum achievable acceleration given a maximum voltage supply, a position, and a velocity.doubleminAchievableVelocity(double maxVoltage, double angle, double acceleration) Calculates the minimum achievable velocity given a maximum voltage supply, a position, 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
Arm feedforward struct for serialization. -
proto
Arm feedforward protobuf for serialization.
-
-
Constructor Details
-
ArmFeedforward
public ArmFeedforward(double ks, double kg, double kv, double ka, double dt) Creates a new ArmFeedforward 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/(rad/s).ka- The acceleration gain in V/(rad/s²).dt- The period in seconds.- Throws:
IllegalArgumentException- for kv < zero.IllegalArgumentException- for ka < zero.IllegalArgumentException- for period ≤ zero.
-
ArmFeedforward
public ArmFeedforward(double ks, double kg, double kv, double ka) Creates a new ArmFeedforward 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/(rad/s).ka- The acceleration gain in V/(rad/s²).- Throws:
IllegalArgumentException- for kv < zero.IllegalArgumentException- for ka < zero.
-
ArmFeedforward
public ArmFeedforward(double ks, double kg, double kv) Creates a new ArmFeedforward 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/(rad/s).- Throws:
IllegalArgumentException- for kv < zero.
-
-
Method Details
-
setKs
public void setKs(double ks) Sets the static gain.This setter is intended for online tuning only. Feedforward gains are assumed constant, so gain scheduling means the system was not correctly modeled.
- Parameters:
ks- The static gain in volts.
-
setKg
public void setKg(double kg) Sets the gravity gain.This setter is intended for online tuning only. Feedforward gains are assumed constant, so gain scheduling means the system was not correctly modeled.
- Parameters:
kg- The gravity gain in volts.
-
setKv
public void setKv(double kv) Sets the velocity gain.This setter is intended for online tuning only. Feedforward gains are assumed constant, so gain scheduling means the system was not correctly modeled.
- Parameters:
kv- The velocity gain in V/(rad/s).
-
setKa
public void setKa(double ka) Sets the acceleration gain.This setter is intended for online tuning only. Feedforward gains are assumed constant, so gain scheduling means the system was not correctly modeled.
- Parameters:
ka- The acceleration gain in V/(rad/s²).
-
getKs
public double getKs()Returns the static gain in volts.- Returns:
- The static gain in volts.
-
getKg
public double getKg()Returns the gravity gain in volts.- Returns:
- The gravity gain in volts.
-
getKv
public double getKv()Returns the velocity gain in V/(rad/s).- Returns:
- The velocity gain.
-
getKa
public double getKa()Returns the acceleration gain in V/(rad/s²).- Returns:
- The acceleration gain.
-
getDt
public double getDt()Returns the period in seconds.- Returns:
- The period in seconds.
-
calculate
public double calculate(double position, double velocity) Calculates the feedforward from the gains and velocity reference assuming continuous control (acceleration is assumed to be zero).- Parameters:
position- The position reference in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel with the floor). If your encoder does not follow this convention, an offset should be added.velocity- The velocity reference in radians per second.- Returns:
- The computed feedforward.
-
calculate
public double calculate(double currentAngle, double currentVelocity, double nextVelocity) Calculates the feedforward from the gains and references assuming continuous control.- Parameters:
currentAngle- The current angle in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel to the floor). If your encoder does not follow this convention, an offset should be added.currentVelocity- The current velocity reference in radians per second.nextVelocity- The next velocity reference in radians per second.- Returns:
- The computed feedforward in volts.
-
maxAchievableVelocity
public double maxAchievableVelocity(double maxVoltage, double angle, double acceleration) Calculates the maximum achievable velocity given a maximum voltage supply, a position, 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 arm.angle- The angle of the arm, in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel with the floor). If your encoder does not follow this convention, an offset should be added.acceleration- The acceleration of the arm, in (rad/s²).- Returns:
- The maximum possible velocity in (rad/s) at the given acceleration and angle.
-
minAchievableVelocity
public double minAchievableVelocity(double maxVoltage, double angle, double acceleration) Calculates the minimum achievable velocity given a maximum voltage supply, a position, 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 arm, in volts.angle- The angle of the arm, in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel with the floor). If your encoder does not follow this convention, an offset should be added.acceleration- The acceleration of the arm, in (rad/s²).- Returns:
- The minimum possible velocity in (rad/s) at the given acceleration and angle.
-
maxAchievableAcceleration
public double maxAchievableAcceleration(double maxVoltage, double angle, double velocity) Calculates the maximum achievable acceleration given a maximum voltage supply, a position, 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 arm, in volts.angle- The angle of the arm, in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel with the floor). If your encoder does not follow this convention, an offset should be added.velocity- The velocity of the elevator, in (rad/s)- Returns:
- The maximum possible acceleration in (rad/s²) at the given velocity.
-
minAchievableAcceleration
public double minAchievableAcceleration(double maxVoltage, double angle, double velocity) Calculates the minimum achievable acceleration given a maximum voltage supply, a position, 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 arm, in volts.angle- The angle of the arm, in radians. This angle should be measured from the horizontal (i.e. if the provided angle is 0, the arm should be parallel with the floor). If your encoder does not follow this convention, an offset should be added.velocity- The velocity of the elevator, in (rad/s)- Returns:
- The maximum possible acceleration in (rad/s²) at the given velocity.
-