Class Drive
java.lang.Object
org.teamvan.robot.mechanisms.drive.Drive
- All Implemented Interfaces:
Mechanism
Swerve drivetrain mechanism, ported from the AdvantageKit TalonFX swerve template to the WPILib
2027
Mechanism API.
Commands claim sole ownership of the drivetrain through the command scheduler, so no command
can drive the robot while another one already does. Per-loop work is split into updateInputs() (read hardware, sample odometry) and updateOutputs() (publish
telemetry), which the robot calls around Scheduler.getDefault().run().
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doublestatic final doubleThe frequency at which the Phoenix odometry thread samples module and gyro signals.static final Lock -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVisionMeasurement(Pose2d visionRobotPoseMeters, double timestampSeconds, Matrix<N3, N1> visionMeasurementStdDevs) Adds a new timestamped vision measurement.doubleReturns the average velocity of the modules in rotations/sec (Phoenix native units).doubleReturns the maximum angular speed in radians per sec.doubleReturns the maximum linear speed in meters per sec.static Translation2d[]Returns an array of module translations.getPose()Returns the current odometry pose.Returns the current odometry rotation.double[]Returns the position of each module in radians.joystickDrive(DoubleSupplier xSupplier, DoubleSupplier ySupplier, DoubleSupplier omegaSupplier) Returns a field-relative drive command from the given stick suppliers.joystickDrive(Gamepad gamepad) Returns a field-relative drive command that reads the gamepad's left stick for linear velocity and its right stick for rotation.voidrunCharacterization(double output) Runs the drive in a straight line with the specified drive output.voidrunVelocity(ChassisVelocities velocities) Runs the drive at the desired velocity.voidResets the current odometry pose.voidstop()Stops the drive.voidStops the drive and turns the modules to an X arrangement to resist movement.voidReads the drivetrain hardware and integrates the high-frequency odometry samples.voidPublishes the drivetrain's measured state to telemetry.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Mechanism
getDefaultCommand, getName, getRegisteredScheduler, getRunningCommands, idle, idleFor, run, runRepeatedly, setDefaultCommand
-
Field Details
-
ODOMETRY_FREQUENCY
public static final double ODOMETRY_FREQUENCYThe frequency at which the Phoenix odometry thread samples module and gyro signals. -
DRIVE_BASE_RADIUS
public static final double DRIVE_BASE_RADIUS -
odometryLock
-
-
Constructor Details
-
Drive
-
-
Method Details
-
updateInputs
public void updateInputs()Reads the drivetrain hardware and integrates the high-frequency odometry samples. Call this before running the command scheduler so commands act on fresh data. -
updateOutputs
public void updateOutputs()Publishes the drivetrain's measured state to telemetry. Call this after running the command scheduler so the reported state reflects the outputs commands just wrote. -
runVelocity
Runs the drive at the desired velocity.- Parameters:
velocities- Velocities in meters/sec
-
runCharacterization
public void runCharacterization(double output) Runs the drive in a straight line with the specified drive output. -
joystickDrive
Returns a field-relative drive command that reads the gamepad's left stick for linear velocity and its right stick for rotation. Intended to be set as the drivetrain's default command.- Parameters:
gamepad- the driver's gamepad- Returns:
- the joystick drive command
-
joystickDrive
public Command joystickDrive(DoubleSupplier xSupplier, DoubleSupplier ySupplier, DoubleSupplier omegaSupplier) Returns a field-relative drive command from the given stick suppliers.- Parameters:
xSupplier- forward input in [-1, 1], positive forwardySupplier- leftward input in [-1, 1], positive leftomegaSupplier- counter-clockwise input in [-1, 1], positive counter-clockwise- Returns:
- the joystick drive command
-
stop
public void stop()Stops the drive. -
stopWithX
public void stopWithX()Stops the drive and turns the modules to an X arrangement to resist movement. The modules will return to their normal orientations the next time a nonzero velocity is requested. -
getWheelRadiusCharacterizationPositions
public double[] getWheelRadiusCharacterizationPositions()Returns the position of each module in radians. -
getFFCharacterizationVelocity
public double getFFCharacterizationVelocity()Returns the average velocity of the modules in rotations/sec (Phoenix native units). -
getPose
Returns the current odometry pose. -
getRotation
Returns the current odometry rotation. -
setPose
Resets the current odometry pose. -
addVisionMeasurement
-
getMaxLinearSpeedMetersPerSec
public double getMaxLinearSpeedMetersPerSec()Returns the maximum linear speed in meters per sec. -
getMaxAngularSpeedRadPerSec
public double getMaxAngularSpeedRadPerSec()Returns the maximum angular speed in radians per sec. -
getModuleTranslations
Returns an array of module translations.
-