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 TypeMethodDescriptionvoiddrive(double forwardMetersPerSecond, double sidewaysMetersPerSecond, double radiansPerSecond, boolean fieldRelative, boolean rateLimit) Swerve drive function.voiddriveRobotRelative(edu.wpi.first.math.kinematics.ChassisSpeeds chassisSpeeds) Drive the robot withChassisSpeeds(mainly used for path planner)edu.wpi.first.math.kinematics.ChassisSpeedsGets the robots chassis speed relative to the fieldedu.wpi.first.math.geometry.Pose2dgetPose()Get robot's pose.edu.wpi.first.math.estimator.SwerveDrivePoseEstimatorGet the pose estimator instanceedu.wpi.first.math.kinematics.ChassisSpeedsGet the speed of the chassis relative to the robotdoubleheading()Get current heading of robotvoidperiodic()voidResets swerve encodersvoidsetModuleStates(edu.wpi.first.math.kinematics.SwerveModuleState[] desiredStates) Sets states of swerve modulesvoidsetX()Set wheels to an X configuration for docking procedure.voidsetZero()Set wheels to a 0 configuration for calibration and testing.voidzeroGyro()Reset the gyrovoidResets Gyro and odometryMethods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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-ChassisSpeedsobject
-
getRobotRelativeSpeeds
public edu.wpi.first.math.kinematics.ChassisSpeeds getRobotRelativeSpeeds()Get the speed of the chassis relative to the robot- Returns:
ChassisSpeedsof 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
ChassisSpeedsin 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 4SwerveModuleStates)
-
resetEncoders
public void resetEncoders()Resets swerve encoders
-