David's line following code from the LVBots competition, 2015.
Dependencies: GeneralDebouncer Pacer PololuEncoder mbed
Fork of DeadReckoning by
motors.cpp@5:01ad080dc4fa, 2014-02-20 (annotated)
- Committer:
- DavidEGrayson
- Date:
- Thu Feb 20 23:30:53 2014 +0000
- Revision:
- 5:01ad080dc4fa
- Parent:
- 4:1b20a11765c8
- Child:
- 6:89a39870e23d
Succeeded in getting high resolution PWM.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DavidEGrayson | 4:1b20a11765c8 | 1 | #include <mbed.h> |
DavidEGrayson | 4:1b20a11765c8 | 2 | |
DavidEGrayson | 4:1b20a11765c8 | 3 | static PwmOut motor1Pwm(p26); |
DavidEGrayson | 4:1b20a11765c8 | 4 | DigitalOut motor1Dir(p25); |
DavidEGrayson | 4:1b20a11765c8 | 5 | |
DavidEGrayson | 4:1b20a11765c8 | 6 | static PwmOut motor2Pwm(p24); |
DavidEGrayson | 4:1b20a11765c8 | 7 | DigitalOut motor2Dir(p23); |
DavidEGrayson | 4:1b20a11765c8 | 8 | |
DavidEGrayson | 4:1b20a11765c8 | 9 | |
DavidEGrayson | 4:1b20a11765c8 | 10 | void motors_init() |
DavidEGrayson | 4:1b20a11765c8 | 11 | { |
DavidEGrayson | 4:1b20a11765c8 | 12 | motor1Pwm.period_us(50); |
DavidEGrayson | 4:1b20a11765c8 | 13 | motor2Pwm.period_us(50); |
DavidEGrayson | 5:01ad080dc4fa | 14 | motor1Pwm.pulsewidth_us(20); |
DavidEGrayson | 5:01ad080dc4fa | 15 | motor2Pwm.pulsewidth_us(20); |
DavidEGrayson | 5:01ad080dc4fa | 16 | |
DavidEGrayson | 5:01ad080dc4fa | 17 | LPC_PWM1->MR0 = 1200; // Set the period |
DavidEGrayson | 5:01ad080dc4fa | 18 | LPC_PWM1->MCR = (1 << 1); // Reset PWMTC when it is equal to MR0. |
DavidEGrayson | 5:01ad080dc4fa | 19 | LPC_PWM1->MR1 = 10; |
DavidEGrayson | 5:01ad080dc4fa | 20 | LPC_PWM1->MR3 = 600; |
DavidEGrayson | 4:1b20a11765c8 | 21 | } |
DavidEGrayson | 4:1b20a11765c8 | 22 | |
DavidEGrayson | 4:1b20a11765c8 | 23 | void motors_speed_set(int16_t motor1_speed, int16_t motor2_speed) |
DavidEGrayson | 4:1b20a11765c8 | 24 | { |
DavidEGrayson | 5:01ad080dc4fa | 25 | //LPC_PWM1->MR0 = motor1_speed; |
DavidEGrayson | 5:01ad080dc4fa | 26 | //LPC_PWM1->MR2 = motor2_speed; |
DavidEGrayson | 4:1b20a11765c8 | 27 | } |