Class SimpleMotorFeedforward
- All Implemented Interfaces:
ProtobufSerializable, StructSerializable, WPISerializable
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SimpleMotorFeedforwardProtoSimpleMotorFeedforward protobuf for serialization.static final SimpleMotorFeedforwardStructSimpleMotorFeedforward struct for serialization. -
Constructor Summary
ConstructorsConstructorDescriptionSimpleMotorFeedforward(double ks, double kv) Creates a new SimpleMotorFeedforward with the specified gains.SimpleMotorFeedforward(double ks, double kv, double ka) Creates a new SimpleMotorFeedforward with the specified gains and period.SimpleMotorFeedforward(double ks, double kv, double ka, double dt) Creates a new SimpleMotorFeedforward with the specified gains and period. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculate(double velocity) Calculates the feedforward from the gains and velocity reference assuming continuous control (acceleration is assumed to be zero).doublecalculate(double currentVelocity, double nextVelocity) Calculates the feedforward from the gains and references assuming discrete control.doublegetDt()Returns the period in seconds.doublegetKa()Returns the acceleration gain in V/(units/s²).doublegetKs()Returns the static gain in volts.doublegetKv()Returns the velocity gain in V/(units/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.voidsetKs(double ks) Sets the static gain.voidsetKv(double kv) Sets the velocity gain.
-
Field Details
-
struct
SimpleMotorFeedforward struct for serialization. -
proto
SimpleMotorFeedforward protobuf for serialization.
-
-
Constructor Details
-
SimpleMotorFeedforward
public SimpleMotorFeedforward(double ks, double kv, double ka, double dt) Creates a new SimpleMotorFeedforward with the specified gains and period.The units should be radians for angular systems and meters for linear systems.
- Parameters:
ks- The static gain in volts.kv- The velocity gain in V/(units/s).ka- The acceleration gain in V/(units/s²).dt- The period in seconds.- Throws:
IllegalArgumentException- for kv < zero.IllegalArgumentException- for ka < zero.IllegalArgumentException- for period ≤ zero.
-
SimpleMotorFeedforward
public SimpleMotorFeedforward(double ks, double kv, double ka) Creates a new SimpleMotorFeedforward with the specified gains and period. The period is defaulted to 20 ms.The units should be radians for angular systems and meters for linear systems.
- Parameters:
ks- The static gain in volts.kv- The velocity gain in V/(units/s).ka- The acceleration gain in V/(units/s²).- Throws:
IllegalArgumentException- for kv < zero.IllegalArgumentException- for ka < zero.
-
SimpleMotorFeedforward
public SimpleMotorFeedforward(double ks, double kv) Creates a new SimpleMotorFeedforward with the specified gains. Acceleration gain is defaulted to zero. The period is defaulted to 20 ms.The units should be radians for angular systems and meters for linear systems.
- Parameters:
ks- The static gain in volts.kv- The velocity gain in V/(units/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.
-
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/(units/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/(units/s²).
-
getKs
public double getKs()Returns the static gain in volts.- Returns:
- The static gain in volts.
-
getKv
public double getKv()Returns the velocity gain in V/(units/s).The units should be radians for angular systems and meters for linear systems.
- Returns:
- The velocity gain in V/(units/s).
-
getKa
public double getKa()Returns the acceleration gain in V/(units/s²).The units should be radians for angular systems and meters for linear systems.
- Returns:
- The acceleration gain in V/(units/s²).
-
getDt
public double getDt()Returns the period in seconds.- Returns:
- The period in seconds.
-
calculate
public double calculate(double velocity) Calculates the feedforward from the gains and velocity reference assuming continuous control (acceleration is assumed to be zero).- Parameters:
velocity- The velocity reference.- Returns:
- The computed feedforward.
-
calculate
public double calculate(double currentVelocity, double nextVelocity) Calculates the feedforward from the gains and references assuming discrete control.Note this method is inaccurate when the velocity crosses 0.
- Parameters:
currentVelocity- The current velocity reference.nextVelocity- The next velocity reference.- Returns:
- The computed feedforward.
-
maxAchievableVelocity
public double maxAchievableVelocity(double maxVoltage, double acceleration) 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.The units should be radians for angular systems and meters for linear systems.
- Parameters:
maxVoltage- The maximum voltage that can be supplied to the motor, in volts.acceleration- The acceleration of the motor, in (units/s²).- Returns:
- The maximum possible velocity in (units/s) at the given acceleration.
-
minAchievableVelocity
public double minAchievableVelocity(double maxVoltage, double acceleration) 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.The units should be radians for angular systems and meters for linear systems.
- Parameters:
maxVoltage- The maximum voltage that can be supplied to the motor, in volts.acceleration- The acceleration of the motor, in (units/s²).- Returns:
- The maximum possible velocity in (units/s) at the given acceleration.
-
maxAchievableAcceleration
public double maxAchievableAcceleration(double maxVoltage, double velocity) 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.The units should be radians for angular systems and meters for linear systems.
- Parameters:
maxVoltage- The maximum voltage that can be supplied to the motor, in volts.velocity- The velocity of the motor, in (units/s).- Returns:
- The maximum possible acceleration in (units/s²) at the given velocity.
-
minAchievableAcceleration
public double minAchievableAcceleration(double maxVoltage, double velocity) 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.The units should be radians for angular systems and meters for linear systems.
- Parameters:
maxVoltage- The maximum voltage that can be supplied to the motor, in volts.velocity- The velocity of the motor, in (units/s).- Returns:
- The maximum possible acceleration in (units/s²) at the given velocity.
-