diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java index 61eb2c5932c..d730b10de92 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java @@ -11,6 +11,9 @@ import edu.wpi.first.math.controller.proto.ArmFeedforwardProto; import edu.wpi.first.math.controller.struct.ArmFeedforwardStruct; import edu.wpi.first.math.jni.ArmFeedforwardJNI; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; import edu.wpi.first.units.measure.Angle; import edu.wpi.first.units.measure.AngularVelocity; import edu.wpi.first.units.measure.MutVoltage; @@ -41,6 +44,21 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable /** The calculated output voltage measure. */ private final MutVoltage output = Volts.mutable(0.0); + /** + * Creates a new ArmFeedforward with the specified plant, gravity gain, and period. The static + * gain (ks) is assumed to be 0.0. + * + *

The constructor is useful for simulating the SingleJointedArmSim class. + * + * @param plant The system plant + * @param kg The gravity gain in volts. + * @param dtSeconds The period in seconds. + * @throws IllegalArgumentException for period ≤ zero. + */ + public ArmFeedforward(LinearSystem plant, double kg, double dtSeconds) { + this(0.0, kg, -plant.getA(1, 1) / plant.getB(1, 0), 1.0 / plant.getB(1, 0), dtSeconds); + } + /** * Creates a new ArmFeedforward with the specified gains and period. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java index 8445e509c28..3a61b5c519d 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java @@ -9,6 +9,9 @@ import edu.wpi.first.math.controller.proto.ElevatorFeedforwardProto; import edu.wpi.first.math.controller.struct.ElevatorFeedforwardStruct; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.numbers.N2; +import edu.wpi.first.math.system.LinearSystem; import edu.wpi.first.units.measure.LinearVelocity; import edu.wpi.first.units.measure.MutVoltage; import edu.wpi.first.units.measure.Voltage; @@ -38,6 +41,21 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ /** The calculated output voltage measure. */ private final MutVoltage output = Volts.mutable(0.0); + /** + * Creates a new ElevatorFeedforward with the specified plant, gravity gain, and period. The + * static gain (ks) is assumed to be 0.0. + * + *

The constructor is useful for simulating the ElevatorSim class. + * + * @param plant The system plant + * @param kg The gravity gain in volts. + * @param dtSeconds The period in seconds. + * @throws IllegalArgumentException for period ≤ zero. + */ + public ElevatorFeedforward(LinearSystem plant, double kg, double dtSeconds) { + this(0.0, kg, -plant.getA(1, 1) / plant.getB(1, 0), 1.0 / plant.getB(1, 0), dtSeconds); + } + /** * Creates a new ElevatorFeedforward with the specified gains and period. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java index e227a63f5e6..885ff785a50 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java @@ -8,6 +8,8 @@ import edu.wpi.first.math.controller.proto.SimpleMotorFeedforwardProto; import edu.wpi.first.math.controller.struct.SimpleMotorFeedforwardStruct; +import edu.wpi.first.math.numbers.N1; +import edu.wpi.first.math.system.LinearSystem; import edu.wpi.first.units.Measure; import edu.wpi.first.units.PerUnit; import edu.wpi.first.units.TimeUnit; @@ -34,6 +36,21 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria // ** The calculated output voltage measure */ private final MutVoltage output = Volts.mutable(0.0); + /** + * Creates a new SimpleMotorFeedforward with the specified plant and period. Units used to create + * the plant will dictate units of the computed feedforward. The static gain (ks) is assumed to be + * 0.0. + * + *

The constructor is useful for simulating the FlywheelSim and DCMotorSim classes. + * + * @param plant The system plant + * @param dtSeconds The period in seconds. + * @throws IllegalArgumentException for period ≤ zero. + */ + public SimpleMotorFeedforward(LinearSystem plant, double dtSeconds) { + this(0.0, -plant.getA(0, 0) / plant.getB(0, 0), 1.0 / plant.getB(0, 0), dtSeconds); + } + /** * Creates a new SimpleMotorFeedforward with the specified gains and period. *