Class SwerveParser
java.lang.Object
swervelib.core.parser.SwerveParser
- Direct Known Subclasses:
SwerveParser, SwerveParser
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordSwerveParser.SwerveDriveDevices<D extends SwerveDrive>Raw hardware devices created by a command-framework specificSwerveParser#createSwerveDriveDevices, alongside theSwerveDriveit built.protected static final recordRaw hardware devices created bybuildSwerveDrive(SwerveDriveConfig, Supplier).static final recordRaw hardware devices created for a singleSwerveModulebySwerveParser. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ModuleJson[]Array holding the module jsons given inSwerveDriveJson.static PhysicalPropertiesJsonParsed modules/physicalproperties.jsonstatic PIDFPropertiesJsonParsed modules/pidfproperties.jsonstatic SwerveDriveJsonParsed swervedrive.json -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static <C extends SmartMotorControllerConfig<C>>
SwerveParser.SwerveDriveHardwarebuildSwerveDrive(SwerveDriveConfig<?> swerveDriveConfig, Supplier<C> motorConfigSupplier) Build theSwerveModules and gyro from the parsed JSON configuration and apply them to the givenSwerveDriveConfig, collecting the raw vendor hardware devices created along the way.static SwerveParserParses a swerve configuration directory and creates aSwerveParsercontaining the parsed configuration.static voidparseDirectory(File directory) static <T> TRead a JSON file into the given type with WPILib's JSON library (avaje-jsonb).
-
Field Details
-
swerveDriveJson
Parsed swervedrive.json -
pidfPropertiesJson
Parsed modules/pidfproperties.json -
physicalPropertiesJson
Parsed modules/physicalproperties.json -
moduleJsons
Array holding the module jsons given inSwerveDriveJson.
-
-
Constructor Details
-
SwerveParser
public SwerveParser()Construct a swerve parser.
-
-
Method Details
-
parse
Parses a swerve configuration directory and creates aSwerveParsercontaining the parsed configuration.- Parameters:
directory- the directory containing the swerve configuration files- Returns:
- a
SwerveParsercontaining the parsed configuration - Throws:
UncheckedIOException- if the directory or any of its configuration files cannot be read
-
parseDirectory
- Throws:
IOException
-
readJson
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 theSwerveModules and gyro from the parsed JSON configuration and apply them to the givenSwerveDriveConfig, collecting the raw vendor hardware devices created along the way. The command-framework specific parsers create theSwerveDrivefrom the configuredSwerveDriveConfigafterwards.- Type Parameters:
C-SmartMotorControllerConfigtype of the command framework.- Parameters:
swerveDriveConfig-SwerveDriveConfigto apply the modules, gyro, etc. to.motorConfigSupplier- Creates a new, emptySmartMotorControllerConfigbound to the swerve drive's command-framework owner (Subsystem or Mechanism).- Returns:
SwerveParser.SwerveDriveHardwarecontaining the raw devices created for the swerve drive.
-