![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
StingerBot Project
Dependencies: mbed HMC6352 mbed-rtos
Diff: RobotControl.h
- Revision:
- 0:b6fd1c37944a
- Child:
- 1:41cee26b35cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RobotControl.h Fri Apr 11 17:40:07 2014 +0000 @@ -0,0 +1,46 @@ +//******************************************* +//* Robot motor control and drive functions * +//******************************************* + +#include "HMC6352.h" + +//Gyro +HMC6532 compass(p28, p27); + +//H-bridge +PwmOut rightMotorPWM(p21); //Channel A +PwmOut leftMotorPWM(p22); //Channel B +DigitalOut leftMotor1(p23); +DigitalOut leftMotor2(p24); +DigitalOut rightMotor1(p25); +DigitalOut rightMotor2(p26); + +//Non-feedback corrected 'dumb' driving +void setDriveStraight(float speed, bool reverse) { + //Set speed + rightMotorPWM = speed; + leftMotorPWM = speed; + + //Set motor function + leftMotor1 = (!reverse) ? 0 : 1; + leftMotor2 = (!reverse) ? 1 : 0; + rightMotor1 = (!reverse) ? 0 : 1; + rightMotor2 = (!reverse) ? 1 : 0; +} + +//Stop with braking +void stop() { + rightMotorPWM = 0; + leftMotorPWM = 0; + leftMotor1 = 0; + leftMotor2 = 0; + rightMotor1 = 0; + rightMotor2 = 0; +} + +//Need compass module +void gyroDriveStraight(float speed, bool reverse); +void centerTurnLeft(int delta_degrees); +void centerTurnRight(int delta_degrees); +void driveTurnLeft(int delta_degrees); +void driveTurnRight(int delta_degrees);