this is most recent published version of the mbed robots software, demonstrating object avoidance, and some logo based control functions.
Dependencies: mbed Motordriver Servo GP2xx
quickfirstprog.cpp@0:8fe745012832, 2010-12-01 (annotated)
- Committer:
- littlexc
- Date:
- Wed Dec 01 21:34:07 2010 +0000
- Revision:
- 0:8fe745012832
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
littlexc | 0:8fe745012832 | 1 | /* |
littlexc | 0:8fe745012832 | 2 | #include <mbed.h> |
littlexc | 0:8fe745012832 | 3 | #include <motordriver.h> |
littlexc | 0:8fe745012832 | 4 | #include <Servo.h> |
littlexc | 0:8fe745012832 | 5 | #include <GP2xx.h> |
littlexc | 0:8fe745012832 | 6 | //pc interface |
littlexc | 0:8fe745012832 | 7 | Serial pc(USBTX, USBRX); // tx, rx |
littlexc | 0:8fe745012832 | 8 | //servos |
littlexc | 0:8fe745012832 | 9 | Servo LeftServo(p24); |
littlexc | 0:8fe745012832 | 10 | Servo RightServo(p23); |
littlexc | 0:8fe745012832 | 11 | //motors, left and right side |
littlexc | 0:8fe745012832 | 12 | Motor leftM(p22, p6, p5, 1); // pwm, fwd, rev, can break |
littlexc | 0:8fe745012832 | 13 | Motor rightM(p21, p7, p8, 1); // pwm, fwd, rev, can break |
littlexc | 0:8fe745012832 | 14 | //range finders, left and right side, and left and right front |
littlexc | 0:8fe745012832 | 15 | IRRangeFinder LS(p18,1); |
littlexc | 0:8fe745012832 | 16 | IRRangeFinder LF(p17,1); |
littlexc | 0:8fe745012832 | 17 | IRRangeFinder RF(p16,1); |
littlexc | 0:8fe745012832 | 18 | IRRangeFinder RS(p15,1); |
littlexc | 0:8fe745012832 | 19 | //debug leds. |
littlexc | 0:8fe745012832 | 20 | DigitalOut led1 (LED1); |
littlexc | 0:8fe745012832 | 21 | DigitalOut led2 (LED2); |
littlexc | 0:8fe745012832 | 22 | DigitalOut led3 (LED3); |
littlexc | 0:8fe745012832 | 23 | DigitalOut led4 (LED4); |
littlexc | 0:8fe745012832 | 24 | DigitalOut ledleft (p14); |
littlexc | 0:8fe745012832 | 25 | DigitalOut ledright (p13); |
littlexc | 0:8fe745012832 | 26 | DigitalOut ledfront (p12); |
littlexc | 0:8fe745012832 | 27 | |
littlexc | 0:8fe745012832 | 28 | int quickfirstprog() {//initalisation |
littlexc | 0:8fe745012832 | 29 | led1 = led2 = led3 = led4 = 1; |
littlexc | 0:8fe745012832 | 30 | leftM.speed(0.5); |
littlexc | 0:8fe745012832 | 31 | rightM.speed(-0.5); |
littlexc | 0:8fe745012832 | 32 | wait(1); |
littlexc | 0:8fe745012832 | 33 | while (1) {//infinate loop to drive around |
littlexc | 0:8fe745012832 | 34 | switch ( RS.read() ) { |
littlexc | 0:8fe745012832 | 35 | case 4: |
littlexc | 0:8fe745012832 | 36 | leftM.speed(-0.9); |
littlexc | 0:8fe745012832 | 37 | break; |
littlexc | 0:8fe745012832 | 38 | case 5: |
littlexc | 0:8fe745012832 | 39 | leftM.speed(-0.8); |
littlexc | 0:8fe745012832 | 40 | break; |
littlexc | 0:8fe745012832 | 41 | case 7: |
littlexc | 0:8fe745012832 | 42 | leftM.speed(-0.7); |
littlexc | 0:8fe745012832 | 43 | break; |
littlexc | 0:8fe745012832 | 44 | case 8: |
littlexc | 0:8fe745012832 | 45 | leftM.speed(-0.6); |
littlexc | 0:8fe745012832 | 46 | break; |
littlexc | 0:8fe745012832 | 47 | case 10: |
littlexc | 0:8fe745012832 | 48 | leftM.speed(-0.4); |
littlexc | 0:8fe745012832 | 49 | break; |
littlexc | 0:8fe745012832 | 50 | case 12: |
littlexc | 0:8fe745012832 | 51 | leftM.speed(-0.2); |
littlexc | 0:8fe745012832 | 52 | break; |
littlexc | 0:8fe745012832 | 53 | case 14: |
littlexc | 0:8fe745012832 | 54 | leftM.speed(0.0); |
littlexc | 0:8fe745012832 | 55 | break; |
littlexc | 0:8fe745012832 | 56 | case 20: |
littlexc | 0:8fe745012832 | 57 | leftM.speed(0.4); |
littlexc | 0:8fe745012832 | 58 | break; |
littlexc | 0:8fe745012832 | 59 | case 25: |
littlexc | 0:8fe745012832 | 60 | leftM.speed(0.6); |
littlexc | 0:8fe745012832 | 61 | break; |
littlexc | 0:8fe745012832 | 62 | case 30: |
littlexc | 0:8fe745012832 | 63 | leftM.speed(0.8); |
littlexc | 0:8fe745012832 | 64 | break; |
littlexc | 0:8fe745012832 | 65 | } |
littlexc | 0:8fe745012832 | 66 | switch ( LF.read() ) { |
littlexc | 0:8fe745012832 | 67 | case 4: |
littlexc | 0:8fe745012832 | 68 | rightM.speed(-1); |
littlexc | 0:8fe745012832 | 69 | break; |
littlexc | 0:8fe745012832 | 70 | case 5: |
littlexc | 0:8fe745012832 | 71 | rightM.speed(-0.9); |
littlexc | 0:8fe745012832 | 72 | break; |
littlexc | 0:8fe745012832 | 73 | case 7: |
littlexc | 0:8fe745012832 | 74 | rightM.speed(-0.8); |
littlexc | 0:8fe745012832 | 75 | break; |
littlexc | 0:8fe745012832 | 76 | case 8: |
littlexc | 0:8fe745012832 | 77 | rightM.speed(-0.7); |
littlexc | 0:8fe745012832 | 78 | break; |
littlexc | 0:8fe745012832 | 79 | case 10: |
littlexc | 0:8fe745012832 | 80 | rightM.speed(-0.6); |
littlexc | 0:8fe745012832 | 81 | break; |
littlexc | 0:8fe745012832 | 82 | case 12: |
littlexc | 0:8fe745012832 | 83 | rightM.speed(-0.4); |
littlexc | 0:8fe745012832 | 84 | break; |
littlexc | 0:8fe745012832 | 85 | case 14: |
littlexc | 0:8fe745012832 | 86 | rightM.speed(0.0); |
littlexc | 0:8fe745012832 | 87 | break; |
littlexc | 0:8fe745012832 | 88 | case 20: |
littlexc | 0:8fe745012832 | 89 | rightM.speed(0.4); |
littlexc | 0:8fe745012832 | 90 | break; |
littlexc | 0:8fe745012832 | 91 | case 25: |
littlexc | 0:8fe745012832 | 92 | rightM.speed(0.6); |
littlexc | 0:8fe745012832 | 93 | break; |
littlexc | 0:8fe745012832 | 94 | case 30: |
littlexc | 0:8fe745012832 | 95 | rightM.speed(0.8); |
littlexc | 0:8fe745012832 | 96 | break; |
littlexc | 0:8fe745012832 | 97 | } |
littlexc | 0:8fe745012832 | 98 | wait(0.1); |
littlexc | 0:8fe745012832 | 99 | }//end of infinate loop to drive around |
littlexc | 0:8fe745012832 | 100 | }*/ |