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

main.cpp

Committer:
chrigelburri
Date:
2013-05-03
Revision:
18:306d362d692b
Parent:
16:b5d949136a21
Child:
19:b2f76b0fe4c8

File content as of revision 18:306d362d692b:


/*! \mainpage Index Page
 * @author Christian Burri
 * @author Arno Galliker
 *
 * @copyright Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe
 * All rights reserved.
 *
 * @brief
 *
 * This program is for an autonomous robot for the competition
 * at the Hochschule Luzern.
 * We are one of the 32 teams. In the team #1 is:
 * - Bauernfeind Julia <B>WI</B> <a href="mailto:julia.bauernfeind@stud.hslu.ch">julia.bauernfeind@stud.hslu.ch</a>
 * - Büttler Pirmin <B>WI</B> <a href="mailto:pirmin.buetler@stud.hslu.ch">pirmin.buetler@stud.hslu.ch</a>
 * - Amberg Reto <B>I</B> <a href="mailto:reto.amberg@stud.hslu.ch">reto.amberg@stud.hslu.ch</a>
 * - Galliker Arno <B>I</B> <a href="mailto:arno.galliker@stud.hslu.ch">arno.galliker@stud.hslu.ch</a>
 * - Amrein Marcel <B>M</B> <a href="mailto:marcel.amrein@stud.hslu.ch">marcel.amrein@stud.hslu.ch</a>
 * - Flühler Ramon <B>M</B> <a href="mailto:ramon.fluehler@stud.hslu.ch">ramon.fluehler@stud.hslu.ch</a>
 * - Burri Christian <B>ET</B> <a href="mailto:christian.burri@stud.hslu.ch">christian.burri@stud.hslu.ch</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>
 *
 * 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 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>
 */

/**
 * @file main.cpp
 */

#include "defines.h"
#include "State.h"
#include "RobotControl.h"
#include "androidADB.h"
//#include "android.h"

/**
 * @name Hallsensor
 * @{
 */

/**
* @brief <code>hallsensorLeft</code> object with pin15, pin17 and pin16
*/
Hallsensor hallLeft(p18, p17, p16);

/**
 * @brief <code>hallsensorLeft</code> object with pin17, pin28 and pin29
 */
Hallsensor hallRight(p27, p28, p29);
/*! @} */

/**
 * @name Motors and Robot Control
 * @{
 */

/**
* @brief <code>leftMotor</code> object with pin26, pin25, pin24,
* pin19 and <code>hallsensorLeft</code> object
*/
MaxonESCON leftMotor(p26, p25, p24, p19, &hallLeft);

/**
 * @brief <code>rightMotor</code> object with pin23, pin22, pin21,
 * pin20 and <code>hallsensorRight</code> object
 */
MaxonESCON rightMotor(p23, p22, p21, p20, &hallRight);

/**
 * @brief <code>robotControl</code> object with <code>leftMotor</code>,
 * <code>rightMotor</code> and the sampling rate for the run method
 */
RobotControl robotControl(&leftMotor, &rightMotor, PERIOD_ROBOTCONTROL);
/*! @} */

/**
 * @name Logging & State
 * @{
 */

/**
 * @brief Define the struct for the State and the Logging
 */
state_t s;

/**
 * @brief <code>state</code> object with <code>robotControl</code>,
 * <code>rightMotor</code>, <code>leftMotor</code>, <code>battery</code>
 * and the sampling rate for the run method
 */
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);

/**
* @brief Main function. Start the Programm here.
*/
int main()
{

    /**
     * Initialze the filt PLOTS.txt,
     * start the timer for the Logging to the file
     * and start the Task for logging
     **/
    state.initPlotFile();
    state.startTimerFromZero();
    state.start();

    /**
     * Clear all Errors of the ESCON Module, with a disabled to enable event
     */
    robotControl.setEnable(false);
    wait(0.01);
    robotControl.setEnable(true);
    wait(0.1);

    /**
     * Set the startposition and start the Task for controlling the roboter.
     */
    //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(-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(-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.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.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(".");

            /*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());
        }*/



    /**
     * Close the File PLOTS.txt to read the file after with the computer and draw a diagramm
     */

   
     
    state.savePlotFile(s);
    state.closePlotFile();
    state.stop();
    robotControl.setEnable(false);
    
}