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 Details

  • Constructor Details

  • Method Details

    • 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.
    • getInput

      public Matrix<Inputs,​N1> getInput()
      Returns the current input of the plant.
      Returns:
      The current input of the plant.
    • getInput

      public double getInput​(int row)
      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

      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.
    • clampInput

      protected Matrix<Inputs,​N1> clampInput​(Matrix<Inputs,​N1> u)
      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:
      u - The input vector.
      Returns:
      The normalized input.