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:
12:235e318a414f
Parent:
11:775ebb69d5e1
Child:
14:6a45a9f940a8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AndroidADKTerm/android.cpp	Sun Apr 07 08:31:51 2013 +0000
@@ -0,0 +1,190 @@
+#include "android.h"
+
+using namespace std;
+
+AdkTerm::AdkTerm() : AndroidAccessory(INBL,OUTL, "ARM", "mbed", "mbed Terminal", "0.1", "http://www.mbed.org", "0000000012345678")
+{
+
+};
+
+
+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()
+{
+    return x/1000;
+}
+
+float AdkTerm::gety()
+{
+    return y/1000;
+}
+
+float AdkTerm::gett()
+{
+    return t * PI / 180;
+}
+
+/*void AdkTerm::AttachTick()
+{
+    if(!settick)tick.attach(this,&AdkTerm::onTick,0.04);
+    settick = true;
+}
+
+void AdkTerm::onTick()
+{
+    right = 1-Right;
+    left = 1-Left;
+    bool update = false;
+    int templ, tempr;
+
+
+
+    templ = int(left * 10000);
+    tempr = int(right * 10000);
+
+
+
+    if (abs(templ-tl)>170) {
+        update = true;
+    }
+    if (abs(tempr-tr)>170) {
+        update = true;
+    }
+    if (update) {
+        u8* wbuf = _writebuff;
+
+        wbuf[0] = 'P';
+        wbuf[1] =  templ&0xFF;
+        wbuf[2] = (templ>>8) & 0xFF;
+        wbuf[3] =  tempr&0xFF;
+        wbuf[4] = (tempr>>8) & 0xFF;
+        wbuf[5] = 0;
+
+        this->write(wbuf,5);
+    }
+}*/
+
+void AdkTerm::resetDevice()
+{
+    for (int i = 0; i<OUTL; i++) {
+        buffer[i] = 0;
+    }
+    bcount = 0;
+}
+
+void AdkTerm::Tokenize(const string& str,
+                       vector<string>& tokens,
+                       const string& delimiters /*= " "*/)
+{
+    // Skip delimiters at beginning.
+    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+    // Find first "non-delimiter".
+    string::size_type pos     = str.find_first_of(delimiters, lastPos);
+
+    while (string::npos != pos || string::npos != lastPos) {
+        // Found a token, add it to the vector.
+        tokens.push_back(str.substr(lastPos, pos - lastPos));
+        // Skip delimiters.  Note the "not_of"
+        lastPos = str.find_first_not_of(delimiters, pos);
+        // Find next "non-delimiter"
+        pos = str.find_first_of(delimiters, lastPos);
+    }
+}
+
+int AdkTerm::callbackRead(u8 *buf, int len)
+{
+    // convert buffer (unsigned char) to string
+    std::string str(reinterpret_cast<char*>(buf), len);
+
+    // new vector of strings
+    vector<string> tokens;
+
+    // tokenize the string with the semicolon separator
+    Tokenize(str, tokens, ";");
+    copy(tokens.begin(), tokens.end(), ostream_iterator<string>(cout, ", "));
+
+
+    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);
+    }
+
+//   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;
+    return 0;
+}
+
+void AdkTerm::serialIRQ()
+{
+    //buffer[bcount] = pc.getc();
+
+
+    if (buffer[bcount] == '\n' || buffer[bcount] == '\r') {
+        u8* wbuf = _writebuff;
+        for (int i = 0; i<OUTL; i++) {
+            wbuf[i] = buffer[i];
+            buffer[i] = 0;
+        }
+        //pc.printf("Sending: %s\n\r",wbuf);
+        ind = true;
+        this->write(wbuf,bcount);
+        bcount = 0;
+    } else {
+        if (buffer[bcount] != 0x08 && buffer[bcount] != 0x7F ) {
+            bcount++;
+            if (bcount == OUTL) {
+                bcount = 0;
+            }
+        } else {
+            bcount--;
+        }
+    }
+
+}
+
+
+// gehört nicht mehr zur klasse für zum testen.......!!!!!!!!
+