![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
StingerBot Project
Dependencies: mbed HMC6352 mbed-rtos
RobotControl.h@0:b6fd1c37944a, 2014-04-11 (annotated)
- Committer:
- Strikewolf
- Date:
- Fri Apr 11 17:40:07 2014 +0000
- Revision:
- 0:b6fd1c37944a
- Child:
- 1:41cee26b35cc
Intial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Strikewolf | 0:b6fd1c37944a | 1 | //******************************************* |
Strikewolf | 0:b6fd1c37944a | 2 | //* Robot motor control and drive functions * |
Strikewolf | 0:b6fd1c37944a | 3 | //******************************************* |
Strikewolf | 0:b6fd1c37944a | 4 | |
Strikewolf | 0:b6fd1c37944a | 5 | #include "HMC6352.h" |
Strikewolf | 0:b6fd1c37944a | 6 | |
Strikewolf | 0:b6fd1c37944a | 7 | //Gyro |
Strikewolf | 0:b6fd1c37944a | 8 | HMC6532 compass(p28, p27); |
Strikewolf | 0:b6fd1c37944a | 9 | |
Strikewolf | 0:b6fd1c37944a | 10 | //H-bridge |
Strikewolf | 0:b6fd1c37944a | 11 | PwmOut rightMotorPWM(p21); //Channel A |
Strikewolf | 0:b6fd1c37944a | 12 | PwmOut leftMotorPWM(p22); //Channel B |
Strikewolf | 0:b6fd1c37944a | 13 | DigitalOut leftMotor1(p23); |
Strikewolf | 0:b6fd1c37944a | 14 | DigitalOut leftMotor2(p24); |
Strikewolf | 0:b6fd1c37944a | 15 | DigitalOut rightMotor1(p25); |
Strikewolf | 0:b6fd1c37944a | 16 | DigitalOut rightMotor2(p26); |
Strikewolf | 0:b6fd1c37944a | 17 | |
Strikewolf | 0:b6fd1c37944a | 18 | //Non-feedback corrected 'dumb' driving |
Strikewolf | 0:b6fd1c37944a | 19 | void setDriveStraight(float speed, bool reverse) { |
Strikewolf | 0:b6fd1c37944a | 20 | //Set speed |
Strikewolf | 0:b6fd1c37944a | 21 | rightMotorPWM = speed; |
Strikewolf | 0:b6fd1c37944a | 22 | leftMotorPWM = speed; |
Strikewolf | 0:b6fd1c37944a | 23 | |
Strikewolf | 0:b6fd1c37944a | 24 | //Set motor function |
Strikewolf | 0:b6fd1c37944a | 25 | leftMotor1 = (!reverse) ? 0 : 1; |
Strikewolf | 0:b6fd1c37944a | 26 | leftMotor2 = (!reverse) ? 1 : 0; |
Strikewolf | 0:b6fd1c37944a | 27 | rightMotor1 = (!reverse) ? 0 : 1; |
Strikewolf | 0:b6fd1c37944a | 28 | rightMotor2 = (!reverse) ? 1 : 0; |
Strikewolf | 0:b6fd1c37944a | 29 | } |
Strikewolf | 0:b6fd1c37944a | 30 | |
Strikewolf | 0:b6fd1c37944a | 31 | //Stop with braking |
Strikewolf | 0:b6fd1c37944a | 32 | void stop() { |
Strikewolf | 0:b6fd1c37944a | 33 | rightMotorPWM = 0; |
Strikewolf | 0:b6fd1c37944a | 34 | leftMotorPWM = 0; |
Strikewolf | 0:b6fd1c37944a | 35 | leftMotor1 = 0; |
Strikewolf | 0:b6fd1c37944a | 36 | leftMotor2 = 0; |
Strikewolf | 0:b6fd1c37944a | 37 | rightMotor1 = 0; |
Strikewolf | 0:b6fd1c37944a | 38 | rightMotor2 = 0; |
Strikewolf | 0:b6fd1c37944a | 39 | } |
Strikewolf | 0:b6fd1c37944a | 40 | |
Strikewolf | 0:b6fd1c37944a | 41 | //Need compass module |
Strikewolf | 0:b6fd1c37944a | 42 | void gyroDriveStraight(float speed, bool reverse); |
Strikewolf | 0:b6fd1c37944a | 43 | void centerTurnLeft(int delta_degrees); |
Strikewolf | 0:b6fd1c37944a | 44 | void centerTurnRight(int delta_degrees); |
Strikewolf | 0:b6fd1c37944a | 45 | void driveTurnLeft(int delta_degrees); |
Strikewolf | 0:b6fd1c37944a | 46 | void driveTurnRight(int delta_degrees); |