SwerveSubsystem

object SwerveSubsystem : SubsystemBase

The subsystem that controls the swerve drive.

Author

Falon Clark

Since

1/15/2024

Properties

Link copied to clipboard

Whether the robot should drive field oriented or robot oriented.

Link copied to clipboard
val HeadingPID: PIDController

PID Controller for the heading of the robot. Currently not used, as feedforward is a much better solution to fix drift.

Link copied to clipboard

The maximum speed of the swerve drive

Link copied to clipboard
var swerveStates: StructArrayPublisher<SwerveModuleState>

SwerveModuleStates publisher for swerve display

Link copied to clipboard
var tab: ShuffleboardTab

The Shuffleboard tab for the SwerveSubsystem

Functions

Link copied to clipboard
fun addVisionMeasurement(measurement: Pose2d, timestamp: Double)

Add a vision measurement to the swerve drive's pose estimator.

Link copied to clipboard
fun calculateHeadingPID(measurement: Double, setpoint: Double): Double

Calculate the heading PID for the robot.

Link copied to clipboard

Configures PathPlanner's AutoBuilder.

Link copied to clipboard
fun drive(velocity: ChassisSpeeds)

Simple drive method that uses ChassisSpeeds to control the robot.

fun drive(translation: Translation2d, rotation: Double, fieldOriented: Boolean)

Simple drive method that translates and rotates the robot.

fun drive(translation: Translation2d, rotation: Double, fieldOriented: Boolean, centerOfRotation: Translation2d)

Advanced drive method that translates and rotates the robot, with a custom center of rotation.

Link copied to clipboard
fun getAutonomousCommand(autoName: String, setOdomAtStart: Boolean): Command

Gets a command that follows a path created in PathPlanner.

Link copied to clipboard
fun getDriveSysIDCommand(): Command

Generate a full command to SysID the drive motors

Link copied to clipboard
fun getDriveSysIDRoutine(): SysIdRoutine

Get a SysIdRoutine for the drive motors.

Link copied to clipboard
fun getFieldVelocity(): ChassisSpeeds?

Method to get the current field oriented velocity of the robot.

Link copied to clipboard
fun getHeading(): Rotation2d

Method to get the current heading of the robot.

Link copied to clipboard
fun getKinematics(): SwerveDriveKinematics

Method to get the Kinematics object of the swerve drive.

Link copied to clipboard
fun getPitch(): Rotation2d

Method to get the current pitch of the robot.

Link copied to clipboard
fun getPose(): Pose2d

Method to get the current pose of the robot.

Link copied to clipboard
fun getRobotVelocity(): ChassisSpeeds?

Method to get the current robot oriented velocity of the robot.

Link copied to clipboard
fun getSwerveController(): SwerveController

Method to get the SwerveController object of the swerve drive.

Link copied to clipboard
fun getSwerveDriveConfiguration(): SwerveDriveConfiguration

Method to get the SwerveDriveConfiguration object of the swerve drive.

Link copied to clipboard
fun getTargetSpeeds(vForward: Double, vSide: Double, angle: Rotation2d): ChassisSpeeds

Method to generate a ChassisSpeeds object from a desired X, Y, and Rotational velocity.

fun getTargetSpeeds(vForward: Double, vSide: Double, headingX: Double, headingY: Double): ChassisSpeeds

Method to generate a ChassisSpeeds object from a desired X, Y, and angle X and Y components.

Link copied to clipboard
fun lock()

Method to toggle the lock position of the swerve drive to prevent motion.

Link copied to clipboard
fun postTrajectory(trajectory: Trajectory)

Method to display a desired trajectory to a field2d object.

Link copied to clipboard
fun resetOdometry(initialHolonomicPose: Pose2d)

Method to reset the odometry of the robot to a desired pose.

Link copied to clipboard
fun setChassisSpeeds(chassisSpeeds: ChassisSpeeds)

Method to set the desired speeds of the swerve drive.

Link copied to clipboard

Method to toggle the motor's brakes.

Link copied to clipboard

Directly send voltage to the drive motors.

Link copied to clipboard
fun setVisionMeasurementStdDevs(stdDevX: Double, stdDevY: Double, stdDevTheta: Double)

Set the standard deviations of the vision measurements.

Link copied to clipboard
fun sysIdAngleMotorCommand(): Command

Return SysID command for angle motors from YAGSL

Link copied to clipboard
fun sysIdDriveMotor(): Command?

Return SysID command for drive motors from YAGSL

Link copied to clipboard

function to toggle field oriented drive

Link copied to clipboard
fun zeroGyro()

Method to zero the gyro.