WPILib 2012
WPILibRoboticsLibraryforFRC
RobotDrive.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2008. All Rights Reserved.                                                         */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef ROBOTDRIVE_H_
00008 #define ROBOTDRIVE_H_
00009 
00010 #include "ErrorBase.h"
00011 #include <stdlib.h>
00012 #include <vxWorks.h>
00013 #include "MotorSafety.h"
00014 #include "MotorSafetyHelper.h"
00015 
00016 class SpeedController;
00017 class GenericHID;
00018 
00027 class RobotDrive: public MotorSafety, public ErrorBase
00028 {
00029 public:
00030         typedef enum
00031         {
00032                 kFrontLeftMotor = 0,
00033                 kFrontRightMotor = 1,
00034                 kRearLeftMotor = 2,
00035                 kRearRightMotor = 3
00036         } MotorType;
00037 
00038         RobotDrive(UINT32 leftMotorChannel, UINT32 rightMotorChannel);
00039         RobotDrive(UINT32 frontLeftMotorChannel, UINT32 rearLeftMotorChannel,
00040                                 UINT32 frontRightMotorChannel, UINT32 rearRightMotorChannel);
00041         RobotDrive(SpeedController *leftMotor, SpeedController *rightMotor);
00042         RobotDrive(SpeedController &leftMotor, SpeedController &rightMotor);
00043         RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
00044                                 SpeedController *frontRightMotor, SpeedController *rearRightMotor);
00045         RobotDrive(SpeedController &frontLeftMotor, SpeedController &rearLeftMotor,
00046                                 SpeedController &frontRightMotor, SpeedController &rearRightMotor);
00047         virtual ~RobotDrive();
00048 
00049         void Drive(float outputMagnitude, float curve);
00050         void TankDrive(GenericHID *leftStick, GenericHID *rightStick);
00051         void TankDrive(GenericHID &leftStick, GenericHID &rightStick);
00052         void TankDrive(GenericHID *leftStick, UINT32 leftAxis, GenericHID *rightStick, UINT32 rightAxis);
00053         void TankDrive(GenericHID &leftStick, UINT32 leftAxis, GenericHID &rightStick, UINT32 rightAxis);
00054         void TankDrive(float leftValue, float rightValue);
00055         void ArcadeDrive(GenericHID *stick, bool squaredInputs = true);
00056         void ArcadeDrive(GenericHID &stick, bool squaredInputs = true);
00057         void ArcadeDrive(GenericHID *moveStick, UINT32 moveChannel, GenericHID *rotateStick, UINT32 rotateChannel, bool squaredInputs = true);
00058         void ArcadeDrive(GenericHID &moveStick, UINT32 moveChannel, GenericHID &rotateStick, UINT32 rotateChannel, bool squaredInputs = true);
00059         void ArcadeDrive(float moveValue, float rotateValue, bool squaredInputs = true);
00060         void MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle = 0.0);
00061         void MecanumDrive_Polar(float magnitude, float direction, float rotation);
00062         void HolonomicDrive(float magnitude, float direction, float rotation);
00063         virtual void SetLeftRightMotorOutputs(float leftOutput, float rightOutput);
00064         void SetInvertedMotor(MotorType motor, bool isInverted);
00065         void SetSensitivity(float sensitivity);
00066         void SetMaxOutput(double maxOutput);
00067 
00068         void SetExpiration(float timeout);
00069         float GetExpiration();
00070         bool IsAlive();
00071         void StopMotor();
00072         bool IsSafetyEnabled();
00073         void SetSafetyEnabled(bool enabled);
00074         void GetDescription(char *desc);
00075 
00076 protected:
00077         void InitRobotDrive();
00078         float Limit(float num);
00079         void Normalize(double *wheelSpeeds);
00080         void RotateVector(double &x, double &y, double angle);
00081 
00082         static const INT32 kMaxNumberOfMotors = 4;
00083 
00084         INT32 m_invertedMotors[kMaxNumberOfMotors];
00085         float m_sensitivity;
00086         double m_maxOutput;
00087         bool m_deleteSpeedControllers;
00088         SpeedController *m_frontLeftMotor;
00089         SpeedController *m_frontRightMotor;
00090         SpeedController *m_rearLeftMotor;
00091         SpeedController *m_rearRightMotor;
00092         MotorSafetyHelper *m_safetyHelper;
00093         
00094 private:
00095         DISALLOW_COPY_AND_ASSIGN(RobotDrive);
00096 };
00097 
00098 #endif
00099 
 All Classes Functions Variables