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-19
Revision:
23:4d8173c5183b
Parent:
22:bfec16575c91

File content as of revision 23:4d8173c5183b:


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

PwmOut led[4] = { LED1, LED2, LED3, LED4 };


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

    int garagenumber = 1;
    float x = -2.954f + 0.308 * garagenumber;
    float ypre = 1.30f;
    float ygoal = 0.80f;

    /**
     * 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
     *  Slow PWM sample for the end
     **/
    state.start();
    state.initPlotFile();
    state.closePlotFile();
    while(s.voltageBattery < BAT_MIN) {
        for (float f = 0.1f; f < 6.3f; f += 0.1f) {
            for(int i = 0; i <= 3; i  ++) {
                led[i] = state.dim( i, f );
            }
            wait_ms(20);
        }
        wait(0.05);
        for (float f = 0.1f; f < 6.3f; f += 0.1f) {
            for(int i = 0; i <= 3; i  ++) {
                led[i] = state.dim( 3-i, f );
            }
            wait_ms(20);
        }
        wait(0.05);
    }
    state.stop();
    for(int i = 0; i <= 3; i  ++) {
        led[i] = state.dim( 0, 0.0f );
    }
    wait(0.5);
    state.start();
    state.initPlotFile();
    state.startTimerFromZero();

    /**
     * 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();
    robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
    wait(0.1);
    state.savePlotFile(s);

    /**
     * Sets the desired Points.
     */
    robotControl.setDesiredPositionAndAngle(-1.35f, 1.85f,  3*PI/8);
    while(!(robotControl.getDistanceError() <= 0.7)) {
        state.savePlotFile(s);
    };

    robotControl.setDesiredPositionAndAngle(-0.75f, 2.85f,  3*PI/8);
    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.1f, 3.0f,  -PI/2);
    while(!(robotControl.getDistanceError() <= 1.0)) {
        state.savePlotFile(s);
    };

    robotControl.setDesiredPositionAndAngle(-2.0f, 1.8f,  -PI/2);
    while(!(robotControl.getDistanceError() <= 1.0)) {
        state.savePlotFile(s);
    };

    robotControl.setDesiredPositionAndAngle(x, ypre,  -PI/2);
    while(!(robotControl.getDistanceError() <= 0.4)) {
        state.savePlotFile(s);
    };
    robotControl.setDesiredPositionAndAngle(x, ygoal, -PI/2);
    while(!(s.millis >= 19000)) {
        state.savePlotFile(s);
    }


    /*
        pc.baud(460800);
        pc.printf("********************* MicroBridge 4568 ********************************\n\r");

        init();

        // Initialise the ADB subsystem.

        pc.printf("connection isOpen\n");

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

            ADB::poll();

            if (getDesiredTheta() > (2 * PI)) {
                //robotControl.setAllToZero(0, 0, PI/2 );
                robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
                robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
            }
            else
            {
            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
     */
    state.savePlotFile(s);
    state.closePlotFile();
    state.stop();
    robotControl.setEnable(false);
    robotControl.stop();

    /**
     * Fast PWM sample for the end
     */
    while(1) {
        for (float f = 0.1f; f < 6.3f; f += 0.1f) {
            for(int i = 0; i <= 3; i  ++) {
                led[i] = state.dim( i, f );
            }
            wait_ms(5);
        }
        wait(0.1);
        for (float f = 0.1f; f < 6.3f; f += 0.1f) {
            for(int i = 0; i <= 3; i  ++) {
                led[i] = state.dim( 3-i, f );
            }
            wait_ms(5);
        }
        wait(0.05);
    }

}