Class Feedforward

java.lang.Object
com.crossbotics.ftchelper.control.Feedforward

public final class Feedforward extends Object
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).
Powers are at 12.8 V (a full battery): 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

    Fields
    Modifier and Type
    Field
    Description
    final double
    Power to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
    final double
    Power to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
    final double
    Power to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
    final double
    Power to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
    static final double
    The battery voltage the numbers are for.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Feedforward(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 Type
    Method
    Description
    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.
    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.
    double
    The top speed at full power (counts per second), 0 if kV is not set.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • NOMINAL_VOLTS

      public static final double NOMINAL_VOLTS
      The battery voltage the numbers are for.
      See Also:
    • kS

      public final double kS
      Power to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
    • kV

      public final double kV
      Power to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
    • kA

      public final double kA
      Power to start moving (kS), per speed (kV), per acceleration (kA), to hold against gravity (kG).
    • kG

      public final double kG
      Power 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

      public String toString()
      Overrides:
      toString in class Object