Now you can download a copy of these docs so you can use them offline! Download now

#include <RobotDrive.h>

Inheritance diagram for RobotDrive:
Collaboration diagram for RobotDrive:

Public Types

enum  MotorType { kFrontLeftMotor = 0, kFrontRightMotor = 1, kRearLeftMotor = 2, kRearRightMotor = 3 }
 

Public Member Functions

 RobotDrive (uint32_t leftMotorChannel, uint32_t rightMotorChannel)
 
 RobotDrive (uint32_t frontLeftMotorChannel, uint32_t rearLeftMotorChannel, uint32_t frontRightMotorChannel, uint32_t rearRightMotorChannel)
 
 RobotDrive (SpeedController *leftMotor, SpeedController *rightMotor)
 
 RobotDrive (SpeedController &leftMotor, SpeedController &rightMotor)
 
 RobotDrive (SpeedController *frontLeftMotor, SpeedController *rearLeftMotor, SpeedController *frontRightMotor, SpeedController *rearRightMotor)
 
 RobotDrive (SpeedController &frontLeftMotor, SpeedController &rearLeftMotor, SpeedController &frontRightMotor, SpeedController &rearRightMotor)
 
virtual ~RobotDrive ()
 
void Drive (float outputMagnitude, float curve)
 
void TankDrive (GenericHID *leftStick, GenericHID *rightStick, bool squaredInputs=true)
 
void TankDrive (GenericHID &leftStick, GenericHID &rightStick, bool squaredInputs=true)
 
void TankDrive (GenericHID *leftStick, uint32_t leftAxis, GenericHID *rightStick, uint32_t rightAxis, bool squaredInputs=true)
 
void TankDrive (GenericHID &leftStick, uint32_t leftAxis, GenericHID &rightStick, uint32_t rightAxis, bool squaredInputs=true)
 
void TankDrive (float leftValue, float rightValue, bool squaredInputs=true)
 
void ArcadeDrive (GenericHID *stick, bool squaredInputs=true)
 
void ArcadeDrive (GenericHID &stick, bool squaredInputs=true)
 
void ArcadeDrive (GenericHID *moveStick, uint32_t moveChannel, GenericHID *rotateStick, uint32_t rotateChannel, bool squaredInputs=true)
 
void ArcadeDrive (GenericHID &moveStick, uint32_t moveChannel, GenericHID &rotateStick, uint32_t rotateChannel, bool squaredInputs=true)
 
void ArcadeDrive (float moveValue, float rotateValue, bool squaredInputs=true)
 
void MecanumDrive_Cartesian (float x, float y, float rotation, float gyroAngle=0.0)
 
void MecanumDrive_Polar (float magnitude, float direction, float rotation)
 
void HolonomicDrive (float magnitude, float direction, float rotation)
 
virtual void SetLeftRightMotorOutputs (float leftOutput, float rightOutput)
 
void SetInvertedMotor (MotorType motor, bool isInverted)
 
void SetSensitivity (float sensitivity)
 
void SetMaxOutput (double maxOutput)
 
void SetExpiration (float timeout)
 
float GetExpiration ()
 
bool IsAlive ()
 
void StopMotor ()
 
bool IsSafetyEnabled ()
 
void SetSafetyEnabled (bool enabled)
 
