WORK IN PROGRESS

Dependencies:   m3pi_ng mbed

Fork of ThursWork by der Roboter

Files at this revision

API Documentation at this revision

Comitter:
satyson
Date:
Tue May 27 13:20:56 2014 +0000
Parent:
2:cc7b01c5a9b0
Commit message:
Finished I believe

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r cc7b01c5a9b0 -r bf9a0cd9750c main.cpp
--- a/main.cpp	Tue May 27 12:49:21 2014 +0000
+++ b/main.cpp	Tue May 27 13:20:56 2014 +0000
@@ -4,6 +4,7 @@
 #include "iostream"
 #include "btbee.h"
  
+ 
 using namespace std;
  
 m3pi thinggy;
@@ -18,8 +19,8 @@
     //..................................................................................................\\
     //......BlueTooth Communication.....................................................................\\
     //..................................................................................................\\
-    
-    // initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////////
+
+   // initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////////
    thinggy.locate(0,1);
    btbee.reset();
    for (int i = 0; i <4; i++) {
@@ -32,13 +33,11 @@
 
    // end initialization stuff ////////////////////////////////////////////////////////////////////////////////////////////////
 
-   thinggy.locate(0,0);
-   wait(0.3);
-   
+  
    thinggy.locate(0,0);
-   thinggy.printf("%s","Tell Me");
+   thinggy.printf("%s","ThySeeMe");
    thinggy.locate(0,1);
-   thinggy.printf("%s","  Why  ");
+   thinggy.printf("%s","Rolling");
 
    // wait for the user to push P21, should be pressed when the bt link is established (green led "link")
    while(m3pi_pb) {
@@ -49,8 +48,8 @@
    int iline=1;
    char arr_read[30]; // this should be long enough to store any reply coming in over bt.
    int  chars_read;   // number of chars read in a bt reply
-   bool go = true;
-   while (go) {
+   
+   while (true) {
        // this writes "Line 001\n" to "Line 005\n" and then "end\n" to the btbee
        if ( btbee.writeable() ) {
            if (iline==6) {
@@ -60,27 +59,14 @@
            else {
                if (iline <6){
                btbee.printf("Line %0.3d \n",iline);
+               m3pi_led[0]=0;
                thinggy.locate(0,0);
                thinggy.printf("Sent %0.3d",iline);
                iline++;
                }
            }//else
        }//if_write
-       go = false;
-    } // while_true
-    
-    go = true;
-    
-    
-    /*
-    while(go){
-       // wait for an input
-      while ( !btbee.readable() ) {
-           wait(0.01);
-           thinggy.locate(0,0);
-           thinggy.printf("I'm waiting");
-       }//while_notReadable
-    */  
+
        // check for answers after each write /not write
        while ( btbee.readable() ) {
            btbee.read_all(arr_read, 30, &chars_read );
@@ -91,99 +77,31 @@
                thinggy.locate(0,1);
                thinggy.cls();
                thinggy.printf("TurningL");
-               // add code to turn left
+               thinggy.left_motor(0.2);
+               thinggy.right_motor(-0.2);
                }
            else if (arr_read[0] == 'r'){
                thinggy.locate(0,1);
                thinggy.cls();
                thinggy.printf("TurningR");
+               thinggy.left_motor(-0.2);
+               thinggy.right_motor(0.2);
                // add code to turn right
                }
            else if (arr_read[0] == 'f'){
                thinggy.locate(0,1);
                thinggy.cls();
                thinggy.printf("GoingFwd");
-               // add code to go forward
+               thinggy.forward(0.1);
                }
-           
-           
-           //thinggy.print(arr_read,chars_read);
+           else if (arr_read[0] == 's'){
+               thinggy.locate(0,1);
+               thinggy.cls();
+               thinggy.printf("Stopping");
+               thinggy.stop();
+               }    
        }//while_readable
-       
        wait(0.1);
    }//while_true
-    
-    //..................................................................................................\\
-    //......End BlueTooth Communication.................................................................\\
-    //..................................................................................................\\
-    
-/*    
-    
-    
-    
-    float speed = 0.25;
-    float correction;
-    float k = -0.3;
-    int sensor[5];
-    int returned;   
-    thinggy.locate(0,1);
-    thinggy.printf("Villan");
-    thinggy.locate(0,0);
-    thinggy.printf("Pimpin");
-    
-    
-    
-    wait(1.0);
- 
-    thinggy.sensor_auto_calibrate();
- 
-    thinggy.calibrated_sensor(sensor);
-    returned = (sensor[1] + sensor[2] + sensor[3])/3;
- 
-    
-    
-    while(1) {
-        // change "if" to while
-        while(returned < 220){
-                while(sensor[0] < sensor[4] && thinggy.line_position() != 0){
-                    thinggy.left_motor(.2);
-                    thinggy.right_motor(-.2);
-                    thinggy.calibrated_sensor(sensor);
-                }
-                while(sensor[4] > sensor[0] && thinggy.line_position() != 0){
-                    thinggy.left_motor(-.2);
-                    thinggy.right_motor(.2);
-                    thinggy.calibrated_sensor(sensor);
-                }
-                thinggy.calibrated_sensor(sensor);
-                returned = (sensor[1] + sensor[2] + sensor[3])/3;
-        }
-        
-        // Curves and straightaways    
-        while(returned > 220){
- 
-        float position = thinggy.line_position();
-        correction = k*(position);
-       
-         // -1.0 is far left, 1.0 is far right, 0.0 in the middle
-        
-        //speed limiting for right motor
-        if(speed + correction > 1){
-            thinggy.right_motor(0.6);
-            thinggy.left_motor(speed-correction);
-        } 
-        else if(speed - correction > 1){
-            thinggy.right_motor(speed+correction);
-            thinggy.left_motor(0.6);
-        }
-        else{
-            thinggy.left_motor(speed-correction);
-            thinggy.right_motor(speed+correction);
-        }
-         thinggy.calibrated_sensor(sensor);
-         returned = (sensor[1] + sensor[2] + sensor[3])/3;   
-        }
-    thinggy.calibrated_sensor(sensor);
-    returned = (sensor[1] + sensor[2] + sensor[3])/3;
-    }
-*/
+
+}//main
\ No newline at end of file