Added some helper functions and cleared up some optimizations

This commit is contained in:
thenetworkgrinch
2023-03-20 19:20:26 -05:00
parent 9887cf3c26
commit 670154f061
111 changed files with 445 additions and 280 deletions

View File

@@ -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;
}
}