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

#include <LQRController.hpp>

Public Member Functions

 LQRController (LQRConfig config)
 
void UpdateConfig (LQRConfig config)
 
void Reset (wpi::units::radian_t angle, wpi::units::radians_per_second_t velocity)
 
void Reset (wpi::units::meter_t distance, wpi::units::meters_per_second_t velocity)
 
wpi::units::volt_t Calculate (wpi::units::radian_t measured, wpi::units::radian_t position, wpi::units::radians_per_second_t velocity)
 
wpi::units::volt_t Calculate (wpi::units::meter_t measured, wpi::units::meter_t position, wpi::units::meters_per_second_t velocity)
 
wpi::units::volt_t Calculate (wpi::units::radians_per_second_t measured, wpi::units::radians_per_second_t velocity)
 
wpi::units::volt_t Calculate (wpi::units::meters_per_second_t measured, wpi::units::meters_per_second_t velocity)
 
LQRConfig::LQRType GetType () const
 
const std::optional< LQRConfig > & GetConfig () const
 

Detailed Description

Linear Quadratic Regulator controller wrapper.

Wraps a WPILib LinearSystemLoop to provide a common Calculate() interface for flywheel (velocity), arm, and elevator (position + velocity) plant types.

Internally the LQR gain matrix and Kalman filter are heap-allocated alongside the LinearSystemLoop so that the loop's internal raw pointers remain valid for the lifetime of this object. Never copy or std::move an LQRController while it is in use.

Constructor & Destructor Documentation

◆ LQRController()

yams::math::LQRController::LQRController ( LQRConfig  config)
explicit

Construct an LQRController by building the loop from an LQRConfig.

Parameters
configFully-configured LQRConfig.

Member Function Documentation

◆ Calculate() [1/4]

wpi::units::volt_t yams::math::LQRController::Calculate ( wpi::units::meter_t  measured,
wpi::units::meter_t  position,
wpi::units::meters_per_second_t  velocity 
)

Calculate the next voltage output for a linear positional mechanism (elevator).

Parameters
measuredCurrent measured distance.
positionTarget distance setpoint.
velocityTarget linear velocity setpoint.
Returns
Voltage to apply to the motor.

◆ Calculate() [2/4]

wpi::units::volt_t yams::math::LQRController::Calculate ( wpi::units::meters_per_second_t  measured,
wpi::units::meters_per_second_t  velocity 
)

Calculate the next voltage output for a linear velocity mechanism.

Parameters
measuredCurrent measured linear velocity.
velocityTarget linear velocity setpoint.
Returns
Voltage to apply to the motor.

◆ Calculate() [3/4]

wpi::units::volt_t yams::math::LQRController::Calculate ( wpi::units::radian_t  measured,
wpi::units::radian_t  position,
wpi::units::radians_per_second_t  velocity 
)

Calculate the next voltage output for an angular positional mechanism (arm).

Parameters
measuredCurrent measured angle.
positionTarget angle setpoint.
velocityTarget angular velocity setpoint.
Returns
Voltage to apply to the motor.

◆ Calculate() [4/4]

wpi::units::volt_t yams::math::LQRController::Calculate ( wpi::units::radians_per_second_t  measured,
wpi::units::radians_per_second_t  velocity 
)

Calculate the next voltage output for an angular velocity mechanism (flywheel).

Parameters
measuredCurrent measured angular velocity.
velocityTarget angular velocity setpoint.
Returns
Voltage to apply to the motor.

◆ GetConfig()

const std::optional< LQRConfig > & yams::math::LQRController::GetConfig ( ) const

Get the optional LQRConfig used to construct this controller.

Returns
Reference to the optional config.

◆ GetType()

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

Get the configured LQR plant type.

Returns
LQRType.

◆ Reset() [1/2]

void yams::math::LQRController::Reset ( wpi::units::meter_t  distance,
wpi::units::meters_per_second_t  velocity 
)

Reset the linear position+velocity state of the controller (elevator).

Parameters
distanceCurrent mechanism distance.
velocityCurrent mechanism linear velocity.

◆ Reset() [2/2]

void yams::math::LQRController::Reset ( wpi::units::radian_t  angle,
wpi::units::radians_per_second_t  velocity 
)

Reset the angular position+velocity state of the controller (arm/elevator).

Parameters
angleCurrent mechanism angle.
velocityCurrent mechanism velocity.

◆ UpdateConfig()

void yams::math::LQRController::UpdateConfig ( LQRConfig  config)

Replace the current LQR configuration and rebuild the internal loop.

Parameters
configNew LQRConfig to apply.

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