![]() |
FRC Paradigm Shift #1259
Documentation for the 2021 Robot
|
Public Types | |
using | SwerveModuleStates = wpi::array< SwerveModuleState, DriveConstants::kNumSwerveModules > |
Readable alias for array of swerve modules. More... | |
Public Member Functions | |
DriveSubsystem (Gyro *gyro) | |
void | Periodic () override |
Will be called periodically whenever the CommandScheduler runs. More... | |
void | Drive (meters_per_second_t xSpeed, meters_per_second_t ySpeed, radians_per_second_t rot, bool fieldRelative) |
void | RotationDrive (meters_per_second_t xSpeed, meters_per_second_t ySpeed, radian_t rot, bool fieldRelative) |
void | RotationDrive (meters_per_second_t xSpeed, meters_per_second_t ySpeed, double xRot, double yRot, bool fieldRelative) |
void | HeadingDrive (meters_per_second_t xSpeed, meters_per_second_t ySpeed, radians_per_second_t rot, bool fieldRelative) |
void | UpdateLastHeading () |
Updates the last heading set for Heading Drive. Needs to be called if transitioning from other Drive functions to HeadingDrive. More... | |
void | ResetEncoders () |
Resets the drive encoders to currently read a position of 0. More... | |
void | SetModuleStates (SwerveModuleStates desiredStates) |
Sets the drive SpeedControllers to a power from -1 to 1. More... | |
Pose2d | GetPose () |
double | PWMToPulseWidth (CANifier::PWMChannel pwmChannel) |
void | ResetOdometry (Pose2d pose) |
void | WheelsForward () |
Set all 4 wheels to the zero position. More... | |
void | ResetRelativeToAbsolute () |
Resync all relative NEO turn encoders to the absolute encoders. More... | |
Public Attributes | |
SwerveDriveKinematics< kNumSwerveModules > | kDriveKinematics |
The kinematics object converts inputs into 4 individual swerve module turn angle and wheel speeds. More... | |
Private Member Functions | |
SwerveModuleStates | getCurrentWheelSpeeds () |
Get all 4 swerve module wheel speed to update the odometry with. More... | |
Private Attributes | |
CANifier | m_canifier |
Reads the absolute encoder pulse widths. More... | |
Gyro * | m_gyro |
Gyro to determine field relative driving, from RobotContainer. More... | |
SwerveDriveOdometry< DriveConstants::kNumSwerveModules > | m_odometry |
Odometry class for tracking robot pose. More... | |
frc2::PIDController | m_rotationPIDController |
PID to control overall robot chassis rotation. More... | |
double | m_lastHeading |
Last maintained heading, used for HeadingDrive. More... | |
bool | m_rotationalInput |
Whether or not rotation input was provided, used for HeadingDrive. More... | |
Swerve Modules | |
The drive subsystem owns all 4 swerve modules | |
SwerveModule | m_frontLeft |
SwerveModule | m_frontRight |
SwerveModule | m_rearRight |
SwerveModule | m_rearLeft |
Definition at line 37 of file DriveSubsystem.h.
using DriveSubsystem::SwerveModuleStates = wpi::array<SwerveModuleState, DriveConstants::kNumSwerveModules> |
Readable alias for array of swerve modules.
Definition at line 101 of file DriveSubsystem.h.
< Order as returned by kDriveKinematics.ToSwerveModuleStates
Enumerator | |
---|---|
kFrontLeft | |
kFrontRight | |
kRearLeft | |
kRearRight |
Definition at line 40 of file DriveSubsystem.h.
DriveSubsystem::DriveSubsystem | ( | Gyro * | gyro | ) |
Definition at line 11 of file DriveSubsystem.cpp.
References Gyro::GetHeadingAsRot2d(), DriveConstants::kCanifierID, kDriveKinematics, DriveConstants::kFrontLeftDriveMotorPort, DriveConstants::kFrontLeftDriveMotorReversed, DriveConstants::kFrontLeftOffset, DriveConstants::kFrontLeftPWM, DriveConstants::kFrontLeftTurningMotorPort, DriveConstants::kFrontRightDriveMotorPort, DriveConstants::kFrontRightDriveMotorReversed, DriveConstants::kFrontRightOffset, DriveConstants::kFrontRightPWM, DriveConstants::kFrontRightTurningMotorPort, DriveConstants::kRearLeftDriveMotorPort, DriveConstants::kRearLeftDriveMotorReversed, DriveConstants::kRearLeftOffset, DriveConstants::kRearLeftPWM, DriveConstants::kRearLeftTurningMotorPort, DriveConstants::kRearRightDriveMotorPort, DriveConstants::kRearRightDriveMotorReversed, DriveConstants::kRearRightOffset, DriveConstants::kRearRightPWM, DriveConstants::kRearRightTurningMotorPort, DriveConstants::kRotationDriveIMaxRange, DriveConstants::kRotationDriveTolerance, m_canifier, m_frontRight, m_gyro, m_lastHeading, m_odometry, m_rearLeft, m_rearRight, m_rotationalInput, m_rotationPIDController, and PWMToPulseWidth().
|
override |
Will be called periodically whenever the CommandScheduler runs.
Definition at line 83 of file DriveSubsystem.cpp.
References Gyro::GetHeadingAsRot2d(), SwerveModule::GetState(), m_frontLeft, m_frontRight, m_gyro, m_odometry, m_rearLeft, m_rearRight, and SwerveModule::Periodic().
void DriveSubsystem::Drive | ( | meters_per_second_t | xSpeed, |
meters_per_second_t | ySpeed, | ||
radians_per_second_t | rot, | ||
bool | fieldRelative | ||
) |
Drives the robot at given x, y and theta speeds. Speeds range from [-1, 1] and the linear speeds have no effect on the angular speed.
xSpeed | Speed of the robot in the x direction (forward/backwards). |
ySpeed | Speed of the robot in the y direction (sideways). |
rot | Angular rate of the robot. |
fieldRelative | Whether the provided x and y speeds are relative to the field. |
isAuto | Whether the bot is using function for auto or not. False by default. |
Definition at line 177 of file DriveSubsystem.cpp.
References Gyro::GetHeadingAsRot2d(), kDriveKinematics, DriveConstants::kDriveSpeed, kFrontLeft, kFrontRight, kRearLeft, kRearRight, m_frontLeft, m_frontRight, m_gyro, m_rearLeft, m_rearRight, and SwerveModule::SetDesiredState().
void DriveSubsystem::RotationDrive | ( | meters_per_second_t | xSpeed, |
meters_per_second_t | ySpeed, | ||
radian_t | rot, | ||
bool | fieldRelative | ||
) |
xSpeed | Speed of the robot in the x direction (forward/backwards). |
ySpeed | Speed of the robot in the y direction (sideways). |
rot | Angle of the robot in radians |
fieldRelative | Whether the provided translational speeds are relative to the field. |
Definition at line 97 of file DriveSubsystem.cpp.
References Drive(), Gyro::GetHeadingAsRot2d(), Gyro::GetTurnRate(), DriveConstants::kRotationDriveDirectionLimit, DriveConstants::kRotationDriveMaxSpeed, m_gyro, m_rotationPIDController, and Util::NegPiToPiRads().
void DriveSubsystem::RotationDrive | ( | meters_per_second_t | xSpeed, |
meters_per_second_t | ySpeed, | ||
double | xRot, | ||
double | yRot, | ||
bool | fieldRelative | ||
) |
xSpeed | Speed of the robot in the x direction (forward/backwards). |
ySpeed | Speed of the robot in the y direction (sideways). |
xRot | Angle of the robot on the x axis |
yRot | Angle of the robot on the y axis |
fieldRelative | Whether the provided translational speeds are relative to the field. |
Definition at line 136 of file DriveSubsystem.cpp.
References Drive(), m_rotationalInput, and RotationDrive().
void DriveSubsystem::HeadingDrive | ( | meters_per_second_t | xSpeed, |
meters_per_second_t | ySpeed, | ||
radians_per_second_t | rot, | ||
bool | fieldRelative | ||
) |
Drives the robot and maintains robot angle with no rotational input
xSpeed | Speed of the robot in the x direction (forward/backwards). |
ySpeed | Speed of the robot in the y direction (sideways). |
rot | Angular rate of the robot. |
fieldRelative | Whether the provided x and y speeds are relative to the field. |
Definition at line 152 of file DriveSubsystem.cpp.
References Drive(), m_lastHeading, m_rotationalInput, RotationDrive(), and UpdateLastHeading().
void DriveSubsystem::UpdateLastHeading | ( | ) |
Updates the last heading set for Heading Drive. Needs to be called if transitioning from other Drive functions to HeadingDrive.
Definition at line 218 of file DriveSubsystem.cpp.
References Gyro::GetHeadingAsRot2d(), m_gyro, and m_lastHeading.
void DriveSubsystem::ResetEncoders | ( | ) |
Resets the drive encoders to currently read a position of 0.
Definition at line 223 of file DriveSubsystem.cpp.
References m_frontLeft, m_frontRight, m_rearLeft, m_rearRight, and SwerveModule::ResetEncoders().
void DriveSubsystem::SetModuleStates | ( | SwerveModuleStates | desiredStates | ) |
Sets the drive SpeedControllers to a power from -1 to 1.
Definition at line 209 of file DriveSubsystem.cpp.
References kDriveKinematics, kFrontLeft, kFrontRight, AutoConstants::kMaxSpeed, kRearLeft, kRearRight, m_frontLeft, m_frontRight, m_rearLeft, m_rearRight, and SwerveModule::SetDesiredState().
Pose2d DriveSubsystem::GetPose | ( | ) |
Returns the currently-estimated pose of the robot.
Definition at line 231 of file DriveSubsystem.cpp.
References m_odometry.
double DriveSubsystem::PWMToPulseWidth | ( | CANifier::PWMChannel | pwmChannel | ) |
Converts PWM input on the CANifier to a pulse width
pwmChannel | The PWM channel to pass in |
Definition at line 236 of file DriveSubsystem.cpp.
References DriveConstants::kPulseWidthToZeroOne, and m_canifier.
void DriveSubsystem::ResetOdometry | ( | Pose2d | pose | ) |
Resets the odometry to the specified pose.
pose | The pose to which to set the odometry. |
Definition at line 243 of file DriveSubsystem.cpp.
References Gyro::GetHeadingAsRot2d(), m_gyro, and m_odometry.
void DriveSubsystem::WheelsForward | ( | ) |
Set all 4 wheels to the zero position.
Definition at line 256 of file DriveSubsystem.cpp.
References m_frontLeft, m_frontRight, m_rearLeft, m_rearRight, and SwerveModule::SetDesiredState().
void DriveSubsystem::ResetRelativeToAbsolute | ( | ) |
Resync all relative NEO turn encoders to the absolute encoders.
Definition at line 248 of file DriveSubsystem.cpp.
References m_frontLeft, m_frontRight, m_rearLeft, m_rearRight, and SwerveModule::ResetRelativeToAbsolute().
|
inlineprivate |
Get all 4 swerve module wheel speed to update the odometry with.
Definition at line 133 of file DriveSubsystem.h.
SwerveDriveKinematics<kNumSwerveModules> DriveSubsystem::kDriveKinematics |
The kinematics object converts inputs into 4 individual swerve module turn angle and wheel speeds.
Definition at line 125 of file DriveSubsystem.h.
|
private |
Definition at line 147 of file DriveSubsystem.h.
|
private |
Definition at line 148 of file DriveSubsystem.h.
|
private |
Definition at line 149 of file DriveSubsystem.h.
|
private |
Definition at line 150 of file DriveSubsystem.h.
|
private |
Reads the absolute encoder pulse widths.
Definition at line 154 of file DriveSubsystem.h.
|
private |
Gyro to determine field relative driving, from RobotContainer.
Definition at line 156 of file DriveSubsystem.h.
|
private |
Odometry class for tracking robot pose.
Definition at line 158 of file DriveSubsystem.h.
|
private |
PID to control overall robot chassis rotation.
Definition at line 161 of file DriveSubsystem.h.
|
private |
Last maintained heading, used for HeadingDrive.
Definition at line 167 of file DriveSubsystem.h.
|
private |
Whether or not rotation input was provided, used for HeadingDrive.
Definition at line 169 of file DriveSubsystem.h.