mirror of
https://github.com/BroncBotz3481/YAGSL
synced 2026-06-19 06:21:40 +00:00
Added some helper functions and cleared up some optimizations
This commit is contained in:
@@ -183,30 +183,27 @@ public class SwerveModule
|
||||
double angle = desiredState.angle.getDegrees();
|
||||
|
||||
// If we are forcing the angle
|
||||
if (force)
|
||||
{
|
||||
angleMotor.setReference(angle, Math.toDegrees(desiredState.omegaRadPerSecond) * configuration.angleKV);
|
||||
} else
|
||||
if (!force)
|
||||
{
|
||||
// Prevents module rotation if speed is less than 1%
|
||||
angle = Math.abs(desiredState.speedMetersPerSecond) <= (configuration.maxSpeed * 0.01) ? lastAngle : angle;
|
||||
// Prevent module rotation if angle is the same as the previous angle.
|
||||
if (angle != lastAngle || synchronizeEncoderQueued)
|
||||
}
|
||||
|
||||
// Prevent module rotation if angle is the same as the previous angle.
|
||||
if (angle != lastAngle || synchronizeEncoderQueued)
|
||||
{
|
||||
// Synchronize encoders if queued and send in the current position as the value from the absolute encoder.
|
||||
if (absoluteEncoder != null && synchronizeEncoderQueued)
|
||||
{
|
||||
// Synchronize encoders if queued and send in the current position as the value from the absolute encoder.
|
||||
if (absoluteEncoder != null && synchronizeEncoderQueued)
|
||||
{
|
||||
double absoluteEncoderPosition = getAbsolutePosition();
|
||||
angleMotor.setPosition(absoluteEncoderPosition);
|
||||
angleMotor.setReference(angle,
|
||||
Math.toDegrees(desiredState.omegaRadPerSecond) * configuration.angleKV,
|
||||
absoluteEncoderPosition);
|
||||
synchronizeEncoderQueued = false;
|
||||
} else
|
||||
{
|
||||
angleMotor.setReference(
|
||||
angle, Math.toDegrees(desiredState.omegaRadPerSecond) * configuration.angleKV);
|
||||
}
|
||||
double absoluteEncoderPosition = getAbsolutePosition();
|
||||
angleMotor.setPosition(absoluteEncoderPosition);
|
||||
angleMotor.setReference(angle,
|
||||
Math.toDegrees(desiredState.omegaRadPerSecond) * configuration.angleKV,
|
||||
absoluteEncoderPosition);
|
||||
synchronizeEncoderQueued = false;
|
||||
} else
|
||||
{
|
||||
angleMotor.setReference(angle, Math.toDegrees(desiredState.omegaRadPerSecond) * configuration.angleKV);
|
||||
}
|
||||
}
|
||||
lastAngle = angle;
|
||||
@@ -321,4 +318,34 @@ public class SwerveModule
|
||||
{
|
||||
driveMotor.setMotorBrake(brake);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the angle {@link SwerveMotor} for the {@link SwerveModule}.
|
||||
*
|
||||
* @return {@link SwerveMotor} for the angle/steering motor of the module.
|
||||
*/
|
||||
public SwerveMotor getAngleMotor()
|
||||
{
|
||||
return angleMotor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the drive {@link SwerveMotor} for the {@link SwerveModule}.
|
||||
*
|
||||
* @return {@link SwerveMotor} for the drive motor of the module.
|
||||
*/
|
||||
public SwerveMotor getDriveMotor()
|
||||
{
|
||||
return driveMotor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the {@link SwerveModuleConfiguration} for the {@link SwerveModule} with the parsed configurations.
|
||||
*
|
||||
* @return {@link SwerveModuleConfiguration} for the {@link SwerveModule}.
|
||||
*/
|
||||
public SwerveModuleConfiguration getConfiguration()
|
||||
{
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user