Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
control::SwerveController Class Reference

Controller to handle the wheel rotations for driving with swerve modes. More...

#include <SwerveController.h>

Public Member Functions

 SwerveController (double baseWidth, double baseLength, int epsilon)
 Construct a new controller object.
 
drive_commands_t setTurnInPlaceCmdVel (double dtheta, const swerve_rots_t &wheel_rots) const
 Request the robot to turn in place using swerve.
 
drive_commands_t setTurnInPlaceCmdVel (double dtheta, const swerve_rots_t &wheel_rots, double &scaleFactor) const
 Request the robot to turn in place using swerve.
 
drive_commands_t setCrabCmdVel (double dtheta, double dy, const swerve_rots_t &wheel_rots) const
 Request the robot to drive side to side and turn with given velocities using swerve.
 
drive_commands_t setCrabCmdVel (double dtheta, double dy, const swerve_rots_t &wheel_rots, double &scaleFactor) const
 Request the robot to drive side to side and turn with given velocities using swerve.
 
const kinematics::SwerveDriveKinematicsswerveKinematics () const
 Get the SwerveDriveKinematics object used by the controller.
 
void setOverride (bool override)
 Set the override flag for wheel rotation checking.
 
bool isOverridden () const
 Check the override flag for wheel rotation checking.
 
DriveMode getDriveMode () const
 Get the current drive mode of the controller.
 
swerve_rots_t setDriveMode (DriveMode mode)
 Set the drive mode of the controller.
 
bool checkWheelRotation (DriveMode mode, const swerve_rots_t &wheel_rots) const
 Check to see if all wheels are at their target position.
 
swerve_rots_t getSteerRots (DriveMode mode) const
 Get the wheel steer rotations for a given drive mode in millidegrees.
 

Detailed Description

Controller to handle the wheel rotations for driving with swerve modes.

Constructor & Destructor Documentation

◆ SwerveController()

control::SwerveController::SwerveController ( double baseWidth,
double baseLength,
int epsilon )

Construct a new controller object.

Parameters
baseWidthThe width of the wheelbase. The units themselves don't matter, as long as you're consistent.
baseLengthThe length of the wheelbase. The units themselves don't matter, as long as you're consistent.
epsilonThe allowable error from the actual wheel rotation to the wheel rotations defined by DRIVE_MODE to process a drive request

Member Function Documentation

◆ checkWheelRotation()

bool SwerveController::checkWheelRotation ( DriveMode mode,
const swerve_rots_t & wheel_rots ) const

Check to see if all wheels are at their target position.

Parameters
modeThe drive mode to compare wheel rotations against.
wheel_rotsThe rotation of all four wheels in millidegrees
Returns
bool if the wheels are within STEER_EPSILON of their target position OR if overide_steer_check is true.

◆ getDriveMode()

DriveMode SwerveController::getDriveMode ( ) const

Get the current drive mode of the controller.

Returns
DriveMode The current drive mode.

◆ isOverridden()

bool SwerveController::isOverridden ( ) const

Check the override flag for wheel rotation checking.

Returns
True iff the rotation checking is overridden.

◆ setCrabCmdVel() [1/2]

drive_commands_t SwerveController::setCrabCmdVel ( double dtheta,
double dy,
const swerve_rots_t & wheel_rots ) const

Request the robot to drive side to side and turn with given velocities using swerve.

Essentially rotate the reference frame of the robot by 90 degrees CCW.

Parameters
dthetaThe heading velocity.
dyThe side-to-side velocity.
wheel_rotsThe rotation of all four wheels in millidegrees
Returns
drive_commands_t The power commands for all four wheels.

◆ setCrabCmdVel() [2/2]

drive_commands_t SwerveController::setCrabCmdVel ( double dtheta,
double dy,
const swerve_rots_t & wheel_rots,
double & scaleFactor ) const

Request the robot to drive side to side and turn with given velocities using swerve.

Essentially rotate the reference frame of the robot by 90 degrees CCW.

Parameters
dthetaThe heading velocity.
dyThe side-to-side velocity.
wheel_rotsThe rotation of all four wheels in millidegrees
scaleFactorThis is an output parameter. If the requested velocities are too high, they will be scaled down. The returned value is the scale divisor. If no scaling was performed, 1 is returned.
Returns
drive_commands_t The power commands for all four wheels.

◆ setDriveMode()

swerve_rots_t SwerveController::setDriveMode ( DriveMode mode)

Set the drive mode of the controller.

Parameters
modeThe new drive mode to set.
Returns
swerve_rots_t The wheel steer rotations associated with this drive mode.

◆ setOverride()

void SwerveController::setOverride ( bool override)

Set the override flag for wheel rotation checking.

When set to true, the checkWheelRotation function will always return true, bypassing the wheel rotation check.

Parameters
overrideOverride the wheel rotation check.

◆ setTurnInPlaceCmdVel() [1/2]

drive_commands_t SwerveController::setTurnInPlaceCmdVel ( double dtheta,
const swerve_rots_t & wheel_rots ) const

Request the robot to turn in place using swerve.

Parameters
dthetaThe heading velocity.
wheel_rotsThe rotation of all four wheels in millidegrees
Returns
drive_commands_t The power commands for all four wheels.

◆ setTurnInPlaceCmdVel() [2/2]

drive_commands_t SwerveController::setTurnInPlaceCmdVel ( double dtheta,
const swerve_rots_t & wheel_rots,
double & scaleFactor ) const

Request the robot to turn in place using swerve.

Parameters
dthetaThe heading velocity.
wheel_rotsThe rotation of all four wheels in millidegrees
scaleFactorThis is an output parameter. If the requested velocities are too high, they will be scaled down. The returned value is the scale divisor. If no scaling was performed, 1 is returned.
Returns
drive_commands_t The power commands for all four wheels.

◆ swerveKinematics()

const kinematics::SwerveDriveKinematics & SwerveController::swerveKinematics ( ) const

Get the SwerveDriveKinematics object used by the controller.

Returns
const kinematics::SwerveDriveKinematics& The SwerveDriveKinematics object.

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