Class SwerveParser

java.lang.Object
swervelib.core.parser.SwerveParser
Direct Known Subclasses:
SwerveParser, SwerveParser

public class SwerveParser extends Object
Helper class used to parse the JSON directory with specified configuration options.

This class is command-framework agnostic. Robot code should use swervelib.commands2.SwerveParser or swervelib.commands3.SwerveParser to create a SwerveDrive bound to its command framework.

  • Field Details

    • swerveDriveJson

      public static SwerveDriveJson swerveDriveJson
      Parsed swervedrive.json
    • pidfPropertiesJson

      public static PIDFPropertiesJson pidfPropertiesJson
      Parsed modules/pidfproperties.json
    • physicalPropertiesJson

      public static PhysicalPropertiesJson physicalPropertiesJson
      Parsed modules/physicalproperties.json
    • moduleJsons

      public static ModuleJson[] moduleJsons
      Array holding the module jsons given in SwerveDriveJson.
  • Constructor Details

    • SwerveParser

      public SwerveParser()
      Construct a swerve parser.
  • Method Details

    • parse

      public static SwerveParser parse(File directory)
      Parses a swerve configuration directory and creates a SwerveParser containing the parsed configuration.
      Parameters:
      directory - the directory containing the swerve configuration files
      Returns:
      a SwerveParser containing the parsed configuration
      Throws:
      UncheckedIOException - if the directory or any of its configuration files cannot be read
    • parseDirectory

      public static void parseDirectory(File directory) throws IOException
      Throws:
      IOException
    • readJson

      public static <T> T readJson(File file, Class<T> type) throws IOException
      Read a JSON file into the given type with WPILib's JSON library (avaje-jsonb). Properties in the file that the type doesn't have (e.g. $schema) are ignored.
      Type Parameters:
      T - Type to read the file into.
      Parameters:
      file - JSON file to read.
      type - Type to read the file into.
      Returns:
      Parsed file.
      Throws:
      IOException - If the file can't be read.
    • buildSwerveDrive

      protected static <C extends SmartMotorControllerConfig<C>> SwerveParser.SwerveDriveHardware buildSwerveDrive(SwerveDriveConfig<?> swerveDriveConfig, Supplier<C> motorConfigSupplier)
      Build the SwerveModules and gyro from the parsed JSON configuration and apply them to the given SwerveDriveConfig, collecting the raw vendor hardware devices created along the way. The command-framework specific parsers create the SwerveDrive from the configured SwerveDriveConfig afterwards.
      Type Parameters:
      C - SmartMotorControllerConfig type of the command framework.
      Parameters:
      swerveDriveConfig - SwerveDriveConfig to apply the modules, gyro, etc. to.
      motorConfigSupplier - Creates a new, empty SmartMotorControllerConfig bound to the swerve drive's command-framework owner (Subsystem or Mechanism).
      Returns:
      SwerveParser.SwerveDriveHardware containing the raw devices created for the swerve drive.