WPILibC++ 2025.2.1
|
Combines a controller, feedforward, and observer for controlling a mechanism with full state feedback. More...
#include <frc/system/LinearSystemLoop.h>
Public Types | |
using | StateVector = Vectord<States> |
using | InputVector = Vectord<Inputs> |
using | OutputVector = Vectord<Outputs> |
Public Member Functions | |
LinearSystemLoop (LinearSystem< States, Inputs, Outputs > &plant, LinearQuadraticRegulator< States, Inputs > &controller, KalmanFilter< States, Inputs, Outputs > &observer, units::volt_t maxVoltage, units::second_t dt) | |
Constructs a state-space loop with the given plant, controller, and observer. | |
LinearSystemLoop (LinearSystem< States, Inputs, Outputs > &plant, LinearQuadraticRegulator< States, Inputs > &controller, KalmanFilter< States, Inputs, Outputs > &observer, std::function< InputVector(const InputVector &)> clampFunction, units::second_t dt) | |
Constructs a state-space loop with the given plant, controller, and observer. | |
LinearSystemLoop (LinearQuadraticRegulator< States, Inputs > &controller, const LinearPlantInversionFeedforward< States, Inputs > &feedforward, KalmanFilter< States, Inputs, Outputs > &observer, units::volt_t maxVoltage) | |
Constructs a state-space loop with the given controller, feedforward and observer. | |
LinearSystemLoop (LinearQuadraticRegulator< States, Inputs > &controller, const LinearPlantInversionFeedforward< States, Inputs > &feedforward, KalmanFilter< States, Inputs, Outputs > &observer, std::function< InputVector(const InputVector &)> clampFunction) | |
Constructs a state-space loop with the given controller, feedforward, observer and clamp function. | |
LinearSystemLoop (LinearSystemLoop &&)=default | |
LinearSystemLoop & | operator= (LinearSystemLoop &&)=default |
const StateVector & | Xhat () const |
Returns the observer's state estimate x-hat. | |
double | Xhat (int i) const |
Returns an element of the observer's state estimate x-hat. | |
const StateVector & | NextR () const |
Returns the controller's next reference r. | |
double | NextR (int i) const |
Returns an element of the controller's next reference r. | |
InputVector | U () const |
Returns the controller's calculated control input u. | |
double | U (int i) const |
Returns an element of the controller's calculated control input u. | |
void | SetXhat (const StateVector &xHat) |
Set the initial state estimate x-hat. | |
void | SetXhat (int i, double value) |
Set an element of the initial state estimate x-hat. | |
void | SetNextR (const StateVector &nextR) |
Set the next reference r. | |
const LinearQuadraticRegulator< States, Inputs > & | Controller () const |
Return the controller used internally. | |
const LinearPlantInversionFeedforward< States, Inputs > | Feedforward () const |
Return the feedforward used internally. | |
const KalmanFilter< States, Inputs, Outputs > & | Observer () const |
Return the observer used internally. | |
void | Reset (const StateVector &initialState) |
Zeroes reference r and controller output u. | |
StateVector | Error () const |
Returns difference between reference r and current state x-hat. | |
void | Correct (const OutputVector &y) |
Correct the state estimate x-hat using the measurements in y. | |
void | Predict (units::second_t dt) |
Sets new controller output, projects model forward, and runs observer prediction. | |
InputVector | ClampInput (const InputVector &u) const |
Clamps input vector between system's minimum and maximum allowable input. | |
Protected Attributes | |
LinearQuadraticRegulator< States, Inputs > * | m_controller |
LinearPlantInversionFeedforward< States, Inputs > | m_feedforward |
KalmanFilter< States, Inputs, Outputs > * | m_observer |
std::function< InputVector(const InputVector &)> | m_clampFunc |
Clamping function. | |
StateVector | m_nextR |
Static Protected Attributes | |
static constexpr int | kStates = States |
static constexpr int | kInputs = Inputs |
static constexpr int | kOutputs = Outputs |
Combines a controller, feedforward, and observer for controlling a mechanism with full state feedback.
For everything in this file, "inputs" and "outputs" are defined from the perspective of the plant. This means U is an input and Y is an output (because you give the plant U (powers) and it gives you back a Y (sensor values). This is the opposite of what they mean from the perspective of the controller (U is an output because that's what goes to the motors and Y is an input because that's what comes back from the sensors).
For more on the underlying math, read https://file.tavsys.net/control/controls-engineering-in-frc.pdf.
States | Number of states. |
Inputs | Number of inputs. |
Outputs | Number of outputs. |
using frc::LinearSystemLoop< States, Inputs, Outputs >::InputVector = Vectord<Inputs> |
using frc::LinearSystemLoop< States, Inputs, Outputs >::OutputVector = Vectord<Outputs> |
using frc::LinearSystemLoop< States, Inputs, Outputs >::StateVector = Vectord<States> |
|
inline |
Constructs a state-space loop with the given plant, controller, and observer.
By default, the initial reference is all zeros. Users should call reset with the initial system state before enabling the loop. This constructor assumes that the input(s) to this system are voltage.
plant | State-space plant. |
controller | State-space controller. |
observer | State-space observer. |
maxVoltage | The maximum voltage that can be applied. Commonly 12. |
dt | The nominal timestep. |
|
inline |
Constructs a state-space loop with the given plant, controller, and observer.
By default, the initial reference is all zeros. Users should call reset with the initial system state before enabling the loop. This constructor assumes that the input(s) to this system are voltage.
plant | State-space plant. |
controller | State-space controller. |
observer | State-space observer. |
clampFunction | The function used to clamp the input vector. |
dt | The nominal timestep. |
|
inline |
Constructs a state-space loop with the given controller, feedforward and observer.
By default, the initial reference is all zeros. Users should call reset with the initial system state.
controller | State-space controller. |
feedforward | Plant inversion feedforward. |
observer | State-space observer. |
maxVoltage | The maximum voltage that can be applied. Assumes that the inputs are voltages. |
|
inline |
Constructs a state-space loop with the given controller, feedforward, observer and clamp function.
By default, the initial reference is all zeros. Users should call reset with the initial system state.
controller | State-space controller. |
feedforward | Plant-inversion feedforward. |
observer | State-space observer. |
clampFunction | The function used to clamp the input vector. |
|
default |
|
inline |
Clamps input vector between system's minimum and maximum allowable input.
u | Input vector to clamp. |
|
inline |
Return the controller used internally.
|
inline |
Correct the state estimate x-hat using the measurements in y.
y | Measurement vector. |
|
inline |
Returns difference between reference r and current state x-hat.
|
inline |
Return the feedforward used internally.
|
inline |
Returns the controller's next reference r.
|
inline |
Returns an element of the controller's next reference r.
i | Row of r. |
|
inline |
Return the observer used internally.
|
default |
|
inline |
Sets new controller output, projects model forward, and runs observer prediction.
After calling this, the user should send the elements of u to the actuators.
dt | Timestep for model update. |
|
inline |
Zeroes reference r and controller output u.
The previous reference of the PlantInversionFeedforward and the initial state estimate of the KalmanFilter are set to the initial state provided.
initialState | The initial state. |
|
inline |
Set the next reference r.
nextR | Next reference. |
|
inline |
Set the initial state estimate x-hat.
xHat | The initial state estimate x-hat. |
|
inline |
Set an element of the initial state estimate x-hat.
i | Row of x-hat. |
value | Value for element of x-hat. |
|
inline |
Returns the controller's calculated control input u.
|
inline |
Returns an element of the controller's calculated control input u.
i | Row of u. |
|
inline |
Returns the observer's state estimate x-hat.
|
inline |
Returns an element of the observer's state estimate x-hat.
i | Row of x-hat. |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
protected |
Clamping function.
|
protected |
|
protected |
|
protected |
|
protected |