Class Feedforward
java.lang.Object
com.crossbotics.ftchelper.control.Feedforward
The power a motor needs for a speed, worked out from how the motor behaves ("feedforward"), instead
of waiting for an error to build up like a PID does. The Characterizer finds the numbers.
Feedforward ff = new Feedforward(0.06, 0.00037, 0.00004); // from the Characterizer's results
double power = ff.power(1500, 0); // the power for 1500 counts per second, not speeding up
lift.setPower(liftFf.power(800, 0) + pid.calculate(target, lift.getCurrentPosition())); // plus a PID for the rest
power = kS x sign(speed) + kV x speed + kA x acceleration + kG
- kS: the power just to start moving (friction).
- kV: the power for each count per second of speed.
- kA: the power for each count per second, per second, of speeding up.
- kG: the power that holds a lift against gravity (0 for wheels and flywheels).
power(double, double, double) scales for the battery
you have now. Speeds are in encoder counts per second, the same as DcMotorEx.getVelocity().
Docs: docs/modules/control.md-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal doublePower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).final doublePower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).final doublePower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).final doublePower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).static final doubleThe battery voltage the numbers are for. -
Constructor Summary
ConstructorsConstructorDescriptionFeedforward(double kS, double kV, double kA) For wheels and flywheels (no gravity).Feedforward(double kS, double kV, double kA, double kG) For a lift: kG = the power that holds it still against gravity. -
Method Summary
Modifier and TypeMethodDescriptiondoublepower(double velocity, double acceleration) The power for this speed and acceleration (counts per second, and per second per second), at 12.8 V.doublepower(double velocity, double acceleration, double batteryVolts) The same for the battery you have now: a weaker battery needs more power for the same speed.doubletopSpeed()The top speed at full power (counts per second), 0 if kV is not set.toString()
-
Field Details
-
NOMINAL_VOLTS
public static final double NOMINAL_VOLTSThe battery voltage the numbers are for.- See Also:
-
kS
public final double kSPower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG). -
kV
public final double kVPower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG). -
kA
public final double kAPower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG). -
kG
public final double kGPower to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
-
-
Constructor Details
-
Feedforward
public Feedforward(double kS, double kV, double kA) For wheels and flywheels (no gravity). -
Feedforward
public Feedforward(double kS, double kV, double kA, double kG) For a lift: kG = the power that holds it still against gravity.
-
-
Method Details
-
power
public double power(double velocity, double acceleration) The power for this speed and acceleration (counts per second, and per second per second), at 12.8 V. -
power
public double power(double velocity, double acceleration, double batteryVolts) The same for the battery you have now: a weaker battery needs more power for the same speed. Not limited to -1..1: clip it yourself (or let setPower do it).- Parameters:
batteryVolts- the battery's voltage now (the hub's voltage sensor)
-
topSpeed
public double topSpeed()The top speed at full power (counts per second), 0 if kV is not set. -
toString
-