Test servo, IR sensor, and motor setup on Sparkfun Shadow robot base
Dependencies: Motordriver mbed
Fork of Magician_Motor_Test by
main.cpp@0:5c26b3940003, 2011-10-26 (annotated)
- Committer:
- 4180_1
- Date:
- Wed Oct 26 01:12:51 2011 +0000
- Revision:
- 0:5c26b3940003
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:5c26b3940003 | 1 | // Magician robot motor test |
4180_1 | 0:5c26b3940003 | 2 | |
4180_1 | 0:5c26b3940003 | 3 | #include "mbed.h" |
4180_1 | 0:5c26b3940003 | 4 | #include "motordriver.h" |
4180_1 | 0:5c26b3940003 | 5 | |
4180_1 | 0:5c26b3940003 | 6 | DigitalOut myled(LED1); |
4180_1 | 0:5c26b3940003 | 7 | |
4180_1 | 0:5c26b3940003 | 8 | //See http://mbed.org/cookbook/Motor |
4180_1 | 0:5c26b3940003 | 9 | //Connections to dual H-brdige driver for the two drive motors |
4180_1 | 0:5c26b3940003 | 10 | Motor left(p21, p22, p23, 1); // pwm, fwd, rev, has brake feature |
4180_1 | 0:5c26b3940003 | 11 | Motor right(p26, p25, p24, 1); |
4180_1 | 0:5c26b3940003 | 12 | |
4180_1 | 0:5c26b3940003 | 13 | int main() { |
4180_1 | 0:5c26b3940003 | 14 | while (1) { |
4180_1 | 0:5c26b3940003 | 15 | myled=1; |
4180_1 | 0:5c26b3940003 | 16 | // Sweep the motor speed from full-speed reverse (-1.0) to full speed forwards (1.0) |
4180_1 | 0:5c26b3940003 | 17 | for (float s= -1.0; s < 1.0 ; s += 0.01) { |
4180_1 | 0:5c26b3940003 | 18 | left.speed(s); |
4180_1 | 0:5c26b3940003 | 19 | right.speed(s); |
4180_1 | 0:5c26b3940003 | 20 | wait(0.02); |
4180_1 | 0:5c26b3940003 | 21 | } |
4180_1 | 0:5c26b3940003 | 22 | // Turn off motors - coast one and brake one |
4180_1 | 0:5c26b3940003 | 23 | left.coast(); |
4180_1 | 0:5c26b3940003 | 24 | right.stop(1); |
4180_1 | 0:5c26b3940003 | 25 | myled=0; |
4180_1 | 0:5c26b3940003 | 26 | wait(1); |
4180_1 | 0:5c26b3940003 | 27 | } |
4180_1 | 0:5c26b3940003 | 28 | } |