WPILibC++ 2024.3.2
|
A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive base, "tank drive", or West Coast Drive. More...
#include <frc/drive/DifferentialDrive.h>
Classes | |
struct | WheelSpeeds |
Wheel speeds for a differential drive. More... | |
Public Member Functions | |
WPI_IGNORE_DEPRECATED | DifferentialDrive (MotorController &leftMotor, MotorController &rightMotor) |
Construct a DifferentialDrive. More... | |
WPI_UNIGNORE_DEPRECATED | DifferentialDrive (std::function< void(double)> leftMotor, std::function< void(double)> rightMotor) |
Construct a DifferentialDrive. More... | |
~DifferentialDrive () override=default | |
DifferentialDrive (DifferentialDrive &&)=default | |
DifferentialDrive & | operator= (DifferentialDrive &&)=default |
void | ArcadeDrive (double xSpeed, double zRotation, bool squareInputs=true) |
Arcade drive method for differential drive platform. More... | |
void | CurvatureDrive (double xSpeed, double zRotation, bool allowTurnInPlace) |
Curvature drive method for differential drive platform. More... | |
void | TankDrive (double leftSpeed, double rightSpeed, bool squareInputs=true) |
Tank drive method for differential drive platform. More... | |
void | StopMotor () override |
Called to stop the motor when the timeout expires. More... | |
std::string | GetDescription () const override |
Returns a description to print when an error occurs. More... | |
void | InitSendable (wpi::SendableBuilder &builder) override |
Initializes this Sendable object. More... | |
Public Member Functions inherited from frc::RobotDriveBase | |
RobotDriveBase () | |
~RobotDriveBase () override=default | |
RobotDriveBase (RobotDriveBase &&)=default | |
RobotDriveBase & | operator= (RobotDriveBase &&)=default |
void | SetDeadband (double deadband) |
Sets the deadband applied to the drive inputs (e.g., joystick values). More... | |
void | SetMaxOutput (double maxOutput) |
Configure the scaling factor for using RobotDrive with motor controllers in a mode other than PercentVbus or to limit the maximum output. More... | |
void | FeedWatchdog () |
Feed the motor safety object. More... | |
void | StopMotor () override=0 |
Called to stop the motor when the timeout expires. More... | |
std::string | GetDescription () const override=0 |
Returns a description to print when an error occurs. More... | |
Public Member Functions inherited from frc::MotorSafety | |
MotorSafety () | |
virtual | ~MotorSafety () |
MotorSafety (MotorSafety &&rhs) | |
MotorSafety & | operator= (MotorSafety &&rhs) |
void | Feed () |
Feed the motor safety object. More... | |
void | SetExpiration (units::second_t expirationTime) |
Set the expiration time for the corresponding motor safety object. More... | |
units::second_t | GetExpiration () const |
Retrieve the timeout value for the corresponding motor safety object. More... | |
bool | IsAlive () const |
Determine if the motor is still operating or has timed out. More... | |
void | SetSafetyEnabled (bool enabled) |
Enable/disable motor safety for this device. More... | |
bool | IsSafetyEnabled () const |
Return the state of the motor safety enabled flag. More... | |
void | Check () |
Check if this motor has exceeded its timeout. More... | |
virtual void | StopMotor ()=0 |
Called to stop the motor when the timeout expires. More... | |
virtual std::string | GetDescription () const =0 |
Returns a description to print when an error occurs. More... | |
Public Member Functions inherited from wpi::Sendable | |
virtual | ~Sendable ()=default |
virtual void | InitSendable (SendableBuilder &builder)=0 |
Initializes this Sendable object. More... | |
Public Member Functions inherited from wpi::SendableHelper< DifferentialDrive > | |
SendableHelper (const SendableHelper &rhs)=default | |
SendableHelper (SendableHelper &&rhs) | |
SendableHelper & | operator= (const SendableHelper &rhs)=default |
SendableHelper & | operator= (SendableHelper &&rhs) |
Static Public Member Functions | |
static WheelSpeeds | ArcadeDriveIK (double xSpeed, double zRotation, bool squareInputs=true) |
Arcade drive inverse kinematics for differential drive platform. More... | |
static WheelSpeeds | CurvatureDriveIK (double xSpeed, double zRotation, bool allowTurnInPlace) |
Curvature drive inverse kinematics for differential drive platform. More... | |
static WheelSpeeds | TankDriveIK (double leftSpeed, double rightSpeed, bool squareInputs=true) |
Tank drive inverse kinematics for differential drive platform. More... | |
Static Public Member Functions inherited from frc::MotorSafety | |
static void | CheckMotors () |
Check the motors to see if any have timed out. More... | |
Additional Inherited Members | |
Public Types inherited from frc::RobotDriveBase | |
enum | MotorType { kFrontLeft = 0 , kFrontRight = 1 , kRearLeft = 2 , kRearRight = 3 , kLeft = 0 , kRight = 1 , kBack = 2 } |
The location of a motor on the robot for the purpose of driving. More... | |
Protected Member Functions inherited from wpi::SendableHelper< DifferentialDrive > | |
SendableHelper ()=default | |
~SendableHelper () | |
Static Protected Member Functions inherited from frc::RobotDriveBase | |
static void | Desaturate (std::span< double > wheelSpeeds) |
Renormalize all wheel speeds if the magnitude of any wheel is greater than 1.0. More... | |
Protected Attributes inherited from frc::RobotDriveBase | |
double | m_deadband = kDefaultDeadband |
Input deadband. More... | |
double | m_maxOutput = kDefaultMaxOutput |
Maximum output. More... | |
Static Protected Attributes inherited from frc::RobotDriveBase | |
static constexpr double | kDefaultDeadband = 0.02 |
Default input deadband. More... | |
static constexpr double | kDefaultMaxOutput = 1.0 |
Default maximum output. More... | |
A class for driving differential drive/skid-steer drive platforms such as the Kit of Parts drive base, "tank drive", or West Coast Drive.
These drive bases typically have drop-center / skid-steer with two or more wheels per side (e.g., 6WD or 8WD). This class takes a setter per side. For four and six motor drivetrains, use CAN motor controller followers or PWMMotorController::AddFollower().
A differential drive robot has left and right wheels separated by an arbitrary width.
Drive base diagram:
|_______| | | | | | | |_|___|_| | |
Each drive function provides different inverse kinematic relations for a differential drive robot.
This library uses the NWU axes convention (North-West-Up as external reference in the world frame). The positive X axis points ahead, the positive Y axis points to the left, and the positive Z axis points up. Rotations follow the right-hand rule, so counterclockwise rotation around the Z axis is positive.
Inputs smaller then 0.02 will be set to 0, and larger values will be scaled so that the full range is still used. This deadband value can be changed with SetDeadband().
MotorSafety is enabled by default. The tankDrive, arcadeDrive, or curvatureDrive methods should be called periodically to avoid Motor Safety timeouts.
WPI_IGNORE_DEPRECATED frc::DifferentialDrive::DifferentialDrive | ( | MotorController & | leftMotor, |
MotorController & | rightMotor | ||
) |
Construct a DifferentialDrive.
To pass multiple motors per side, use CAN motor controller followers or PWMSpeedController::AddFollower(). If a motor needs to be inverted, do so before passing it in.
leftMotor | Left motor. |
rightMotor | Right motor. |
WPI_UNIGNORE_DEPRECATED frc::DifferentialDrive::DifferentialDrive | ( | std::function< void(double)> | leftMotor, |
std::function< void(double)> | rightMotor | ||
) |
Construct a DifferentialDrive.
To pass multiple motors per side, use CAN motor controller followers or PWMSpeedController::AddFollower(). If a motor needs to be inverted, do so before passing it in.
leftMotor | Left motor setter. |
rightMotor | Right motor setter. |
|
overridedefault |
|
default |
void frc::DifferentialDrive::ArcadeDrive | ( | double | xSpeed, |
double | zRotation, | ||
bool | squareInputs = true |
||
) |
Arcade drive method for differential drive platform.
Note: Some drivers may prefer inverted rotation controls. This can be done by negating the value passed for rotation.
xSpeed | The speed at which the robot should drive along the X axis [-1.0..1.0]. Forward is positive. |
zRotation | The rotation rate of the robot around the Z axis [-1.0..1.0]. Counterclockwise is positive. |
squareInputs | If set, decreases the input sensitivity at low speeds. |
|
static |
Arcade drive inverse kinematics for differential drive platform.
Note: Some drivers may prefer inverted rotation controls. This can be done by negating the value passed for rotation.
xSpeed | The speed at which the robot should drive along the X axis [-1.0..1.0]. Forward is positive. |
zRotation | The rotation rate of the robot around the Z axis [-1.0..1.0]. Clockwise is positive. |
squareInputs | If set, decreases the input sensitivity at low speeds. |
void frc::DifferentialDrive::CurvatureDrive | ( | double | xSpeed, |
double | zRotation, | ||
bool | allowTurnInPlace | ||
) |
Curvature drive method for differential drive platform.
The rotation argument controls the curvature of the robot's path rather than its rate of heading change. This makes the robot more controllable at high speeds.
xSpeed | The robot's speed along the X axis [-1.0..1.0]. Forward is positive. |
zRotation | The normalized curvature [-1.0..1.0]. Counterclockwise is positive. |
allowTurnInPlace | If set, overrides constant-curvature turning for turn-in-place maneuvers. zRotation will control turning rate instead of curvature. |
|
static |
Curvature drive inverse kinematics for differential drive platform.
The rotation argument controls the curvature of the robot's path rather than its rate of heading change. This makes the robot more controllable at high speeds.
xSpeed | The robot's speed along the X axis [-1.0..1.0]. Forward is positive. |
zRotation | The normalized curvature [-1.0..1.0]. Clockwise is positive. |
allowTurnInPlace | If set, overrides constant-curvature turning for turn-in-place maneuvers. zRotation will control turning rate instead of curvature. |
|
overridevirtual |
Returns a description to print when an error occurs.
Implements frc::RobotDriveBase.
|
overridevirtual |
|
default |
|
overridevirtual |
Called to stop the motor when the timeout expires.
Implements frc::RobotDriveBase.
void frc::DifferentialDrive::TankDrive | ( | double | leftSpeed, |
double | rightSpeed, | ||
bool | squareInputs = true |
||
) |
Tank drive method for differential drive platform.
leftSpeed | The robot left side's speed along the X axis [-1.0..1.0]. Forward is positive. |
rightSpeed | The robot right side's speed along the X axis [-1.0..1.0]. Forward is positive. |
squareInputs | If set, decreases the input sensitivity at low speeds. |
|
static |
Tank drive inverse kinematics for differential drive platform.
leftSpeed | The robot left side's speed along the X axis [-1.0..1.0]. Forward is positive. |
rightSpeed | The robot right side's speed along the X axis [-1.0..1.0]. Forward is positive. |
squareInputs | If set, decreases the input sensitivity at low speeds. |