|
YAMS
Yet Another Mechanism System
|
#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 |
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.
| using yams::math::LQRConfig::Loop1 = wpi::math::LinearSystemLoop<1, 1, 1> |
LinearSystemLoop type alias for 1-state plants (flywheel).
| using yams::math::LQRConfig::Loop2 = wpi::math::LinearSystemLoop<2, 1, 1> |
LinearSystemLoop type alias for 2-state plants (arm, elevator).
|
strong |
| 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.
| wpi::units::volt_t yams::math::LQRConfig::GetMaxVoltage | ( | ) | const |
Get the configured maximum voltage.
| 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.
| wpi::units::second_t yams::math::LQRConfig::GetPeriod | ( | ) | const |
Get the configured loop period.
| 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.
| std::vector< double > yams::math::LQRConfig::GetRElems | ( | ) | const |
Get the control effort (voltage) tolerances in use, in volts.
| std::vector< double > yams::math::LQRConfig::GetStateStdDevs | ( | ) | const |
Get the model's standard deviations in use, in the SI units of GetQElems().
| 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.
| LQRConfig & yams::math::LQRConfig::WithArmSystem | ( | const wpi::math::DCMotor & | motor, |
| double | momentOfInertia, | ||
| double | gearing ) |
Configure a single-jointed arm plant model.
| motor | DC motor model. |
| momentOfInertia | Moment of inertia of the arm (kg·m²). |
| gearing | Gear reduction from motor to arm joint. |
| LQRConfig & yams::math::LQRConfig::WithElevatorSystem | ( | const wpi::math::DCMotor & | motor, |
| double | mass, | ||
| double | drumRadius, | ||
| double | gearing ) |
Configure an elevator plant model.
| motor | DC motor model. |
| mass | Carriage mass (kg). |
| drumRadius | Radius of the drum (m). |
| gearing | Gear reduction from motor to drum. |
| LQRConfig & yams::math::LQRConfig::WithFlywheelSystem | ( | const wpi::math::DCMotor & | motor, |
| double | momentOfInertia, | ||
| double | gearing ) |
Configure a flywheel plant model.
| motor | DC motor model. |
| momentOfInertia | Moment of inertia of the flywheel (kg·m²). |
| gearing | Gear reduction from motor to flywheel. |
| LQRConfig & yams::math::LQRConfig::WithMaxVoltage | ( | wpi::units::volt_t | maxVoltage | ) |
Set the maximum voltage output of the LinearSystemLoop.
| maxVoltage | Maximum voltage (default 12 V). |
| LQRConfig & yams::math::LQRConfig::WithMeasurementStdDevs | ( | const std::vector< double > & | measStdDevs | ) |
Set the encoder's standard deviation, as when live tuning it, checking it.
| measStdDevs | One standard deviation, above 0. |
| std::invalid_argument | if there isn't one value, or it isn't above 0. |
| LQRConfig & yams::math::LQRConfig::WithMeasurementStdDevs | ( | std::initializer_list< double > | measStdDevs | ) |
Set the Kalman filter measurement standard deviations.
| measStdDevs | Standard deviations of the encoder measurements. |
| LQRConfig & yams::math::LQRConfig::WithPeriod | ( | wpi::units::second_t | period | ) |
Set the loop period for the LQR.
| period | Loop period (default 20 ms). |
| LQRConfig & yams::math::LQRConfig::WithQElems | ( | const std::vector< double > & | qElems | ) |
Set the state error tolerances, as when live tuning them, checking them.
| qElems | One tolerance per modeled state, each above 0, in the SI units of GetQElems(). |
| std::invalid_argument | if the number of values doesn't match the mechanism type, or one isn't above 0. |
| 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.
| qElems | Q-matrix diagonal entries (one per state). |
| LQRConfig & yams::math::LQRConfig::WithRElems | ( | const std::vector< double > & | rElems | ) |
Set the control effort (voltage) tolerance, as when live tuning it, checking it.
| rElems | One tolerance, above 0, in volts. |
| std::invalid_argument | if there isn't one value, or it isn't above 0. |
| 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).
| rElems | R-matrix diagonal entries (one per input). |
| LQRConfig & yams::math::LQRConfig::WithStateStdDevs | ( | const std::vector< double > & | stateStdDevs | ) |
Set the model's standard deviations, as when live tuning them, checking them.
| stateStdDevs | One standard deviation per modeled state, each above 0. |
| std::invalid_argument | if the number of values doesn't match the mechanism type, or one isn't above 0. |
| LQRConfig & yams::math::LQRConfig::WithStateStdDevs | ( | std::initializer_list< double > | stateStdDevs | ) |
Set the Kalman filter model standard deviations.
| stateStdDevs | Standard deviations of the model states. |
|
friend |