YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
yams::math::LQRConfig Class Reference

#include <LQRConfig.hpp>

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::variant< wpi::math::LinearSystem< 1, 1, 1 >, wpi::math::LinearSystem< 2, 1, 1 > > GetSystem () const
 
std::variant< Loop1, Loop2 > 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.

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< Loop1, Loop2 > yams::math::LQRConfig::GetLoop ( ) const

Build and return the complete LinearSystemLoop ready for use.

Returns
Variant holding Loop1 (flywheel) or Loop2 (arm/elevator).

◆ GetMaxVoltage()

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

Get the configured maximum voltage.

Returns
Maximum voltage.

◆ GetPeriod()

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

Get the configured loop period.

Returns
Loop period.

◆ 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()

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()

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()

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()

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.

Friends And Related Symbol Documentation

◆ LQRController

friend class LQRController
friend

The documentation for this class was generated from the following file: