FRC Paradigm Shift #1259
Documentation for the 2021 Robot
DriveSubsystem Class Reference
Inheritance diagram for DriveSubsystem:

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...
 
Gyrom_gyro
 Gyro to determine field relative driving, from RobotContainer. More...
 
SwerveDriveOdometry< DriveConstants::kNumSwerveModulesm_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
 

Detailed Description

Definition at line 37 of file DriveSubsystem.h.

Member Typedef Documentation

Readable alias for array of swerve modules.

Definition at line 101 of file DriveSubsystem.h.

Member Enumeration Documentation

< Order as returned by kDriveKinematics.ToSwerveModuleStates

Enumerator
kFrontLeft 
kFrontRight 
kRearLeft 
kRearRight 

Definition at line 40 of file DriveSubsystem.h.

Constructor & Destructor Documentation

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().

12  : m_frontLeft
13  {
16  , [this](CANifier::PWMChannel channel){ return PWMToPulseWidth(channel); }
20  , string("FrontLeft")
21  }
22  , m_frontRight
23  {
26  , [this](CANifier::PWMChannel channel){ return PWMToPulseWidth(channel); }
30  , string("FrontRight")
31  }
32  , m_rearRight
33  {
36  , [this](CANifier::PWMChannel channel){ return PWMToPulseWidth(channel); }
40  , string("RearRight")
41  }
42  , m_rearLeft
43  {
46  , [this](CANifier::PWMChannel channel){ return PWMToPulseWidth(channel); }
47  , kRearLeftPWM
50  , string("RearLeft")
51  }
53  , m_gyro(gyro)
55 {
56 
57  #ifdef MANUAL_MODULE_STATES
58  SmartDashboard::PutNumber("T_D_MFL", 0);
59  SmartDashboard::PutNumber("T_D_MFR", 0);
60  SmartDashboard::PutNumber("T_D_MRR", 0);
61  SmartDashboard::PutNumber("T_D_MRL", 0);
62  SmartDashboard::PutNumber("T_D_MFLV", 0);
63  SmartDashboard::PutNumber("T_D_MFRV", 0);
64  SmartDashboard::PutNumber("T_D_MRRV", 0);
65  SmartDashboard::PutNumber("T_D_MRLV", 0);
66  #endif
67 
68  #ifdef TUNE_ROTATION_DRIVE
69  SmartDashboard::PutNumber("T_D_RP", 0);
70  SmartDashboard::PutNumber("T_D_RI", 0);
71  SmartDashboard::PutNumber("T_D_RD", 0);
72  SmartDashboard::PutNumber("T_D_RMax", 0);
73  SmartDashboard::PutNumber("T_D_RTMax", 0);
74  #endif
75 
77  m_rotationPIDController.SetIntegratorRange(0, kRotationDriveIMaxRange);
78 
79  m_lastHeading = 0;
80  m_rotationalInput = true;
81 }
constexpr int kCanifierID
CANifier CAN ID (for absolute encoder PWM inputs)
Definition: Constants.h:42
frc::Rotation2d GetHeadingAsRot2d()
Definition: Gyro.h:22
constexpr double kFrontRightOffset
Definition: Constants.h:89
constexpr CANifier::PWMChannel kFrontRightPWM
Definition: Constants.h:61
constexpr int kRearRightDriveMotorPort
Rear Right Drive CAN ID (TalonFX)
Definition: Constants.h:50
SwerveDriveOdometry< DriveConstants::kNumSwerveModules > m_odometry
Odometry class for tracking robot pose.
constexpr int kFrontLeftDriveMotorPort
Front Left Drive CAN ID (TalonFX)
Definition: Constants.h:44
CANifier m_canifier
Reads the absolute encoder pulse widths.
constexpr double kRearRightOffset
Definition: Constants.h:90
constexpr double kRotationDriveTolerance
Tolerance for turning.
Definition: Constants.h:113
frc2::PIDController m_rotationPIDController
PID to control overall robot chassis rotation.
SwerveModule m_frontRight
constexpr int kFrontRightTurningMotorPort
Front Right Turn CAN ID (SparkMAX)
Definition: Constants.h:48
double PWMToPulseWidth(CANifier::PWMChannel pwmChannel)
constexpr int kFrontRightDriveMotorPort
Front Right Drive CAN ID (TalonFX)
Definition: Constants.h:47
double m_lastHeading
Last maintained heading, used for HeadingDrive.
constexpr int kRearLeftDriveMotorPort
Rear Left Drive CAN ID (TalonFX)
Definition: Constants.h:53
constexpr CANifier::PWMChannel kRearLeftPWM
Definition: Constants.h:63
Gyro * m_gyro
Gyro to determine field relative driving, from RobotContainer.
constexpr int kFrontLeftTurningMotorPort
Front Left Turn CAN ID (SparkMAX)
Definition: Constants.h:45
constexpr double kRearLeftOffset
Definition: Constants.h:91
constexpr double kFrontLeftOffset
Definition: Constants.h:88
constexpr bool kRearRightDriveMotorReversed
Definition: Constants.h:72
constexpr CANifier::PWMChannel kFrontLeftPWM
Definition: Constants.h:60
constexpr int kRearRightTurningMotorPort
Rear Right Turn CAN ID (SparkMAX)
Definition: Constants.h:51
constexpr bool kFrontRightDriveMotorReversed
Definition: Constants.h:71
constexpr bool kRearLeftDriveMotorReversed
Definition: Constants.h:70
constexpr int kRearLeftTurningMotorPort
Definition: Constants.h:54
constexpr CANifier::PWMChannel kRearRightPWM
Definition: Constants.h:62
constexpr double kRotationDriveIMaxRange
Definition: Constants.h:106
SwerveModule m_rearRight
constexpr bool kFrontLeftDriveMotorReversed
Definition: Constants.h:69
SwerveDriveKinematics< kNumSwerveModules > kDriveKinematics
The kinematics object converts inputs into 4 individual swerve module turn angle and wheel speeds...
SwerveModule m_frontLeft
bool m_rotationalInput
Whether or not rotation input was provided, used for HeadingDrive.
SwerveModule m_rearLeft

Member Function Documentation

void DriveSubsystem::Periodic ( )
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().

84 {
89  , m_rearRight.GetState());
90 
95 }
frc::Rotation2d GetHeadingAsRot2d()
Definition: Gyro.h:22
SwerveDriveOdometry< DriveConstants::kNumSwerveModules > m_odometry
Odometry class for tracking robot pose.
SwerveModule m_frontRight
Gyro * m_gyro
Gyro to determine field relative driving, from RobotContainer.
SwerveModuleState GetState()
SwerveModule m_rearRight
SwerveModule m_frontLeft
SwerveModule m_rearLeft
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.

Parameters
xSpeedSpeed of the robot in the x direction (forward/backwards).
ySpeedSpeed of the robot in the y direction (sideways).
rotAngular rate of the robot.
fieldRelativeWhether the provided x and y speeds are relative to the field.
isAutoWhether 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().

181 {
182  ChassisSpeeds chassisSpeeds;
183  if (fieldRelative)
184  chassisSpeeds = ChassisSpeeds::FromFieldRelativeSpeeds(xSpeed, ySpeed, rot, m_gyro->GetHeadingAsRot2d());
185  else
186  chassisSpeeds = ChassisSpeeds{xSpeed, ySpeed, rot};
187 
188  auto states = kDriveKinematics.ToSwerveModuleStates(chassisSpeeds);
189 
190  kDriveKinematics.NormalizeWheelSpeeds(&states, kDriveSpeed);
191 
192  #ifdef MANUAL_MODULE_STATES
193  states[kFrontLeft].angle = Rotation2d(radian_t(SmartDashboard::GetNumber("T_D_MFL", 0.0)));
194  states[kFrontRight].angle = Rotation2d(radian_t(SmartDashboard::GetNumber("T_D_MFR", 0.0)));
195  states[kRearRight].angle = Rotation2d(radian_t(SmartDashboard::GetNumber("T_D_MRR", 0.0)));
196  states[kRearLeft].angle = Rotation2d(radian_t(SmartDashboard::GetNumber("T_D_MRL", 0.0)));
197  states[kFrontLeft].speed = SmartDashboard::GetNumber("T_D_MFLV", 0.0) * 1_mps;
198  states[kFrontRight].speed = SmartDashboard::GetNumber("T_D_MFRV", 0.0) * 1_mps;
199  states[kRearRight].speed = SmartDashboard::GetNumber("T_D_MRRV", 0.0) * 1_mps;
200  states[kRearLeft].speed = SmartDashboard::GetNumber("T_D_MRLV", 0.0) * 1_mps;
201  #endif
202 
207 }
frc::Rotation2d GetHeadingAsRot2d()
Definition: Gyro.h:22
SwerveModule m_frontRight
void SetDesiredState(SwerveModuleState &state)
Gyro * m_gyro
Gyro to determine field relative driving, from RobotContainer.
constexpr auto kDriveSpeed
Definition: Constants.h:36
SwerveModule m_rearRight
SwerveDriveKinematics< kNumSwerveModules > kDriveKinematics
The kinematics object converts inputs into 4 individual swerve module turn angle and wheel speeds...
SwerveModule m_frontLeft
SwerveModule m_rearLeft
void DriveSubsystem::RotationDrive ( meters_per_second_t  xSpeed,
meters_per_second_t  ySpeed,
radian_t  rot,
bool  fieldRelative 
)
Parameters
xSpeedSpeed of the robot in the x direction (forward/backwards).
ySpeedSpeed of the robot in the y direction (sideways).
rotAngle of the robot in radians
fieldRelativeWhether 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().

101 {
102  double error = rot.to<double>() - m_gyro->GetHeadingAsRot2d().Radians().to<double>();
103  double desiredSet = Util::NegPiToPiRads(error);
104  double max = kRotationDriveMaxSpeed;
105  double maxTurn = kRotationDriveDirectionLimit;
106 
107  #ifdef TUNE_ROTATION_DRIVE
108  double P = SmartDashboard::GetNumber("T_D_RP", 0);
109  double I = SmartDashboard::GetNumber("T_D_RI", 0);
110  double D = SmartDashboard::GetNumber("T_D_RD", 0);
111  double m = SmartDashboard::GetNumber("T_D_RMax", 0);
112  double mTurn = SmartDashboard::GetNumber("T_D_RTMax", 0);
113 
114  m_rotationPIDController.SetP(P);
115  m_rotationPIDController.SetI(I);
116  m_rotationPIDController.SetD(D);
117  max = m;
118  maxTurn = mTurn;
119  #endif
120 
121  double desiredTurnRate = m_rotationPIDController.Calculate(0, desiredSet);
122 
123  double currentTurnRate = m_gyro->GetTurnRate() * wpi::math::pi / 180;
124 
125  // Prevent sharp turning if already fast going in the opposite direction
126  if ((abs(currentTurnRate) >= maxTurn) && (signbit(desiredTurnRate) != signbit(currentTurnRate)))
127  desiredTurnRate *= -1.0;
128 
129  // Power limiting
130  if (abs(desiredTurnRate) > max)
131  desiredTurnRate = signbit(desiredTurnRate) ? max * -1.0 : max;
132 
133  Drive(xSpeed, ySpeed, radians_per_second_t(desiredTurnRate), fieldRelative);
134 }
frc::Rotation2d GetHeadingAsRot2d()
Definition: Gyro.h:22
void Drive(meters_per_second_t xSpeed, meters_per_second_t ySpeed, radians_per_second_t rot, bool fieldRelative)
double GetTurnRate()
Definition: Gyro.cpp:20
constexpr double kRotationDriveMaxSpeed
Max speed for control.
Definition: Constants.h:109
static double NegPiToPiRads(double theta)
Definition: Util.cpp:35
constexpr double kRotationDriveDirectionLimit
Speeds higher than value will prevent robot from changing directions for a turn.
Definition: Constants.h:111
frc2::PIDController m_rotationPIDController
PID to control overall robot chassis rotation.
Gyro * m_gyro
Gyro to determine field relative driving, from RobotContainer.
void DriveSubsystem::RotationDrive ( meters_per_second_t  xSpeed,
meters_per_second_t  ySpeed,
double  xRot,
double  yRot,
bool  fieldRelative 
)
Parameters
xSpeedSpeed of the robot in the x direction (forward/backwards).
ySpeedSpeed of the robot in the y direction (sideways).
xRotAngle of the robot on the x axis
yRotAngle of the robot on the y axis
fieldRelativeWhether the provided translational speeds are relative to the field.

Definition at line 136 of file DriveSubsystem.cpp.

References Drive(), m_rotationalInput, and RotationDrive().

141 {
142  if (xRot != 0 || yRot != 0)
143  {
144  m_rotationalInput = true;
145  RotationDrive(xSpeed, ySpeed, radian_t(atan2f(yRot, xRot)), fieldRelative);
146  }
147  else
148  Drive(xSpeed, ySpeed, radians_per_second_t(0), fieldRelative);
149 
150 }
void RotationDrive(meters_per_second_t xSpeed, meters_per_second_t ySpeed, radian_t rot, bool fieldRelative)
void Drive(meters_per_second_t xSpeed, meters_per_second_t ySpeed, radians_per_second_t rot, bool fieldRelative)
bool m_rotationalInput
Whether or not rotation input was provided, used for HeadingDrive.
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

Parameters
xSpeedSpeed of the robot in the x direction (forward/backwards).
ySpeedSpeed of the robot in the y direction (sideways).
rotAngular rate of the robot.
fieldRelativeWhether 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().

156 {
157  if (xSpeed.to<double>() == 0 && ySpeed.to<double>() == 0 && rot.to<double>() == 0)
158  {
159  Drive(xSpeed, ySpeed, rot, fieldRelative);
160  return;
161  }
162 
163  if (rot.to<double>() == 0 && m_rotationalInput)
164  {
165  m_rotationalInput = false;
167  }
168  else if (rot.to<double>() != 0)
169  m_rotationalInput = true;
170 
171  if (!m_rotationalInput && (xSpeed.to<double>() != 0 || ySpeed.to<double>() != 0))
172  RotationDrive(xSpeed, ySpeed, radian_t(m_lastHeading), fieldRelative);
173  else
174  Drive(xSpeed, ySpeed, rot, fieldRelative);
175 }
void RotationDrive(meters_per_second_t xSpeed, meters_per_second_t ySpeed, radian_t rot, bool fieldRelative)
void Drive(meters_per_second_t xSpeed, meters_per_second_t ySpeed, radians_per_second_t rot, bool fieldRelative)
double m_lastHeading
Last maintained heading, used for HeadingDrive.
void UpdateLastHeading()
Updates the last heading set for Heading Drive. Needs to be called if transitioning from other Drive ...
bool m_rotationalInput
Whether or not rotation input was provided, used for HeadingDrive.
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.

219 {
220  m_lastHeading = m_gyro->GetHeadingAsRot2d().Radians().to<double>();
221 }
frc::Rotation2d GetHeadingAsRot2d()
Definition: Gyro.h:22
double m_lastHeading
Last maintained heading, used for HeadingDrive.
Gyro * m_gyro
Gyro to determine field relative driving, from RobotContainer.
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().

224 {
229 }
SwerveModule m_frontRight
void ResetEncoders()
Resets the drive motor encoders to 0.
SwerveModule m_rearRight
SwerveModule m_frontLeft
SwerveModule m_rearLeft
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().

210 {
211  kDriveKinematics.NormalizeWheelSpeeds(&desiredStates, AutoConstants::kMaxSpeed);
212  m_frontLeft.SetDesiredState(desiredStates[kFrontLeft]);
213  m_frontRight.SetDesiredState(desiredStates[kFrontRight]);
214  m_rearRight.SetDesiredState(desiredStates[kRearRight]);
215  m_rearLeft.SetDesiredState(desiredStates[kRearLeft]);
216 }
SwerveModule m_frontRight
void SetDesiredState(SwerveModuleState &state)
constexpr auto kMaxSpeed
Definition: Constants.h:163
SwerveModule m_rearRight
SwerveDriveKinematics< kNumSwerveModules > kDriveKinematics
The kinematics object converts inputs into 4 individual swerve module turn angle and wheel speeds...
SwerveModule m_frontLeft
SwerveModule m_rearLeft
Pose2d DriveSubsystem::GetPose ( )

Returns the currently-estimated pose of the robot.

Returns
The pose.

Definition at line 231 of file DriveSubsystem.cpp.

References m_odometry.

232 {
233  return m_odometry.GetPose();
234 }
SwerveDriveOdometry< DriveConstants::kNumSwerveModules > m_odometry
Odometry class for tracking robot pose.
double DriveSubsystem::PWMToPulseWidth ( CANifier::PWMChannel  pwmChannel)

Converts PWM input on the CANifier to a pulse width

Parameters
pwmChannelThe PWM channel to pass in
Returns
The pulse width of the PWM channel

Definition at line 236 of file DriveSubsystem.cpp.

References DriveConstants::kPulseWidthToZeroOne, and m_canifier.

237 {
238  double dutyCycleAndPeriod[2];
239  m_canifier.GetPWMInput(pwmChannel, dutyCycleAndPeriod);
240  return dutyCycleAndPeriod[0] * dutyCycleAndPeriod[1] / kPulseWidthToZeroOne;
241 }
CANifier m_canifier
Reads the absolute encoder pulse widths.
constexpr double kPulseWidthToZeroOne
Definition: Constants.h:98
void DriveSubsystem::ResetOdometry ( Pose2d  pose)

