This program is for an autonomous robot for the competition at the Hochschule Luzern. We are one of the 32 teams. <a href="http://cruisingcrepe.wordpress.com/">http://cruisingcrepe.wordpress.com/</a> 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: <a href="http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf">http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf</a>
Fork of autonomousRobotAndroid by
Revision 14:6a45a9f940a8, committed 2013-04-11
- Comitter:
- chrigelburri
- Date:
- Thu Apr 11 09:22:35 2013 +0000
- Parent:
- 13:a7c30ee09bae
- Child:
- 15:cb1337567ad4
- Commit message:
- android 2.0 implemented (untested!)
Changed in this revision
--- 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
--- a/AndroidADKTerm/android.h Thu Apr 11 07:09:48 2013 +0000 +++ b/AndroidADKTerm/android.h Thu Apr 11 09:22:35 2013 +0000 @@ -1,6 +1,7 @@ #ifndef _ANDROID_H_ #define _ANDROID_H_ +#include "RobotControl.h" #include "mbed.h" #include "AndroidAccessory.h" #include "defines.h" @@ -13,12 +14,10 @@ /** * @author Arno Galliker * - * @subsection LICENSE - * - * Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe + * @copyright Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe * All rights reserved. * - * @subsection DESCRIPTION + * @brief * * This class implements communication with the android smartphone * For more information see the Android ADK Cookbook: @@ -27,127 +26,116 @@ * Originally created by p07gbar from work by Makoto Abe */ -#define OUTL 100 -#define INBL 100 +//#define OUTL 100 +//#define INBL 100 -class AdkTerm : public AndroidAccessory +class AdkTerm : public AndroidAccessory, public Task { private: - /** Attaches a tick to send messages over the USB buffer in a certain interval */ - void AttachTick(); + /** @brief Instance of RobotControl*/ + RobotControl* robotControl; - /** Method to call when a tick period is over */ - void onTick(); - - /** Char buffer with a size of OUTL */ + float period; + + /** @brief Char buffer with a size of OUTL */ char buffer[OUTL]; - /** Buffer count ??? */ + state_t* s; + + /** @brief Buffer count ??? */ int bcount; - - /** Instance of ticker */ - Ticker tick; - - //float right,left,rl,ll; - //int tl,tr; - - //Timeout n; - - /** States if tick is on */ - bool settick; - - /** States if something is written to the buffer?? */ + + /** @brief States if something is written to the buffer?? */ bool ind; - - /** Desired position in meters for x-coordinate, given by android */ - float x; - - /** Desired position in meters for y-coordinate, given by android */ - float y; - - /** Desired position in degrees for theta, given by android */ - float t; + + /** @brief Desired position in meters for x-coordinate, given by android */ + float desiredX; + + /** @brief Desired position in meters for y-coordinate, given by android */ + float desiredY; + + /** @brief Desired position in degrees for theta, given by android */ + float desiredTheta; public: /** - * Creates a <code>AdkTerm</code> object and initializes all private + * @brief Creates a <code>AdkTerm</code> object and initializes all private * state variables. Constructor + * @param robotControl RobotControl obejct reference + * @param period length of a period in seconds */ - AdkTerm(); + AdkTerm(RobotControl* robotControl, state_t* s, float period); /** - * Sets initial configurations and clears the buffer - * + * @brief Sets initial configurations and clears the buffer + * */ void setupDevice(); /** - * Returns the desired position in meters for x-coordinate, given by android + * @brief Returns the desired position in meters for x-coordinate, given by android * @return x-coordinate,given in [m] */ - float getx(); + float getDesiredX(); /** * Returns the desired position in meters for y-coordinate, given by android * @return y-coordinate,given in [m] */ - float gety(); + float getDesiredY(); - /** - * Returns the esired position in degrees for theta, given by android - * @return y-coordinate,given in degrees [°] - */ - float gett(); + /** + * @brief Returns the esired position in degrees for theta, given by android + * @return y-coordinate,given in degrees [°] + */ + float getDesiredTheta(); + + /** @brief Method to call when a tick period is over */ + void onTick(); private: /** - * - * - */ - //void AttachTick(); - - /** - * - * - */ - // void onTick(); - - /** - * Clears the buffer and bcount - * + * @brief Clears the buffer and bcount */ void resetDevice(); /** - * Takes an string, a vector of strings for the delimited tokens, and a with the + * @brief Takes an string, a vector of strings for the delimited tokens, and a with the * @param str * @param tokens * @param delimiters */ - void Tokenize(const string& str, vector<string>& tokens, const string& delimiters = " "); + void Tokenize(const string& str, + vector<string>& tokens, + const string& delimiters = " "); /** - * + * @brief * @param buf * @param len */ int callbackRead(u8 *buf, int len); /** - * + * @brief * */ int callbackWrite(); /** - * + * @brief * */ void serialIRQ(); + + /** + * @brief Run method actualize every period + */ + void run(); };
--- a/RobotControl/RobotControl.cpp Thu Apr 11 07:09:48 2013 +0000 +++ b/RobotControl/RobotControl.cpp Thu Apr 11 09:22:35 2013 +0000 @@ -159,7 +159,7 @@ float RobotControl::getDistanceError() { - return sqrt( ( getxPositionError() * getxPositionError() ) + (getyPositionError() * getyPositionError() ) ); + return sqrt( ( getxPositionError() * getxPositionError() ) + ( getyPositionError() * getyPositionError() ) ); } float RobotControl::getThetaErrorToGoal()
--- a/defines.h Thu Apr 11 07:09:48 2013 +0000 +++ b/defines.h Thu Apr 11 09:22:35 2013 +0000 @@ -192,7 +192,7 @@ /** * @brief 10Hz Rate for the Android communication , given in [s] */ -#define PERIOD_ANDROID 0.1f +#define PERIOD_ANDROID 0.5f /*! @} */ /** @@ -254,6 +254,7 @@ float setVelocity; /** @brief Setpoint rotation velocitiy [rad/s] */ float setOmega; + /** @brief State of the car */ int state; /** @brief distance to Goal */ float rho;
--- a/main.cpp Thu Apr 11 07:09:48 2013 +0000 +++ b/main.cpp Thu Apr 11 09:22:35 2013 +0000 @@ -36,19 +36,7 @@ #include "defines.h" #include "State.h" #include "RobotControl.h" -//#include "android.h" - -/** - * @name Communication - * @{ - */ - -/** - * @brief <code>adkTerm</code> object is for the communication with a smartphone. - * The operation system must be a android. - */ -//AdkTerm adkTerm; -/*! @} */ +#include "android.h" /** * @name Hallsensor @@ -108,8 +96,21 @@ State state(&s, &robotControl, &leftMotor, &rightMotor, p15, PERIOD_STATE); /*! @} */ +/** + * @name Communication + * @{ + */ + +/** + * @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); +/*! @} */ + + // @todo PC USB communications DAs wird danach gelöscht -//Serial pc(USBTX, USBRX); +Serial pc(USBTX, USBRX); /** * @brief Main function. Start the Programm here. @@ -140,6 +141,15 @@ 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(); + + adkTerm.start(); // robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2); @@ -147,7 +157,7 @@ // wait(0.1); ////////////////////////////////////////// - +/* robotControl.setDesiredPositionAndAngle(0.0f, 1.0f, PI); while(!(robotControl.getDistanceError() <= 0.1)) { state.savePlotFile(s); @@ -173,7 +183,7 @@ state.savePlotFile(s); }; - +*/ @@ -295,24 +305,16 @@ } */ - - - - /* - - 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(); + while (1) { USBLoop(); - pc.printf("Android x: %f ",adkTerm.getx()); - pc.printf("Android y: %f ",adkTerm.gety()); - pc.printf("Android t: %f\n",adkTerm.gett()); - robotControl.setDesiredPositionAndAngle(adkTerm.getx(), adkTerm.gety(), adkTerm.gett()); + pc.printf("From Android x: %f y: %f t: %f",adkTerm.getDesiredX(), adkTerm.getDesiredY(),adkTerm.getDesiredTheta()); + robotControl.setDesiredPositionAndAngle(adkTerm.getDesiredX(), adkTerm.getDesiredY(), adkTerm.getDesiredTheta()); + + pc.printf( "To Android: x: %f y: %f t: %f; \n \n", robotControl.getxActualPosition(), + robotControl.getyActualPosition(), + robotControl.getActualTheta()); }