Class DriveTrainSimulationConfig

java.lang.Object
org.ironmaple.simulation.drivesims.configs.DriveTrainSimulationConfig

public class DriveTrainSimulationConfig extends Object

Stores the configurations for a swerve drive simulation.

This class is used to hold all the parameters necessary for simulating a swerve drivetrain, allowing for realistic performance testing and evaluation.

  • Field Details

  • Constructor Details

    • DriveTrainSimulationConfig

      public DriveTrainSimulationConfig(Mass robotMass, Distance bumperLengthX, Distance bumperWidthY, Distance trackLengthX, Distance trackWidthY, Supplier<GyroSimulation> gyroSimulationFactory, Supplier<SwerveModuleSimulation>... swerveModuleSimulationFactory)

      Ordinary Constructor

      Creates an instance of DriveTrainSimulationConfig with specified parameters.

      Parameters:
      robotMass - the mass of the robot, including bumpers.
      bumperLengthX - the length of the bumper (distance from front to back).
      bumperWidthY - the width of the bumper (distance from left to right).
      trackLengthX - the distance between the front and rear wheels.
      trackWidthY - the distance between the left and right wheels.
      swerveModuleSimulationFactory - the factory that creates appropriate swerve module simulation for the drivetrain. You can specify one factory to apply the same configuration over all modules or specify four factories in the order (FL, FR, BL, BR).
      gyroSimulationFactory - the factory that creates appropriate gyro simulation for the drivetrain.
  • Method Details

    • Default

      public static DriveTrainSimulationConfig Default()

      Default Constructor.

      Creates a DriveTrainSimulationConfig with all the data set to default values.

      Though the config starts with default values, any configuration can be modified after creation.

      The default configurations are:

      • Robot Mass of 45 kilograms.
      • Bumper Length of 0.76 meters.
      • Bumper Width of 0.76 meters.
      • Track Length of 0.52 meters.
      • Track Width of 0.52 meters.
      • Default swerve module simulations based on Falcon 500 motors.
      • Default gyro simulation using the Pigeon2 gyro.
      Returns:
      a new instance of DriveTrainSimulationConfig with all configs set to default values.
    • withRobotMass

      public DriveTrainSimulationConfig withRobotMass(Mass robotMass)

      Sets the robot mass.

      Updates the mass of the robot in kilograms.

      Parameters:
      robotMass - the new mass of the robot.
      Returns:
      the current instance of DriveTrainSimulationConfig for method chaining.
    • withBumperSize

      public DriveTrainSimulationConfig withBumperSize(Distance bumperLengthX, Distance bumperWidthY)

      Sets the bumper size.

      Updates the dimensions of the bumper.

      Parameters:
      bumperLengthX - the length of the bumper.
      bumperWidthY - the width of the bumper.
      Returns:
      the current instance of DriveTrainSimulationConfig for method chaining.
    • withTrackLengthTrackWidth

      public DriveTrainSimulationConfig withTrackLengthTrackWidth(Distance trackLengthX, Distance trackWidthY)

      Sets the track length and width.

      Updates the translations for the swerve modules based on the specified track length and track width.

      For non-rectangular chassis configuration, use withCustomModuleTranslations(Translation2d[]) instead.

      Parameters:
      trackLengthX - the distance between the front and rear wheels.
      trackWidthY - the distance between the left and right wheels.
      Returns:
      the current instance of DriveTrainSimulationConfig for method chaining.
    • withCustomModuleTranslations

      public DriveTrainSimulationConfig withCustomModuleTranslations(Translation2d[] moduleTranslations)

      Sets custom module translations.

      Updates the translations of the swerve modules with user-defined values.

      For ordinary rectangular modules configuration, use withTrackLengthTrackWidth(Distance, Distance) instead.

      Parameters:
      moduleTranslations - the custom translations for the swerve modules.
      Returns:
      the current instance of DriveTrainSimulationConfig for method chaining.
    • withSwerveModules

      public DriveTrainSimulationConfig withSwerveModules(Supplier<SwerveModuleSimulation>... swerveModuleSimulationFactory)

      Sets the swerve module simulation factory.

      Updates the factory used to create swerve module simulations.

      Parameters:
      swerveModuleSimulationFactory - the new factory (or factories) for swerve module simulations. You can specify one factory to apply the same configuration over all modules, or specify four factories in the order (FL, FR, BL, BR)
      Returns:
      the current instance of DriveTrainSimulationConfig for method chaining.
    • withSwerveModule

      public DriveTrainSimulationConfig withSwerveModule(Supplier<SwerveModuleSimulation> swerveModuleSimulationFactory)

      Sets the swerve module simulation factory.

      Updates the factory used to create swerve module simulations.

      Uses the same configuration over all the modules

      Parameters:
      swerveModuleSimulationFactory - the new factory for swerve module simulations.
      Returns:
      the current instance of DriveTrainSimulationConfig for method chaining.
    • withGyro

      public DriveTrainSimulationConfig withGyro(Supplier<GyroSimulation> gyroSimulationFactory)

      Sets the gyro simulation factory.

      Updates the factory used to create gyro simulations.

      Parameters:
      gyroSimulationFactory - the new factory for gyro simulations.
      Returns:
      the current instance of DriveTrainSimulationConfig for method chaining.
    • getDensityKgPerSquaredMeters

      public double getDensityKgPerSquaredMeters()

      Calculates the density of the robot.

      Returns the density of the robot based on its mass and bumper dimensions.

      Returns:
      the density in kilograms per square meter.
    • trackLengthX

      public Distance trackLengthX()

      Calculates the track length in the X direction.

      Returns the total distance between the frontmost and rearmost module translations in the X direction.

      Returns:
      the track length.
      Throws:
      IllegalStateException - if the module translations are empty.
    • trackWidthY

      public Distance trackWidthY()

      Calculates the track width in the Y direction.

      Returns the total distance between the leftmost and rightmost module translations in the Y direction.

      Returns:
      the track width.
      Throws:
      IllegalStateException - if the module translations are empty.
    • driveBaseRadius

      public Distance driveBaseRadius()