David's line following code from the LVBots competition, 2015.
Dependencies: GeneralDebouncer Pacer PololuEncoder mbed
Fork of DeadReckoning by
Diff: motors.cpp
- Revision:
- 32:83a13b06093c
- Parent:
- 9:9734347b5756
- Child:
- 40:e79cefc241f8
diff -r 739b91331f31 -r 83a13b06093c motors.cpp --- a/motors.cpp Tue Mar 04 03:04:00 2014 +0000 +++ b/motors.cpp Tue Mar 04 04:32:51 2014 +0000 @@ -15,6 +15,9 @@ DigitalOut motorLeftDir(p25); DigitalOut motorRightDir(p23); +int16_t motorLeftSpeed = 0;; +int16_t motorRightSpeed = 0; + void motorsInit() { //PwmOut(p26).period_us(100); @@ -45,8 +48,11 @@ LPC_PWM1->TCR = (1 << 0) | (1 << 3); // Enable the PWM counter and enable PWM. } -void motorsSpeedSet(int16_t motorLeftSpeed, int16_t motorRightSpeed) +void motorsSpeedSet(int16_t newMotorLeftSpeed, int16_t newMotorRightSpeed) { + motorLeftSpeed = newMotorLeftSpeed; + motorRightSpeed = newMotorRightSpeed; + if (motorLeftSpeed < 0) { motorLeftSpeed = -motorLeftSpeed;