Class Module
java.lang.Object
frc.robot.subsystems.drive.module.Module
Subsystem for a single swerve drive module.
Handles the control of drive and turn motors for a single wheel, including kinematics conversions and hardware fault monitoring.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all faults and warnings.Returns the current turn angle of the module.Returns the current drive position of the module in meters.Returns the current drive velocity of the module in meters per second.Returns the module velocity in rad/sec for feedforward characterization.Returns the module positions received this cycle from the asynchronous thread.double[]Returns the timestamps of the samples received this cycle from the asynchronous thread.Returns the module position (turn angle and drive position).getState()Returns the module state (turn angle and drive velocity).Returns the module position in radians for wheel radius characterization.booleanReturns whether or not the subsystem is healthyvoidperiodic()Updates hardware inputs, calculates odometry data, and updates status alerts.voidrunCharacterization(Voltage output) Runs the module with the specified output while holding the turn module to zero degrees.voidrunSetpoint(SwerveModuleState state) Runs the module with the specified setpoint state.voidstop()Disables all outputs to motors.voidupdateHighFreq(double timestampSec) Updates high-frequency data for the module, which can be used for real-time pose estimation or control loops.
-
Constructor Details
-
Module
Creates a new Module subsystem.- Parameters:
io- The abstraction layer for the module hardware.index- The index of the module (0-3).
-
-
Method Details
-
periodic
public void periodic()Updates hardware inputs, calculates odometry data, and updates status alerts. -
updateHighFreq
public void updateHighFreq(double timestampSec) Updates high-frequency data for the module, which can be used for real-time pose estimation or control loops.- Parameters:
timestampSec- The timestamp for the data point.
-
runSetpoint
Runs the module with the specified setpoint state.Optimizes the state to minimize turn angle (turning < 90 degrees instead of > 90) and scales the drive velocity based on the cosine of the error between the setpoint angle and current angle.
- Parameters:
state- The desired state (angle and velocity) for the module.
-
runCharacterization
Runs the module with the specified output while holding the turn module to zero degrees.- Parameters:
output- The voltage to apply to the drive motor.
-
stop
public void stop()Disables all outputs to motors. -
getCurrentAngle
Returns the current turn angle of the module.- Returns:
- The current angle as an Angle measure.
-
getCurrentPosition
Returns the current drive position of the module in meters.- Returns:
- The current distance as a Distance measure.
-
getCurrentVelocity
Returns the current drive velocity of the module in meters per second.- Returns:
- The current velocity as a LinearVelocity measure.
-
getPosition
Returns the module position (turn angle and drive position).- Returns:
- The current SwerveModulePosition.
-
getState
Returns the module state (turn angle and drive velocity).- Returns:
- The current SwerveModuleState.
-
getOdometryPositions
Returns the module positions received this cycle from the asynchronous thread.- Returns:
- An array of SwerveModulePositions.
-
getOdometryTimestamps
public double[] getOdometryTimestamps()Returns the timestamps of the samples received this cycle from the asynchronous thread.- Returns:
- An array of timestamps in seconds.
-
getWheelRadiusCharacterizationPosition
Returns the module position in radians for wheel radius characterization.- Returns:
- The drive position in radians.
-
getFFCharacterizationVelocity
Returns the module velocity in rad/sec for feedforward characterization.- Returns:
- The drive velocity in radians per second.
-
isHealthy
public boolean isHealthy()Returns whether or not the subsystem is healthy- Returns:
- True if the subsystem is healthy, false otherwise.
-
clearFaults
public void clearFaults()Clears all faults and warnings.
-