Simple controller class for Stinger Robot without using Robotics Connection board.
Embed:
(wiki syntax)
Show/hide line numbers
Robot.h
00001 #ifndef ROBOT_H 00002 #define ROBOT_H 00003 00004 // This library was designed simplify operation of Stinger robot only with MBED and two H-Bridges. 00005 // Is is still in development. 00006 // Class Robot integrated QEI, PID and Motor classes to work together through use of Ticker function to 00007 // regularly poll QEI objects, adjust PID and Motor objects. 00008 // Right now all pins have been preassigned, later empty constructor will be added with individual pin assignments. 00009 // Pinouts are: 00010 // rightMotor = new Motor(p23, p6, p5); // pwm, fwd, rev 00011 // leftMotor = new Motor(p22, p8, p7); // pwm, fwd, rev 00012 // leftQei = new QEI(p29, p30, NC, 624, QEI::X2_ENCODING); //chanA, chanB, index, ppr 00013 // rightQei = new QEI(p27, p28, NC, 624, QEI::X2_ENCODING); //chanB, chanA, index, ppr 00014 // leftPid = new PID(0.4312, 0.1, 0.0, RATE); //Kc, Ti, Td 00015 // rightPid = new PID(0.4312, 0.1, 0.0, RATE); //Kc, Ti, Td 00016 00017 #include "mbed.h" 00018 #include "Motor.h" 00019 #include "QEI.h" 00020 #include "PID.h" 00021 00022 #define MAX_SPEED 3200 00023 #define RATE 0.05 00024 #define DPP 14.2 //Pulses per degree of motor rotation 00025 00026 /** 00027 * Robot class. 00028 */ 00029 00030 class Robot { 00031 public: 00032 /** 00033 * Constructor 00034 */ 00035 Robot(); 00036 /** 00037 * Destructor 00038 */ 00039 virtual ~Robot(); 00040 /** 00041 * Move Straight 00042 * @param s speed between -1.0 and 1.0 00043 * @param clix Number of pulses to move 00044 */ 00045 void MoveStraightPulses(float s, int clix); 00046 /** 00047 * Move Straight 00048 * @param speed speed between -1.0 and 1.0 00049 * @param in Number of inches to move 00050 */ 00051 void MoveStraightInches(float speed, float in); 00052 /** 00053 * Move Straight 00054 * @param seed speed between -1.0 and 1.0 00055 * @param rotations Number of wheel rotations to move 00056 */ 00057 void MoveStraightRotations(float speed, float rotations); 00058 /** 00059 * Stop Left Wheel 00060 */ 00061 void StopLeft(); 00062 /** 00063 * Stop Right Wheel 00064 */ 00065 void StopRight(); 00066 /** 00067 * Stop 00068 */ 00069 void Stop(); 00070 /** 00071 * Pivet left 00072 * @param deg degrees 00073 */ 00074 void PivetLeft(float deg); 00075 /** 00076 * Pivet right 00077 * @param deg degrees 00078 */ 00079 void PivetRight(float deg); 00080 void RotateLeftWheel(float rpm, float deg); //Rotate Wheel <deg> Degrees 00081 void RotateRightWheel(float rpm, float deg); //Rotate Wheel <deg> Degrees 00082 /** 00083 * Returns 0 if robot is not moving 00084 * Returns 1 otherwise 00085 * @returns flat 00086 */ 00087 int IsBusy(); 00088 00089 00090 protected: 00091 Motor *rightMotor; 00092 Motor *leftMotor; 00093 QEI *leftQei; 00094 QEI *rightQei; 00095 PID *leftPid; 00096 PID *rightPid; 00097 Serial *pc; 00098 /** 00099 * Ticker function 00100 */ 00101 void Call(); 00102 00103 private: 00104 Ticker ticker; 00105 volatile int leftPulses; 00106 volatile int rightPulses; 00107 volatile int leftPrevPulses; 00108 volatile int rightPrevPulses; 00109 volatile int leftPulsesGoTo; 00110 volatile int rightPulsesGoTo; 00111 volatile int leftSpeed; 00112 volatile int rightSpeed; 00113 volatile float rightVelocity; 00114 volatile float leftVelocity; 00115 float leftDirection; 00116 float rightDirection; 00117 }; 00118 00119 #endif /* ROBOT_H */
Generated on Sat Jul 16 2022 16:53:19 by 1.7.2