void GetDescription (char *desc)
 
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (ErrorBase *rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Protected Member Functions

void InitRobotDrive ()
 
float Limit (float num)
 
void Normalize (double *wheelSpeeds)
 
void RotateVector (double &x, double &y, double angle)
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.
 

Protected Attributes

int32_t m_invertedMotors [kMaxNumberOfMotors]
 
float m_sensitivity
 
double m_maxOutput
 
bool m_deleteSpeedControllers
 
SpeedControllerm_frontLeftMotor
 
SpeedControllerm_frontRightMotor
 
SpeedControllerm_rearLeftMotor
 
SpeedControllerm_rearRightMotor
 
MotorSafetyHelperm_safetyHelper
 
- Protected Attributes inherited from ErrorBase
Error m_error
 

Static Protected Attributes

static const int32_t kMaxNumberOfMotors = 4
 
- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
 
static Error _globalError
 

Additional Inherited Members

- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 

Detailed Description

Utility class for handling Robot drive based on a definition of the motor configuration. The robot drive class handles basic driving for a robot. Currently, 2 and 4 motor standard drive trains are supported. In the future other drive types like swerve and meccanum might be implemented. Motor channel numbers are passed supplied on creation of the class. Those are used for either the Drive function (intended for hand created drive code, such as autonomous) or with the Tank/Arcade functions intended to be used for Operator Control driving.

Definition at line 27 of file RobotDrive.h.

Constructor & Destructor Documentation

RobotDrive::RobotDrive ( uint32_t  leftMotorChannel,
uint32_t  rightMotorChannel 
)

Constructor for RobotDrive with 2 motors specified with channel numbers. Set up parameters for a two wheel drive system where the left and right motor pwm channels are specified in the call. This call assumes Jaguars for controlling the motors.

Parameters
leftMotorChannelThe PWM channel number on the default digital module that drives the left motor.
rightMotorChannelThe PWM channel number on the default digital module that drives the right motor.

Definition at line 52 of file RobotDrive.cpp.

RobotDrive::RobotDrive ( uint32_t  frontLeftMotor,
uint32_t  rearLeftMotor,
uint32_t  frontRightMotor,
uint32_t  rearRightMotor 
)

Constructor for RobotDrive with 4 motors specified with channel numbers. Set up parameters for a four wheel drive system where all four motor pwm channels are specified in the call. This call assumes Jaguars for controlling the motors.

Parameters
frontLeftMotorFront left motor channel number on the default digital module
rearLeftMotorRear Left motor channel number on the default digital module
frontRightMotorFront right motor channel number on the default digital module
rearRightMotorRear Right motor channel number on the default digital module

Definition at line 75 of file RobotDrive.cpp.

RobotDrive::RobotDrive ( SpeedController leftMotor,
SpeedController rightMotor 
)

Constructor for RobotDrive with 2 motors specified as SpeedController objects. The SpeedController version of the constructor enables programs to use the RobotDrive classes with subclasses of the SpeedController objects, for example, versions with ramping or reshaping of the curve to suit motor bias or deadband elimination.

Parameters
leftMotorThe left SpeedController object used to drive the robot.
rightMotorthe right SpeedController object used to drive the robot.

Definition at line 99 of file RobotDrive.cpp.

RobotDrive::RobotDrive ( SpeedController frontLeftMotor,
SpeedController rearLeftMotor,
SpeedController frontRightMotor,
SpeedController rearRightMotor 
)

Constructor for RobotDrive with 4 motors specified as SpeedController objects. Speed controller input version of RobotDrive (see previous comments).

Parameters
rearLeftMotorThe back left SpeedController object used to drive the robot.
frontLeftMotorThe front left SpeedController object used to drive the robot
rearRightMotorThe back right SpeedController object used to drive the robot.
frontRightMotorThe front right SpeedController object used to drive the robot.

Definition at line 137 of file RobotDrive.cpp.

RobotDrive::~RobotDrive ( )
virtual

RobotDrive destructor. Deletes motor objects that were not passed in and created internally only.

Definition at line 176 of file RobotDrive.cpp.

Member Function Documentation

void RobotDrive::ArcadeDrive ( GenericHID stick,
bool  squaredInputs = true 
)

Arcade drive implements single stick driving. Given a single Joystick, the class assumes the Y axis for the move value and the X axis for the rotate value. (Should add more information here regarding the way that arcade drive works.)

Parameters
stickThe joystick to use for Arcade single-stick driving. The Y-axis will be selected for forwards/backwards and the X-axis will be selected for rotation rate.
squaredInputsIf true, the sensitivity will be increased for small values

Definition at line 333 of file RobotDrive.cpp.

void RobotDrive::ArcadeDrive ( GenericHID stick,
bool  squaredInputs = true 
)

Arcade drive implements single stick driving. Given a single Joystick, the class assumes the Y axis for the move value and the X axis for the rotate value. (Should add more information here regarding the way that arcade drive works.)

Parameters
stickThe joystick to use for Arcade single-stick driving. The Y-axis will be selected for forwards/backwards and the X-axis will be selected for rotation rate.
squaredInputsIf true, the sensitivity will be increased for small values

Definition at line 348 of file RobotDrive.cpp.

void RobotDrive::ArcadeDrive ( GenericHID moveStick,
uint32_t  moveAxis,
GenericHID rotateStick,
uint32_t  rotateAxis,
bool  squaredInputs = true 
)

Arcade drive implements single stick driving. Given two joystick instances and two axis, compute the values to send to either two or four motors.

Parameters
moveStickThe Joystick object that represents the forward/backward direction
moveAxisThe axis on the moveStick object to use for fowards/backwards (typically Y_AXIS)
rotateStickThe Joystick object that represents the rotation value
rotateAxisThe axis on the rotation object to use for the rotate right/left (typically X_AXIS)
squaredInputsSetting this parameter to true increases the sensitivity at lower speeds

Definition at line 364 of file RobotDrive.cpp.

void RobotDrive::ArcadeDrive ( GenericHID moveStick,
uint32_t  moveAxis,
GenericHID rotateStick,
uint32_t  rotateAxis,
bool  squaredInputs = true 
)

Arcade drive implements single stick driving. Given two joystick instances and two axis, compute the values to send to either two or four motors.

Parameters
moveStickThe Joystick object that represents the forward/backward direction
moveAxisThe axis on the moveStick object to use for fowards/backwards (typically Y_AXIS)
rotateStickThe Joystick object that represents the rotation value
rotateAxisThe axis on the rotation object to use for the rotate right/left (typically X_AXIS)
squaredInputsSetting this parameter to true increases the sensitivity at lower speeds

Definition at line 385 of file RobotDrive.cpp.

void RobotDrive::ArcadeDrive ( float  moveValue,
float  rotateValue,
bool  squaredInputs = true 
)

Arcade drive implements single stick driving. This function lets you directly provide joystick values from any source.

Parameters
moveValueThe value to use for fowards/backwards
rotateValueThe value to use for the rotate right/left
squaredInputsIf set, increases the sensitivity at low speeds

Definition at line 402 of file RobotDrive.cpp.

void RobotDrive::Drive ( float  outputMagnitude,
float  curve 
)

Drive the motors at "speed" and "curve".

The speed and curve are -1.0 to +1.0 values where 0.0 represents stopped and not turning. The algorithm for adding in the direction attempts to provide a constant turn radius for differing speeds.

This function will most likely be used in an autonomous routine.

Parameters
outputMagnitudeThe forward component of the output magnitude to send to the motors.
curveThe rate of turn, constant for different forward speeds.

Definition at line 200 of file RobotDrive.cpp.

void RobotDrive::HolonomicDrive ( float  magnitude,
float  direction,
float  rotation 
)

Holonomic Drive method for Mecanum wheeled robots.

This is an alias to MecanumDrive_Polar() for backward compatability

Parameters
magnitudeThe speed that the robot should drive in a given direction. [-1.0..1.0]
directionThe direction the robot should drive. The direction and maginitute are independent of the rotation rate.
rotationThe rate of rotation for the robot that is completely independent of the magnitute or direction. [-1.0..1.0]

Definition at line 580 of file RobotDrive.cpp.

void RobotDrive::InitRobotDrive ( )
protected

Common function to initialize all the robot drive constructors. Create a motor safety object (the real reason for the common code) and initialize all the motor assignments. The default timeout is set for the robot drive.

Definition at line 34 of file RobotDrive.cpp.

float RobotDrive::Limit ( float  num)
protected

Limit motor values to the -1.0 to +1.0 range.

Definition at line 614 of file RobotDrive.cpp.

void RobotDrive::MecanumDrive_Cartesian ( float  x,
float  y,
float  rotation,
float  gyroAngle = 0.0 
)

Drive method for Mecanum wheeled robots.

A method for driving with Mecanum wheeled robots. There are 4 wheels on the robot, arranged so that the front and back wheels are toed in 45 degrees. When looking at the wheels from the top, the roller axles should form an X across the robot.

This is designed to be directly driven by joystick axes.

Parameters
xThe speed that the robot should drive in the X direction. [-1.0..1.0]
yThe speed that the robot should drive in the Y direction. This input is inverted to match the forward == -1.0 that joysticks produce. [-1.0..1.0]
rotationThe rate of rotation for the robot that is completely independent of the translation. [-1.0..1.0]
gyroAngleThe current angle reading from the gyro. Use this to implement field-oriented controls.

Definition at line 484 of file RobotDrive.cpp.

void RobotDrive::MecanumDrive_Polar ( float  magnitude,
float  direction,
float  rotation 
)

Drive method for Mecanum wheeled robots.

A method for driving with Mecanum wheeled robots. There are 4 wheels on the robot, arranged so that the front and back wheels are toed in 45 degrees. When looking at the wheels from the top, the roller axles should form an X across the robot.

Parameters
magnitudeThe speed that the robot should drive in a given direction. [-1.0..1.0]
directionThe direction the robot should drive in degrees. The direction and maginitute are independent of the rotation rate.
rotationThe rate of rotation for the robot that is completely independent of the magnitute or direction. [-1.0..1.0]

Definition at line 533 of file RobotDrive.cpp.

void RobotDrive::Normalize ( double *  wheelSpeeds)
protected

Normalize all wheel speeds if the magnitude of any wheel is greater than 1.0.

Definition at line 630 of file RobotDrive.cpp.

void RobotDrive::RotateVector ( double &  x,
double &  y,
double  angle 
)
protected

Rotate a vector in Cartesian space.

Definition at line 651 of file RobotDrive.cpp.

void RobotDrive::SetLeftRightMotorOutputs ( float  leftOutput,
float  rightOutput 
)
virtual

Set the speed of the right and left motors. This is used once an appropriate drive setup function is called such as TwoWheelDrive(). The motors are set to "leftOutput" and "rightOutput" and includes flipping the direction of one side for opposing motors.

Parameters
leftOutputThe speed to send to the left side of the robot.
rightOutputThe speed to send to the right side of the robot.

Definition at line 592 of file RobotDrive.cpp.

void RobotDrive::SetMaxOutput ( double  maxOutput)

Configure the scaling factor for using RobotDrive with motor controllers in a mode other than PercentVbus.

Parameters
maxOutputMultiplied with the output percentage computed by the drive functions.

Definition at line 694 of file RobotDrive.cpp.

void RobotDrive::SetSensitivity ( float  sensitivity)

Set the turning sensitivity.

This only impacts the Drive() entry-point.

Parameters
sensitivityEffectively sets the turning sensitivity (or turn radius for a given value)

Definition at line 685 of file RobotDrive.cpp.

void RobotDrive::TankDrive ( GenericHID leftStick,
GenericHID rightStick,
bool  squaredInputs = true 
)

Provide tank steering using the stored robot configuration. Drive the robot using two joystick inputs. The Y-axis will be selected from each Joystick object.

Parameters
leftStickThe joystick to control the left side of the robot.
rightStickThe joystick to control the right side of the robot.

Definition at line 241 of file RobotDrive.cpp.

void RobotDrive::TankDrive ( GenericHID leftStick,
uint32_t  leftAxis,
GenericHID rightStick,
uint32_t  rightAxis,
bool  squaredInputs = true 
)

Provide tank steering using the stored robot configuration. This function lets you pick the axis to be used on each Joystick object for the left and right sides of the robot.

Parameters
leftStickThe Joystick object to use for the left side of the robot.
leftAxisThe axis to select on the left side Joystick object.
rightStickThe Joystick object to use for the right side of the robot.
rightAxisThe axis to select on the right side Joystick object.

Definition at line 265 of file RobotDrive.cpp.

void RobotDrive::TankDrive ( float  leftValue,
float  rightValue,
bool  squaredInputs = true 
)

Provide tank steering using the stored robot configuration. This function lets you directly provide joystick values from any source.

Parameters
leftValueThe value of the left stick.
rightValueThe value of the right stick.

Definition at line 289 of file RobotDrive.cpp.


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

Generated on Sat Apr 26 2014 12:26:46 for WPILibC++ by doxygen 1.8.6