WPILibC++ 2024.3.2
|
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 > ¤tXhat, 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 |
The plant that represents the linear system. More... | |
Vectord< States > | m_x |
State vector. More... | |
Vectord< Inputs > | m_u |
Input vector. More... | |
Vectord< Outputs > | m_y |
Output vector. More... | |
std::array< double, Outputs > | m_measurementStdDevs |
The standard deviations of measurements, used for adding noise to the measurements. More... | |
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.
States | Number of states of the system. |
Inputs | Number of inputs to the system. |
Outputs | Number of outputs of the system. |
|
inlineexplicit |
Creates a simulated generic linear system.
system | The system to simulate. |
measurementStdDevs | The standard deviations of the measurements. |
|
virtualdefault |
|
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.
u | The input vector. |
|
inlinevirtual |
Returns the current drawn by this simulated system.
Override this method to add a custom current calculation.
Reimplemented in frc::sim::DCMotorSim, frc::sim::ElevatorSim, frc::sim::FlywheelSim, and frc::sim::SingleJointedArmSim.
|
inline |
Returns the current output of the plant.
|
inline |
Returns an element of the current output of the plant.
row | The row to return. |
|
inline |
Sets the system inputs (usually voltages).
u | The system inputs. |
|
inline |
|
inline |
Sets the system state.
state | The new state. |
|
inline |
Updates the simulation.
dt | The time between updates. |
|
inlineprotectedvirtual |
Updates the state estimate of the system.
currentXhat | The current state estimate. |
u | The system inputs (usually voltage). |
dt | The time difference between controller updates. |
|
protected |
The standard deviations of measurements, used for adding noise to the measurements.
|
protected |
The plant that represents the linear system.
|
protected |
Input vector.
|
protected |
State vector.
|
protected |
Output vector.