YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
yams::math::LQRConfig Class Reference

#include <LQRConfig.hpp>

Classes

struct  LoopBundle

Public Types

enum class  LQRType { FLYWHEEL , ARM , ELEVATOR }
using Loop1 = wpi::math::LinearSystemLoop<1, 1, 1>
using Loop2 = wpi::math::LinearSystemLoop<2, 1, 1>

Public Member Functions

LQRConfig & WithType (LQRType type)
LQRConfig & WithFlywheelSystem (const wpi::math::DCMotor &motor, double momentOfInertia, double gearing)
LQRConfig & WithArmSystem (const wpi::math::DCMotor &motor, double momentOfInertia, double gearing)
LQRConfig & WithElevatorSystem (const wpi::math::DCMotor &motor, double mass, double drumRadius, double gearing)
LQRConfig & WithQElems (std::initializer_list< double > qElems)
LQRConfig & WithRElems (std::initializer_list< double > rElems)
LQRConfig & WithStateStdDevs (std::initializer_list< double > stateStdDevs)
LQRConfig & WithMeasurementStdDevs (std::initializer_list< double > measStdDevs)
LQRConfig & WithMaxVoltage (wpi::units::volt_t maxVoltage)
LQRConfig & WithPeriod (wpi::units::second_t period)
LQRType GetType () const
wpi::units::second_t GetPeriod () const
wpi::units::volt_t GetMaxVoltage () const
std::vector< double > GetQElems () const
std::vector< double > GetRElems () const
std::vector< double > GetStateStdDevs () const
std::vector< double > GetMeasurementStdDevs () const
LQRConfig & WithQElems (const std::vector< double > &qElems)
LQRConfig & WithRElems (const std::vector< double > &rElems)
LQRConfig & WithStateStdDevs (const std::vector< double > &stateStdDevs)
LQRConfig & WithMeasurementStdDevs (const std::vector< double > &measStdDevs)
std::variant< wpi::math::LinearSystem< 1, 1, 1 >, wpi::math::LinearSystem< 2, 1, 1 > > GetSystem () const
std::variant< std::unique_ptr< LoopBundle< 1 > >, std::unique_ptr< LoopBundle< 2 > > > GetLoop () const

Friends

class LQRController

Detailed Description

Configuration for an LQR (Linear Quadratic Regulator) closed-loop controller.

Uses a fluent builder pattern; all With* methods return *this for chaining. After configuring the plant type, gains, and noise parameters call GetLoop() to obtain the ready-to-use LinearSystemLoop, in a LoopBundle that owns everything it points to.

Member Typedef Documentation

◆ Loop1

using yams::math::LQRConfig::Loop1 = wpi::math::LinearSystemLoop<1, 1, 1>

LinearSystemLoop type alias for 1-state plants (flywheel).

◆ Loop2

using yams::math::LQRConfig::Loop2 = wpi::math::LinearSystemLoop<2, 1, 1>

LinearSystemLoop type alias for 2-state plants (arm, elevator).

Member Enumeration Documentation

◆ LQRType

enum class yams::math::LQRConfig::LQRType
strong

Identifies which plant model the LQR is built for.

Enumerator
FLYWHEEL 

Flywheel (1-state velocity model).

ARM 

Single-jointed arm (2-state position+velocity model).

ELEVATOR 

Elevator (2-state position+velocity model).

Member Function Documentation

◆ GetLoop()

std::variant< std::unique_ptr< LoopBundle< 1 > >, std::unique_ptr< LoopBundle< 2 > > > yams::math::LQRConfig::GetLoop ( ) const

Build and return the complete LinearSystemLoop ready for use, with the plant, LQR and Kalman filter it points to.

Returns
Variant holding a 1-state bundle (flywheel) or a 2-state bundle (arm/elevator).

◆ GetMaxVoltage()

wpi::units::volt_t yams::math::LQRConfig::GetMaxVoltage ( ) const

Get the configured maximum voltage.

Returns
Maximum voltage.

◆ GetMeasurementStdDevs()

std::vector< double > yams::math::LQRConfig::GetMeasurementStdDevs ( ) const

Get the encoder's standard deviations in use, in SI units: rad/s for a flywheel, rad for an arm, m for an elevator.

Returns
One standard deviation per measurement.

◆ GetPeriod()

wpi::units::second_t yams::math::LQRConfig::GetPeriod ( ) const

Get the configured loop period.

Returns
Loop period.

◆ GetQElems()

std::vector< double > yams::math::LQRConfig::GetQElems ( ) const

Get the state error tolerances in use, in SI units: rad/s for a flywheel, rad and rad/s for an arm, m and m/s for an elevator. Unset tolerances are the defaults the loop is built with.

Returns
One tolerance per modeled state.

◆ GetRElems()

std::vector< double > yams::math::LQRConfig::GetRElems ( ) const

Get the control effort (voltage) tolerances in use, in volts.

Returns
One tolerance per input.

◆ GetStateStdDevs()

std::vector< double > yams::math::LQRConfig::GetStateStdDevs ( ) const

Get the model's standard deviations in use, in the SI units of GetQElems().

Returns
One standard deviation per modeled state.

◆ GetSystem()

std::variant< wpi::math::LinearSystem< 1, 1, 1 >, wpi::math::LinearSystem< 2, 1, 1 > > yams::math::LQRConfig::GetSystem ( ) const

Build and return the linear plant model.

