Files
YAGSL/swervelib/parser/SwerveModuleConfiguration.java

173 lines
6.3 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
import edu.wpi.first.math.geometry.Translation2d;
2023-02-13 17:21:24 -06:00
import swervelib.encoders.SwerveAbsoluteEncoder;
import swervelib.motors.SwerveMotor;
2023-11-09 17:32:48 -06:00
import swervelib.parser.json.MotorConfigDouble;
2023-02-13 14:37:05 -06:00
/**
2023-02-13 17:21:24 -06:00
* Swerve Module configuration class which is used to configure {@link swervelib.SwerveModule}.
2023-02-13 14:37:05 -06:00
*/
public class SwerveModuleConfiguration
{
2023-11-09 17:32:48 -06:00
/**
* Conversion factor for drive motor onboard PID's and angle PID's. Use
* {@link swervelib.math.SwerveMath#calculateMetersPerRotation(double, double, double)} and
* {@link swervelib.math.SwerveMath#calculateDegreesPerSteeringRotation(double, double)} respectively to calculate the
* conversion factors.
*/
public final MotorConfigDouble conversionFactors;
2023-02-13 14:37:05 -06:00
/**
* Angle offset in degrees for the Swerve Module.
*/
public final double angleOffset;
/**
* Whether the absolute encoder is inverted.
*/
public final boolean absoluteEncoderInverted;
/**
* State of inversion of the drive motor.
*/
public final boolean driveMotorInverted;
/**
* State of inversion of the angle motor.
*/
public final boolean angleMotorInverted;
/**
* PIDF configuration options for the angle motor closed-loop PID controller.
*/
public PIDFConfig anglePIDF;
/**
* PIDF configuration options for the drive motor closed-loop PID controller.
*/
public PIDFConfig velocityPIDF;
/**
* Swerve module location relative to the robot.
*/
public Translation2d moduleLocation;
/**
* Physical characteristics of the swerve module.
*/
public SwerveModulePhysicalCharacteristics physicalCharacteristics;
/**
* The drive motor and angle motor of this swerve module.
*/
public SwerveMotor driveMotor, angleMotor;
/**
* The Absolute Encoder for the swerve module.
*/
public SwerveAbsoluteEncoder absoluteEncoder;
2023-04-08 12:31:07 -05:00
/**
* Name for the swerve module for telemetry.
*/
public String name;
2024-01-26 11:29:15 -06:00
/**
* Should do cosine compensation when not pointing correct direction;.
*/
public boolean useCosineCompensator;
2023-02-13 14:37:05 -06:00
/**
* Construct a configuration object for swerve modules.
*
2023-11-09 17:32:48 -06:00
* @param driveMotor Drive {@link SwerveMotor}.
* @param angleMotor Angle {@link SwerveMotor}
* @param absoluteEncoder Absolute encoder {@link SwerveAbsoluteEncoder}.
* @param angleOffset Absolute angle offset to 0.
* @param absoluteEncoderInverted Absolute encoder inverted.
* @param angleMotorInverted State of inversion of the angle motor.
* @param driveMotorInverted Drive motor inverted.
* @param xMeters Module location in meters from the center horizontally.
* @param yMeters Module location in meters from center vertically.
* @param anglePIDF Angle PIDF configuration.
* @param velocityPIDF Velocity PIDF configuration.
* @param physicalCharacteristics Physical characteristics of the swerve module.
* @param name The name for the swerve module.
* @param conversionFactors Conversion factors to be applied to the drive and angle motors.
2024-01-26 11:29:15 -06:00
* @param useCosineCompensator Should use cosineCompensation.
2023-02-13 14:37:05 -06:00
*/
public SwerveModuleConfiguration(
SwerveMotor driveMotor,
SwerveMotor angleMotor,
2023-11-09 17:32:48 -06:00
MotorConfigDouble conversionFactors,
SwerveAbsoluteEncoder absoluteEncoder,
double angleOffset,
double xMeters,
double yMeters,
PIDFConfig anglePIDF,
PIDFConfig velocityPIDF,
SwerveModulePhysicalCharacteristics physicalCharacteristics,
boolean absoluteEncoderInverted,
boolean driveMotorInverted,
boolean angleMotorInverted,
2024-01-26 11:29:15 -06:00
String name,
boolean useCosineCompensator)
2023-02-13 14:37:05 -06:00
{
this.driveMotor = driveMotor;
this.angleMotor = angleMotor;
2023-11-09 17:32:48 -06:00
this.conversionFactors = conversionFactors;
2023-02-13 14:37:05 -06:00
this.absoluteEncoder = absoluteEncoder;
this.angleOffset = angleOffset;
this.absoluteEncoderInverted = absoluteEncoderInverted;
this.driveMotorInverted = driveMotorInverted;
this.angleMotorInverted = angleMotorInverted;
this.moduleLocation = new Translation2d(xMeters, yMeters);
this.anglePIDF = anglePIDF;
this.velocityPIDF = velocityPIDF;
this.physicalCharacteristics = physicalCharacteristics;
2023-04-08 12:31:07 -05:00
this.name = name;
2024-01-26 11:29:15 -06:00
this.useCosineCompensator = useCosineCompensator;
2023-02-13 14:37:05 -06:00
}
/**
* Construct a configuration object for swerve modules. Assumes the absolute encoder and drive motor are not
* inverted.
*
* @param driveMotor Drive {@link SwerveMotor}.
* @param angleMotor Angle {@link SwerveMotor}
2023-11-09 17:32:48 -06:00
* @param conversionFactors Conversion factors for angle/azimuth motors drive factors.
2023-02-13 14:37:05 -06:00
* @param absoluteEncoder Absolute encoder {@link SwerveAbsoluteEncoder}.
* @param angleOffset Absolute angle offset to 0.
* @param xMeters Module location in meters from the center horizontally.
* @param yMeters Module location in meters from center vertically.
* @param anglePIDF Angle PIDF configuration.
* @param velocityPIDF Velocity PIDF configuration.
* @param physicalCharacteristics Physical characteristics of the swerve module.
2023-04-08 12:31:07 -05:00
* @param name Name for the module.
2024-01-26 11:29:15 -06:00
* @param useCosineCompensator Should use cosineCompensation.
2023-02-13 14:37:05 -06:00
*/
public SwerveModuleConfiguration(
SwerveMotor driveMotor,
SwerveMotor angleMotor,
2023-11-09 17:32:48 -06:00
MotorConfigDouble conversionFactors,
SwerveAbsoluteEncoder absoluteEncoder,
double angleOffset,
double xMeters,
double yMeters,
PIDFConfig anglePIDF,
PIDFConfig velocityPIDF,
2023-04-08 12:31:07 -05:00
SwerveModulePhysicalCharacteristics physicalCharacteristics,
2024-01-26 11:29:15 -06:00
String name,
boolean useCosineCompensator)
2023-02-13 14:37:05 -06:00
{
this(
driveMotor,
angleMotor,
2023-11-09 17:32:48 -06:00
conversionFactors,
absoluteEncoder,
angleOffset,
xMeters,
yMeters,
anglePIDF,
velocityPIDF,
physicalCharacteristics,
false,
false,
false,
2024-01-26 11:29:15 -06:00
name,
useCosineCompensator);
2023-02-13 14:37:05 -06:00
}
}