Class DifferentialDrive
- All Implemented Interfaces:
TelemetryLoggable
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(PWMMotorController).
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 RobotDriveBase.setDeadband(double).
MotorSafety is enabled by default. The tankDrive,
arcadeDrive, or curvatureDrive methods should be called periodically to avoid Motor Safety
timeouts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classWheel velocities for a differential drive.Nested classes/interfaces inherited from class RobotDriveBase
RobotDriveBase.MotorType -
Field Summary
Fields inherited from class RobotDriveBase
DEFAULT_DEADBAND, DEFAULT_MAX_OUTPUT, m_deadband, m_maxOutput -
Constructor Summary
ConstructorsConstructorDescriptionDifferentialDrive(DoubleConsumer leftMotor, DoubleConsumer rightMotor) Construct a DifferentialDrive.DifferentialDrive(MotorController leftMotor, MotorController rightMotor) Construct a DifferentialDrive. -
Method Summary
Modifier and TypeMethodDescriptionvoidarcadeDrive(double xVelocity, double zRotation) Arcade drive method for differential drive platform.voidarcadeDrive(double xVelocity, double zRotation, boolean squareInputs) Arcade drive method for differential drive platform.arcadeDriveIK(double xVelocity, double zRotation, boolean squareInputs) Arcade drive inverse kinematics for differential drive platform.voidcurvatureDrive(double xVelocity, double zRotation, boolean allowTurnInPlace) Curvature drive method for differential drive platform.curvatureDriveIK(double xVelocity, double zRotation, boolean allowTurnInPlace) Curvature drive inverse kinematics for differential drive platform.Returns a description to print when an error occurs.Gets the telemetry table type.voidlogTo(TelemetryTable table) Logs the object to aTelemetryTable.voidCalled to stop the motor when the timeout expires.voidtankDrive(double leftVelocity, double rightVelocity) Tank drive method for differential drive platform.voidtankDrive(double leftVelocity, double rightVelocity, boolean squareInputs) Tank drive method for differential drive platform.tankDriveIK(double leftVelocity, double rightVelocity, boolean squareInputs) Tank drive inverse kinematics for differential drive platform.Methods inherited from class RobotDriveBase
feedWatchdog, normalize, setDeadband, setMaxOutputMethods inherited from class MotorSafety
check, checkMotors, feed, getExpiration, isAlive, isSafetyEnabled, setExpiration, setSafetyEnabled
-
Constructor Details
-
DifferentialDrive
Construct a DifferentialDrive.To pass multiple motors per side, use CAN motor controller followers or
PWMMotorController.addFollower(PWMMotorController). If a motor needs to be inverted, do so before passing it in.- Parameters:
leftMotor- Left motor.rightMotor- Right motor.
-
DifferentialDrive
Construct a DifferentialDrive.To pass multiple motors per side, use CAN motor controller followers or
PWMMotorController.addFollower(PWMMotorController). If a motor needs to be inverted, do so before passing it in.- Parameters:
leftMotor- Left motor setter.rightMotor- Right motor setter.
-
-
Method Details
-
arcadeDrive
public void arcadeDrive(double xVelocity, double zRotation) Arcade drive method for differential drive platform. The calculated values will be squared to decrease sensitivity at low velocities.- Parameters:
xVelocity- The robot's velocity along the X axis [-1.0..1.0]. Forward is positive.zRotation- The robot's rotation rate around the Z axis [-1.0..1.0]. Counterclockwise is positive.
-
arcadeDrive
public void arcadeDrive(double xVelocity, double zRotation, boolean squareInputs) Arcade drive method for differential drive platform.- Parameters:
xVelocity- The robot's velocity along the X axis [-1.0..1.0]. Forward is positive.zRotation- The robot's rotation rate around the Z axis [-1.0..1.0]. Counterclockwise is positive.squareInputs- If set, decreases the input sensitivity at low velocities.
-
curvatureDrive
public void curvatureDrive(double xVelocity, double zRotation, boolean 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 velocities.
- Parameters:
xVelocity- The robot's velocity 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.
-
tankDrive
public void tankDrive(double leftVelocity, double rightVelocity) Tank drive method for differential drive platform. The calculated values will be squared to decrease sensitivity at low velocities.- Parameters:
leftVelocity- The robot's left side velocity along the X axis [-1.0..1.0]. Forward is positive.rightVelocity- The robot's right side velocity along the X axis [-1.0..1.0]. Forward is positive.
-
tankDrive
public void tankDrive(double leftVelocity, double rightVelocity, boolean squareInputs) Tank drive method for differential drive platform.- Parameters:
leftVelocity- The robot left side's velocity along the X axis [-1.0..1.0]. Forward is positive.rightVelocity- The robot right side's velocity along the X axis [-1.0..1.0]. Forward is positive.squareInputs- If set, decreases the input sensitivity at low velocities.
-
arcadeDriveIK
public static DifferentialDrive.WheelVelocities arcadeDriveIK(double xVelocity, double zRotation, boolean squareInputs) Arcade drive inverse kinematics for differential drive platform.- Parameters:
xVelocity- The robot's velocity along the X axis [-1.0..1.0]. Forward is positive.zRotation- The robot's rotation rate around the Z axis [-1.0..1.0]. Counterclockwise is positive.squareInputs- If set, decreases the input sensitivity at low velocities.- Returns:
- Wheel velocities [-1.0..1.0].
-
curvatureDriveIK
public static DifferentialDrive.WheelVelocities curvatureDriveIK(double xVelocity, double zRotation, boolean allowTurnInPlace) 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 velocities.
- Parameters:
xVelocity- The robot's velocity 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 rotation rate around the Z axis instead of curvature.- Returns:
- Wheel velocities [-1.0..1.0].
-
tankDriveIK
public static DifferentialDrive.WheelVelocities tankDriveIK(double leftVelocity, double rightVelocity, boolean squareInputs) Tank drive inverse kinematics for differential drive platform.- Parameters:
leftVelocity- The robot left side's velocity along the X axis [-1.0..1.0]. Forward is positive.rightVelocity- The robot right side's velocity along the X axis [-1.0..1.0]. Forward is positive.squareInputs- If set, decreases the input sensitivity at low velocities.- Returns:
- Wheel velocities [-1.0..1.0].
-
stopMotor
public void stopMotor()Description copied from class:MotorSafetyCalled to stop the motor when the timeout expires.- Specified by:
stopMotorin classRobotDriveBase
-
getDescription
Description copied from class:MotorSafetyReturns a description to print when an error occurs.- Specified by:
getDescriptionin classRobotDriveBase- Returns:
- Description to print when an error occurs.
-
logTo
Description copied from interface:TelemetryLoggableLogs the object to aTelemetryTable.- Specified by:
logToin interfaceTelemetryLoggable- Parameters:
table- telemetry table
-
getTelemetryType
Description copied from interface:TelemetryLoggableGets the telemetry table type. Default is no specified table type (null). A mismatch in type during logging results in a reported warning, so this should always return the same value.- Specified by:
getTelemetryTypein interfaceTelemetryLoggable- Returns:
- Table type
-