stepper test
Dependencies: LongRangeSensor R5_StepperDrive mbed scanner
main.cpp@0:76bca1f580a0, 2016-04-01 (annotated)
- Committer:
- j_j205
- Date:
- Fri Apr 01 22:21:38 2016 +0000
- Revision:
- 0:76bca1f580a0
stepper test jj
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j_j205 | 0:76bca1f580a0 | 1 | #include "scanner.h" |
j_j205 | 0:76bca1f580a0 | 2 | #include "StepperDrive.h" |
j_j205 | 0:76bca1f580a0 | 3 | #include "LongRangeSensor.h" |
j_j205 | 0:76bca1f580a0 | 4 | #include "stdint.h" |
j_j205 | 0:76bca1f580a0 | 5 | #include "mbed.h" |
j_j205 | 0:76bca1f580a0 | 6 | |
j_j205 | 0:76bca1f580a0 | 7 | Serial pc(USBTX, USBRX); |
j_j205 | 0:76bca1f580a0 | 8 | Serial bluetooth(PTE16,PTE17); // bluetooth |
j_j205 | 0:76bca1f580a0 | 9 | InterruptIn start(SW1); |
j_j205 | 0:76bca1f580a0 | 10 | DigitalOut led_red(LED_RED); |
j_j205 | 0:76bca1f580a0 | 11 | DigitalOut led_green(LED_GREEN); |
j_j205 | 0:76bca1f580a0 | 12 | bool active = false; |
j_j205 | 0:76bca1f580a0 | 13 | |
j_j205 | 0:76bca1f580a0 | 14 | void activate() |
j_j205 | 0:76bca1f580a0 | 15 | { |
j_j205 | 0:76bca1f580a0 | 16 | led_red = 1; |
j_j205 | 0:76bca1f580a0 | 17 | led_green = 0; |
j_j205 | 0:76bca1f580a0 | 18 | active = true; |
j_j205 | 0:76bca1f580a0 | 19 | } |
j_j205 | 0:76bca1f580a0 | 20 | |
j_j205 | 0:76bca1f580a0 | 21 | int main() |
j_j205 | 0:76bca1f580a0 | 22 | { |
j_j205 | 0:76bca1f580a0 | 23 | pc.baud(115200); |
j_j205 | 0:76bca1f580a0 | 24 | bluetooth.baud(9600); /* interface via Bluetooth at 9600 */ |
j_j205 | 0:76bca1f580a0 | 25 | start.mode(PullUp); /* Start/Stop button is active low needing PullUp */ |
j_j205 | 0:76bca1f580a0 | 26 | start.fall(&activate); |
j_j205 | 0:76bca1f580a0 | 27 | |
j_j205 | 0:76bca1f580a0 | 28 | led_red = 0; |
j_j205 | 0:76bca1f580a0 | 29 | led_green = 1; |
j_j205 | 0:76bca1f580a0 | 30 | |
j_j205 | 0:76bca1f580a0 | 31 | StepperDrive drive(pc, PTE19, PTE18, 1, PTE3, PTE2, 0, 10.0625, 8.4800, 650); // 8.375 |
j_j205 | 0:76bca1f580a0 | 32 | //(serial &, stepPinLeft, dirPinLeft, invertLeft, stepPinRight, dirPinRight, invertRight, wheelCircum, wheelSepar, periodUs) |
j_j205 | 0:76bca1f580a0 | 33 | |
j_j205 | 0:76bca1f580a0 | 34 | LongRangeSensor longRangeL(pc, PTB2); |
j_j205 | 0:76bca1f580a0 | 35 | LongRangeSensor longRangeR(pc, PTB3); |
j_j205 | 0:76bca1f580a0 | 36 | |
j_j205 | 0:76bca1f580a0 | 37 | Scanner scanner(pc, drive, PTB0, PTB1, longRangeL, longRangeR, 1.0); // original period = 0.075 |
j_j205 | 0:76bca1f580a0 | 38 | // (Serial &, PinName servoL, PinName servoR, shortRangeL, shortRangeR, longRangeL, longRangeR, period) |
j_j205 | 0:76bca1f580a0 | 39 | |
j_j205 | 0:76bca1f580a0 | 40 | pc.printf("\nWaiting for START BUTTON\n"); |
j_j205 | 0:76bca1f580a0 | 41 | bluetooth.printf("\nWaiting for START BUTTON\n"); |
j_j205 | 0:76bca1f580a0 | 42 | while(!active) // wait for start_button |
j_j205 | 0:76bca1f580a0 | 43 | { |
j_j205 | 0:76bca1f580a0 | 44 | wait(1e-6); |
j_j205 | 0:76bca1f580a0 | 45 | } |
j_j205 | 0:76bca1f580a0 | 46 | |
j_j205 | 0:76bca1f580a0 | 47 | pc.printf("\nBegin 1st peg retrieval"); |
j_j205 | 0:76bca1f580a0 | 48 | bluetooth.printf("\nBegin 1st peg retrieval"); |
j_j205 | 0:76bca1f580a0 | 49 | |
j_j205 | 0:76bca1f580a0 | 50 | drive.move(13.0, 0.0); |
j_j205 | 0:76bca1f580a0 | 51 | scanner.setLocalizeRightFlag(0); |
j_j205 | 0:76bca1f580a0 | 52 | pc.printf("\n LocalizeRight on"); |
j_j205 | 0:76bca1f580a0 | 53 | bluetooth.printf("\n LocalizeRight on"); |
j_j205 | 0:76bca1f580a0 | 54 | scanner.setLocalizeLeftFlag(0); |
j_j205 | 0:76bca1f580a0 | 55 | // wait for move to complete |
j_j205 | 0:76bca1f580a0 | 56 | while(!drive.isMoveDone()) |
j_j205 | 0:76bca1f580a0 | 57 | { |
j_j205 | 0:76bca1f580a0 | 58 | wait(1e-6); |
j_j205 | 0:76bca1f580a0 | 59 | } |
j_j205 | 0:76bca1f580a0 | 60 | pc.printf("\nMoved from 0 to 1"); |
j_j205 | 0:76bca1f580a0 | 61 | bluetooth.printf("\nMoved from 0 to 1"); |
j_j205 | 0:76bca1f580a0 | 62 | |
j_j205 | 0:76bca1f580a0 | 63 | scanner.setLocalizeRightFlag(0); |
j_j205 | 0:76bca1f580a0 | 64 | pc.printf("\n LocalizeRight off"); |
j_j205 | 0:76bca1f580a0 | 65 | bluetooth.printf("\n LocalizeRight off"); |
j_j205 | 0:76bca1f580a0 | 66 | scanner.setLocalizeLeftFlag(0); |
j_j205 | 0:76bca1f580a0 | 67 | drive.move(0.0, (-90.0)*(3.14159 / 180.0)); |
j_j205 | 0:76bca1f580a0 | 68 | // wait for move to complete |
j_j205 | 0:76bca1f580a0 | 69 | while(!drive.isMoveDone()) |
j_j205 | 0:76bca1f580a0 | 70 | { |
j_j205 | 0:76bca1f580a0 | 71 | wait(1e-6); |
j_j205 | 0:76bca1f580a0 | 72 | } |
j_j205 | 0:76bca1f580a0 | 73 | pc.printf("\nMoved left 90 degrees"); |
j_j205 | 0:76bca1f580a0 | 74 | bluetooth.printf("\nMoved left 90 degrees"); |
j_j205 | 0:76bca1f580a0 | 75 | |
j_j205 | 0:76bca1f580a0 | 76 | drive.move(15.0, 0.0); |
j_j205 | 0:76bca1f580a0 | 77 | scanner.setLocalizeRightFlag(0); |
j_j205 | 0:76bca1f580a0 | 78 | scanner.setLocalizeLeftFlag(0); |
j_j205 | 0:76bca1f580a0 | 79 | // wait for move to complete |
j_j205 | 0:76bca1f580a0 | 80 | while(!drive.isMoveDone()) |
j_j205 | 0:76bca1f580a0 | 81 | { |
j_j205 | 0:76bca1f580a0 | 82 | wait(1e-6); |
j_j205 | 0:76bca1f580a0 | 83 | } |
j_j205 | 0:76bca1f580a0 | 84 | pc.printf("\nMoved from 1 to 3"); |
j_j205 | 0:76bca1f580a0 | 85 | bluetooth.printf("\nMoved from 1 to 3"); |
j_j205 | 0:76bca1f580a0 | 86 | |
j_j205 | 0:76bca1f580a0 | 87 | scanner.setLocalizeRightFlag(0); |
j_j205 | 0:76bca1f580a0 | 88 | scanner.setLocalizeLeftFlag(0); |
j_j205 | 0:76bca1f580a0 | 89 | drive.move(0.0, (90.0)*(3.14159 / 180.0)); |
j_j205 | 0:76bca1f580a0 | 90 | // wait for move to complete |
j_j205 | 0:76bca1f580a0 | 91 | while(!drive.isMoveDone()) |
j_j205 | 0:76bca1f580a0 | 92 | { |
j_j205 | 0:76bca1f580a0 | 93 | wait(1e-6); |
j_j205 | 0:76bca1f580a0 | 94 | } |
j_j205 | 0:76bca1f580a0 | 95 | pc.printf("\nMoved right 90 degrees"); |
j_j205 | 0:76bca1f580a0 | 96 | bluetooth.printf("\nMoved right 90 degrees"); |
j_j205 | 0:76bca1f580a0 | 97 | |
j_j205 | 0:76bca1f580a0 | 98 | drive.move(6.0, 0.0); |
j_j205 | 0:76bca1f580a0 | 99 | scanner.setLocalizeRightFlag(0); |
j_j205 | 0:76bca1f580a0 | 100 | scanner.setLocalizeLeftFlag(0); |
j_j205 | 0:76bca1f580a0 | 101 | // wait for move to complete |
j_j205 | 0:76bca1f580a0 | 102 | while(!drive.isMoveDone()) |
j_j205 | 0:76bca1f580a0 | 103 | { |
j_j205 | 0:76bca1f580a0 | 104 | wait(1e-6); |
j_j205 | 0:76bca1f580a0 | 105 | } |
j_j205 | 0:76bca1f580a0 | 106 | pc.printf("\nMoved from 3 to 15"); |
j_j205 | 0:76bca1f580a0 | 107 | bluetooth.printf("\nMoved from 3 to 15"); |
j_j205 | 0:76bca1f580a0 | 108 | |
j_j205 | 0:76bca1f580a0 | 109 | drive.move(60.0, 0.0); |
j_j205 | 0:76bca1f580a0 | 110 | scanner.setLocalizeRightFlag(1); |
j_j205 | 0:76bca1f580a0 | 111 | pc.printf("\n LocalizeRight on"); |
j_j205 | 0:76bca1f580a0 | 112 | scanner.setLocalizeLeftFlag(0); |
j_j205 | 0:76bca1f580a0 | 113 | // wait for move to complete |
j_j205 | 0:76bca1f580a0 | 114 | while(!drive.isMoveDone()) |
j_j205 | 0:76bca1f580a0 | 115 | { |
j_j205 | 0:76bca1f580a0 | 116 | wait(1e-6); |
j_j205 | 0:76bca1f580a0 | 117 | } |
j_j205 | 0:76bca1f580a0 | 118 | pc.printf("\nMoved from 15 to 7"); |
j_j205 | 0:76bca1f580a0 | 119 | bluetooth.printf("\nMoved from 15 to 7"); |
j_j205 | 0:76bca1f580a0 | 120 | |
j_j205 | 0:76bca1f580a0 | 121 | pc.printf("\nExercise Complete"); |
j_j205 | 0:76bca1f580a0 | 122 | bluetooth.printf("\nExercise Complete"); |
j_j205 | 0:76bca1f580a0 | 123 | } |