jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. */
|
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */
|
| 4 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #ifndef ROBOTDRIVE_H_
|
| 8 | #define ROBOTDRIVE_H_
|
| 9 |
|
| 10 | #include "ErrorBase.h"
|
| 11 | #include <stdlib.h>
|
| 12 | #include <vxWorks.h>
|
| 13 | #include "MotorSafety.h"
|
| 14 | #include "MotorSafetyHelper.h"
|
| 15 |
|
| 16 | class SpeedController;
|
| 17 | class GenericHID;
|
| 18 |
|
| 19 | /**
|
| 20 | * Utility class for handling Robot drive based on a definition of the motor configuration.
|
| 21 | * The robot drive class handles basic driving for a robot. Currently, 2 and 4 motor standard
|
| 22 | * drive trains are supported. In the future other drive types like swerve and meccanum might
|
| 23 | * be implemented. Motor channel numbers are passed supplied on creation of the class. Those are
|
| 24 | * used for either the Drive function (intended for hand created drive code, such as autonomous)
|
| 25 | * or with the Tank/Arcade functions intended to be used for Operator Control driving.
|
| 26 | */
|
| 27 | class RobotDrive: public MotorSafety, public ErrorBase
|
| 28 | {
|
| 29 | public:
|
| 30 | typedef enum
|
| 31 | {
|
| 32 | kFrontLeftMotor = 0,
|
| 33 | kFrontRightMotor = 1,
|
| 34 | kRearLeftMotor = 2,
|
| 35 | kRearRightMotor = 3
|
| 36 | } MotorType;
|
| 37 |
|
| 38 | RobotDrive(UINT32 leftMotorChannel, UINT32 rightMotorChannel);
|
| 39 | RobotDrive(UINT32 frontLeftMotorChannel, UINT32 rearLeftMotorChannel,
|
| 40 | UINT32 frontRightMotorChannel, UINT32 rearRightMotorChannel);
|
| 41 | RobotDrive(SpeedController *leftMotor, SpeedController *rightMotor);
|
| 42 | RobotDrive(SpeedController &leftMotor, SpeedController &rightMotor);
|
| 43 | RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
|
| 44 | SpeedController *frontRightMotor, SpeedController *rearRightMotor);
|
| 45 | RobotDrive(SpeedController &frontLeftMotor, SpeedController &rearLeftMotor,
|
| 46 | SpeedController &frontRightMotor, SpeedController &rearRightMotor);
|
| 47 | virtual ~RobotDrive();
|
| 48 |
|
| 49 | void Drive(float outputMagnitude, float curve);
|
| 50 | void TankDrive(GenericHID *leftStick, GenericHID *rightStick, bool squaredInputs = true);
|
| 51 | void TankDrive(GenericHID &leftStick, GenericHID &rightStick, bool squaredInputs = true);
|
| 52 | void TankDrive(GenericHID *leftStick, UINT32 leftAxis, GenericHID *rightStick, UINT32 rightAxis, bool squaredInputs = true);
|
| 53 | void TankDrive(GenericHID &leftStick, UINT32 leftAxis, GenericHID &rightStick, UINT32 rightAxis, bool squaredInputs = true);
|
| 54 | void TankDrive(float leftValue, float rightValue, bool squaredInputs = true);
|
| 55 | void ArcadeDrive(GenericHID *stick, bool squaredInputs = true);
|
| 56 | void ArcadeDrive(GenericHID &stick, bool squaredInputs = true);
|
| 57 | void ArcadeDrive(GenericHID *moveStick, UINT32 moveChannel, GenericHID *rotateStick, UINT32 rotateChannel, bool squaredInputs = true);
|
| 58 | void ArcadeDrive(GenericHID &moveStick, UINT32 moveChannel, GenericHID &rotateStick, UINT32 rotateChannel, bool squaredInputs = true);
|
| 59 | void ArcadeDrive(float moveValue, float rotateValue, bool squaredInputs = true);
|
| 60 | void MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle = 0.0);
|
| 61 | void MecanumDrive_Polar(float magnitude, float direction, float rotation);
|
| 62 | void HolonomicDrive(float magnitude, float direction, float rotation);
|
| 63 | virtual void SetLeftRightMotorOutputs(float leftOutput, float rightOutput);
|
| 64 | void SetInvertedMotor(MotorType motor, bool isInverted);
|
| 65 | void SetSensitivity(float sensitivity);
|
| 66 | void SetMaxOutput(double maxOutput);
|
| 67 |
|
| 68 | void SetExpiration(float timeout);
|
| 69 | float GetExpiration();
|
| 70 | bool IsAlive();
|
| 71 | void StopMotor();
|
| 72 | bool IsSafetyEnabled();
|
| 73 | void SetSafetyEnabled(bool enabled);
|
| 74 | void GetDescription(char *desc);
|
| 75 |
|
| 76 | protected:
|
| 77 | void InitRobotDrive();
|
| 78 | float Limit(float num);
|
| 79 | void Normalize(double *wheelSpeeds);
|
| 80 | void RotateVector(double &x, double &y, double angle);
|
| 81 |
|
| 82 | static const INT32 kMaxNumberOfMotors = 4;
|
| 83 |
|
| 84 | INT32 m_invertedMotors[kMaxNumberOfMotors];
|
| 85 | float m_sensitivity;
|
| 86 | double m_maxOutput;
|
| 87 | bool m_deleteSpeedControllers;
|
| 88 | SpeedController *m_frontLeftMotor;
|
| 89 | SpeedController *m_frontRightMotor;
|
| 90 | SpeedController *m_rearLeftMotor;
|
| 91 | SpeedController *m_rearRightMotor;
|
| 92 | MotorSafetyHelper *m_safetyHelper;
|
| 93 |
|
| 94 | private:
|
| 95 | INT32 GetNumMotors()
|
| 96 | {
|
| 97 | int motors = 0;
|
| 98 | if (m_frontLeftMotor) motors++;
|
| 99 | if (m_frontRightMotor) motors++;
|
| 100 | if (m_rearLeftMotor) motors++;
|
| 101 | if (m_rearRightMotor) motors++;
|
| 102 | return motors;
|
| 103 | }
|
| 104 | DISALLOW_COPY_AND_ASSIGN(RobotDrive);
|
| 105 | };
|
| 106 |
|
| 107 | #endif
|
| 108 |
|