David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.
Dependencies: PololuEncoder Pacer mbed GeneralDebouncer
Revision 4:1b20a11765c8, committed 2014-02-20
- Comitter:
- DavidEGrayson
- Date:
- Thu Feb 20 22:59:28 2014 +0000
- Parent:
- 3:59c80d4b4bf2
- Child:
- 5:01ad080dc4fa
- Commit message:
- Succeeded in generating basic PWM signals with PwmOut.
Changed in this revision
--- a/main.cpp Thu Feb 20 22:24:32 2014 +0000 +++ b/main.cpp Thu Feb 20 22:59:28 2014 +0000 @@ -1,6 +1,7 @@ #include <mbed.h> #include "PololuEncoder.h" #include "Pacer.h" +#include "motors.h" DigitalOut led1(LED1), led2(LED2); @@ -30,12 +31,17 @@ wait_us(50); encoder1.init(); encoder2.init(); + + motors_init(); + + motors_speed_set(5, 55); Pacer reportPacer(250000); Pacer blinkPacer(200000); uint32_t eventCount = 0; uint32_t count = 0; - while(1) { + while(1) + { while(encoderBuffer.hasEvents()) { PololuEncoderEvent event = encoderBuffer.readEvent();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motors.cpp Thu Feb 20 22:59:28 2014 +0000 @@ -0,0 +1,20 @@ +#include <mbed.h> + +static PwmOut motor1Pwm(p26); +DigitalOut motor1Dir(p25); + +static PwmOut motor2Pwm(p24); +DigitalOut motor2Dir(p23); + + +void motors_init() +{ + motor1Pwm.period_us(50); + motor2Pwm.period_us(50); +} + +void motors_speed_set(int16_t motor1_speed, int16_t motor2_speed) +{ + motor1Pwm.pulsewidth_us(motor1_speed); + motor2Pwm.pulsewidth_us(motor2_speed); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motors.h Thu Feb 20 22:59:28 2014 +0000 @@ -0,0 +1,2 @@ +void motors_init(); +void motors_speed_set(int16_t motor1_speed, int16_t motor2_speed);