WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
frc::LinearSystem< States, Inputs, Outputs > Class Template Reference

A plant defined using state-space notation. More...

#include <frc/system/LinearSystem.h>

Public Types

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

Public Member Functions

constexpr LinearSystem (const Matrixd< States, States > &A, const Matrixd< States, Inputs > &B, const Matrixd< Outputs, States > &C, const Matrixd< Outputs, Inputs > &D)
 Constructs a discrete plant with the given continuous system coefficients.
 
constexpr LinearSystem (const LinearSystem &)=default
 
constexpr LinearSystemoperator= (const LinearSystem &)=default
 
constexpr LinearSystem (LinearSystem &&)=default
 
constexpr LinearSystemoperator= (LinearSystem &&)=default
 
constexpr const Matrixd< States, States > & A () const
 Returns the system matrix A.
 
constexpr double A (int i, int j) const
 Returns an element of the system matrix A.
 
constexpr const Matrixd< States, Inputs > & B () const
 Returns the input matrix B.
 
constexpr double B (int i, int j) const
 Returns an element of the input matrix B.
 
constexpr const Matrixd< Outputs, States > & C () const
 Returns the output matrix C.
 
constexpr double C (int i, int j) const
 Returns an element of the output matrix C.
 
constexpr const Matrixd< Outputs, Inputs > & D () const
 Returns the feedthrough matrix D.
 
constexpr double D (int i, int j) const
 Returns an element of the feedthrough matrix D.
 
StateVector CalculateX (const StateVector &x, const InputVector &clampedU, units::second_t dt) const
 Computes the new x given the old x and the control input.
 
OutputVector CalculateY (const StateVector &x, const InputVector &clampedU) const
 Computes the new y given the control input.
 
template<std::same_as< int >... OutputIndices>
LinearSystem< States, Inputs, sizeof...(OutputIndices)> Slice (OutputIndices... outputIndices)
 Returns the LinearSystem with the outputs listed in outputIndices.
 

Detailed Description

template<int States, int Inputs, int Outputs>
class frc::LinearSystem< States, Inputs, Outputs >

A plant defined using state-space notation.

A plant is a mathematical model of a system's dynamics.

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.
OutputsNumber of outputs.

Member Typedef Documentation

◆ InputVector

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

◆ OutputVector

template<int States, int Inputs, int Outputs>
using frc::LinearSystem< States, Inputs, Outputs >::OutputVector = Vectord<Outputs>

◆ StateVector

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

Constructor & Destructor Documentation

◆ LinearSystem() [1/3]

template<int States, int Inputs, int Outputs>
frc::LinearSystem< States, Inputs, Outputs >::LinearSystem ( const Matrixd< States, States > & A,
const Matrixd< States, Inputs > & B,
const Matrixd< Outputs, States > & C,
const Matrixd< Outputs, Inputs > & D )
inlineconstexpr

Constructs a discrete plant with the given continuous system coefficients.

Parameters
ASystem matrix.
BInput matrix.
COutput matrix.
DFeedthrough matrix.
Throws:
std::domain_error if any matrix element isn't finite.

◆ LinearSystem() [2/3]

template<int States, int Inputs, int Outputs>
frc::LinearSystem< States, Inputs, Outputs >::LinearSystem ( const LinearSystem< States, Inputs, Outputs > & )
constexprdefault

◆ LinearSystem() [3/3]

template<int States, int Inputs, int Outputs>
frc::LinearSystem< States, Inputs, Outputs >::LinearSystem ( LinearSystem< States, Inputs, Outputs > && )
constexprdefault

Member Function Documentation

◆ A() [1/2]

template<int States, int Inputs, int Outputs>
const Matrixd< States, States > & frc::LinearSystem< States, Inputs, Outputs >::A ( ) const
inlineconstexpr

Returns the system matrix A.

◆ A() [2/2]

template<int States, int Inputs, int Outputs>
double frc::LinearSystem< States, Inputs, Outputs >::A ( int i,
int j ) const
inlineconstexpr

Returns an element of the system matrix A.

Parameters
iRow of A.
jColumn of A.

◆ B() [1/2]

template<int States, int Inputs, int Outputs>
const Matrixd< States, Inputs > & frc::LinearSystem< States, Inputs, Outputs >::B ( ) const
inlineconstexpr

Returns the input matrix B.

◆ B() [2/2]

template<int States, int Inputs, int Outputs>
double frc::LinearSystem< States, Inputs, Outputs >::B ( int i,
int j ) const
inlineconstexpr

Returns an element of the input matrix B.

Parameters
iRow of B.
jColumn of B.

◆ C() [1/2]

template<int States, int Inputs, int Outputs>
const Matrixd< Outputs, States > & frc::LinearSystem< States, Inputs, Outputs >::C ( ) const
inlineconstexpr

Returns the output matrix C.

◆ C() [2/2]

template<int States, int Inputs, int Outputs>
double frc::LinearSystem< States, Inputs, Outputs >::C ( int i,
int j ) const
inlineconstexpr

Returns an element of the output matrix C.

Parameters
iRow of C.
jColumn of C.

◆ CalculateX()

template<int States, int Inputs, int Outputs>
StateVector frc::LinearSystem< States, Inputs, Outputs >::CalculateX ( const StateVector & x,
const InputVector & clampedU,
units::second_t dt ) const
inline

Computes the new x given the old x and the control input.

This is used by state observers directly to run updates based on state estimate.

Parameters
xThe current state.
clampedUThe control input.
dtTimestep for model update.

◆ CalculateY()

template<int States, int Inputs, int Outputs>
OutputVector frc::LinearSystem< States, Inputs, Outputs >::CalculateY ( const StateVector & x,
const InputVector & clampedU ) const
inline

Computes the new y given the control input.

This is used by state observers directly to run updates based on state estimate.

Parameters
xThe current state.
clampedUThe control input.

◆ D() [1/2]

template<int States, int Inputs, int Outputs>
const Matrixd< Outputs, Inputs > & frc::LinearSystem< States, Inputs, Outputs >::D ( ) const
inlineconstexpr

Returns the feedthrough matrix D.

◆ D() [2/2]

template<int States, int Inputs, int Outputs>
double frc::LinearSystem< States, Inputs, Outputs >::D ( int i,
int j ) const
inlineconstexpr

Returns an element of the feedthrough matrix D.

Parameters
iRow of D.
jColumn of D.

◆ operator=() [1/2]

template<int States, int Inputs, int Outputs>
LinearSystem & frc::LinearSystem< States, Inputs, Outputs >::operator= ( const LinearSystem< States, Inputs, Outputs > & )
constexprdefault

◆ operator=() [2/2]

template<int States, int Inputs, int Outputs>
LinearSystem & frc::LinearSystem< States, Inputs, Outputs >::operator= ( LinearSystem< States, Inputs, Outputs > && )
constexprdefault

◆ Slice()

template<int States, int Inputs, int Outputs>
template<std::same_as< int >... OutputIndices>
LinearSystem< States, Inputs, sizeof...(OutputIndices)> frc::LinearSystem< States, Inputs, Outputs >::Slice ( OutputIndices... outputIndices)
inline

Returns the LinearSystem with the outputs listed in outputIndices.

This is used by state observers such as the Kalman Filter.

Parameters
outputIndicesthe list of output indices to include in the sliced system.
Returns
the sliced LinearSystem with outputs set to row vectors of LinearSystem.
Throws:
std::domain_error if any outputIndices are outside the range of system outputs.
Throws:
std::domain_error if number of outputIndices exceeds the system outputs.
Throws:
std::domain_error if duplication exists in outputIndices.

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