Package frc.robot.subsystems
Class SwerveSubsystem
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frc.robot.subsystems.SwerveSubsystem
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable
,edu.wpi.first.wpilibj2.command.Subsystem
public class SwerveSubsystem
extends edu.wpi.first.wpilibj2.command.SubsystemBase
-
Constructor Summary
ConstructorsConstructorDescriptionThis subsystems manages all of the swerve drive logic and also gives data to odometry -
Method Summary
Modifier and TypeMethodDescriptionvoid
drive
(double forwardMetersPerSecond, double sidewaysMetersPerSecond, double radiansPerSecond, boolean fieldRelative, boolean rateLimit) Swerve drive function.void
driveRobotRelative
(edu.wpi.first.math.kinematics.ChassisSpeeds chassisSpeeds) Drive the robot withChassisSpeeds
(mainly used for path planner)edu.wpi.first.math.kinematics.ChassisSpeeds
Gets the robots chassis speed relative to the fieldedu.wpi.first.math.geometry.Pose2d
getPose()
Get robot's pose.edu.wpi.first.math.estimator.SwerveDrivePoseEstimator
Get the pose estimator instanceedu.wpi.first.math.kinematics.ChassisSpeeds
Get the speed of the chassis relative to the robotdouble
heading()
Get current heading of robotvoid
periodic()
void
Resets swerve encodersvoid
setModuleStates
(edu.wpi.first.math.kinematics.SwerveModuleState[] desiredStates) Sets states of swerve modulesvoid
setX()
Set wheels to an X configuration for docking procedure.void
setZero()
Set wheels to a 0 configuration for calibration and testing.void
zeroGyro()
Reset the gyrovoid
Resets Gyro and odometryMethods 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
-
Constructor Details
-
SwerveSubsystem
public SwerveSubsystem()This subsystems manages all of the swerve drive logic and also gives data to odometry
-
-
Method Details
-
periodic
public void periodic() -
getPose
public edu.wpi.first.math.geometry.Pose2d getPose()Get robot's pose.- Returns:
- Returns the robots current position of the field as a
Pose2d
-
heading
public double heading()Get current heading of robot- Returns:
- Heading of robot in radians
-
getPoseEstimator
public edu.wpi.first.math.estimator.SwerveDrivePoseEstimator getPoseEstimator()Get the pose estimator instance- Returns:
- Instance of the
SwerveDrivePoseEstimator
-
driveRobotRelative
public void driveRobotRelative(edu.wpi.first.math.kinematics.ChassisSpeeds chassisSpeeds) Drive the robot withChassisSpeeds
(mainly used for path planner)- Parameters:
chassisSpeeds
-ChassisSpeeds
object
-
getRobotRelativeSpeeds
public edu.wpi.first.math.kinematics.ChassisSpeeds getRobotRelativeSpeeds()Get the speed of the chassis relative to the robot- Returns:
ChassisSpeeds
of the current robots speed
-
getFieldRelativeChassisSpeeds
public edu.wpi.first.math.kinematics.ChassisSpeeds getFieldRelativeChassisSpeeds()Gets the robots chassis speed relative to the field- Returns:
- Returns robot speed as a
ChassisSpeeds
in meters/second
-
drive
public void drive(double forwardMetersPerSecond, double sidewaysMetersPerSecond, double radiansPerSecond, boolean fieldRelative, boolean rateLimit) Swerve drive function.- Parameters:
forwardMetersPerSecond
- The target forward m/ssidewaysMetersPerSecond
- The target sideways m/sradiansPerSecond
- The target Rad/sfieldRelative
- If the robot is robot relative (forwards is front of robot) or field relative (forward is opposite side of field)rateLimit
- If we should apply slew rates (should always be true unless you know what your doing)
-
setX
public void setX()Set wheels to an X configuration for docking procedure. -
setZero
public void setZero()Set wheels to a 0 configuration for calibration and testing. -
zeroGyro
public void zeroGyro()Reset the gyro -
zeroGyroAndOdometry
public void zeroGyroAndOdometry()Resets Gyro and odometry -
setModuleStates
public void setModuleStates(edu.wpi.first.math.kinematics.SwerveModuleState[] desiredStates) Sets states of swerve modules- Parameters:
desiredStates
- target states for the swerve modules (requires a list of 4SwerveModuleState
s)
-
resetEncoders
public void resetEncoders()Resets swerve encoders
-