16#include "units/time.h"
17#include "units/voltage.h"
39template <
int States,
int Inputs,
int Outputs>
61 units::volt_t maxVoltage, units::second_t dt)
63 plant, controller, observer,
89 observer, clampFunction) {}
107 controller, feedforward, observer, [=](const
InputVector& u) {
175 double U(
int i)
const {
return U()(i); }
#define EXPORT_TEMPLATE_DECLARE(export)
Definition SymbolExports.h:94
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
A Kalman filter combines predictions from a model and measurements to give an estimate of the true sy...
Definition KalmanFilter.h:46
Constructs a plant inversion model-based feedforward from a LinearSystem.
Definition LinearPlantInversionFeedforward.h:33
Contains the controller coefficients and logic for a linear-quadratic regulator (LQR).
Definition LinearQuadraticRegulator.h:38
A plant defined using state-space notation.
Definition LinearSystem.h:35
Combines a controller, feedforward, and observer for controlling a mechanism with full state feedback...
Definition LinearSystemLoop.h:40
void Correct(const OutputVector &y)
Correct the state estimate x-hat using the measurements in y.
Definition LinearSystemLoop.h:246
static constexpr int kOutputs
Definition LinearSystemLoop.h:288
double NextR(int i) const
Returns an element of the controller's next reference r.
Definition LinearSystemLoop.h:161
InputVector U() const
Returns the controller's calculated control input u.
Definition LinearSystemLoop.h:166
void SetXhat(const StateVector &xHat)
Set the initial state estimate x-hat.
Definition LinearSystemLoop.h:182
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.
Definition LinearSystemLoop.h:81
void Reset(const StateVector &initialState)
Zeroes reference r and controller output u.
Definition LinearSystemLoop.h:229
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.
Definition LinearSystemLoop.h:58
Vectord< States > StateVector
Definition LinearSystemLoop.h:42
const LinearQuadraticRegulator< States, Inputs > & Controller() const
Return the controller used internally.
Definition LinearSystemLoop.h:202
LinearSystemLoop(LinearSystemLoop &&)=default
StateVector m_nextR
Definition LinearSystemLoop.h:283
Vectord< Inputs > InputVector
Definition LinearSystemLoop.h:43
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.
Definition LinearSystemLoop.h:121
void SetNextR(const StateVector &nextR)
Set the next reference r.
Definition LinearSystemLoop.h:197
LinearQuadraticRegulator< States, Inputs > * m_controller
Definition LinearSystemLoop.h:273
Vectord< Outputs > OutputVector
Definition LinearSystemLoop.h:44
void Predict(units::second_t dt)
Sets new controller output, projects model forward, and runs observer prediction.
Definition LinearSystemLoop.h:257
double Xhat(int i) const
Returns an element of the observer's state estimate x-hat.
Definition LinearSystemLoop.h:149
static constexpr int kStates
Definition LinearSystemLoop.h:286
LinearSystemLoop & operator=(LinearSystemLoop &&)=default
double U(int i) const
Returns an element of the controller's calculated control input u.
Definition LinearSystemLoop.h:175
const StateVector & NextR() const
Returns the controller's next reference r.
Definition LinearSystemLoop.h:154
std::function< InputVector(const InputVector &)> m_clampFunc
Clamping function.
Definition LinearSystemLoop.h:280
const KalmanFilter< States, Inputs, Outputs > & Observer() const
Return the observer used internally.
Definition LinearSystemLoop.h:218
LinearPlantInversionFeedforward< States, Inputs > m_feedforward
Definition LinearSystemLoop.h:274
const StateVector & Xhat() const
Returns the observer's state estimate x-hat.
Definition LinearSystemLoop.h:142
InputVector ClampInput(const InputVector &u) const
Clamps input vector between system's minimum and maximum allowable input.
Definition LinearSystemLoop.h:270
const LinearPlantInversionFeedforward< States, Inputs > Feedforward() const
Return the feedforward used internally.
Definition LinearSystemLoop.h:211
static constexpr int kInputs
Definition LinearSystemLoop.h:287
void SetXhat(int i, double value)
Set an element of the initial state estimate x-hat.
Definition LinearSystemLoop.h:190
KalmanFilter< States, Inputs, Outputs > * m_observer
Definition LinearSystemLoop.h:275
StateVector Error() const
Returns difference between reference r and current state x-hat.
Definition LinearSystemLoop.h:239
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.
Definition LinearSystemLoop.h:102
static void ReportUsage(MathUsageId id, int count)
Definition MathShared.h:80
Eigen::Vector< double, Size > Vectord
Definition EigenCore.h:12
Vectord< Inputs > DesaturateInputVector(const Vectord< Inputs > &u, double maxMagnitude)
Renormalize all inputs if any exceeds the maximum magnitude.
Definition StateSpaceUtil.h:411
@ kSystem_LinearSystemLoop