Class SwerveModuleSimulation

java.lang.Object
swervelib.simulation.SwerveModuleSimulation

public class SwerveModuleSimulation extends Object
Class to hold simulation data for SwerveModule
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private double
    Time delta since last update
    private double
    Fake motor position.
    private double
    The fake speed of the previous state, used to calculate fakePos.
    private double
    Last time queried.
    private edu.wpi.first.math.kinematics.SwerveModuleState
    Current simulated swerve module state.
    private final edu.wpi.first.wpilibj.Timer
    Main timer to simulate the passage of time.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create simulation class and initialize module at 0.
  • Method Summary

    Modifier and Type
    Method
    Description
    edu.wpi.first.math.kinematics.SwerveModulePosition
    Get the simulated swerve module position.
    edu.wpi.first.math.kinematics.SwerveModuleState
    Get the SwerveModuleState of the simulated module.
    void
    updateStateAndPosition(edu.wpi.first.math.kinematics.SwerveModuleState desiredState)
    Update the position and state of the module.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • timer

      private final edu.wpi.first.wpilibj.Timer timer
      Main timer to simulate the passage of time.
    • dt

      private double dt
      Time delta since last update
    • fakePos

      private double fakePos
      Fake motor position.
    • fakeSpeed

      private double fakeSpeed
      The fake speed of the previous state, used to calculate fakePos.
    • lastTime

      private double lastTime
      Last time queried.
    • state

      private edu.wpi.first.math.kinematics.SwerveModuleState state
      Current simulated swerve module state.
  • Constructor Details

    • SwerveModuleSimulation

      public SwerveModuleSimulation()
      Create simulation class and initialize module at 0.
  • Method Details

    • updateStateAndPosition

      public void updateStateAndPosition(edu.wpi.first.math.kinematics.SwerveModuleState desiredState)
      Update the position and state of the module. Called from SwerveModule.setDesiredState(edu.wpi.first.math.kinematics.SwerveModuleState, boolean, boolean) function when simulated.
      Parameters:
      desiredState - State the swerve module is set to.
    • getPosition

      public edu.wpi.first.math.kinematics.SwerveModulePosition getPosition()
      Get the simulated swerve module position.
      Returns:
      SwerveModulePosition of the simulated module.
    • getState

      public edu.wpi.first.math.kinematics.SwerveModuleState getState()
      Get the SwerveModuleState of the simulated module.
      Returns:
      SwerveModuleState of the simulated module.