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:
Tue May 21 17:42:50 2013 +0000
Revision:
33:ac39982fd3b2
Parent:
32:767044a3e421
Child:
34:62996eed658a
korrigiert christian

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 33:ac39982fd3b2 116 * Check at first the Battery voltage. Starts when the voltage
chrigelburri 33:ac39982fd3b2 117 * is greater than the min is.
chrigelburri 12:235e318a414f 118 * start the timer for the Logging to the file
chrigelburri 33:ac39982fd3b2 119 * and start the Task for logging.
chrigelburri 12:235e318a414f 120 **/
chrigelburri 22:bfec16575c91 121 state.start();
chrigelburri 32:767044a3e421 122
chrigelburri 24:08241be546ba 123 while(s.voltageBattery < BAT_MIN) {
chrigelburri 24:08241be546ba 124 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 125 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 126 led[i] = state.dim( i, f );
chrigelburri 24:08241be546ba 127 }
chrigelburri 24:08241be546ba 128 wait_ms(20);
chrigelburri 24:08241be546ba 129 }
chrigelburri 24:08241be546ba 130 wait(0.05);
chrigelburri 24:08241be546ba 131 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 132 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 133 led[i] = state.dim( 3-i, f );
chrigelburri 24:08241be546ba 134 }
chrigelburri 24:08241be546ba 135 wait_ms(20);
chrigelburri 24:08241be546ba 136 }
chrigelburri 24:08241be546ba 137 wait(0.05);
chrigelburri 24:08241be546ba 138 }
chrigelburri 24:08241be546ba 139 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 140 led[i] = state.dim( 0, 0.0f );
chrigelburri 24:08241be546ba 141 }
chrigelburri 28:b3e195e80439 142
chrigelburri 22:bfec16575c91 143 wait(0.5);
chrigelburri 16:b5d949136a21 144 state.initPlotFile();
chrigelburri 12:235e318a414f 145 state.startTimerFromZero();
chrigelburri 28:b3e195e80439 146 robotControl.start();
chrigelburri 12:235e318a414f 147
chrigelburri 12:235e318a414f 148 /**
chrigelburri 33:ac39982fd3b2 149 * Clear all Errors of the ESCON Module, with a disabled to enable event.
chrigelburri 12:235e318a414f 150 */
chrigelburri 1:6cd533a712c6 151 robotControl.setEnable(false);
chrigelburri 16:b5d949136a21 152 wait(0.01);
chrigelburri 1:6cd533a712c6 153 robotControl.setEnable(true);
chrigelburri 6:48eeb41188dd 154 wait(0.1);
chrigelburri 28:b3e195e80439 155 robotControl.setEnable(false);
chrigelburri 12:235e318a414f 156
chrigelburri 29:937c74ff040e 157 /**
chrigelburri 29:937c74ff040e 158 * Initialise the ADB subsystem.
chrigelburri 32:767044a3e421 159 * Set Theta for to go to Startloop.
chrigelburri 29:937c74ff040e 160 */
chrigelburri 28:b3e195e80439 161 init();
chrigelburri 28:b3e195e80439 162 setDesiredTheta(400.0f);
chrigelburri 28:b3e195e80439 163
chrigelburri 28:b3e195e80439 164 while(getDesiredTheta() < (4 * PI)) {
chrigelburri 32:767044a3e421 165 ADB::poll();
chrigelburri 28:b3e195e80439 166 if (getDesiredTheta() > (2 * PI)) {
chrigelburri 29:937c74ff040e 167 /**
chrigelburri 33:ac39982fd3b2 168 * Runs at first till the Startbutton has pressed.
chrigelburri 29:937c74ff040e 169 */
chrigelburri 28:b3e195e80439 170 state.startTimerFromZero();
chrigelburri 28:b3e195e80439 171 robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
chrigelburri 28:b3e195e80439 172 robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
chrigelburri 28:b3e195e80439 173 robotControl.setEnable(false);
chrigelburri 30:c32fc6174efe 174 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 175 } else {
chrigelburri 28:b3e195e80439 176 robotControl.setEnable(true);
chrigelburri 28:b3e195e80439 177 robotControl.setDesiredPositionAndAngle(getDesiredX(), getDesiredY(), getDesiredTheta());
chrigelburri 30:c32fc6174efe 178 state.savePlotFile(s);
chrigelburri 30:c32fc6174efe 179 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 180 state.savePlotFile(s);
chrigelburri 28:b3e195e80439 181 }
chrigelburri 28:b3e195e80439 182 writeActualPosition(robotControl.getxActualPosition(),
chrigelburri 28:b3e195e80439 183 robotControl.getyActualPosition(),
chrigelburri 28:b3e195e80439 184 robotControl.getActualTheta(),
chrigelburri 28:b3e195e80439 185 s.state&STATE_UNDER,
chrigelburri 28:b3e195e80439 186 s.state&STATE_LEFT,
chrigelburri 28:b3e195e80439 187 s.state&STATE_RIGHT,
chrigelburri 28:b3e195e80439 188 s.voltageBattery);
chrigelburri 30:c32fc6174efe 189 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 190
chrigelburri 28:b3e195e80439 191 }
chrigelburri 6:48eeb41188dd 192
chrigelburri 22:bfec16575c91 193 /**
chrigelburri 29:937c74ff040e 194 * Sets the acutal value for a fast stop.
chrigelburri 33:ac39982fd3b2 195 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm.
chrigelburri 22:bfec16575c91 196 */
chrigelburri 28:b3e195e80439 197 robotControl.setDesiredPositionAndAngle(robotControl.getxActualPosition(),
chrigelburri 28:b3e195e80439 198 robotControl.getyActualPosition(),
chrigelburri 28:b3e195e80439 199 robotControl.getActualTheta());
chrigelburri 26:a201dcd4e618 200 robotControl.stop();
chrigelburri 26:a201dcd4e618 201 state.savePlotFile(s);
chrigelburri 26:a201dcd4e618 202 leftMotor.setVelocity(0.0f);
chrigelburri 26:a201dcd4e618 203 rightMotor.setVelocity(0.0f);
chrigelburri 8:696c2f9dfc62 204
chrigelburri 21:48248c5b8992 205 /**
chrigelburri 33:ac39982fd3b2 206 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm.
chrigelburri 21:48248c5b8992 207 */
chrigelburri 10:09ddb819fdcb 208 state.savePlotFile(s);
chrigelburri 10:09ddb819fdcb 209 state.closePlotFile();
chrigelburri 10:09ddb819fdcb 210 state.stop();
chrigelburri 10:09ddb819fdcb 211 robotControl.setEnable(false);
chrigelburri 24:08241be546ba 212 robotControl.stop();
chrigelburri 24:08241be546ba 213
chrigelburri 24:08241be546ba 214 /**
chrigelburri 33:ac39982fd3b2 215 * Fast PWM sample for the end.
chrigelburri 24:08241be546ba 216 */
chrigelburri 24:08241be546ba 217 while(1) {
chrigelburri 24:08241be546ba 218 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 219 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 220 led[i] = state.dim( i, f );
chrigelburri 24:08241be546ba 221 }
chrigelburri 24:08241be546ba 222 wait_ms(5);
chrigelburri 24:08241be546ba 223 }
chrigelburri 24:08241be546ba 224 wait(0.1);
chrigelburri 24:08241be546ba 225 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 226 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 227 led[i] = state.dim( 3-i, f );
chrigelburri 24:08241be546ba 228 }
chrigelburri 24:08241be546ba 229 wait_ms(5);
chrigelburri 24:08241be546ba 230 }
chrigelburri 24:08241be546ba 231 wait(0.05);
chrigelburri 24:08241be546ba 232 }
chrigelburri 32:767044a3e421 233
chrigelburri 10:09ddb819fdcb 234 }