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
- The number of states of the system.Inputs
- The number of inputs to the system.Outputs
- The number of outputs of the system.
- Direct Known Subclasses:
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 theIterativeRobotBase.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()
-
-
Constructor Summary
Constructors Constructor Description LinearSystemSim(LinearSystem<States,Inputs,Outputs> system)
Creates a simulated generic linear system.LinearSystemSim(LinearSystem<States,Inputs,Outputs> system, Matrix<Outputs,N1> measurementStdDevs)
Creates a simulated generic linear system with measurement noise.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Matrix<Inputs,N1>
clampInput(Matrix<Inputs,N1> u)
Clamp the input vector such that no element exceeds the given voltage.double
getCurrentDrawAmps()
Returns the current drawn by this simulated system.Matrix<Outputs,N1>
getOutput()
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
setInput(Matrix<Inputs,N1> u)
Sets the system inputs (usually voltages).void
setState(Matrix<States,N1> state)
Sets the system state.void
update(double dtSeconds)
Updates the simulation.protected Matrix<States,N1>
updateX(Matrix<States,N1> currentXhat, Matrix<Inputs,N1> u, double dtSeconds)
Updates the state estimate of the system.
-
-
-
Constructor Detail
-
LinearSystemSim
public LinearSystemSim(LinearSystem<States,Inputs,Outputs> system)
Creates a simulated generic linear system.- Parameters:
system
- The system to simulate.
-
LinearSystemSim
public LinearSystemSim(LinearSystem<States,Inputs,Outputs> system, Matrix<Outputs,N1> measurementStdDevs)
Creates a simulated generic linear system with measurement noise.- Parameters:
system
- The system being controlled.measurementStdDevs
- Standard deviations of measurements. Can be null if no noise is desired.
-
-
Method Detail
-
update
public void update(double dtSeconds)
Updates the simulation.- Parameters:
dtSeconds
- The time between updates.
-
getOutput
public Matrix<Outputs,N1> getOutput()
Returns the current output of the plant.- Returns:
- The current output of the plant.
-
getOutput
public double getOutput(int row)
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
public void setInput(Matrix<Inputs,N1> u)
Sets the system inputs (usually voltages).- Parameters:
u
- The system inputs.
-
setInput
public void setInput(int row, double value)
Sets the system inputs.- Parameters:
row
- The row in the input matrix to set.value
- The value to set the row to.
-
setInput
public void setInput(double... u)
Sets the system inputs.- Parameters:
u
- An array of doubles that represent the inputs of the system.
-
setState
public void setState(Matrix<States,N1> state)
Sets the system state.- Parameters:
state
- The new state.
-
getCurrentDrawAmps
public double getCurrentDrawAmps()
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.
-
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.
-
-