Class LQRConfig

java.lang.Object
yams.core.math.LQRConfig

public class LQRConfig extends Object
LQR Configuration for LQRController

The LQR cost matrices determine how the regulator balances state error against control effort:

  • Q (state cost, via qelms) penalizes deviation from the desired state (position, velocity). Smaller values tolerate larger state errors; larger values drive the controller to correct errors more aggressively.
  • R (control effort cost, via relms) penalizes the voltage applied to the motor. Smaller values allow higher voltages (more aggressive); larger values keep the output gentler. The default of 12 V matches the approximate maximum battery voltage.

Example Arm LQR configuration

import static org.wpilib.units.Units.*;

LQRConfig config = new LQRConfig(
        DCMotor.getNEO(1),
        MechanismGearing.ofReduction(60.0),
        KilogramSquareMeters.of(0.25))
    .withArm(
        Radians.of(0.01),          // qelms position: 0.01 rad error tolerance
        RadiansPerSecond.of(0.5),  // qelms velocity: 0.5 rad/s error tolerance
        Radians.of(0.05),          // model position std dev
        RadiansPerSecond.of(0.5),  // model velocity std dev
        Radians.of(0.01))          // encoder position std dev
    .withControlEffort(Volts.of(12))
    .withMaxVoltage(Volts.of(12))
    .withAggressiveness(10);

LQRController armController = new LQRController(config);
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    LQR Type
  • Constructor Summary

    Constructors
    Constructor
    Description
    LQRConfig(org.wpilib.math.system.DCMotor motor, MechanismGearing gearing, org.wpilib.units.measure.MomentOfInertia moi)
    Create a new LQR Configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.wpilib.math.estimator.KalmanFilter<?,?,?>
    getKalmanFilter(org.wpilib.math.system.LinearSystem<?,?,?> plant)
    Get the KalmanFilter for the LQR.
    org.wpilib.math.system.LinearSystemLoop<?,?,?>
    Get the LinearSystemLoop with the currently configured LQR.
    org.wpilib.math.system.LinearSystemLoop<?,?,?>
    getLoop(org.wpilib.math.system.LinearSystem<?,?,?> plant, org.wpilib.math.controller.LinearQuadraticRegulator<?,?,?> controller, org.wpilib.math.estimator.KalmanFilter<?,?,?> observer)
    Get the LinearSystemLoop.
    org.wpilib.units.measure.Time
    Get the loop time for the LQR.
    org.wpilib.math.controller.LinearQuadraticRegulator<?,?,?>
    getRegulator(org.wpilib.math.system.LinearSystem<?,?,?> plant)
    Get the LinearQuadraticRegulator.
    org.wpilib.math.system.LinearSystem<?,?,?>
    Get the LinearSystem for the LQR.
    Get the LQRConfig.LQRType of the LQR.
    withAggressiveness(double aggressiveness)
    Aggressiveness of the LQR, how fast it will attempt to achieve the desired state.
    withArm(org.wpilib.units.measure.Angle qelmsPosition, org.wpilib.units.measure.AngularVelocity qelmsVelocity, org.wpilib.units.measure.Angle modelPositionTrust, org.wpilib.units.measure.AngularVelocity modelVelocityTrust, org.wpilib.units.measure.Angle encoderPositionTrust)
    Construct an Arm LQR Configuration.
    withControlEffort(org.wpilib.units.measure.Voltage effort)
    Set the control effort for the LQR.
    withElevator(org.wpilib.units.measure.Distance qelmsPosition, org.wpilib.units.measure.LinearVelocity qelmsVelocity, org.wpilib.units.measure.Distance modelPositionTrust, org.wpilib.units.measure.LinearVelocity modelVelocityTrust, org.wpilib.units.measure.Distance encoderPositionTrust, org.wpilib.units.measure.Mass mass, org.wpilib.units.measure.Distance drumRadius)
    Construct an Elevator LQR Configuration.
    withFlyWheel(org.wpilib.units.measure.AngularVelocity qelms, org.wpilib.units.measure.AngularVelocity modelTrust, org.wpilib.units.measure.AngularVelocity encoderTrust)
    Construct a Flywheel LQR Configuration.
    withMaxVoltage(org.wpilib.units.measure.Voltage voltage)
    Set the maximum voltage for the LinearSystemLoop.
    withMeasurementDelay(org.wpilib.units.measure.Time delay)
    Set the measurement delay of the LQR.
    withRelms(org.wpilib.units.measure.Voltage relms)
    Set the control effort for the LQR.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait