Package yams.mechanisms.swerve
Class SwerveDrive
java.lang.Object
yams.mechanisms.swerve.SwerveDrive
Swerve Drive mechanism
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVisionMeasurement(Pose2d robotPose, double timestamp) Add a vision measurement to theSwerveDrivePoseEstimatorand update the gyro reading with the given timestamp of the vision measurement.voidaddVisionMeasurement(Pose2d robotPose, double timestamp, Matrix<N3, N1> visionMeasurementStdDevs) Add a vision measurement to theSwerveDrivePoseEstimatorand update the gyro reading with the given timestamp of the vision measurement.drive(Supplier<ChassisSpeeds> robotRelativeChassisSpeeds) Create aRunCommandto drive the swerve drive with robot relative chassis speeds.driveToPose(Pose2d pose) Drive the robot to the given pose.Get the angle difference between the robot's current pose and the given pose.Get theSwerveDriveConfigof the drive.getDistanceFromPose(Pose2d pose) Get theDistancefrom the given pose to the robot.Get the field relative speed of the drive.Get the Gyro Angle.Create theSwerveDriveKinematicsso you can recreate a newSwerveDrivePoseEstimator.Get theSwerveModulePositionof the modules.Get theSwerveModuleStateof the modules.getName()Get the name of the drive.getPose()Gets the measured pose (position and rotation) of the robot, as reported by odometry.Get the robot relative speed of the drive.getStateFromRobotRelativeChassisSpeeds(ChassisSpeeds robotRelativeChassisSpeeds) Get theSwerveModuleStates of the swerve drive given a robot relative chassis speed..voidlockPose()Point all modules toward the robot center, thus making the robot very difficult to move.voidResets the azimuth PID controller.voidresetOdometry(Pose2d pose) Resets odometry to the given pose.voidResets the translation PID controller.voidsetFieldRelativeChassisSpeeds(ChassisSpeeds fieldRelativeChassisSpeeds) Set field relative chassis speeds.voidsetRobotRelativeChassisSpeeds(ChassisSpeeds robotRelativeChassisSpeeds) Set robot relative chassis speeds.voidsetSwerveModuleStates(SwerveModuleState[] states) Set theSwerveModuleStates of the swerve drive directly.voidsetVisionMeasurementStdDevs(Matrix<N3, N1> visionMeasurementStdDevs) Sets the pose estimator's trust of global measurements.voidSimulate the drive, updating the gyroscope based off of module states.voidUpdate the telemetry andSwerveDrivePoseEstimatorof the drive.voidzeroGyro()Resets the gyro angle to zero and resets odometry to the same position, but facing toward 0 (red alliance station).
-
Constructor Details
-
SwerveDrive
Create a SwerveDrive.- Parameters:
config-SwerveDriveConfigfor the drive.
-
-
Method Details
-
drive
Create aRunCommandto drive the swerve drive with robot relative chassis speeds.- Parameters:
robotRelativeChassisSpeeds-Supplier<ChassisSpeeds>for the robot relative chassis speeds. Could also useSwerveInputStream- Returns:
RunCommandto drive the swerve drive.- Implementation Note:
- Not compatible with AdvantageKit
-
getGyroAngle
Get the Gyro Angle.- Returns:
- Gyro angle, or maple sim odometry gyro angle.
-
lockPose
public void lockPose()Point all modules toward the robot center, thus making the robot very difficult to move. Forcing the robot to keep the current pose.- Implementation Note:
- Not compatible with AdvantageKit
-
setSwerveModuleStates
Set theSwerveModuleStates of the swerve drive directly.- Parameters:
states-SwerveModuleStates to use, must be the same count as the swerve drive is configured order is Clockwise from FL.- Implementation Note:
- Not compatible with AdvantageKit if MapleSim is defined.
-
getStateFromRobotRelativeChassisSpeeds
public SwerveModuleState[] getStateFromRobotRelativeChassisSpeeds(ChassisSpeeds robotRelativeChassisSpeeds) Get theSwerveModuleStates of the swerve drive given a robot relative chassis speed..- Parameters:
robotRelativeChassisSpeeds- Robot relativeChassisSpeeds.- Returns:
SwerveModuleStates of the swerve drive.
-
setRobotRelativeChassisSpeeds
Set robot relative chassis speeds.- Parameters:
robotRelativeChassisSpeeds- Robot relative chassis speeds.
-
setFieldRelativeChassisSpeeds
Set field relative chassis speeds.- Parameters:
fieldRelativeChassisSpeeds- Field relative chassis speeds.
-
getPose
Gets the measured pose (position and rotation) of the robot, as reported by odometry.- Returns:
- The robot's pose
-
getKinematics
Create theSwerveDriveKinematicsso you can recreate a newSwerveDrivePoseEstimator.- Returns:
SwerveDriveKinematics
-
zeroGyro
public void zeroGyro()Resets the gyro angle to zero and resets odometry to the same position, but facing toward 0 (red alliance station).- Implementation Note:
- Not compatible with AdvantageKit
-
getName
Get the name of the drive.- Returns:
- Name of the drive.
-
resetOdometry
Resets odometry to the given pose. Gyro angle and module positions do not need to be reset when calling this method. However, if either gyro angle or module position is reset, this must be called in order for odometry to keep working.- Parameters:
pose- The pose to set the odometry to. Field relative, blue-origin where 0deg is facing towards RED alliance.
-
resetAzimuthPID
public void resetAzimuthPID()Resets the azimuth PID controller. -
resetTranslationPID
public void resetTranslationPID()Resets the translation PID controller. -
getDistanceFromPose
Get theDistancefrom the given pose to the robot. -
getAngleDifferenceFromPose
Get the angle difference between the robot's current pose and the given pose. -
driveToPose
Drive the robot to the given pose. -
addVisionMeasurement
public void addVisionMeasurement(Pose2d robotPose, double timestamp, Matrix<N3, N1> visionMeasurementStdDevs) Add a vision measurement to theSwerveDrivePoseEstimatorand update the gyro reading with the given timestamp of the vision measurement.- Parameters:
robotPose- RobotPose2das measured by vision.timestamp- Timestamp the measurement was taken as time since startup, should be taken fromTimer.getFPGATimestamp()or similar sources.visionMeasurementStdDevs- Vision measurement standard deviation that will be sent to theSwerveDrivePoseEstimator.The standard deviation of the vision measurement, for best accuracy calculate the standard deviation at 2 or more points and fit a line to it with the calculated optimal standard deviation. (Units should be meters per pixel). By optimizing this you can get * vision accurate to inches instead of feet.
-
setVisionMeasurementStdDevs
Sets the pose estimator's trust of global measurements. This might be used to change trust in vision measurements after the autonomous period, or to change trust as distance to a vision target increases.- Parameters:
visionMeasurementStdDevs- Standard deviations of the vision measurements. Increase these numbers to trust global measurements from vision less. This matrix is in the form [x, y, theta], with units in meters and radians.
-
addVisionMeasurement
Add a vision measurement to theSwerveDrivePoseEstimatorand update the gyro reading with the given timestamp of the vision measurement.- Parameters:
robotPose- RobotPose2das measured by vision.timestamp- Timestamp the measurement was taken as time since startup, should be taken fromTimer.getFPGATimestamp()or similar sources.
-
updateTelemetry
public void updateTelemetry()Update the telemetry andSwerveDrivePoseEstimatorof the drive. -
simIterate
public void simIterate()Simulate the drive, updating the gyroscope based off of module states. -
getRobotRelativeSpeed
Get the robot relative speed of the drive.- Returns:
- Robot relative speed of the drive.
-
getFieldRelativeSpeed
Get the field relative speed of the drive.- Returns:
- Field relative speed of the drive.
-
getModulePositions
Get theSwerveModulePositionof the modules.- Returns:
SwerveModulePositionof the modules.
-
getModuleStates
Get theSwerveModuleStateof the modules.- Returns:
SwerveModuleStateof the modules.
-
getConfig
Get theSwerveDriveConfigof the drive.- Returns:
SwerveDriveConfigof the drive.
-