Files
YAGSL/swervelib/parser/SwerveDriveConfiguration.java

84 lines
2.6 KiB
Java
Raw Normal View History

2023-02-13 17:21:24 -06:00
package swervelib.parser;
2023-02-13 14:37:05 -06:00
2023-11-09 17:32:48 -06:00
import edu.wpi.first.math.controller.SimpleMotorFeedforward;
2023-02-13 14:37:05 -06:00
import edu.wpi.first.math.geometry.Translation2d;
2023-02-13 17:21:24 -06:00
import swervelib.SwerveModule;
import swervelib.imu.SwerveIMU;
2023-02-13 14:37:05 -06:00
/**
* Swerve drive configurations used during SwerveDrive construction.
*/
2023-04-08 12:31:07 -05:00
public class SwerveDriveConfiguration
{
2023-02-13 14:37:05 -06:00
2023-04-08 12:31:07 -05:00
/**
* Swerve Module locations.
*/
2023-11-09 17:32:48 -06:00
public Translation2d[] moduleLocationsMeters;
2023-04-08 12:31:07 -05:00
/**
* Swerve IMU
*/
2023-11-09 17:32:48 -06:00
public SwerveIMU imu;
2023-04-08 12:31:07 -05:00
/**
* Invert the imu measurements.
*/
2023-11-09 17:32:48 -06:00
public boolean invertedIMU = false;
2023-04-08 12:31:07 -05:00
/**
* Number of modules on the robot.
*/
2023-11-09 17:32:48 -06:00
public int moduleCount;
2023-04-08 12:31:07 -05:00
/**
* Swerve Modules.
*/
2023-11-09 17:32:48 -06:00
public SwerveModule[] modules;
/**
* Physical characteristics of the swerve drive from physicalproperties.json.
*/
public SwerveModulePhysicalCharacteristics physicalCharacteristics;
2023-02-13 14:37:05 -06:00
2023-04-08 12:31:07 -05:00
/**
* Create swerve drive configuration.
*
2023-11-09 17:32:48 -06:00
* @param moduleConfigs Module configuration.
* @param swerveIMU Swerve IMU.
* @param invertedIMU Invert the IMU.
* @param driveFeedforward The drive motor feedforward to use for the {@link SwerveModule}.
2023-04-08 12:31:07 -05:00
*/
public SwerveDriveConfiguration(
SwerveModuleConfiguration[] moduleConfigs,
SwerveIMU swerveIMU,
2023-11-09 17:32:48 -06:00
boolean invertedIMU,
SimpleMotorFeedforward driveFeedforward,
SwerveModulePhysicalCharacteristics physicalCharacteristics)
2023-04-08 12:31:07 -05:00
{
this.moduleCount = moduleConfigs.length;
this.imu = swerveIMU;
this.invertedIMU = invertedIMU;
2023-11-09 17:32:48 -06:00
this.modules = createModules(moduleConfigs, driveFeedforward);
2023-04-08 12:31:07 -05:00
this.moduleLocationsMeters = new Translation2d[moduleConfigs.length];
for (SwerveModule module : modules)
{
this.moduleLocationsMeters[module.moduleNumber] = module.configuration.moduleLocation;
2023-02-13 14:37:05 -06:00
}
2023-11-09 17:32:48 -06:00
this.physicalCharacteristics = physicalCharacteristics;
2023-04-08 12:31:07 -05:00
}
2023-02-13 14:37:05 -06:00
2023-04-08 12:31:07 -05:00
/**
* Create modules based off of the SwerveModuleConfiguration.
*
2023-11-09 17:32:48 -06:00
* @param swerves Swerve constants.
* @param driveFeedforward Drive feedforward created using
* {@link swervelib.math.SwerveMath#createDriveFeedforward(double, double, double)}.
2023-04-08 12:31:07 -05:00
* @return Swerve Modules.
*/
2023-11-09 17:32:48 -06:00
public SwerveModule[] createModules(SwerveModuleConfiguration[] swerves, SimpleMotorFeedforward driveFeedforward)
2023-04-08 12:31:07 -05:00
{
SwerveModule[] modArr = new SwerveModule[swerves.length];
for (int i = 0; i < swerves.length; i++)
{
2023-11-09 17:32:48 -06:00
modArr[i] = new SwerveModule(i, swerves[i], driveFeedforward);
2023-02-13 14:37:05 -06:00
}
2023-04-08 12:31:07 -05:00
return modArr;
}
2023-02-13 14:37:05 -06:00
}