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

Committer:
chrigelburri
Date:
Mon May 20 11:51:33 2013 +0000
Revision:
27:a13ede88e75f
Parent:
26:a201dcd4e618
mit led methode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chrigelburri 18:306d362d692b 1
chrigelburri 10:09ddb819fdcb 2 /*! \mainpage Index Page
chrigelburri 2:d8e1613dc38b 3 * @author Christian Burri
chrigelburri 11:775ebb69d5e1 4 * @author Arno Galliker
chrigelburri 2:d8e1613dc38b 5 *
chrigelburri 11:775ebb69d5e1 6 * @copyright Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe
chrigelburri 1:6cd533a712c6 7 * All rights reserved.
chrigelburri 2:d8e1613dc38b 8 *
chrigelburri 11:775ebb69d5e1 9 * @brief
chrigelburri 2:d8e1613dc38b 10 *
chrigelburri 15:cb1337567ad4 11 * This program is for an autonomous robot for the competition
chrigelburri 4:3a97923ff2d4 12 * at the Hochschule Luzern.
chrigelburri 3:92ba0254af87 13 * We are one of the 32 teams. In the team #1 is:
chrigelburri 11:775ebb69d5e1 14 * - Bauernfeind Julia <B>WI</B> <a href="mailto:julia.bauernfeind@stud.hslu.ch">julia.bauernfeind@stud.hslu.ch</a>
chrigelburri 11:775ebb69d5e1 15 * - Büttler Pirmin <B>WI</B> <a href="mailto:pirmin.buetler@stud.hslu.ch">pirmin.buetler@stud.hslu.ch</a>
chrigelburri 11:775ebb69d5e1 16 * - Amberg Reto <B>I</B> <a href="mailto:reto.amberg@stud.hslu.ch">reto.amberg@stud.hslu.ch</a>
chrigelburri 11:775ebb69d5e1 17 * - Galliker Arno <B>I</B> <a href="mailto:arno.galliker@stud.hslu.ch">arno.galliker@stud.hslu.ch</a>
chrigelburri 11:775ebb69d5e1 18 * - Amrein Marcel <B>M</B> <a href="mailto:marcel.amrein@stud.hslu.ch">marcel.amrein@stud.hslu.ch</a>
chrigelburri 11:775ebb69d5e1 19 * - Flühler Ramon <B>M</B> <a href="mailto:ramon.fluehler@stud.hslu.ch">ramon.fluehler@stud.hslu.ch</a>
chrigelburri 11:775ebb69d5e1 20 * - Burri Christian <B>ET</B> <a href="mailto:christian.burri@stud.hslu.ch">christian.burri@stud.hslu.ch</a>
chrigelburri 4:3a97923ff2d4 21 *
chrigelburri 13:a7c30ee09bae 22 * The postition control is based on this Documentation: Control of Wheeled Mobile Robots:
chrigelburri 13:a7c30ee09bae 23 * An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli.
chrigelburri 15:cb1337567ad4 24 * 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>
chrigelburri 2:d8e1613dc38b 25 *
chrigelburri 21:48248c5b8992 26 * The connection to an android smartphone is realise with the library MicroBridge(Android ADB) from Junichi Katsu.
chrigelburri 21:48248c5b8992 27 * For more information see here: <a href="http://mbed.org/users/jksoft/code/MicroBridge/">http://mbed.org/users/jksoft/code/MicroBridge/</a>
chrigelburri 21:48248c5b8992 28 *
chrigelburri 13:a7c30ee09bae 29 * The rest of the classes are only based on standard library from mbed.
chrigelburri 15:cb1337567ad4 30 * For more information see here: <a href="http://mbed.org/users/mbed_official/code/mbed/">http://mbed.org/users/mbed_official/code/mbed/</a>
chrigelburri 1:6cd533a712c6 31 */
chrigelburri 1:6cd533a712c6 32
chrigelburri 11:775ebb69d5e1 33 /**
chrigelburri 11:775ebb69d5e1 34 * @file main.cpp
chrigelburri 11:775ebb69d5e1 35 */
chrigelburri 11:775ebb69d5e1 36
chrigelburri 1:6cd533a712c6 37 #include "defines.h"
chrigelburri 1:6cd533a712c6 38 #include "State.h"
chrigelburri 1:6cd533a712c6 39 #include "RobotControl.h"
chrigelburri 18:306d362d692b 40 #include "androidADB.h"
chrigelburri 11:775ebb69d5e1 41
chrigelburri 24:08241be546ba 42
chrigelburri 24:08241be546ba 43 /**
chrigelburri 11:775ebb69d5e1 44 * @name Hallsensor
chrigelburri 11:775ebb69d5e1 45 * @{
chrigelburri 11:775ebb69d5e1 46 */
chrigelburri 12:235e318a414f 47
chrigelburri 12:235e318a414f 48 /**
chrigelburri 12:235e318a414f 49 * @brief <code>hallsensorLeft</code> object with pin15, pin17 and pin16
chrigelburri 12:235e318a414f 50 */
chrigelburri 11:775ebb69d5e1 51 Hallsensor hallLeft(p18, p17, p16);
chrigelburri 12:235e318a414f 52
chrigelburri 11:775ebb69d5e1 53 /**
chrigelburri 11:775ebb69d5e1 54 * @brief <code>hallsensorLeft</code> object with pin17, pin28 and pin29
chrigelburri 11:775ebb69d5e1 55 */
chrigelburri 11:775ebb69d5e1 56 Hallsensor hallRight(p27, p28, p29);
chrigelburri 11:775ebb69d5e1 57 /*! @} */
chrigelburri 1:6cd533a712c6 58
chrigelburri 10:09ddb819fdcb 59 /**
chrigelburri 11:775ebb69d5e1 60 * @name Motors and Robot Control
chrigelburri 12:235e318a414f 61 * @{
chrigelburri 10:09ddb819fdcb 62 */
chrigelburri 12:235e318a414f 63
chrigelburri 12:235e318a414f 64 /**
chrigelburri 12:235e318a414f 65 * @brief <code>leftMotor</code> object with pin26, pin25, pin24,
chrigelburri 12:235e318a414f 66 * pin19 and <code>hallsensorLeft</code> object
chrigelburri 12:235e318a414f 67 */
chrigelburri 1:6cd533a712c6 68 MaxonESCON leftMotor(p26, p25, p24, p19, &hallLeft);
chrigelburri 12:235e318a414f 69
chrigelburri 11:775ebb69d5e1 70 /**
chrigelburri 12:235e318a414f 71 * @brief <code>rightMotor</code> object with pin23, pin22, pin21,
chrigelburri 12:235e318a414f 72 * pin20 and <code>hallsensorRight</code> object
chrigelburri 11:775ebb69d5e1 73 */
chrigelburri 1:6cd533a712c6 74 MaxonESCON rightMotor(p23, p22, p21, p20, &hallRight);
chrigelburri 1:6cd533a712c6 75
chrigelburri 11:775ebb69d5e1 76 /**
chrigelburri 12:235e318a414f 77 * @brief <code>robotControl</code> object with <code>leftMotor</code>,
chrigelburri 12:235e318a414f 78 * <code>rightMotor</code> and the sampling rate for the run method
chrigelburri 11:775ebb69d5e1 79 */
chrigelburri 11:775ebb69d5e1 80 RobotControl robotControl(&leftMotor, &rightMotor, PERIOD_ROBOTCONTROL);
chrigelburri 11:775ebb69d5e1 81 /*! @} */
chrigelburri 1:6cd533a712c6 82
chrigelburri 11:775ebb69d5e1 83 /**
chrigelburri 11:775ebb69d5e1 84 * @name Logging & State
chrigelburri 11:775ebb69d5e1 85 * @{
chrigelburri 11:775ebb69d5e1 86 */
chrigelburri 12:235e318a414f 87
chrigelburri 12:235e318a414f 88 /**
chrigelburri 12:235e318a414f 89 * @brief Define the struct for the State and the Logging
chrigelburri 12:235e318a414f 90 */
chrigelburri 11:775ebb69d5e1 91 state_t s;
chrigelburri 12:235e318a414f 92
chrigelburri 11:775ebb69d5e1 93 /**
chrigelburri 12:235e318a414f 94 * @brief <code>state</code> object with <code>robotControl</code>,
chrigelburri 12:235e318a414f 95 * <code>rightMotor</code>, <code>leftMotor</code>, <code>battery</code>
chrigelburri 12:235e318a414f 96 * and the sampling rate for the run method
chrigelburri 11:775ebb69d5e1 97 */
chrigelburri 11:775ebb69d5e1 98 State state(&s, &robotControl, &leftMotor, &rightMotor, p15, PERIOD_STATE);
chrigelburri 11:775ebb69d5e1 99 /*! @} */
chrigelburri 1:6cd533a712c6 100
chrigelburri 14:6a45a9f940a8 101 /**
chrigelburri 14:6a45a9f940a8 102 * @name Communication
chrigelburri 14:6a45a9f940a8 103 * @{
chrigelburri 14:6a45a9f940a8 104 */
chrigelburri 14:6a45a9f940a8 105
chrigelburri 14:6a45a9f940a8 106 /*! @} */
chrigelburri 14:6a45a9f940a8 107
chrigelburri 12:235e318a414f 108 // @todo PC USB communications DAs wird danach gelöscht
chrigelburri 18:306d362d692b 109 Serial pc(USBTX, USBRX);
chrigelburri 1:6cd533a712c6 110
chrigelburri 12:235e318a414f 111 /**
chrigelburri 12:235e318a414f 112 * @brief Main function. Start the Programm here.
chrigelburri 12:235e318a414f 113 */
chrigelburri 1:6cd533a712c6 114 int main()
chrigelburri 1:6cd533a712c6 115 {
chrigelburri 12:235e318a414f 116
chrigelburri 12:235e318a414f 117 /**
chrigelburri 22:bfec16575c91 118 * Check at first the Battery voltage. Starts when the voltages greater as the min is.
chrigelburri 12:235e318a414f 119 * start the timer for the Logging to the file
chrigelburri 12:235e318a414f 120 * and start the Task for logging
chrigelburri 12:235e318a414f 121 **/
chrigelburri 22:bfec16575c91 122 state.start();
chrigelburri 22:bfec16575c91 123 state.initPlotFile();
chrigelburri 22:bfec16575c91 124 state.closePlotFile();
chrigelburri 24:08241be546ba 125 while(s.voltageBattery < BAT_MIN) {
chrigelburri 27:a13ede88e75f 126 state.ledArray(20.0f);
chrigelburri 24:08241be546ba 127 }
chrigelburri 27:a13ede88e75f 128
chrigelburri 22:bfec16575c91 129 state.stop();
chrigelburri 22:bfec16575c91 130 wait(0.5);
chrigelburri 22:bfec16575c91 131 state.start();
chrigelburri 16:b5d949136a21 132 state.initPlotFile();
chrigelburri 12:235e318a414f 133 state.startTimerFromZero();
chrigelburri 27:a13ede88e75f 134 robotControl.start();
chrigelburri 12:235e318a414f 135
chrigelburri 12:235e318a414f 136 /**
chrigelburri 12:235e318a414f 137 * Clear all Errors of the ESCON Module, with a disabled to enable event
chrigelburri 12:235e318a414f 138 */
chrigelburri 1:6cd533a712c6 139 robotControl.setEnable(false);
chrigelburri 16:b5d949136a21 140 wait(0.01);
chrigelburri 1:6cd533a712c6 141 robotControl.setEnable(true);
chrigelburri 6:48eeb41188dd 142 wait(0.1);
chrigelburri 27:a13ede88e75f 143 robotControl.setEnable(false);
chrigelburri 12:235e318a414f 144
chrigelburri 27:a13ede88e75f 145 // Verbindung zum putty kann spöter gelöscht werden......
chrigelburri 27:a13ede88e75f 146 pc.baud(460800);
chrigelburri 27:a13ede88e75f 147 pc.printf("********************* MicroBridge 4568 ********************************\n\r");
chrigelburri 27:a13ede88e75f 148
chrigelburri 27:a13ede88e75f 149
chrigelburri 27:a13ede88e75f 150 // Initialise the ADB subsystem.
chrigelburri 27:a13ede88e75f 151 init();
chrigelburri 27:a13ede88e75f 152 setDesiredTheta(400.0f);
chrigelburri 27:a13ede88e75f 153 pc.printf("connection isOpen\n");
chrigelburri 27:a13ede88e75f 154
chrigelburri 27:a13ede88e75f 155 while(getDesiredTheta() < (4 * PI)) {
chrigelburri 27:a13ede88e75f 156
chrigelburri 27:a13ede88e75f 157 ADB::poll();
chrigelburri 27:a13ede88e75f 158 if (getDesiredTheta() > (2 * PI)) {
chrigelburri 27:a13ede88e75f 159 // Runs at first till the Startbutton has pressed
chrigelburri 27:a13ede88e75f 160 state.startTimerFromZero();
chrigelburri 27:a13ede88e75f 161 robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
chrigelburri 27:a13ede88e75f 162 robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
chrigelburri 27:a13ede88e75f 163 robotControl.setEnable(false);
chrigelburri 27:a13ede88e75f 164 } else {
chrigelburri 27:a13ede88e75f 165 robotControl.setEnable(true);
chrigelburri 27:a13ede88e75f 166 robotControl.setDesiredPositionAndAngle(getDesiredX(), getDesiredY(), getDesiredTheta());
chrigelburri 27:a13ede88e75f 167
chrigelburri 27:a13ede88e75f 168
chrigelburri 27:a13ede88e75f 169 state.savePlotFile(s);
chrigelburri 27:a13ede88e75f 170 //void writeActualPosition(float x, float y, float t, int state_u, int state_l, int state_r, float volt_b)
chrigelburri 27:a13ede88e75f 171 }
chrigelburri 27:a13ede88e75f 172
chrigelburri 27:a13ede88e75f 173 writeActualPosition(robotControl.getxActualPosition(),
chrigelburri 27:a13ede88e75f 174 robotControl.getyActualPosition(),
chrigelburri 27:a13ede88e75f 175 robotControl.getActualTheta(),
chrigelburri 27:a13ede88e75f 176 s.state&STATE_UNDER,
chrigelburri 27:a13ede88e75f 177 s.state&STATE_LEFT,
chrigelburri 27:a13ede88e75f 178 s.state&STATE_RIGHT,
chrigelburri 27:a13ede88e75f 179 s.voltageBattery);
chrigelburri 27:a13ede88e75f 180 //connection->write(sizeof(str),(unsigned char*)&str);
chrigelburri 27:a13ede88e75f 181
chrigelburri 27:a13ede88e75f 182 wait(0.25);
chrigelburri 27:a13ede88e75f 183
chrigelburri 27:a13ede88e75f 184 }
chrigelburri 6:48eeb41188dd 185
chrigelburri 22:bfec16575c91 186 /**
chrigelburri 27:a13ede88e75f 187 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm
chrigelburri 22:bfec16575c91 188 */
chrigelburri 27:a13ede88e75f 189 robotControl.setDesiredPositionAndAngle(robotControl.getxActualPosition(),
chrigelburri 27:a13ede88e75f 190 robotControl.getyActualPosition(),
chrigelburri 27:a13ede88e75f 191 robotControl.getActualTheta());
chrigelburri 26:a201dcd4e618 192 robotControl.stop();
chrigelburri 26:a201dcd4e618 193 state.savePlotFile(s);
chrigelburri 26:a201dcd4e618 194 leftMotor.setVelocity(0.0f);
chrigelburri 26:a201dcd4e618 195 rightMotor.setVelocity(0.0f);
chrigelburri 26:a201dcd4e618 196 while(!(s.millis >= 15000)) {
chrigelburri 26:a201dcd4e618 197 state.savePlotFile(s);
chrigelburri 26:a201dcd4e618 198 };
chrigelburri 8:696c2f9dfc62 199
chrigelburri 21:48248c5b8992 200 /**
chrigelburri 21:48248c5b8992 201 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm
chrigelburri 21:48248c5b8992 202 */
chrigelburri 10:09ddb819fdcb 203 state.savePlotFile(s);
chrigelburri 10:09ddb819fdcb 204 state.closePlotFile();
chrigelburri 10:09ddb819fdcb 205 state.stop();
chrigelburri 10:09ddb819fdcb 206 robotControl.setEnable(false);
chrigelburri 24:08241be546ba 207 robotControl.stop();
chrigelburri 24:08241be546ba 208
chrigelburri 24:08241be546ba 209 /**
chrigelburri 24:08241be546ba 210 * Fast PWM sample for the end
chrigelburri 24:08241be546ba 211 */
chrigelburri 24:08241be546ba 212 while(1) {
chrigelburri 27:a13ede88e75f 213 state.ledArray(20.0f);
chrigelburri 24:08241be546ba 214 }
chrigelburri 21:48248c5b8992 215
chrigelburri 10:09ddb819fdcb 216 }