Class ModuleIOSim

java.lang.Object
frc.robot.subsystems.drive.module.ModuleIOSim
All Implemented Interfaces:
ModuleIO

public class ModuleIOSim extends Object implements ModuleIO
Physics simulation implementation of ModuleIO.

This class uses SparkMaxSim to simulate the Spark MAX motor controllers, backed by DCMotorSim physics models for accurate motor behavior. The Spark's built-in closed-loop PID is used for velocity and position control, matching the real robot's ModuleIOSpark.

  • Constructor Details

    • ModuleIOSim

      public ModuleIOSim(int module)
      Creates a new ModuleIOSim and initializes the simulated Spark MAX motor controllers.
      Parameters:
      module - The module index (0 for front-left, 1 for front-right, 2 for back-left, 3 for back-right).
  • Method Details

    • updateHighFreq

      public void updateHighFreq(double timestampSec)
      Description copied from interface: ModuleIO
      Polls high-frequency data for the 200Hz odometry loop.
      Specified by:
      updateHighFreq in interface ModuleIO
      Parameters:
      timestampSec - The exact timestamp of the current 200Hz tick.
    • updateInputs

      public void updateInputs(ModuleIO.ModuleIOInputs inputs)
      Description copied from interface: ModuleIO
      Updates the set of loggable inputs.
      Specified by:
      updateInputs in interface ModuleIO
      Parameters:
      inputs - The inputs object to update.
    • setDriveOpenLoop

      public void setDriveOpenLoop(Voltage output)
      Description copied from interface: ModuleIO
      Run the drive motor at the specified open loop voltage.
      Specified by:
      setDriveOpenLoop in interface ModuleIO
      Parameters:
      output - The voltage to apply.
    • setTurnOpenLoop

      public void setTurnOpenLoop(Voltage output)
      Description copied from interface: ModuleIO
      Run the turn motor at the specified open loop voltage.
      Specified by:
      setTurnOpenLoop in interface ModuleIO
      Parameters:
      output - The voltage to apply.
    • setDriveVelocity

      public void setDriveVelocity(AngularVelocity velocity)
      Description copied from interface: ModuleIO
      Run the drive motor at the specified angular velocity.
      Specified by:
      setDriveVelocity in interface ModuleIO
      Parameters:
      velocity - The target velocity in radians per second.
    • setTurnPosition

      public void setTurnPosition(Angle rotation)
      Description copied from interface: ModuleIO
      Run the turn motor to the specified rotation.
      Specified by:
      setTurnPosition in interface ModuleIO
      Parameters:
      rotation - The target angle as an Angle measure.