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:
14:6a45a9f940a8
Parent:
12:235e318a414f
Child:
15:cb1337567ad4
--- a/AndroidADKTerm/android.cpp	Thu Apr 11 07:09:48 2013 +0000
+++ b/AndroidADKTerm/android.cpp	Thu Apr 11 09:22:35 2013 +0000
@@ -1,78 +1,72 @@
 #include "android.h"
-
+//#define PI                    3.141592654f
 using namespace std;
 
-AdkTerm::AdkTerm() : AndroidAccessory(INBL,OUTL, "ARM", "mbed", "mbed Terminal", "0.1", "http://www.mbed.org", "0000000012345678")
+AdkTerm::AdkTerm(RobotControl* robotControl,
+                 state_t* s,
+                 float period)
+    : AndroidAccessory(INBL,
+                       OUTL,
+                       "ARM",
+                       "mbed",
+                       "mbed Terminal",
+                       "0.1",
+                       "http://www.mbed.org",
+                       "0000000012345678"),
+    Task(period)
 {
-
+    this->robotControl = robotControl;
+    this->period = period;
+    this->s = s;
 };
 
-
 void AdkTerm::setupDevice()
 {
-    settick = false;
     for (int i = 0; i<OUTL; i++) {
         buffer[i] = 0;
     }
     bcount = 0;
-    //n.attach(this,&AdkTerm::AttachTick,5);
-    //tick.attach(this,&AdkTerm::onTick,0.1);
 }
 
-float AdkTerm::getx()
+float AdkTerm::getDesiredX()
 {
-    return x/1000;
+    return desiredX/1000;
 }
 
-float AdkTerm::gety()
+float AdkTerm::getDesiredY()
 {
-    return y/1000;
+    return desiredY/1000;
 }
 
-float AdkTerm::gett()
+float AdkTerm::getDesiredTheta()
 {
-    return t * PI / 180;
-}
-
-/*void AdkTerm::AttachTick()
-{
-    if(!settick)tick.attach(this,&AdkTerm::onTick,0.04);
-    settick = true;
+    return desiredTheta * PI / 180;
 }
 
-void AdkTerm::onTick()
-{
-    right = 1-Right;
-    left = 1-Left;
-    bool update = false;
-    int templ, tempr;
 
-
+void AdkTerm::run()
+{
 
-    templ = int(left * 10000);
-    tempr = int(right * 10000);
-
-
+    u8* wbuf = _writebuff;
 
-    if (abs(templ-tl)>170) {
-        update = true;
-    }
-    if (abs(tempr-tr)>170) {
-        update = true;
-    }
-    if (update) {
-        u8* wbuf = _writebuff;
+    // floats to string
+    char str[32];
+    
+    //send to android
+    sprintf( str, "%f;%f;%f;%i;%i;%i;%f", robotControl->getxActualPosition(),
+             robotControl->getyActualPosition(),
+             robotControl->getActualTheta(),
+             s->state&STATE_UNDER == 0 ? 0 : 1,
+             s->state&STATE_LEFT == 0 ? 0 : 1,
+             s->state&STATE_RIGHT == 0 ? 0 : 1,
+             s->voltageBattery);
 
-        wbuf[0] = 'P';
-        wbuf[1] =  templ&0xFF;
-        wbuf[2] = (templ>>8) & 0xFF;
-        wbuf[3] =  tempr&0xFF;
-        wbuf[4] = (tempr>>8) & 0xFF;
-        wbuf[5] = 0;
+    //copy to wbuf
+    strcpy( (char*) wbuf, str );
 
-        this->write(wbuf,5);
-    }
-}*/
+    this->write(wbuf,32);
+
+}
 
 void AdkTerm::resetDevice()
 {
@@ -117,40 +111,14 @@
     if(tokens.size() > 2) {
 
         //string to float
-        x = ::atof(tokens.at(0).c_str());
-        y = ::atof(tokens.at(1).c_str());
-        t = ::atof(tokens.at(2).c_str());
-
-        //pc.printf("Android x(%d): %f\n\r\n",len,x);
-       // pc.printf("Android y(%d): %f\n\r\n",len,y);
-        //pc.printf("Android t(%d): %f\n\r\n",len,t);
-    } else {
-        //pc.printf("Android sayys(%d): %s\n\r\n",len,str);
+        desiredX = ::atof(tokens.at(0).c_str());
+        desiredY = ::atof(tokens.at(1).c_str());
+        desiredTheta = ::atof(tokens.at(2).c_str());
     }
 
-//   switch ( buf[0] ) {
-//       case 'x':
-//           if (buf[1] == ":"){pc.printf("X-Coordinate(%d): %s\n\r\n",len,buf)};
-//           break;
-//       case 'y':
-//           if (buf[1] == ":"){pc.printf("Y-Coordinate(%d): %s\n\r\n",len,buf)};
-//           break;
-//       case 't':
-//           if (buf[1] == ":"){pc.printf("Z-Coordinate(%d): %s\n\r\n",len,buf)};
-//           break;
-//       default:
-//           pc.printf("Command not recognized (%d): %s\n\r\n\n\n",len,buf);
-//   }
-
-
-    //AttachTick();
-
     return 0;
 }
 
-// split: receives a char delimiter; returns a vector of strings
-// By default ignores repeated delimiters, unless argument rep == 1.
-
 int AdkTerm::callbackWrite()
 {
     ind = false;
@@ -183,8 +151,4 @@
         }
     }
 
-}
-
-
-// gehört nicht mehr zur klasse für zum testen.......!!!!!!!!
-
+}
\ No newline at end of file