for bluetooth
Dependencies: btbee m3pi_ng mbed
Fork of WarehouseBot1 by
Diff: Robot-bae8eb81a9d7/main.cpp
- Revision:
- 1:2db3ccba18c8
- Parent:
- 0:0f96a93fbf39
- Child:
- 2:2d147091491d
diff -r 0f96a93fbf39 -r 2db3ccba18c8 Robot-bae8eb81a9d7/main.cpp --- a/Robot-bae8eb81a9d7/main.cpp Wed Jun 03 13:32:30 2015 +0000 +++ b/Robot-bae8eb81a9d7/main.cpp Wed Jun 03 14:29:48 2015 +0000 @@ -39,9 +39,15 @@ int Run = 1; - vector< vector<string> > Lookup(6, vector<string>(6)); + string blah[36] = {"", "LRRL", "SSRL", "RLSRL", "RLLLRSRLL", "LRLL", + "RLLR", "", "SSR", "RLRR", "RLLRLSR", "LRSLR", + "RLSS", "LLS", "", "RR", "RLSLR", "LRSSS", + "RLSRL", "LLRL", "LL", "", "RLSS", "RLRLS", + "RRSRR", "LSRLRRL", "LRSRL", "SSRL", "", "RLRRRL", + "RRR", "LRSLR", "SSSLR", "SRLL", "RLLLRL", ""}; + //vector< vector<string> > Lookup(6, vector<string>(6)); - Lookup[1][4] = "LLS"; + //Lookup[1][2] = "LLS"; @@ -49,7 +55,7 @@ time_wait.start(); - turns = Lookup[0][1]; + turns = blah[(3-1)*6+(2-1)]; while(Run) { time_wait.reset(); //Get raw sensor values @@ -65,37 +71,48 @@ } - + if((x[0]>300 || x[4]>300) && (direction < turns.size()) && !passed) { + if(turns.at(direction) == 'L'){ + previous_pos = 0; robot.stop(); - wait(1); + //wait(1); turnLeft(); robot.stop(); + //continue; + /*wait(1); goStraight(); - wait(1); + wait(1);*/ } else if(turns.at(direction) == 'R'){ + previous_pos = 0; robot.stop(); - wait(1); + //wait(1); turnRight(); robot.stop(); + + /*wait(1); goStraight(); - wait(1); + wait(1);*/ } else{ robot.stop(); wait(1); goStraight(); - wait(1); + //wait(1); } - robot.printf("Size: %d", direction); + robot.cls(); + robot.printf("Size %d", direction); ++direction; - robot.calibrated_sensor(x); + passed = true; + continue; } else if (x[0]>300 || x[4]>300 && direction >= turns.size()){ robot.stop(); + robot.cls(); + robot.printf("Try again"); break; } else if (x[0]>300 || x[4]>300 && passed) @@ -146,14 +163,14 @@ robot.stop(); - char hail[]= {'V','1','5','O','4','E','4','C','8','D','8','E','8','C','8','D','8' + /*char hail[]= {'V','1','5','O','4','E','4','C','8','D','8','E','8','C','8','D','8' ,'E','8','F','4','D','8','E','8','F','8','D','8','E','8','F','8','G' ,'4','A','4','E','1','6','E','1','6','F','8','C','8','D','8','E','8' ,'G','8','E','8','D','8','C','4' }; int numb = 59; - robot.playtune(hail,numb); + robot.playtune(hail,numb);*/ } @@ -162,7 +179,7 @@ void turnRight(){ Timer turner; turner.start(); - while (turner.read_ms() < 105){ + while (turner.read_ms() < 130){ robot.right(.5); } turner.stop(); @@ -171,7 +188,7 @@ void turnLeft(){ Timer turner; turner.start(); - while (turner.read_ms() < 105){ + while (turner.read_ms() < 130){ robot.left(.5); } turner.stop(); @@ -180,7 +197,7 @@ void goStraight(){ Timer turner; turner.start(); - while (turner.read_ms() < 50){ + while (turner.read_ms() < 25){ robot.forward(.5); } turner.stop();