Package frclib.drivebase
Class FrcSwerveDrive
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
frclib.drivebase.FrcRobotDrive
frclib.drivebase.FrcSwerveDrive
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable
,edu.wpi.first.wpilibj2.command.Subsystem
This class creates the FrcSwerve drive base subsystem that consists of wheel motors and related objects for
driving a swerve robot.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
This specifies different absolute encoder types supported for Swerve steering.static class
This class contains Swerve Robot Info.Nested classes/interfaces inherited from class frclib.drivebase.FrcRobotDrive
FrcRobotDrive.ImuType, FrcRobotDrive.RobotInfo, FrcRobotDrive.VisionInfo
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal TrcEncoder[]
final TrcMotor[]
final TrcSwerveModule[]
final TrcDbgTrace
Fields inherited from class frclib.drivebase.FrcRobotDrive
driveBase, driveMotors, imu, INDEX_LEFT_BACK, INDEX_LEFT_CENTER, INDEX_LEFT_FRONT, INDEX_RIGHT_BACK, INDEX_RIGHT_CENTER, INDEX_RIGHT_FRONT, pidDrive, purePursuitDrive, robotInfo
-
Constructor Summary
ConstructorsConstructorDescriptionFrcSwerveDrive
(FrcSwerveDrive.SwerveInfo swerveInfo) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionint
displaySteerZeroCalibration
(int lineNum) This method displays the steer zero calibration progress to the dashboard.edu.wpi.first.math.geometry.Rotation2d
edu.wpi.first.math.geometry.Rotation2d
edu.wpi.first.math.kinematics.SwerveModulePosition[]
edu.wpi.first.math.geometry.Pose2d
getPose()
void
periodic()
double[]
This method reads the steering zero calibration data from the calibration data file.void
This method is called periodically to sample the steer encoders for averaging the zero position data.void
saveSteeringCalibrationData
(double[] zeros) This method saves the calibration data to a file on the Robot Controller.void
setHeading
(edu.wpi.first.math.geometry.Rotation2d heading) void
setModuleStates
(edu.wpi.first.math.kinematics.SwerveModuleState[] desiredStates) void
setPose
(edu.wpi.first.math.geometry.Pose2d pose) void
setSteerAngle
(double angle, boolean optimize, boolean hold) This method sets the steering angle of all swerve modules.void
setXModeEnabled
(String owner, boolean enabled) This method set all the wheels into an X configuration so that nobody can bump us out of position.void
This method starts the steering calibration.void
This method stops the steering calibration and saves the calibration data to a file.void
Methods inherited from class frclib.drivebase.FrcRobotDrive
cancel, cancel, configDriveBase, getGyroPitch, getGyroRoll, getGyroYaw
Methods 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, startRun
-
Field Details
-
tracer
-
swerveInfo
-
steerEncoders
-
steerMotors
-
swerveModules
-
-
Constructor Details
-
FrcSwerveDrive
Constructor: Create an instance of the object.- Parameters:
swerveInfo
- specifies the Swerve Robot Info.
-
-
Method Details
-
setSteerAngle
public void setSteerAngle(double angle, boolean optimize, boolean hold) This method sets the steering angle of all swerve modules.- Parameters:
angle
- specifies the steer angle.optimize
- specifies true to optimize (only turns within +/- 90 degrees), false otherwse.hold
- specifies true to hold the angle, false otherwise.
-
setXModeEnabled
This method set all the wheels into an X configuration so that nobody can bump us out of position. If owner is specifies, it will acquire execlusive ownership of the drivebase on behalf of the specified owner. On disable, it will release the ownership.- Parameters:
owner
- specifies the ID string of the caller for checking ownership, can be null if caller is not ownership aware.enabled
- specifies true to enable anti-defense mode, false to disable.
-
displaySteerZeroCalibration
public int displaySteerZeroCalibration(int lineNum) This method displays the steer zero calibration progress to the dashboard.- Parameters:
lineNum
- specifies the starting line number to display the info on the dashboard.- Returns:
- updated line number to the next available line on the dashboard.
-
startSteeringCalibration
public void startSteeringCalibration()This method starts the steering calibration. -
stopSteeringCalibration
public void stopSteeringCalibration()This method stops the steering calibration and saves the calibration data to a file. -
runSteeringCalibration
public void runSteeringCalibration()This method is called periodically to sample the steer encoders for averaging the zero position data. -
saveSteeringCalibrationData
public void saveSteeringCalibrationData(double[] zeros) This method saves the calibration data to a file on the Robot Controller.- Parameters:
zeros
- specifies the steering zero calibration data to be saved.
-
readSteeringCalibrationData
public double[] readSteeringCalibrationData()This method reads the steering zero calibration data from the calibration data file.- Returns:
- calibration data of all four swerve modules.
-
setModuleStates
public void setModuleStates(edu.wpi.first.math.kinematics.SwerveModuleState[] desiredStates) -
getModulePositions
public edu.wpi.first.math.kinematics.SwerveModulePosition[] getModulePositions() -
getPose
public edu.wpi.first.math.geometry.Pose2d getPose() -
setPose
public void setPose(edu.wpi.first.math.geometry.Pose2d pose) -
getHeading
public edu.wpi.first.math.geometry.Rotation2d getHeading() -
setHeading
public void setHeading(edu.wpi.first.math.geometry.Rotation2d heading) -
zeroHeading
public void zeroHeading() -
getGyroAngle
public edu.wpi.first.math.geometry.Rotation2d getGyroAngle() -
periodic
public void periodic()
-