Class MotorFeedforward

java.lang.Object
com.stuypulse.stuylib.control.feedforward.MotorFeedforward

public class MotorFeedforward extends Object
A motor feedforward model, which can be used to calculate an output voltage given a desired velocity of a motor.

A feedforward model often uses the dynamics of a system to calculate a voltage for a movement that is specified by a desired velocity.

Feedforward models often take into account acceleration as well, but this is implicitly calculated from desired velocities so that only sensible movements can be specified.

A motor feedforward *model* can be converted into *controllers* through 3 decorator methods: `.velocity()`, `.position()`, and `.angle()`. `.velocity()` returns a velocity feedforward controller, while `.position()` returns a position feedforward controller, and `.angle()` returns an angle feedforward controller. These methods differ on what the controller's setpoint unit is.

For example, the velocity feedforward controller takes in velocity setpoints, which are directly passed to the model. On the other hand, a position feedforward controller takes in positional setpoints, which are then differentiated to get velocity and then fed to the feedforward controller. An angle feedforward controller is a positional controller that is forced to use angular units, so angular velocity is calculated and then fed to the feedforward model.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a feedforward model for a motor
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a controller that uses this feedforward model to calculate a motor output given angle setpoints.
    final double
    calculate(double velocity)
    Calculates a motor output given a desired velocity
    Creates a controller that uses this feedforward model to calculate a motor output given positional setpoints.
    Creates a controller that uses this feedforward model to calculate a motor output given velocity setpoints.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MotorFeedforward

      public MotorFeedforward(Number kS, Number kV, Number kA)
      Create a feedforward model for a motor
      Parameters:
      kS - volts, describes portion of voltage to overcome static friction
      kV - volts * seconds / distance, describes voltage needed to hold constant velocity
      kA - volts * seconds^2 / distance, describes voltage needed to move at an acceleration
  • Method Details

    • velocity

      public final Controller velocity()
      Creates a controller that uses this feedforward model to calculate a motor output given velocity setpoints.
      Returns:
      a velocity controller for this feedforward model
    • position

      public final Controller position()
      Creates a controller that uses this feedforward model to calculate a motor output given positional setpoints.

      NOTE: The derivative of the position setpoints is calculated and then plugged into this model.

      Returns:
      the position controller for this feedforward model
    • angle

      public final AngleController angle()
      Creates a controller that uses this feedforward model to calculate a motor output given angle setpoints.

      NOTE: the angular velocity of the angle setpoints is calculated and then plugged into this model.

      Returns:
      the angle controller for this feedforward model
    • calculate

      public final double calculate(double velocity)
      Calculates a motor output given a desired velocity

      Implicitly determines acceleration by taking the derivative of velocity.

      Parameters:
      velocity - desired velocity
      Returns:
      motor output, often in volts