David's line following code from the LVBots competition, 2015.
Dependencies: GeneralDebouncer Pacer PololuEncoder mbed
Fork of DeadReckoning by
Diff: motors.cpp
- Revision:
- 9:9734347b5756
- Parent:
- 8:78b1ff957cba
- Child:
- 32:83a13b06093c
diff -r 78b1ff957cba -r 9734347b5756 motors.cpp --- a/motors.cpp Sat Feb 22 02:23:21 2014 +0000 +++ b/motors.cpp Sat Feb 22 03:03:37 2014 +0000 @@ -2,20 +2,20 @@ #include "motors.h" // Application mbed pin LPC1768 -// Motor 1 PWM p26 P2[0]/PWM1[1] -// Motor 1 dir p25 -// Motor 2 PWM p24 P2[2]/PWM1[3] -// Motor 2 dir p23 +// Motor L PWM p26 P2[0]/PWM1[1] +// Motor L dir p25 +// Motor R PWM p24 P2[2]/PWM1[3] +// Motor R dir p23 // Clock structure: // System clock: 96 MHz // In LPC_SC->PCLKSEL0, PWM is assigned to system clock / 4 by default, so it ticks at 24 MHz. // This allows us to have 1200 possible speeds at 20 kHz. -DigitalOut motor1Dir(p25); -DigitalOut motor2Dir(p23); +DigitalOut motorLeftDir(p25); +DigitalOut motorRightDir(p23); -void motors_init() +void motorsInit() { //PwmOut(p26).period_us(100); @@ -40,34 +40,34 @@ LPC_PWM1->MR0 = 1200; // Set the period. This must be done before enabling PWM. LPC_PWM1->LER = (1 << 0); - motors_speed_set(0, 0); + motorsSpeedSet(0, 0); LPC_PWM1->TCR = (1 << 0) | (1 << 3); // Enable the PWM counter and enable PWM. } -void motors_speed_set(int16_t motor1_speed, int16_t motor2_speed) +void motorsSpeedSet(int16_t motorLeftSpeed, int16_t motorRightSpeed) { - if (motor1_speed < 0) + if (motorLeftSpeed < 0) { - motor1_speed = -motor1_speed; - motor1Dir = 0; + motorLeftSpeed = -motorLeftSpeed; + motorLeftDir = 0; } else { - motor1Dir = 1; + motorLeftDir = 1; } - LPC_PWM1->MR1 = motor1_speed; + LPC_PWM1->MR1 = motorLeftSpeed; - if (motor2_speed < 0) + if (motorRightSpeed < 0) { - motor2_speed = -motor2_speed; - motor2Dir = 0; + motorRightSpeed = -motorRightSpeed; + motorRightDir = 0; } else { - motor2Dir = 1; + motorRightDir = 1; } - LPC_PWM1->MR3 = motor2_speed; + LPC_PWM1->MR3 = motorRightSpeed; LPC_PWM1->LER |= (1<<1) | (1<<3); }