Combines a controller, feedforward, and observer for controlling a mechanism with full state feedback.
More...
|
| 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. More...
|
|
| 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. More...
|
|
| 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. More...
|
|
| 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. More...
|
|
| LinearSystemLoop (LinearSystemLoop &&)=default |
|
LinearSystemLoop & | operator= (LinearSystemLoop &&)=default |
|
const StateVector & | Xhat () const |
| Returns the observer's state estimate x-hat. More...
|
|
double | Xhat (int i) const |
| Returns an element of the observer's state estimate x-hat. More...
|
|
const StateVector & | NextR () const |
| Returns the controller's next reference r. More...
|
|
double | NextR (int i) const |
| Returns an element of the controller's next reference r. More...
|
|
InputVector | U () const |
| Returns the controller's calculated control input u. More...
|
|
double | U (int i) const |
| Returns an element of the controller's calculated control input u. More...
|
|
void | SetXhat (const StateVector &xHat) |
| Set the initial state estimate x-hat. More...
|
|
void | SetXhat (int i, double value) |
| Set an element of the initial state estimate x-hat. More...
|
|
void | SetNextR (const StateVector &nextR) |
| Set the next reference r. More...
|
|
const LinearQuadraticRegulator< States, Inputs > & | Controller () const |
| Return the controller used internally. More...
|
|
const LinearPlantInversionFeedforward< States, Inputs > | Feedforward () const |
| Return the feedforward used internally. More...
|
|
const KalmanFilter< States, Inputs, Outputs > & | Observer () const |
| Return the observer used internally. More...
|
|
void | Reset (const StateVector &initialState) |
| Zeroes reference r and controller output u. More...
|
|
StateVector | Error () const |
| Returns difference between reference r and current state x-hat. More...
|
|
void | Correct (const OutputVector &y) |
| Correct the state estimate x-hat using the measurements in y. More...
|
|
void | Predict (units::second_t dt) |
| Sets new controller output, projects model forward, and runs observer prediction. More...
|
|
InputVector | ClampInput (const InputVector &u) const |
| Clamps input vector between system's minimum and maximum allowable input. More...
|
|
template<int States, int Inputs, int Outputs>
class frc::LinearSystemLoop< States, Inputs, 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.
- Template Parameters
-
States | Number of states. |
Inputs | Number of inputs. |
Outputs | Number of outputs. |
template<int States, int Inputs, int Outputs>
frc::LinearSystemLoop< States, Inputs, Outputs >::LinearSystemLoop |
( |
LinearSystem< States, Inputs, Outputs > & |
plant, |
|
|
LinearQuadraticRegulator< States, Inputs > & |
controller, |
|
|
KalmanFilter< States, Inputs, Outputs > & |
observer, |
|
|
units::volt_t |
maxVoltage, |
|
|
units::second_t |
dt |
|
) |
| |
|
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.
- Parameters
-
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. |