linear actuator
Dependencies: Motor PinDetect mbed
Fork of xbee_robot by
main.cpp@0:4b7f01607612, 2011-02-27 (annotated)
- Committer:
- buntyshubho
- Date:
- Sun Feb 27 06:12:22 2011 +0000
- Revision:
- 0:4b7f01607612
- Child:
- 1:57f1410e9614
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
buntyshubho | 0:4b7f01607612 | 1 | //Robot Unit with the Xbee module |
buntyshubho | 0:4b7f01607612 | 2 | |
buntyshubho | 0:4b7f01607612 | 3 | #include "mbed.h" |
buntyshubho | 0:4b7f01607612 | 4 | #include "Motor.h" |
buntyshubho | 0:4b7f01607612 | 5 | |
buntyshubho | 0:4b7f01607612 | 6 | Serial xbee2(p9, p10); |
buntyshubho | 0:4b7f01607612 | 7 | DigitalOut rst2(p8); |
buntyshubho | 0:4b7f01607612 | 8 | |
buntyshubho | 0:4b7f01607612 | 9 | Serial pc(USBTX, USBRX); |
buntyshubho | 0:4b7f01607612 | 10 | |
buntyshubho | 0:4b7f01607612 | 11 | DigitalOut myled2(LED3); |
buntyshubho | 0:4b7f01607612 | 12 | DigitalOut myled1(LED4); |
buntyshubho | 0:4b7f01607612 | 13 | |
buntyshubho | 0:4b7f01607612 | 14 | Motor m1(p23, p11, p12); // pwm, fwd, rev //lEFT MOTOR |
buntyshubho | 0:4b7f01607612 | 15 | Motor m2(p22, p14, p15); // pwm, fwd, rev //rIGHT MOTOR |
buntyshubho | 0:4b7f01607612 | 16 | |
buntyshubho | 0:4b7f01607612 | 17 | Motor m3(p23, p12, p11); // pwm, rev, fwd |
buntyshubho | 0:4b7f01607612 | 18 | Motor m4(p22, p15, p14); // pwm, rev, fwd |
buntyshubho | 0:4b7f01607612 | 19 | int main() { |
buntyshubho | 0:4b7f01607612 | 20 | char temp = '0'; |
buntyshubho | 0:4b7f01607612 | 21 | |
buntyshubho | 0:4b7f01607612 | 22 | // reset the xbees (at least 200ns) |
buntyshubho | 0:4b7f01607612 | 23 | // rst1 = 0; |
buntyshubho | 0:4b7f01607612 | 24 | rst2 = 0; |
buntyshubho | 0:4b7f01607612 | 25 | wait_ms(1); |
buntyshubho | 0:4b7f01607612 | 26 | //rst1 = 1; |
buntyshubho | 0:4b7f01607612 | 27 | rst2 = 1; |
buntyshubho | 0:4b7f01607612 | 28 | wait_ms(1); |
buntyshubho | 0:4b7f01607612 | 29 | |
buntyshubho | 0:4b7f01607612 | 30 | for (float s= -1.0; s < 1.0 ; s += 0.01) { |
buntyshubho | 0:4b7f01607612 | 31 | while(1) { |
buntyshubho | 0:4b7f01607612 | 32 | temp = xbee2.getc(); |
buntyshubho | 0:4b7f01607612 | 33 | if(temp == 'C'){ //FORWARD |
buntyshubho | 0:4b7f01607612 | 34 | m1.speed(s); |
buntyshubho | 0:4b7f01607612 | 35 | m2.speed(s); |
buntyshubho | 0:4b7f01607612 | 36 | wait(0.02); |
buntyshubho | 0:4b7f01607612 | 37 | } |
buntyshubho | 0:4b7f01607612 | 38 | |
buntyshubho | 0:4b7f01607612 | 39 | if(temp == 'D'){ //REVERSE |
buntyshubho | 0:4b7f01607612 | 40 | m3.speed(s); |
buntyshubho | 0:4b7f01607612 | 41 | m4.speed(s); |
buntyshubho | 0:4b7f01607612 | 42 | wait(0.02); |
buntyshubho | 0:4b7f01607612 | 43 | } |
buntyshubho | 0:4b7f01607612 | 44 | |
buntyshubho | 0:4b7f01607612 | 45 | myled1 = 1; |
buntyshubho | 0:4b7f01607612 | 46 | wait_ms(1); |
buntyshubho | 0:4b7f01607612 | 47 | myled1 = 0; |
buntyshubho | 0:4b7f01607612 | 48 | myled2 =1; |
buntyshubho | 0:4b7f01607612 | 49 | |
buntyshubho | 0:4b7f01607612 | 50 | } |
buntyshubho | 0:4b7f01607612 | 51 | } |
buntyshubho | 0:4b7f01607612 | 52 | } |