mirror of
https://github.com/BroncBotz3481/YAGSL
synced 2026-06-19 06:21:40 +00:00
Updated YAGSL to next-gen
This commit is contained in:
@@ -43,6 +43,10 @@ public class SwerveModule
|
||||
* Feedforward for drive motor during closed loop control.
|
||||
*/
|
||||
public SimpleMotorFeedforward feedforward;
|
||||
/**
|
||||
* Maximum speed of the drive motors in meters per second.
|
||||
*/
|
||||
public double maxSpeed;
|
||||
/**
|
||||
* Last swerve module state applied.
|
||||
*/
|
||||
@@ -66,8 +70,11 @@ public class SwerveModule
|
||||
*
|
||||
* @param moduleNumber Module number for kinematics.
|
||||
* @param moduleConfiguration Module constants containing CAN ID's and offsets.
|
||||
* @param driveFeedforward Drive motor feedforward created by
|
||||
* {@link SwerveMath#createDriveFeedforward(double, double, double)}.
|
||||
*/
|
||||
public SwerveModule(int moduleNumber, SwerveModuleConfiguration moduleConfiguration)
|
||||
public SwerveModule(int moduleNumber, SwerveModuleConfiguration moduleConfiguration,
|
||||
SimpleMotorFeedforward driveFeedforward)
|
||||
{
|
||||
// angle = 0;
|
||||
// speed = 0;
|
||||
@@ -78,7 +85,7 @@ public class SwerveModule
|
||||
angleOffset = moduleConfiguration.angleOffset;
|
||||
|
||||
// Initialize Feedforward for drive motor.
|
||||
feedforward = configuration.createDriveFeedforward();
|
||||
feedforward = driveFeedforward;
|
||||
|
||||
// Create motors from configuration and reset them to defaults.
|
||||
angleMotor = moduleConfiguration.angleMotor;
|
||||
@@ -104,14 +111,14 @@ public class SwerveModule
|
||||
}
|
||||
|
||||
// Config angle motor/controller
|
||||
angleMotor.configureIntegratedEncoder(moduleConfiguration.getPositionEncoderConversion(false));
|
||||
angleMotor.configureIntegratedEncoder(moduleConfiguration.conversionFactors.angle);
|
||||
angleMotor.configurePIDF(moduleConfiguration.anglePIDF);
|
||||
angleMotor.configurePIDWrapping(-180, 180);
|
||||
angleMotor.setInverted(moduleConfiguration.angleMotorInverted);
|
||||
angleMotor.setMotorBrake(false);
|
||||
|
||||
// Config drive motor/controller
|
||||
driveMotor.configureIntegratedEncoder(moduleConfiguration.getPositionEncoderConversion(true));
|
||||
driveMotor.configureIntegratedEncoder(moduleConfiguration.conversionFactors.drive);
|
||||
driveMotor.configurePIDF(moduleConfiguration.velocityPIDF);
|
||||
driveMotor.setInverted(moduleConfiguration.driveMotorInverted);
|
||||
driveMotor.setMotorBrake(true);
|
||||
@@ -127,6 +134,27 @@ public class SwerveModule
|
||||
lastState = getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the voltage compensation for the swerve module motor.
|
||||
*
|
||||
* @param optimalVoltage Nominal voltage for operation to output to.
|
||||
*/
|
||||
public void setAngleMotorVoltageCompensation(double optimalVoltage)
|
||||
{
|
||||
angleMotor.setVoltageCompensation(optimalVoltage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the voltage compensation for the swerve module motor.
|
||||
*
|
||||
* @param optimalVoltage Nominal voltage for operation to output to.
|
||||
*/
|
||||
public void setDriveMotorVoltageCompensation(double optimalVoltage)
|
||||
{
|
||||
driveMotor.setVoltageCompensation(optimalVoltage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Queue synchronization of the integrated angle encoder with the absolute encoder.
|
||||
*/
|
||||
@@ -157,7 +185,7 @@ public class SwerveModule
|
||||
|
||||
if (isOpenLoop)
|
||||
{
|
||||
double percentOutput = desiredState.speedMetersPerSecond / configuration.maxSpeed;
|
||||
double percentOutput = desiredState.speedMetersPerSecond / maxSpeed;
|
||||
driveMotor.set(percentOutput);
|
||||
} else
|
||||
{
|
||||
@@ -172,7 +200,7 @@ public class SwerveModule
|
||||
if (!force)
|
||||
{
|
||||
// Prevents module rotation if speed is less than 1%
|
||||
SwerveMath.antiJitter(desiredState, lastState, Math.min(configuration.maxSpeed, 4));
|
||||
SwerveMath.antiJitter(desiredState, lastState, Math.min(maxSpeed, 4));
|
||||
}
|
||||
|
||||
if (SwerveDriveTelemetry.verbosity == TelemetryVerbosity.HIGH)
|
||||
@@ -225,12 +253,10 @@ public class SwerveModule
|
||||
{
|
||||
double velocity;
|
||||
Rotation2d azimuth;
|
||||
double omega;
|
||||
if (!SwerveDriveTelemetry.isSimulation)
|
||||
{
|
||||
velocity = driveMotor.getVelocity();
|
||||
azimuth = Rotation2d.fromDegrees(angleMotor.getPosition());
|
||||
omega = Math.toRadians(angleMotor.getVelocity());
|
||||
} else
|
||||
{
|
||||
return simModule.getState();
|
||||
@@ -310,6 +336,28 @@ public class SwerveModule
|
||||
driveMotor.setMotorBrake(brake);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the conversion factor for the angle/azimuth motor controller.
|
||||
*
|
||||
* @param conversionFactor Angle motor conversion factor for PID, should be generated from
|
||||
* {@link SwerveMath#calculateDegreesPerSteeringRotation(double, double)} or calculated.
|
||||
*/
|
||||
public void setAngleMotorConversionFactor(double conversionFactor)
|
||||
{
|
||||
angleMotor.configureIntegratedEncoder(conversionFactor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the conversion factor for the drive motor controller.
|
||||
*
|
||||
* @param conversionFactor Drive motor conversion factor for PID, should be generated from
|
||||
* {@link SwerveMath#calculateMetersPerRotation(double, double, double)} or calculated.
|
||||
*/
|
||||
public void setDriveMotorConversionFactor(double conversionFactor)
|
||||
{
|
||||
driveMotor.configureIntegratedEncoder(conversionFactor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the angle {@link SwerveMotor} for the {@link SwerveModule}.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user