WPILibC++ 2024.3.2
frc::LinearPlantInversionFeedforward< States, Inputs > Class Template Reference

Constructs a plant inversion model-based feedforward from a LinearSystem. More...

#include <frc/controller/LinearPlantInversionFeedforward.h>

Public Types

using StateVector = Vectord< States >
 
using InputVector = Vectord< Inputs >
 

Public Member Functions

template<int Outputs>
 LinearPlantInversionFeedforward (const LinearSystem< States, Inputs, Outputs > &plant, units::second_t dt)
 Constructs a feedforward with the given plant. More...
 
 LinearPlantInversionFeedforward (const Matrixd< States, States > &A, const Matrixd< States, Inputs > &B, units::second_t dt)
 Constructs a feedforward with the given coefficients. More...
 
const InputVectorUff () const
 Returns the previously calculated feedforward as an input vector. More...
 
double Uff (int i) const
 Returns an element of the previously calculated feedforward. More...
 
const StateVectorR () const
 Returns the current reference vector r. More...
 
double R (int i) const
 Returns an element of the reference vector r. More...
 
void Reset (const StateVector &initialState)
 Resets the feedforward with a specified initial state vector. More...
 
void Reset ()
 Resets the feedforward with a zero initial state vector. More...
 
InputVector Calculate (const StateVector &nextR)
 Calculate the feedforward with only the desired future reference. More...
 
InputVector Calculate (const StateVector &r, const StateVector &nextR)
 Calculate the feedforward with current and future reference vectors. More...
 

Detailed Description

template<int States, int Inputs>
class frc::LinearPlantInversionFeedforward< States, Inputs >

Constructs a plant inversion model-based feedforward from a LinearSystem.

The feedforward is calculated as u_ff = B+ (r_k+1 - A r_k) , where B+ is the pseudoinverse of B.

For more on the underlying math, read https://file.tavsys.net/control/controls-engineering-in-frc.pdf.

Template Parameters
StatesNumber of states.
InputsNumber of inputs.

Member Typedef Documentation

◆ InputVector

template<int States, int Inputs>
using frc::LinearPlantInversionFeedforward< States, Inputs >::InputVector = Vectord<Inputs>

◆ StateVector

template<int States, int Inputs>
using frc::LinearPlantInversionFeedforward< States, Inputs >::StateVector = Vectord<States>

Constructor & Destructor Documentation

◆ LinearPlantInversionFeedforward() [1/2]

template<int States, int Inputs>
template<int Outputs>
frc::LinearPlantInversionFeedforward< States, Inputs >::LinearPlantInversionFeedforward ( const LinearSystem< States, Inputs, Outputs > &  plant,
units::second_t  dt 
)
inline

Constructs a feedforward with the given plant.

Template Parameters
OutputsNumber of outputs.
Parameters
plantThe plant being controlled.
dtDiscretization timestep.

◆ LinearPlantInversionFeedforward() [2/2]

template<int States, int Inputs>
frc::LinearPlantInversionFeedforward< States, Inputs >::LinearPlantInversionFeedforward ( const Matrixd< States, States > &  A,
const Matrixd< States, Inputs > &  B,
units::second_t  dt 
)
inline

Constructs a feedforward with the given coefficients.

Parameters
AContinuous system matrix of the plant being controlled.
BContinuous input matrix of the plant being controlled.
dtDiscretization timestep.

Member Function Documentation

◆ Calculate() [1/2]

template<int States, int Inputs>
InputVector frc::LinearPlantInversionFeedforward< States, Inputs >::Calculate ( const StateVector nextR)
inline

Calculate the feedforward with only the desired future reference.

This uses the internally stored "current" reference.

If this method is used the initial state of the system is the one set using Reset(const StateVector&). If the initial state is not set it defaults to a zero vector.

Parameters
nextRThe reference state of the future timestep (k + dt).
Returns
The calculated feedforward.

◆ Calculate() [2/2]

template<int States, int Inputs>
InputVector frc::LinearPlantInversionFeedforward< States, Inputs >::Calculate ( const StateVector r,
const StateVector nextR 
)
inline

Calculate the feedforward with current and future reference vectors.

Parameters
rThe reference state of the current timestep (k).
nextRThe reference state of the future timestep (k + dt).
Returns
The calculated feedforward.

◆ R() [1/2]

template<int States, int Inputs>
const StateVector & frc::LinearPlantInversionFeedforward< States, Inputs >::R ( ) const
inline

Returns the current reference vector r.

Returns
The current reference vector.

◆ R() [2/2]

template<int States, int Inputs>
double frc::LinearPlantInversionFeedforward< States, Inputs >::R ( int  i) const
inline

Returns an element of the reference vector r.

Parameters
iRow of r.
Returns
The row of the current reference vector.

◆ Reset() [1/2]

template<int States, int Inputs>
void frc::LinearPlantInversionFeedforward< States, Inputs >::Reset ( )
inline

Resets the feedforward with a zero initial state vector.

◆ Reset() [2/2]

template<int States, int Inputs>
void frc::LinearPlantInversionFeedforward< States, Inputs >::Reset ( const StateVector initialState)
inline

Resets the feedforward with a specified initial state vector.

Parameters
initialStateThe initial state vector.

◆ Uff() [1/2]

template<int States, int Inputs>
const InputVector & frc::LinearPlantInversionFeedforward< States, Inputs >::Uff ( ) const
inline

Returns the previously calculated feedforward as an input vector.

Returns
The calculated feedforward.

◆ Uff() [2/2]

template<int States, int Inputs>
double frc::LinearPlantInversionFeedforward< States, Inputs >::Uff ( int  i) const
inline

Returns an element of the previously calculated feedforward.

Parameters
iRow of uff.
Returns
The row of the calculated feedforward.

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