Class SwerveDriveSubsystem
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frc.alotobots.library.subsystems.swervedrive.SwerveDriveSubsystem
The SwerveDriveSubsystem class manages the robot's swerve drive system, handling odometry, module
control, and autonomous path following capabilities.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addVisionMeasurement
(Pose2d visionRobotPoseMeters, double timestampSeconds, Matrix<N3, N1> visionMeasurementStdDevs) Adds vision measurement for pose estimation.Gets measured chassis speeds.double
Gets average module velocity for feedforward characterization.double
Gets maximum angular speed capability.double
Gets maximum linear speed capability.getPose()
Gets current odometry pose.Gets current odometry rotation.double[]
Gets wheel positions for radius characterization.void
periodic()
Periodic update function handling odometry updates and module states.void
runCharacterization
(double output) Runs drive characterization with specified output.void
runVelocity
(ChassisSpeeds speeds) Runs the drive at the desired velocity.void
Resets odometry to specified pose.void
stop()
Stops all drive modules.void
Stops drive and positions modules in X pattern to resist movement.sysIdDynamic
(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) Creates command for dynamic system identification.sysIdQuasistatic
(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) Creates command for quasistatic system identification.Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystem
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Constructor Details
-
SwerveDriveSubsystem
public SwerveDriveSubsystem(GyroIO gyroIO, ModuleIO flModuleIO, ModuleIO frModuleIO, ModuleIO blModuleIO, ModuleIO brModuleIO) Constructs a new SwerveDriveSubsystem.- Parameters:
gyroIO
- Interface for gyro hardwareflModuleIO
- Front left module interfacefrModuleIO
- Front right module interfaceblModuleIO
- Back left module interfacebrModuleIO
- Back right module interface
-
-
Method Details
-
periodic
public void periodic()Periodic update function handling odometry updates and module states. -
runVelocity
Runs the drive at the desired velocity.- Parameters:
speeds
- Desired chassis speeds in meters/sec
-
runCharacterization
public void runCharacterization(double output) Runs drive characterization with specified output.- Parameters:
output
- Characterization output value
-
stop
public void stop()Stops all drive modules. -
stopWithX
public void stopWithX()Stops drive and positions modules in X pattern to resist movement. -
sysIdQuasistatic
public Command sysIdQuasistatic(edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Direction direction) Creates command for quasistatic system identification.- Parameters:
direction
- Test direction- Returns:
- Command for quasistatic test
-
sysIdDynamic
Creates command for dynamic system identification.- Parameters:
direction
- Test direction- Returns:
- Command for dynamic test
-
getChassisSpeeds
Gets measured chassis speeds.- Returns:
- Current chassis speeds
-
getWheelRadiusCharacterizationPositions
public double[] getWheelRadiusCharacterizationPositions()Gets wheel positions for radius characterization.- Returns:
- Array of wheel positions in radians
-
getFFCharacterizationVelocity
public double getFFCharacterizationVelocity()Gets average module velocity for feedforward characterization.- Returns:
- Average velocity in rotations/sec (Phoenix native units)
-
getPose
Gets current odometry pose.- Returns:
- Current robot pose
-
getRotation
Gets current odometry rotation.- Returns:
- Current robot rotation
-
setPose
Resets odometry to specified pose.- Parameters:
pose
- New robot pose
-
addVisionMeasurement
public void addVisionMeasurement(Pose2d visionRobotPoseMeters, double timestampSeconds, Matrix<N3, N1> visionMeasurementStdDevs) Adds vision measurement for pose estimation.- Parameters:
visionRobotPoseMeters
- Vision-measured robot posetimestampSeconds
- Timestamp of measurementvisionMeasurementStdDevs
- Standard deviations of vision measurements
-
getMaxLinearSpeedMetersPerSec
public double getMaxLinearSpeedMetersPerSec()Gets maximum linear speed capability.- Returns:
- Maximum speed in meters per second
-
getMaxAngularSpeedRadPerSec
public double getMaxAngularSpeedRadPerSec()Gets maximum angular speed capability.- Returns:
- Maximum angular speed in radians per second
-