WPILibC++ 2023.4.3-108-ge5452e3
frc::sim::LinearSystemSim< States, Inputs, Outputs > Class Template Reference

This class helps simulate linear systems. More...

#include <frc/simulation/LinearSystemSim.h>

Public Member Functions

 LinearSystemSim (const LinearSystem< States, Inputs, Outputs > &system, const std::array< double, Outputs > &measurementStdDevs={})
 Creates a simulated generic linear system. More...
 
virtual ~LinearSystemSim ()=default
 
void Update (units::second_t dt)
 Updates the simulation. More...
 
const Vectord< Outputs > & GetOutput () const
 Returns the current output of the plant. More...
 
double GetOutput (int row) const
 Returns an element of the current output of the plant. More...
 
void SetInput (const Vectord< Inputs > &u)
 Sets the system inputs (usually voltages). More...
 
void SetInput (int row, double value)
 
void SetState (const Vectord< States > &state)
 Sets the system state. More...
 
virtual units::ampere_t GetCurrentDraw () const
 Returns the current drawn by this simulated system. More...
 

Protected Member Functions

virtual Vectord< States > UpdateX (const Vectord< States > &currentXhat, const Vectord< Inputs > &u, units::second_t dt)
 Updates the state estimate of the system. More...
 
Vectord< Inputs > ClampInput (Vectord< Inputs > u)
 Clamp the input vector such that no element exceeds the given voltage. More...
 

Protected Attributes

LinearSystem< States, Inputs, Outputs > m_plant
 
Vectord< States > m_x
 
Vectord< Outputs > m_y
 
Vectord< Inputs > m_u
 
std::array< double, Outputs > m_measurementStdDevs
 

Detailed Description

template<int States, int Inputs, int Outputs>
class frc::sim::LinearSystemSim< States, Inputs, Outputs >

This class helps simulate linear systems.

To use this class, do the following in the simulationPeriodic() method.

Call the SetInput() method with the inputs to your system (generally voltage). Call the Update() method to update the simulation. Set simulated sensor readings with the simulated positions in the GetOutput() method.

Template Parameters
StatesThe number of states of the system.
InputsThe number of inputs to the system.
OutputsThe number of outputs of the system.

Constructor & Destructor Documentation

◆ LinearSystemSim()

template<int States, int Inputs, int Outputs>
frc::sim::LinearSystemSim< States, Inputs, Outputs >::LinearSystemSim ( const LinearSystem< States, Inputs, Outputs > &  system,
const std::array< double, Outputs > &  measurementStdDevs = {} 
)
inlineexplicit

Creates a simulated generic linear system.

Parameters
systemThe system to simulate.
measurementStdDevsThe standard deviations of the measurements.

◆ ~LinearSystemSim()

template<int States, int Inputs, int Outputs>
virtual frc::sim::LinearSystemSim< States, Inputs, Outputs >::~LinearSystemSim ( )
virtualdefault

Member Function Documentation

◆ ClampInput()

template<int States, int Inputs, int Outputs>
Vectord< Inputs > frc::sim::LinearSystemSim< States, Inputs, Outputs >::ClampInput ( Vectord< Inputs >  u)
inlineprotected

Clamp the input vector such that no element exceeds the given voltage.

If any does, the relative magnitudes of the input will be maintained.

Parameters
uThe input vector.
Returns
The normalized input.

◆ GetCurrentDraw()

template<int States, int Inputs, int Outputs>
virtual units::ampere_t frc::sim::LinearSystemSim< States, Inputs, Outputs >::GetCurrentDraw ( ) const
inlinevirtual

Returns the current drawn by this simulated system.

Override this method to add a custom current calculation.

Returns
The current drawn by this simulated mechanism.

Reimplemented in frc::sim::DCMotorSim, frc::sim::ElevatorSim, frc::sim::FlywheelSim, and frc::sim::SingleJointedArmSim.

◆ GetOutput() [1/2]

template<int States, int Inputs, int Outputs>
const Vectord< Outputs > & frc::sim::LinearSystemSim< States, Inputs, Outputs >::GetOutput ( ) const
inline

Returns the current output of the plant.

Returns
The current output of the plant.

◆ GetOutput() [2/2]

template<int States, int Inputs, int Outputs>
double frc::sim::LinearSystemSim< States, Inputs, Outputs >::GetOutput ( int  row) const
inline

Returns an element of the current output of the plant.

Parameters
rowThe row to return.
Returns
An element of the current output of the plant.

◆ SetInput() [1/2]

template<int States, int Inputs, int Outputs>
void frc::sim::LinearSystemSim< States, Inputs, Outputs >::SetInput ( const Vectord< Inputs > &  u)
inline

Sets the system inputs (usually voltages).

Parameters
uThe system inputs.

◆ SetInput() [2/2]

template<int States, int Inputs, int Outputs>
void frc::sim::LinearSystemSim< States, Inputs, Outputs >::SetInput ( int  row,
double  value 
)
inline

◆ SetState()

template<int States, int Inputs, int Outputs>
void frc::sim::LinearSystemSim< States, Inputs, Outputs >::SetState ( const Vectord< States > &  state)
inline

Sets the system state.

Parameters
stateThe new state.

◆ Update()

template<int States, int Inputs, int Outputs>
void frc::sim::LinearSystemSim< States, Inputs, Outputs >::Update ( units::second_t  dt)
inline

Updates the simulation.

Parameters
dtThe time between updates.

◆ UpdateX()

template<int States, int Inputs, int Outputs>
virtual Vectord< States > frc::sim::LinearSystemSim< States, Inputs, Outputs >::UpdateX ( const Vectord< States > &  currentXhat,
const Vectord< Inputs > &  u,
units::second_t  dt 
)
inlineprotectedvirtual

Updates the state estimate of the system.

Parameters
currentXhatThe current state estimate.
uThe system inputs (usually voltage).
dtThe time difference between controller updates.

Member Data Documentation

◆ m_measurementStdDevs

template<int States, int Inputs, int Outputs>
std::array<double, Outputs> frc::sim::LinearSystemSim< States, Inputs, Outputs >::m_measurementStdDevs
protected

◆ m_plant

template<int States, int Inputs, int Outputs>
LinearSystem<States, Inputs, Outputs> frc::sim::LinearSystemSim< States, Inputs, Outputs >::m_plant
protected

◆ m_u

template<int States, int Inputs, int Outputs>
Vectord<Inputs> frc::sim::LinearSystemSim< States, Inputs, Outputs >::m_u
protected

◆ m_x

template<int States, int Inputs, int Outputs>
Vectord<States> frc::sim::LinearSystemSim< States, Inputs, Outputs >::m_x
protected

◆ m_y

template<int States, int Inputs, int Outputs>
Vectord<Outputs> frc::sim::LinearSystemSim< States, Inputs, Outputs >::m_y
protected

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