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

Constructs a control-affine plant inversion model-based feedforward from given model dynamics. More...

#include <frc/controller/ControlAffinePlantInversionFeedforward.h>

Public Types

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

Public Member Functions

 ControlAffinePlantInversionFeedforward (std::function< StateVector(const StateVector &, const InputVector &)> f, units::second_t dt)
 Constructs a feedforward with given model dynamics as a function of state and input. More...
 
 ControlAffinePlantInversionFeedforward (std::function< StateVector(const StateVector &)> f, const Matrixd< States, Inputs > &B, units::second_t dt)
 Constructs a feedforward with given model dynamics as a function of state, and the plant's B matrix(continuous input matrix). More...
 
 ControlAffinePlantInversionFeedforward (ControlAffinePlantInversionFeedforward &&)=default
 
ControlAffinePlantInversionFeedforwardoperator= (ControlAffinePlantInversionFeedforward &&)=default
 
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::ControlAffinePlantInversionFeedforward< States, Inputs >

Constructs a control-affine plant inversion model-based feedforward from given model dynamics.

If given the vector valued function as f(x, u) where x is the state vector and u is the input vector, the B matrix(continuous input matrix) is calculated through a NumericalJacobian. In this case f has to be control-affine (of the form f(x) + Bu).

The feedforward is calculated as u_ff = B+ (rDot - f(x)) , where B+ is the pseudoinverse of B.

This feedforward does not account for a dynamic B matrix, B is either determined or supplied when the feedforward is created and remains constant.

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::ControlAffinePlantInversionFeedforward< States, Inputs >::InputVector = Vectord<Inputs>

◆ StateVector

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

Constructor & Destructor Documentation

◆ ControlAffinePlantInversionFeedforward() [1/3]

template<int States, int Inputs>
frc::ControlAffinePlantInversionFeedforward< States, Inputs >::ControlAffinePlantInversionFeedforward ( std::function< StateVector(const StateVector &, const InputVector &)>  f,
units::second_t  dt 
)
inline

Constructs a feedforward with given model dynamics as a function of state and input.

Parameters
fA vector-valued function of x, the state, and u, the input, that returns the derivative of the state vector. HAS to be control-affine (of the form f(x) + Bu).
dtThe timestep between calls of calculate().

◆ ControlAffinePlantInversionFeedforward() [2/3]

template<int States, int Inputs>
frc::ControlAffinePlantInversionFeedforward< States, Inputs >::ControlAffinePlantInversionFeedforward ( std::function< StateVector(const StateVector &)>  f,
const Matrixd< States, Inputs > &  B,
units::second_t  dt 
)
inline

Constructs a feedforward with given model dynamics as a function of state, and the plant's B matrix(continuous input matrix).

Parameters
fA vector-valued function of x, the state, that returns the derivative of the state vector.
BContinuous input matrix of the plant being controlled.
dtThe timestep between calls of calculate().

◆ ControlAffinePlantInversionFeedforward() [3/3]

template<int States, int Inputs>
frc::ControlAffinePlantInversionFeedforward< States, Inputs >::ControlAffinePlantInversionFeedforward ( ControlAffinePlantInversionFeedforward< States, Inputs > &&  )
default

Member Function Documentation

◆ Calculate() [1/2]

template<int States, int Inputs>
InputVector frc::ControlAffinePlantInversionFeedforward< 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::ControlAffinePlantInversionFeedforward< 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.

◆ operator=()

template<int States, int Inputs>
ControlAffinePlantInversionFeedforward & frc::ControlAffinePlantInversionFeedforward< States, Inputs >::operator= ( ControlAffinePlantInversionFeedforward< States, Inputs > &&  )
default

◆ R() [1/2]

template<int States, int Inputs>
const StateVector & frc::ControlAffinePlantInversionFeedforward< 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::ControlAffinePlantInversionFeedforward< 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::ControlAffinePlantInversionFeedforward< States, Inputs >::Reset ( )
inline

Resets the feedforward with a zero initial state vector.

◆ Reset() [2/2]

template<int States, int Inputs>
void frc::ControlAffinePlantInversionFeedforward< 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::ControlAffinePlantInversionFeedforward< 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::ControlAffinePlantInversionFeedforward< 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: