Package edu.wpi.first.wpilibj.simulation
Class LinearSystemSim<States extends Num,Inputs extends Num,Outputs extends Num>
java.lang.Object
edu.wpi.first.wpilibj.simulation.LinearSystemSim<States,Inputs,Outputs>
- Type Parameters:
States
- Number of states of the system.Inputs
- Number of inputs to the system.Outputs
- Number of outputs of the system.
- Direct Known Subclasses:
DCMotorSim
,ElevatorSim
,FlywheelSim
,SingleJointedArmSim
public class LinearSystemSim<States extends Num,Inputs extends Num,Outputs extends Num>
extends Object
This class helps simulate linear systems. To use this class, do the following in the
IterativeRobotBase.simulationPeriodic()
method.
Call setInput(double...)
with the inputs to the system (usually voltage).
Call update(double)
to update the simulation.
Set simulated sensor readings with the simulated positions in getOutput()
-
Field Summary
Modifier and TypeFieldDescriptionThe standard deviations of measurements, used for adding noise to the measurements.protected final LinearSystem<States,
Inputs, Outputs> The plant that represents the linear system.Input vector.State vector.Output vector. -
Constructor Summary
ConstructorDescriptionLinearSystemSim
(LinearSystem<States, Inputs, Outputs> system, double... measurementStdDevs) Creates a simulated generic linear system with measurement noise. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
clampInput
(double maxInput) Clamp the input vector such that no element exceeds the maximum allowed value.getInput()
Returns the current input of the plant.double
getInput
(int row) Returns an element of the current input of the plant.Returns the current output of the plant.double
getOutput
(int row) Returns an element of the current output of the plant.void
setInput
(double... u) Sets the system inputs.void
setInput
(int row, double value) Sets the system inputs.void
Sets the system inputs (usually voltages).void
Sets the system state.void
update
(double dtSeconds) Updates the simulation.Updates the state estimate of the system.
-
Field Details
-
m_plant
The plant that represents the linear system. -
m_x
State vector. -
m_u
Input vector. -
m_y
Output vector. -
m_measurementStdDevs
The standard deviations of measurements, used for adding noise to the measurements.
-
-
Constructor Details
-
LinearSystemSim
Creates a simulated generic linear system with measurement noise.- Parameters:
system
- The system being controlled.measurementStdDevs
- Standard deviations of measurements. Can be empty if no noise is desired. If present must have same number of items as Outputs
-
-
Method Details
-
update
Updates the simulation.- Parameters:
dtSeconds
- The time between updates.
-
getOutput
Returns the current output of the plant.- Returns:
- The current output of the plant.
-
getOutput
Returns an element of the current output of the plant.- Parameters:
row
- The row to return.- Returns:
- An element of the current output of the plant.
-
setInput
Sets the system inputs (usually voltages).- Parameters:
u
- The system inputs.
-
setInput
Sets the system inputs.- Parameters:
row
- The row in the input matrix to set.value
- The value to set the row to.
-
setInput
Sets the system inputs.- Parameters:
u
- An array of doubles that represent the inputs of the system.
-
getInput
Returns the current input of the plant.- Returns:
- The current input of the plant.
-
getInput
Returns an element of the current input of the plant.- Parameters:
row
- The row to return.- Returns:
- An element of the current input of the plant.
-
setState
Sets the system state.- Parameters:
state
- The new state.
-
updateX
protected Matrix<States,N1> updateX(Matrix<States, N1> currentXhat, Matrix<Inputs, N1> u, double dtSeconds) Updates the state estimate of the system.- Parameters:
currentXhat
- The current state estimate.u
- The system inputs (usually voltage).dtSeconds
- The time difference between controller updates.- Returns:
- The new state.
-
clampInput
Clamp the input vector such that no element exceeds the maximum allowed value. If any does, the relative magnitudes of the input will be maintained.- Parameters:
maxInput
- The maximum magnitude of the input vector after clamping.
-