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>

Dependencies:   mbed

Fork of autonomousRobotAndroid by Christian Burri

Committer:
chrigelburri
Date:
Mon May 20 17:40:08 2013 +0000
Revision:
32:767044a3e421
Parent:
30:c32fc6174efe
Child:
33:ac39982fd3b2
unn?tiges Gel?scht;

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 &copy; 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 28:b3e195e80439 42 PwmOut led[4] = {LED1, LED2, LED3, LED4};
chrigelburri 24:08241be546ba 43
chrigelburri 24:08241be546ba 44 /**
chrigelburri 11:775ebb69d5e1 45 * @name Hallsensor
chrigelburri 11:775ebb69d5e1 46 * @{
chrigelburri 11:775ebb69d5e1 47 */
chrigelburri 12:235e318a414f 48
chrigelburri 12:235e318a414f 49 /**
chrigelburri 12:235e318a414f 50 * @brief <code>hallsensorLeft</code> object with pin15, pin17 and pin16
chrigelburri 12:235e318a414f 51 */
chrigelburri 11:775ebb69d5e1 52 Hallsensor hallLeft(p18, p17, p16);
chrigelburri 12:235e318a414f 53
chrigelburri 11:775ebb69d5e1 54 /**
chrigelburri 11:775ebb69d5e1 55 * @brief <code>hallsensorLeft</code> object with pin17, pin28 and pin29
chrigelburri 11:775ebb69d5e1 56 */
chrigelburri 11:775ebb69d5e1 57 Hallsensor hallRight(p27, p28, p29);
chrigelburri 11:775ebb69d5e1 58 /*! @} */
chrigelburri 1:6cd533a712c6 59
chrigelburri 10:09ddb819fdcb 60 /**
chrigelburri 11:775ebb69d5e1 61 * @name Motors and Robot Control
chrigelburri 12:235e318a414f 62 * @{
chrigelburri 10:09ddb819fdcb 63 */
chrigelburri 12:235e318a414f 64
chrigelburri 12:235e318a414f 65 /**
chrigelburri 12:235e318a414f 66 * @brief <code>leftMotor</code> object with pin26, pin25, pin24,
chrigelburri 12:235e318a414f 67 * pin19 and <code>hallsensorLeft</code> object
chrigelburri 12:235e318a414f 68 */
chrigelburri 1:6cd533a712c6 69 MaxonESCON leftMotor(p26, p25, p24, p19, &hallLeft);
chrigelburri 12:235e318a414f 70
chrigelburri 11:775ebb69d5e1 71 /**
chrigelburri 12:235e318a414f 72 * @brief <code>rightMotor</code> object with pin23, pin22, pin21,
chrigelburri 12:235e318a414f 73 * pin20 and <code>hallsensorRight</code> object
chrigelburri 11:775ebb69d5e1 74 */
chrigelburri 1:6cd533a712c6 75 MaxonESCON rightMotor(p23, p22, p21, p20, &hallRight);
chrigelburri 1:6cd533a712c6 76
chrigelburri 11:775ebb69d5e1 77 /**
chrigelburri 12:235e318a414f 78 * @brief <code>robotControl</code> object with <code>leftMotor</code>,
chrigelburri 12:235e318a414f 79 * <code>rightMotor</code> and the sampling rate for the run method
chrigelburri 11:775ebb69d5e1 80 */
chrigelburri 11:775ebb69d5e1 81 RobotControl robotControl(&leftMotor, &rightMotor, PERIOD_ROBOTCONTROL);
chrigelburri 11:775ebb69d5e1 82 /*! @} */
chrigelburri 1:6cd533a712c6 83
chrigelburri 11:775ebb69d5e1 84 /**
chrigelburri 11:775ebb69d5e1 85 * @name Logging & State
chrigelburri 11:775ebb69d5e1 86 * @{
chrigelburri 11:775ebb69d5e1 87 */
chrigelburri 12:235e318a414f 88
chrigelburri 12:235e318a414f 89 /**
chrigelburri 12:235e318a414f 90 * @brief Define the struct for the State and the Logging
chrigelburri 12:235e318a414f 91 */
chrigelburri 11:775ebb69d5e1 92 state_t s;
chrigelburri 12:235e318a414f 93
chrigelburri 11:775ebb69d5e1 94 /**
chrigelburri 12:235e318a414f 95 * @brief <code>state</code> object with <code>robotControl</code>,
chrigelburri 12:235e318a414f 96 * <code>rightMotor</code>, <code>leftMotor</code>, <code>battery</code>
chrigelburri 12:235e318a414f 97 * and the sampling rate for the run method
chrigelburri 11:775ebb69d5e1 98 */
chrigelburri 11:775ebb69d5e1 99 State state(&s, &robotControl, &leftMotor, &rightMotor, p15, PERIOD_STATE);
chrigelburri 11:775ebb69d5e1 100 /*! @} */
chrigelburri 1:6cd533a712c6 101
chrigelburri 14:6a45a9f940a8 102 /**
chrigelburri 14:6a45a9f940a8 103 * @name Communication
chrigelburri 14:6a45a9f940a8 104 * @{
chrigelburri 14:6a45a9f940a8 105 */
chrigelburri 14:6a45a9f940a8 106
chrigelburri 14:6a45a9f940a8 107 /*! @} */
chrigelburri 14:6a45a9f940a8 108
chrigelburri 12:235e318a414f 109 /**
chrigelburri 12:235e318a414f 110 * @brief Main function. Start the Programm here.
chrigelburri 12:235e318a414f 111 */
chrigelburri 1:6cd533a712c6 112 int main()
chrigelburri 1:6cd533a712c6 113 {
chrigelburri 12:235e318a414f 114
chrigelburri 12:235e318a414f 115 /**
chrigelburri 32:767044a3e421 116 * Check at first the Battery voltage. Starts when the voltage is greater than the min is.
chrigelburri 12:235e318a414f 117 * start the timer for the Logging to the file
chrigelburri 12:235e318a414f 118 * and start the Task for logging
chrigelburri 12:235e318a414f 119 **/
chrigelburri 22:bfec16575c91 120 state.start();
chrigelburri 32:767044a3e421 121
chrigelburri 24:08241be546ba 122 while(s.voltageBattery < BAT_MIN) {
chrigelburri 24:08241be546ba 123 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 124 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 125 led[i] = state.dim( i, f );
chrigelburri 24:08241be546ba 126 }
chrigelburri 24:08241be546ba 127 wait_ms(20);
chrigelburri 24:08241be546ba 128 }
chrigelburri 24:08241be546ba 129 wait(0.05);
chrigelburri 24:08241be546ba 130 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 131 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 132 led[i] = state.dim( 3-i, f );
chrigelburri 24:08241be546ba 133 }
chrigelburri 24:08241be546ba 134 wait_ms(20);
chrigelburri 24:08241be546ba 135 }
chrigelburri 24:08241be546ba 136 wait(0.05);
chrigelburri 24:08241be546ba 137 }
chrigelburri 24:08241be546ba 138 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 139 led[i] = state.dim( 0, 0.0f );
chrigelburri 24:08241be546ba 140 }
chrigelburri 28:b3e195e80439 141
chrigelburri 22:bfec16575c91 142 wait(0.5);
chrigelburri 16:b5d949136a21 143 state.initPlotFile();
chrigelburri 12:235e318a414f 144 state.startTimerFromZero();
chrigelburri 28:b3e195e80439 145 robotControl.start();
chrigelburri 12:235e318a414f 146
chrigelburri 12:235e318a414f 147 /**
chrigelburri 12:235e318a414f 148 * Clear all Errors of the ESCON Module, with a disabled to enable event
chrigelburri 12:235e318a414f 149 */
chrigelburri 1:6cd533a712c6 150 robotControl.setEnable(false);
chrigelburri 16:b5d949136a21 151 wait(0.01);
chrigelburri 1:6cd533a712c6 152 robotControl.setEnable(true);
chrigelburri 6:48eeb41188dd 153 wait(0.1);
chrigelburri 28:b3e195e80439 154 robotControl.setEnable(false);
chrigelburri 12:235e318a414f 155
chrigelburri 29:937c74ff040e 156 /**
chrigelburri 29:937c74ff040e 157 * Initialise the ADB subsystem.
chrigelburri 32:767044a3e421 158 * Set Theta for to go to Startloop.
chrigelburri 29:937c74ff040e 159 */
chrigelburri 28:b3e195e80439 160 init();
chrigelburri 28:b3e195e80439 161 setDesiredTheta(400.0f);
chrigelburri 28:b3e195e80439 162
chrigelburri 28:b3e195e80439 163 while(getDesiredTheta() < (4 * PI)) {
chrigelburri 32:767044a3e421 164 ADB::poll();
chrigelburri 28:b3e195e80439 165 if (getDesiredTheta() > (2 * PI)) {
chrigelburri 29:937c74ff040e 166 /**
chrigelburri 29:937c74ff040e 167 * Runs at first till the Startbutton has pressed
chrigelburri 29:937c74ff040e 168 */
chrigelburri 28:b3e195e80439 169 state.startTimerFromZero();
chrigelburri 28:b3e195e80439 170 robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
chrigelburri 28:b3e195e80439 171 robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
chrigelburri 28:b3e195e80439 172 robotControl.setEnable(false);
chrigelburri 30:c32fc6174efe 173 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 174 } else {
chrigelburri 28:b3e195e80439 175 robotControl.setEnable(true);
chrigelburri 28:b3e195e80439 176 robotControl.setDesiredPositionAndAngle(getDesiredX(), getDesiredY(), getDesiredTheta());
chrigelburri 30:c32fc6174efe 177 state.savePlotFile(s);
chrigelburri 30:c32fc6174efe 178 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 179 state.savePlotFile(s);
chrigelburri 28:b3e195e80439 180 }
chrigelburri 28:b3e195e80439 181 writeActualPosition(robotControl.getxActualPosition(),
chrigelburri 28:b3e195e80439 182 robotControl.getyActualPosition(),
chrigelburri 28:b3e195e80439 183 robotControl.getActualTheta(),
chrigelburri 28:b3e195e80439 184 s.state&STATE_UNDER,
chrigelburri 28:b3e195e80439 185 s.state&STATE_LEFT,
chrigelburri 28:b3e195e80439 186 s.state&STATE_RIGHT,
chrigelburri 28:b3e195e80439 187 s.voltageBattery);
chrigelburri 30:c32fc6174efe 188 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 189
chrigelburri 28:b3e195e80439 190 }
chrigelburri 6:48eeb41188dd 191
chrigelburri 22:bfec16575c91 192 /**
chrigelburri 29:937c74ff040e 193 * Sets the acutal value for a fast stop.
chrigelburri 28:b3e195e80439 194 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm
chrigelburri 22:bfec16575c91 195 */
chrigelburri 28:b3e195e80439 196 robotControl.setDesiredPositionAndAngle(robotControl.getxActualPosition(),
chrigelburri 28:b3e195e80439 197 robotControl.getyActualPosition(),
chrigelburri 28:b3e195e80439 198 robotControl.getActualTheta());
chrigelburri 26:a201dcd4e618 199 robotControl.stop();
chrigelburri 26:a201dcd4e618 200 state.savePlotFile(s);
chrigelburri 26:a201dcd4e618 201 leftMotor.setVelocity(0.0f);
chrigelburri 26:a201dcd4e618 202 rightMotor.setVelocity(0.0f);
chrigelburri 8:696c2f9dfc62 203
chrigelburri 21:48248c5b8992 204 /**
chrigelburri 21:48248c5b8992 205 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm
chrigelburri 21:48248c5b8992 206 */
chrigelburri 10:09ddb819fdcb 207 state.savePlotFile(s);
chrigelburri 10:09ddb819fdcb 208 state.closePlotFile();
chrigelburri 10:09ddb819fdcb 209 state.stop();
chrigelburri 10:09ddb819fdcb 210 robotControl.setEnable(false);
chrigelburri 24:08241be546ba 211 robotControl.stop();
chrigelburri 24:08241be546ba 212
chrigelburri 24:08241be546ba 213 /**
chrigelburri 24:08241be546ba 214 * Fast PWM sample for the end
chrigelburri 24:08241be546ba 215 */
chrigelburri 24:08241be546ba 216 while(1) {
chrigelburri 24:08241be546ba 217 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 218 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 219 led[i] = state.dim( i, f );
chrigelburri 24:08241be546ba 220 }
chrigelburri 24:08241be546ba 221 wait_ms(5);
chrigelburri 24:08241be546ba 222 }
chrigelburri 24:08241be546ba 223 wait(0.1);
chrigelburri 24:08241be546ba 224 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 225 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 226 led[i] = state.dim( 3-i, f );
chrigelburri 24:08241be546ba 227 }
chrigelburri 24:08241be546ba 228 wait_ms(5);
chrigelburri 24:08241be546ba 229 }
chrigelburri 24:08241be546ba 230 wait(0.05);
chrigelburri 24:08241be546ba 231 }
chrigelburri 32:767044a3e421 232
chrigelburri 10:09ddb819fdcb 233 }