Returns
Variant holding a 1-state system (flywheel) or 2-state system (arm/elevator).

◆ GetType()

LQRType yams::math::LQRConfig::GetType ( ) const

Get the configured LQR plant type.

Returns
LQRType.

◆ WithArmSystem()

LQRConfig & yams::math::LQRConfig::WithArmSystem ( const wpi::math::DCMotor & motor,
double momentOfInertia,
double gearing )

Configure a single-jointed arm plant model.

Parameters
motorDC motor model.
momentOfInertiaMoment of inertia of the arm (kg·m²).
gearingGear reduction from motor to arm joint.
Returns
*this for chaining.

◆ WithElevatorSystem()

LQRConfig & yams::math::LQRConfig::WithElevatorSystem ( const wpi::math::DCMotor & motor,
double mass,
double drumRadius,
double gearing )

Configure an elevator plant model.

Parameters
motorDC motor model.
massCarriage mass (kg).
drumRadiusRadius of the drum (m).
gearingGear reduction from motor to drum.
Returns
*this for chaining.

◆ WithFlywheelSystem()

LQRConfig & yams::math::LQRConfig::WithFlywheelSystem ( const wpi::math::DCMotor & motor,
double momentOfInertia,
double gearing )

Configure a flywheel plant model.

Parameters
motorDC motor model.
momentOfInertiaMoment of inertia of the flywheel (kg·m²).
gearingGear reduction from motor to flywheel.
Returns
*this for chaining.

◆ WithMaxVoltage()

LQRConfig & yams::math::LQRConfig::WithMaxVoltage ( wpi::units::volt_t maxVoltage)

Set the maximum voltage output of the LinearSystemLoop.

Parameters
maxVoltageMaximum voltage (default 12 V).
Returns
*this for chaining.

◆ WithMeasurementStdDevs() [1/2]

LQRConfig & yams::math::LQRConfig::WithMeasurementStdDevs ( const std::vector< double > & measStdDevs)

Set the encoder's standard deviation, as when live tuning it, checking it.

Parameters
measStdDevsOne standard deviation, above 0.
Returns
*this for chaining.
Exceptions
std::invalid_argumentif there isn't one value, or it isn't above 0.

◆ WithMeasurementStdDevs() [2/2]

LQRConfig & yams::math::LQRConfig::WithMeasurementStdDevs ( std::initializer_list< double > measStdDevs)

Set the Kalman filter measurement standard deviations.

Parameters
measStdDevsStandard deviations of the encoder measurements.
Returns
*this for chaining.

◆ WithPeriod()

LQRConfig & yams::math::LQRConfig::WithPeriod ( wpi::units::second_t period)

Set the loop period for the LQR.

Parameters
periodLoop period (default 20 ms).
Returns
*this for chaining.

◆ WithQElems() [1/2]

LQRConfig & yams::math::LQRConfig::WithQElems ( const std::vector< double > & qElems)

Set the state error tolerances, as when live tuning them, checking them.

Parameters
qElemsOne tolerance per modeled state, each above 0, in the SI units of GetQElems().
Returns
*this for chaining.
Exceptions
std::invalid_argumentif the number of values doesn't match the mechanism type, or one isn't above 0.

◆ WithQElems() [2/2]

LQRConfig & yams::math::LQRConfig::WithQElems ( std::initializer_list< double > qElems)

Set the Q matrix diagonal elements (state error tolerances).

Decrease values to more aggressively penalize state excursion.

Parameters
qElemsQ-matrix diagonal entries (one per state).
Returns
*this for chaining.

◆ WithRElems() [1/2]

LQRConfig & yams::math::LQRConfig::WithRElems ( const std::vector< double > & rElems)

Set the control effort (voltage) tolerance, as when live tuning it, checking it.

Parameters
rElemsOne tolerance, above 0, in volts.
Returns
*this for chaining.
Exceptions
std::invalid_argumentif there isn't one value, or it isn't above 0.

◆ WithRElems() [2/2]

LQRConfig & yams::math::LQRConfig::WithRElems ( std::initializer_list< double > rElems)

Set the R matrix diagonal elements (control effort tolerances).

Decrease values to more aggressively penalize control effort. A good starting value is 12 (approximately the maximum battery voltage).

Parameters
rElemsR-matrix diagonal entries (one per input).
Returns
*this for chaining.

◆ WithStateStdDevs() [1/2]

LQRConfig & yams::math::LQRConfig::WithStateStdDevs ( const std::vector< double > & stateStdDevs)

Set the model's standard deviations, as when live tuning them, checking them.

Parameters
stateStdDevsOne standard deviation per modeled state, each above 0.
Returns
*this for chaining.
Exceptions
std::invalid_argumentif the number of values doesn't match the mechanism type, or one isn't above 0.

◆ WithStateStdDevs() [2/2]

LQRConfig & yams::math::LQRConfig::WithStateStdDevs ( std::initializer_list< double > stateStdDevs)

Set the Kalman filter model standard deviations.

Parameters
stateStdDevsStandard deviations of the model states.
Returns
*this for chaining.

◆ WithType()

LQRConfig & yams::math::LQRConfig::WithType ( LQRType type)

Set the LQR plant type explicitly.

Parameters
typeLQRType to use.
Returns
*this for chaining.

◆ LQRController

friend class LQRController
friend

The documentation for this class was generated from the following file:
  • /home/runner/work/YAMS/YAMS/yams/cpp/include/yams/math/LQRConfig.hpp