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-20
Revision:
27:a13ede88e75f
Parent:
26:a201dcd4e618

File content as of revision 27:a13ede88e75f:


/*! \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 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>
 */

/**
 * @file main.cpp
 */

#include "defines.h"
#include "State.h"
#include "RobotControl.h"
#include "androidADB.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
 * @{
 */

/*! @} */

// @todo PC USB communications DAs wird danach gelöscht
Serial pc(USBTX, USBRX);

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

    /**
     * Check at first the Battery voltage. Starts when the voltages greater as the min is.
     * start the timer for the Logging to the file
     * and start the Task for logging
     **/
    state.start();
    state.initPlotFile();
    state.closePlotFile();
    while(s.voltageBattery < BAT_MIN) {
        state.ledArray(20.0f);
    }

    state.stop();
    wait(0.5);
    state.start();
    state.initPlotFile();
    state.startTimerFromZero();
    robotControl.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);
    robotControl.setEnable(false);

    // Verbindung zum putty kann spöter gelöscht werden......
    pc.baud(460800);
    pc.printf("********************* MicroBridge 4568 ********************************\n\r");


    // Initialise the ADB subsystem.
    init();
    setDesiredTheta(400.0f);
    pc.printf("connection isOpen\n");

    while(getDesiredTheta() < (4 * PI)) {

        ADB::poll();
        if (getDesiredTheta() > (2 * PI)) {
            // Runs at first till the Startbutton has pressed
            state.startTimerFromZero();
            robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
            robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
            robotControl.setEnable(false);
        } else {
            robotControl.setEnable(true);
            robotControl.setDesiredPositionAndAngle(getDesiredX(), getDesiredY(), getDesiredTheta());


            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(0.25);

    }

    /**
     * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm
     */
    robotControl.setDesiredPositionAndAngle(robotControl.getxActualPosition(),
                                            robotControl.getyActualPosition(),
                                            robotControl.getActualTheta());
    robotControl.stop();
    state.savePlotFile(s);
    leftMotor.setVelocity(0.0f);
    rightMotor.setVelocity(0.0f);
    while(!(s.millis >= 15000)) {
        state.savePlotFile(s);
    };

    /**
     * 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);
    robotControl.stop();

    /**
    * Fast PWM sample for the end
    */
    while(1) {
        state.ledArray(20.0f);
    }

}