Resets the odometry to the specified pose.

Parameters
poseThe pose to which to set the odometry.

Definition at line 243 of file DriveSubsystem.cpp.

References Gyro::GetHeadingAsRot2d(), m_gyro, and m_odometry.

244 {
245  m_odometry.ResetPosition(pose, m_gyro->GetHeadingAsRot2d());
246 }
frc::Rotation2d GetHeadingAsRot2d()
Definition: Gyro.h:22
SwerveDriveOdometry< DriveConstants::kNumSwerveModules > m_odometry
Odometry class for tracking robot pose.
Gyro * m_gyro
Gyro to determine field relative driving, from RobotContainer.
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().

257 {
258  static SwerveModuleState zeroState { 0_mps, 0_deg };
259  printf("DriveSubsystem::WheelsForward() called");
260  m_frontLeft.SetDesiredState(zeroState);
261  m_frontRight.SetDesiredState(zeroState);
262  m_rearRight.SetDesiredState(zeroState);
263  m_rearLeft.SetDesiredState(zeroState);
264 }
SwerveModule m_frontRight
void SetDesiredState(SwerveModuleState &state)
SwerveModule m_rearRight
SwerveModule m_frontLeft
SwerveModule m_rearLeft
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().

249 {
254 }
SwerveModule m_frontRight
void ResetRelativeToAbsolute()
Resync the relative NEO turn encoder to the absolute encoder.
SwerveModule m_rearRight
SwerveModule m_frontLeft
SwerveModule m_rearLeft
SwerveModuleStates DriveSubsystem::getCurrentWheelSpeeds ( )
inlineprivate

Get all 4 swerve module wheel speed to update the odometry with.

Definition at line 133 of file DriveSubsystem.h.

134  {
135  SwerveModuleStates sms({
140  });
141  return sms;
142  }
SwerveModule m_frontRight
wpi::array< SwerveModuleState, DriveConstants::kNumSwerveModules > SwerveModuleStates
Readable alias for array of swerve modules.
SwerveModuleState GetState()
SwerveModule m_rearRight
SwerveModule m_frontLeft
SwerveModule m_rearLeft

Member Data Documentation

SwerveDriveKinematics<kNumSwerveModules> DriveSubsystem::kDriveKinematics
Initial value:
{
Translation2d( kWheelBase / 2, kTrackWidth / 2),
Translation2d( kWheelBase / 2, -kTrackWidth / 2),
Translation2d(-kWheelBase / 2, kTrackWidth / 2),
Translation2d(-kWheelBase / 2, -kTrackWidth / 2)}

The kinematics object converts inputs into 4 individual swerve module turn angle and wheel speeds.

Definition at line 125 of file DriveSubsystem.h.

SwerveModule DriveSubsystem::m_frontLeft
private

Definition at line 147 of file DriveSubsystem.h.

SwerveModule DriveSubsystem::m_frontRight
private

Definition at line 148 of file DriveSubsystem.h.

SwerveModule DriveSubsystem::m_rearRight
private

Definition at line 149 of file DriveSubsystem.h.

SwerveModule DriveSubsystem::m_rearLeft
private

Definition at line 150 of file DriveSubsystem.h.

CANifier DriveSubsystem::m_canifier
private

Reads the absolute encoder pulse widths.

Definition at line 154 of file DriveSubsystem.h.

Gyro* DriveSubsystem::m_gyro
private

Gyro to determine field relative driving, from RobotContainer.

Definition at line 156 of file DriveSubsystem.h.

SwerveDriveOdometry<DriveConstants::kNumSwerveModules> DriveSubsystem::m_odometry
private

Odometry class for tracking robot pose.

Definition at line 158 of file DriveSubsystem.h.

frc2::PIDController DriveSubsystem::m_rotationPIDController
private
Initial value:

PID to control overall robot chassis rotation.

Definition at line 161 of file DriveSubsystem.h.

double DriveSubsystem::m_lastHeading
private

Last maintained heading, used for HeadingDrive.

Definition at line 167 of file DriveSubsystem.h.

bool DriveSubsystem::m_rotationalInput
private

Whether or not rotation input was provided, used for HeadingDrive.

Definition at line 169 of file DriveSubsystem.h.


The documentation for this class was generated from the following files: