WPILibC++ 2023.4.3-108-ge5452e3
|
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 | |
DifferentialDrive (MotorController &leftMotor, MotorController &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 |
std::string | GetDescription () const override |
The return value from this method is printed out 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 |
std::string | GetDescription () const override=0 |
The return value from this method is printed out 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 |
virtual std::string | GetDescription () const =0 |
The return value from this method is printed out 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 = 0.02 |
double | m_maxOutput = 1.0 |
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 MotorController per side. For four and six motor drivetrains, construct and pass in MotorControllerGroup instances as follows.
Four motor drivetrain:
Six motor drivetrain:
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.
frc::DifferentialDrive::DifferentialDrive | ( | MotorController & | leftMotor, |
MotorController & | rightMotor | ||
) |
Construct a DifferentialDrive.
To pass multiple motors per side, use a MotorControllerGroup. If a motor needs to be inverted, do so before passing it in.
|
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 |
The return value from this method is printed out when an error occurs.
This method must not throw!
Implements frc::RobotDriveBase.
|
overridevirtual |
|
default |
|
overridevirtual |
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. |