This program is for an autonomous robot for the competition at the Hochschule Luzern. http://cruisingcrepe.wordpress.com/ We are one of the 32 teams. http://cruisingcrepe.wordpress.com/ The postition control is based on this Documentation: Control of Wheeled Mobile Robots: An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli. For more information see here: http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf

Dependencies:   mbed

Fork of autonomous Robot Android by Christian Burri

Revision:
21:48248c5b8992
Parent:
20:01b233b0e606
Child:
22:bfec16575c91
--- a/main.cpp	Fri May 03 14:39:24 2013 +0000
+++ b/main.cpp	Fri May 17 06:39:44 2013 +0000
@@ -23,9 +23,9 @@
  * An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli.
  * For more information see here: <a href="http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf">http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf</a>
  *
- * The connection to an android smartphone is realise with the library AndroidAccessory from Rich Bayliss.
- * For more information see here: <a href="https://mbed.org/users/richbayliss/code/AndroidAccessory/docs/tip/">https://mbed.org/users/richbayliss/code/AndroidAccessory/docs/tip/</a>
- * 
+ * The connection to an android smartphone is realise with the library MicroBridge(Android ADB) from Junichi Katsu.
+ * For more information see here: <a href="http://mbed.org/users/jksoft/code/MicroBridge/">http://mbed.org/users/jksoft/code/MicroBridge/</a>
+ *
  * The rest of the classes are only based on standard library from mbed.
  * For more information see here: <a href="http://mbed.org/users/mbed_official/code/mbed/">http://mbed.org/users/mbed_official/code/mbed/</a>
  */
@@ -38,7 +38,6 @@
 #include "State.h"
 #include "RobotControl.h"
 #include "androidADB.h"
-//#include "android.h"
 
 /**
  * @name Hallsensor
@@ -103,11 +102,6 @@
  * @{
  */
 
-/**
- * @brief <code>adkTerm</code> object is for the communication with a smartphone.
- * The operation system must be a android.
- */
-//AdkTerm adkTerm(&robotControl, &s, PERIOD_ANDROID);
 /*! @} */
 
 
@@ -143,121 +137,102 @@
     robotControl.setAllToZero(0, 0, PI/2 );
     //robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
     robotControl.start();
-    /*
-    pc.baud(460800);
-    pc.printf("Welcome to adkTerm\n\n\n\n\n\n\r");
-    pc.printf("here we go... \n");
-    adkTerm.setupDevice();
-    pc.printf("Android Development Kit: start\r\n");
-    USBInit();
-    
-    //wait(3);
-    
-    adkTerm.start();
-
-  */
 
     //  Epä Parkour fahrä
