# SwerveParser
declaration: package: swervelib.parser, class: SwerveParser

Package swervelib.parser

# Class SwerveParser

java.lang.Object
swervelib.parser.SwerveParser

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

## Field Summary

Fields
Modifier and Type
Field
Description
`static ControllerPropertiesJson`
`controllerPropertiesJson`
Parsed controllerproperties.json
`private static final HashMap<String,Integer>`
`moduleConfigs`
Module number mapped to the JSON name.
`static ModuleJson[]`
`moduleJsons`
Array holding the module jsons given in `SwerveDriveJson`.
`static PhysicalPropertiesJson`
`physicalPropertiesJson`
Parsed modules/physicalproperties.json
`static PIDFPropertiesJson`
`pidfPropertiesJson`
Parsed modules/pidfproperties.json
`static SwerveDriveJson`
`swerveDriveJson`
Parsed swervedrive.json

## Constructor Summary

Constructors
Constructor
Description
`SwerveParser(File directory)`
Construct a swerve parser.

## Method Summary

Modifier and Type
Method
Description
`private void`
`checkDirectory(File directory)`
Check directory structure.
`SwerveDrive`
`createSwerveDrive(double maxSpeed)`
Create `SwerveDrive` from JSON configuration directory.
`SwerveDrive`
`createSwerveDrive(double maxSpeed, double angleMotorConversionFactor, double driveMotorConversion)`
Create `SwerveDrive` from JSON configuration directory.
`SwerveDrive`
`createSwerveDrive(edu.wpi.first.math.controller.SimpleMotorFeedforward driveFeedforward, double maxSpeed)`
Create `SwerveDrive` from JSON configuration directory.
`SwerveDrive`
`createSwerveDrive(edu.wpi.first.math.controller.SimpleMotorFeedforward driveFeedforward, double maxSpeed, double angleMotorConversionFactor, double driveMotorConversion)`
Create `SwerveDrive` from JSON configuration directory.
`static SwerveModule`
`getModuleConfigurationByName(String name, SwerveDriveConfiguration driveConfiguration)`
Get the swerve module by the json name.
`private com.fasterxml.jackson.databind.JsonNode`
`openJson(File file)`
Open JSON file.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### moduleConfigs

private static final HashMap<String,Integer> moduleConfigs
Module number mapped to the JSON name.

### swerveDriveJson

public static SwerveDriveJson swerveDriveJson
Parsed swervedrive.json

### controllerPropertiesJson

public static ControllerPropertiesJson controllerPropertiesJson
Parsed controllerproperties.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(File directory) throws IOException
Construct a swerve parser. Will throw an error if there is a missing file.

Parameters:
  `directory` - Directory with swerve configurations.
Throws:
  `IOException` - if a file doesn't exist.

## Method Details

### getModuleConfigurationByName

public static SwerveModule getModuleConfigurationByName(String name, SwerveDriveConfiguration driveConfiguration)
Get the swerve module by the json name.

Parameters:
  `name` - JSON name.
  `driveConfiguration` - `SwerveDriveConfiguration` to pull from.
Returns:
  `SwerveModuleConfiguration` based on the file.

### openJson

private com.fasterxml.jackson.databind.JsonNode openJson(File file)
Open JSON file.

Parameters:
  `file` - JSON File to open.
Returns:
  JsonNode of file.

### checkDirectory

private void checkDirectory(File directory)
Check directory structure.

Parameters:
  `directory` - JSON Configuration Directory

### createSwerveDrive

public SwerveDrive createSwerveDrive(double maxSpeed)
Create `SwerveDrive` from JSON configuration directory.

Parameters:
  `maxSpeed` - Maximum speed of the robot in meters per second, used for both angular acceleration used in `SwerveController` and drive feedforward in `SwerveMath.createDriveFeedforward(double, double, double)`.
Returns:
  `SwerveDrive` instance.

### createSwerveDrive

public SwerveDrive createSwerveDrive(double maxSpeed, double angleMotorConversionFactor, double driveMotorConversion)
Create `SwerveDrive` from JSON configuration directory.

Parameters:
  `maxSpeed` - Maximum speed of the robot in meters per second, used for both angular acceleration used in `SwerveController` and drive feedforward in `SwerveMath.createDriveFeedforward(double, double, double)`.
  `angleMotorConversionFactor` - Angle (AKA azimuth) motor conversion factor to convert motor controller PID loop units to degrees, usually created using `SwerveMath.calculateDegreesPerSteeringRotation(double, double)`.
  `driveMotorConversion` - Drive motor conversion factor to convert motor controller PID loop units to meters per rotation, usually created using `SwerveMath.calculateMetersPerRotation(double, double, double)`.
Returns:
  `SwerveDrive` instance.

### createSwerveDrive

public SwerveDrive createSwerveDrive(edu.wpi.first.math.controller.SimpleMotorFeedforward driveFeedforward, double maxSpeed, double angleMotorConversionFactor, double driveMotorConversion)
Create `SwerveDrive` from JSON configuration directory.

Parameters:
  `driveFeedforward` - Drive feedforward to use for swerve modules, should be created using `SwerveMath.createDriveFeedforward(double, double, double)`.
  `maxSpeed` - Maximum speed of the robot in meters per second for normal+angular acceleration in `SwerveController` of the robot.
  `angleMotorConversionFactor` - Angle (AKA azimuth) motor conversion factor to convert motor controller PID loop units to degrees, usually created using `SwerveMath.calculateDegreesPerSteeringRotation(double, double)`.
  `driveMotorConversion` - Drive motor conversion factor to convert motor controller PID loop units to meters per rotation, usually created using `SwerveMath.calculateMetersPerRotation(double, double, double)`.
Returns:
  `SwerveDrive` instance.

### createSwerveDrive

public SwerveDrive createSwerveDrive(edu.wpi.first.math.controller.SimpleMotorFeedforward driveFeedforward, double maxSpeed)
Create `SwerveDrive` from JSON configuration directory.

Parameters:
  `driveFeedforward` - Drive feedforward to use for swerve modules, should be created using `SwerveMath.createDriveFeedforward(double, double, double)`.
  `maxSpeed` - Maximum speed of the robot in meters per second for normal+angular acceleration in `SwerveController` of the robot
Returns:
  `SwerveDrive` instance.