Package swervelib.simulation
Class SwerveModuleSimulation
java.lang.Object
swervelib.simulation.SwerveModuleSimulation
Class to hold simulation data for
SwerveModule-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate doubleTime delta since last updateprivate doubleFake motor position.private doubleThe fake speed of the previous state, used to calculatefakePos.private doubleLast time queried.private edu.wpi.first.math.kinematics.SwerveModuleStateCurrent simulated swerve module state.private final edu.wpi.first.wpilibj.TimerMain timer to simulate the passage of time. -
Constructor Summary
ConstructorsConstructorDescriptionCreate simulation class and initialize module at 0. -
Method Summary
Modifier and TypeMethodDescriptionedu.wpi.first.math.kinematics.SwerveModulePositionGet the simulated swerve module position.edu.wpi.first.math.kinematics.SwerveModuleStategetState()Get theSwerveModuleStateof the simulated module.voidupdateStateAndPosition(edu.wpi.first.math.kinematics.SwerveModuleState desiredState) Update the position and state of the module.
-
Field Details
-
timer
private final edu.wpi.first.wpilibj.Timer timerMain timer to simulate the passage of time. -
dt
private double dtTime delta since last update -
fakePos
private double fakePosFake motor position. -
fakeSpeed
private double fakeSpeedThe fake speed of the previous state, used to calculatefakePos. -
lastTime
private double lastTimeLast time queried. -
state
private edu.wpi.first.math.kinematics.SwerveModuleState stateCurrent 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 fromSwerveModule.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:
SwerveModulePositionof the simulated module.
-
getState
public edu.wpi.first.math.kinematics.SwerveModuleState getState()Get theSwerveModuleStateof the simulated module.- Returns:
SwerveModuleStateof the simulated module.
-