- /*   
-        robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
-        wait(0.1);
+    /*
+           robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
+           wait(0.1);
 
-        robotControl.setDesiredPositionAndAngle(-1.50f, 1.50f,  3*PI/4);
-        while(!(robotControl.getDistanceError() <= 0.9)) {
-            state.savePlotFile(s);
-        };
+           robotControl.setDesiredPositionAndAngle(-1.50f, 1.50f,  3*PI/4);
+           while(!(robotControl.getDistanceError() <= 0.9)) {
+               state.savePlotFile(s);
+           };
 
-        robotControl.setDesiredPositionAndAngle(-1.20f, 2.1f,  PI/4);
-        while(!(robotControl.getDistanceError() <= 0.7)) {
-            state.savePlotFile(s);
-        };
+           robotControl.setDesiredPositionAndAngle(-1.20f, 2.1f,  PI/4);
+           while(!(robotControl.getDistanceError() <= 0.7)) {
+               state.savePlotFile(s);
+           };
 
-        robotControl.setDesiredPositionAndAngle(-0.5f, 3.0f,  PI/2); //0.75
-        while(!(robotControl.getDistanceError() <= 0.7)) {
-            state.savePlotFile(s);
-        };
+           robotControl.setDesiredPositionAndAngle(-0.5f, 3.0f,  PI/2); //0.75
+           while(!(robotControl.getDistanceError() <= 0.7)) {
+               state.savePlotFile(s);
+           };
 
-        robotControl.setDesiredPositionAndAngle(-1.0f, 3.75f,  3*PI/4);
-        while(!(robotControl.getDistanceError() <= 0.55)) {
-            state.savePlotFile(s);
-        };
+           robotControl.setDesiredPositionAndAngle(-1.0f, 3.75f,  3*PI/4);
+           while(!(robotControl.getDistanceError() <= 0.55)) {
+               state.savePlotFile(s);
+           };
 
 
-        robotControl.setDesiredPositionAndAngle(-1.5f, 3.6f,  PI);
-        while(!(robotControl.getDistanceError() <= 0.05)) {
-            state.savePlotFile(s);
-        };
+           robotControl.setDesiredPositionAndAngle(-1.5f, 3.6f,  PI);
+           while(!(robotControl.getDistanceError() <= 0.05)) {
+               state.savePlotFile(s);
+           };
 
-        robotControl.setDesiredPositionAndAngle(-2.6f, 3.0f,  -PI/2);
-        while(!(robotControl.getDistanceError() <= 1.0)) {
-            state.savePlotFile(s);
-        };
-        
-                robotControl.setDesiredPositionAndAngle(-2.0f, 2.0f,  -PI/2);
-        while(!(robotControl.getDistanceError() <= 1.0)) {
-            state.savePlotFile(s);
-        };
+           robotControl.setDesiredPositionAndAngle(-2.6f, 3.0f,  -PI/2);
+           while(!(robotControl.getDistanceError() <= 1.0)) {
+               state.savePlotFile(s);
+           };
 
-        robotControl.setDesiredPositionAndAngle(-2.65f, 1.30f,  -PI/2);
-        while(!(robotControl.getDistanceError() <= 0.4)) {
-            state.savePlotFile(s);
-        };
-        robotControl.setDesiredPositionAndAngle(-2.65f, 0.80f,  -PI/2);
-        while(!(s.millis >= 32000)) {
-            state.savePlotFile(s);
-        }
-*/
-    
-     /*
-        while (1) {
-            USBLoop();
-            
-            robotControl.setDesiredPositionAndAngle(adkTerm.getDesiredX(), adkTerm.getDesiredY(),  adkTerm.getDesiredTheta());
-            
-            //pc.printf(".");
+                   robotControl.setDesiredPositionAndAngle(-2.0f, 2.0f,  -PI/2);
+           while(!(robotControl.getDistanceError() <= 1.0)) {
+               state.savePlotFile(s);
+           };
 
-            /*pc.printf("From Android x: %f   y: %f  t: %f",adkTerm.getDesiredX(), adkTerm.getDesiredY(),adkTerm.getDesiredTheta());
-            
-            
-            pc.printf( "To Android: x: %f   y: %f   t: %f; \n \n", robotControl.getxActualPosition(),
-             robotControl.getyActualPosition(),
-             robotControl.getActualTheta());
-        }*/
+           robotControl.setDesiredPositionAndAngle(-2.65f, 1.30f,  -PI/2);
+           while(!(robotControl.getDistanceError() <= 0.4)) {
+               state.savePlotFile(s);
+           };
+           robotControl.setDesiredPositionAndAngle(-2.65f, 0.80f,  -PI/2);
+           while(!(s.millis >= 32000)) {
+               state.savePlotFile(s);
+           }
+    */
 
 
 
-    /**
-     * Close the File PLOTS.txt to read the file after with the computer and draw a diagramm
-     */
-     
-     
+
     pc.baud(460800);
+    pc.printf("********************* MicroBridge 4568 ********************************\n\r");
 
-    pc.printf("********************* MicroBridge 4568 ********************************\n\r");
-    
     init();
-    
+
     // Initialise the ADB subsystem.
-   
+
     pc.printf("connection isOpen\n");
 
-    while(1) {
+    while(getDesiredTheta() < (4 * PI)) {
 
         ADB::poll();
-        
+
+        if (getDesiredTheta() > (2 * PI)) {
+            //robotControl.setAllToZero(0, 0, PI/2 );
+            robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
+            robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
+        }
+        else
+        {
         robotControl.setDesiredPositionAndAngle(getDesiredX(), getDesiredY(), getDesiredTheta());
-        
-        //void writeActualPosition(float x, float y, float t, int state_u, int state_l, int state_r, float volt_b)
-        writeActualPosition(robotControl.getxActualPosition(),robotControl.getyActualPosition(), robotControl.getActualTheta(), s.state&STATE_UNDER, s.state&STATE_LEFT, s.state&STATE_RIGHT, s.voltageBattery);
 
+         
+        state.savePlotFile(s);
+        //void writeActualPosition(float x, float y, float t, int state_u, int state_l, int state_r, float volt_b)
+        }
+        
+        writeActualPosition(robotControl.getxActualPosition(),robotControl.getyActualPosition(), robotControl.getActualTheta(), s.state&STATE_UNDER, s.state&STATE_LEFT, s.state&STATE_RIGHT, s.voltageBattery);
         //connection->write(sizeof(str),(unsigned char*)&str);
-        wait(1);
+        
+        wait(0.25);
 
-    } 
-     
+    }
+
+
+    /**
+     * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm
+     */
     state.savePlotFile(s);
     state.closePlotFile();
     state.stop();
     robotControl.setEnable(false);
-    
+
 }