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 Jun 10 08:21:41 2013 +0000
Revision:
38:d76e488e725f
Parent:
36:4226e50a0bcd
Child:
39:a4fd6206da89
copyright noch neu hinzugef?gt. Bereit zur Ver?ffentlichung

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 38:d76e488e725f 14 * - Bauernfeind Julia <B>WI</B>
chrigelburri 38:d76e488e725f 15 * - Büttler Pirmin <B>WI</B>
chrigelburri 38:d76e488e725f 16 * - Amberg Reto <B>I</B>
chrigelburri 38:d76e488e725f 17 * - Galliker Arno <B>I</B>
chrigelburri 38:d76e488e725f 18 * - Amrein Marcel <B>M</B>
chrigelburri 38:d76e488e725f 19 * - Flühler Ramon <B>M</B>
chrigelburri 38:d76e488e725f 20 * - Burri Christian <B>ET</B>
chrigelburri 38:d76e488e725f 21 * Or see: <a href="http://cruisingcrepe.wordpress.com/">http://cruisingcrepe.wordpress.com/</a>
chrigelburri 4:3a97923ff2d4 22 *
chrigelburri 13:a7c30ee09bae 23 * The postition control is based on this Documentation: Control of Wheeled Mobile Robots:
chrigelburri 13:a7c30ee09bae 24 * An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli.
chrigelburri 15:cb1337567ad4 25 * 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 26 *
chrigelburri 21:48248c5b8992 27 * The connection to an android smartphone is realise with the library MicroBridge(Android ADB) from Junichi Katsu.
chrigelburri 21:48248c5b8992 28 * 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 29 *
chrigelburri 13:a7c30ee09bae 30 * The rest of the classes are only based on standard library from mbed.
chrigelburri 15:cb1337567ad4 31 * 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 38:d76e488e725f 32 *
chrigelburri 38:d76e488e725f 33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
chrigelburri 38:d76e488e725f 34 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
chrigelburri 38:d76e488e725f 35 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
chrigelburri 38:d76e488e725f 36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
chrigelburri 38:d76e488e725f 37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
chrigelburri 38:d76e488e725f 38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
chrigelburri 38:d76e488e725f 39 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
chrigelburri 1:6cd533a712c6 40 */
chrigelburri 1:6cd533a712c6 41
chrigelburri 11:775ebb69d5e1 42 /**
chrigelburri 11:775ebb69d5e1 43 * @file main.cpp
chrigelburri 11:775ebb69d5e1 44 */
chrigelburri 11:775ebb69d5e1 45
chrigelburri 1:6cd533a712c6 46 #include "defines.h"
chrigelburri 1:6cd533a712c6 47 #include "State.h"
chrigelburri 1:6cd533a712c6 48 #include "RobotControl.h"
chrigelburri 18:306d362d692b 49 #include "androidADB.h"
chrigelburri 11:775ebb69d5e1 50
chrigelburri 28:b3e195e80439 51 PwmOut led[4] = {LED1, LED2, LED3, LED4};
chrigelburri 24:08241be546ba 52
chrigelburri 24:08241be546ba 53 /**
chrigelburri 11:775ebb69d5e1 54 * @name Hallsensor
chrigelburri 11:775ebb69d5e1 55 * @{
chrigelburri 11:775ebb69d5e1 56 */
chrigelburri 12:235e318a414f 57
chrigelburri 12:235e318a414f 58 /**
chrigelburri 12:235e318a414f 59 * @brief <code>hallsensorLeft</code> object with pin15, pin17 and pin16
chrigelburri 12:235e318a414f 60 */
chrigelburri 11:775ebb69d5e1 61 Hallsensor hallLeft(p18, p17, p16);
chrigelburri 12:235e318a414f 62
chrigelburri 11:775ebb69d5e1 63 /**
chrigelburri 11:775ebb69d5e1 64 * @brief <code>hallsensorLeft</code> object with pin17, pin28 and pin29
chrigelburri 11:775ebb69d5e1 65 */
chrigelburri 11:775ebb69d5e1 66 Hallsensor hallRight(p27, p28, p29);
chrigelburri 11:775ebb69d5e1 67 /*! @} */
chrigelburri 1:6cd533a712c6 68
chrigelburri 10:09ddb819fdcb 69 /**
chrigelburri 11:775ebb69d5e1 70 * @name Motors and Robot Control
chrigelburri 12:235e318a414f 71 * @{
chrigelburri 10:09ddb819fdcb 72 */
chrigelburri 12:235e318a414f 73
chrigelburri 12:235e318a414f 74 /**
chrigelburri 12:235e318a414f 75 * @brief <code>leftMotor</code> object with pin26, pin25, pin24,
chrigelburri 12:235e318a414f 76 * pin19 and <code>hallsensorLeft</code> object
chrigelburri 12:235e318a414f 77 */
chrigelburri 1:6cd533a712c6 78 MaxonESCON leftMotor(p26, p25, p24, p19, &hallLeft);
chrigelburri 12:235e318a414f 79
chrigelburri 11:775ebb69d5e1 80 /**
chrigelburri 12:235e318a414f 81 * @brief <code>rightMotor</code> object with pin23, pin22, pin21,
chrigelburri 12:235e318a414f 82 * pin20 and <code>hallsensorRight</code> object
chrigelburri 11:775ebb69d5e1 83 */
chrigelburri 1:6cd533a712c6 84 MaxonESCON rightMotor(p23, p22, p21, p20, &hallRight);
chrigelburri 1:6cd533a712c6 85
chrigelburri 11:775ebb69d5e1 86 /**
chrigelburri 12:235e318a414f 87 * @brief <code>robotControl</code> object with <code>leftMotor</code>,
chrigelburri 12:235e318a414f 88 * <code>rightMotor</code> and the sampling rate for the run method
chrigelburri 11:775ebb69d5e1 89 */
chrigelburri 11:775ebb69d5e1 90 RobotControl robotControl(&leftMotor, &rightMotor, PERIOD_ROBOTCONTROL);
chrigelburri 11:775ebb69d5e1 91 /*! @} */
chrigelburri 1:6cd533a712c6 92
chrigelburri 11:775ebb69d5e1 93 /**
chrigelburri 11:775ebb69d5e1 94 * @name Logging & State
chrigelburri 11:775ebb69d5e1 95 * @{
chrigelburri 11:775ebb69d5e1 96 */
chrigelburri 12:235e318a414f 97
chrigelburri 12:235e318a414f 98 /**
chrigelburri 12:235e318a414f 99 * @brief Define the struct for the State and the Logging
chrigelburri 12:235e318a414f 100 */
chrigelburri 11:775ebb69d5e1 101 state_t s;
chrigelburri 12:235e318a414f 102
chrigelburri 11:775ebb69d5e1 103 /**
chrigelburri 12:235e318a414f 104 * @brief <code>state</code> object with <code>robotControl</code>,
chrigelburri 12:235e318a414f 105 * <code>rightMotor</code>, <code>leftMotor</code>, <code>battery</code>
chrigelburri 12:235e318a414f 106 * and the sampling rate for the run method
chrigelburri 11:775ebb69d5e1 107 */
chrigelburri 11:775ebb69d5e1 108 State state(&s, &robotControl, &leftMotor, &rightMotor, p15, PERIOD_STATE);
chrigelburri 11:775ebb69d5e1 109 /*! @} */
chrigelburri 1:6cd533a712c6 110
chrigelburri 14:6a45a9f940a8 111 /**
chrigelburri 14:6a45a9f940a8 112 * @name Communication
chrigelburri 14:6a45a9f940a8 113 * @{
chrigelburri 14:6a45a9f940a8 114 */
chrigelburri 14:6a45a9f940a8 115
chrigelburri 14:6a45a9f940a8 116 /*! @} */
chrigelburri 14:6a45a9f940a8 117
chrigelburri 12:235e318a414f 118 /**
chrigelburri 12:235e318a414f 119 * @brief Main function. Start the Programm here.
chrigelburri 12:235e318a414f 120 */
chrigelburri 1:6cd533a712c6 121 int main()
chrigelburri 1:6cd533a712c6 122 {
chrigelburri 12:235e318a414f 123
chrigelburri 12:235e318a414f 124 /**
chrigelburri 34:62996eed658a 125 * Check at first the Battery voltage. Starts when the voltage
chrigelburri 33:ac39982fd3b2 126 * is greater than the min is.
chrigelburri 12:235e318a414f 127 * start the timer for the Logging to the file
chrigelburri 33:ac39982fd3b2 128 * and start the Task for logging.
chrigelburri 12:235e318a414f 129 **/
chrigelburri 22:bfec16575c91 130 state.start();
chrigelburri 34:62996eed658a 131
chrigelburri 24:08241be546ba 132 while(s.voltageBattery < BAT_MIN) {
chrigelburri 24:08241be546ba 133 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 134 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 135 led[i] = state.dim( i, f );
chrigelburri 24:08241be546ba 136 }
chrigelburri 24:08241be546ba 137 wait_ms(20);
chrigelburri 24:08241be546ba 138 }
chrigelburri 24:08241be546ba 139 wait(0.05);
chrigelburri 24:08241be546ba 140 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 141 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 142 led[i] = state.dim( 3-i, f );
chrigelburri 24:08241be546ba 143 }
chrigelburri 24:08241be546ba 144 wait_ms(20);
chrigelburri 24:08241be546ba 145 }
chrigelburri 24:08241be546ba 146 wait(0.05);
chrigelburri 24:08241be546ba 147 }
chrigelburri 24:08241be546ba 148 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 149 led[i] = state.dim( 0, 0.0f );
chrigelburri 24:08241be546ba 150 }
chrigelburri 28:b3e195e80439 151
chrigelburri 22:bfec16575c91 152 wait(0.5);
chrigelburri 16:b5d949136a21 153 state.initPlotFile();
chrigelburri 12:235e318a414f 154 state.startTimerFromZero();
chrigelburri 28:b3e195e80439 155 robotControl.start();
chrigelburri 36:4226e50a0bcd 156 /*
chrigelburri 36:4226e50a0bcd 157 /**
chrigelburri 36:4226e50a0bcd 158 * Clear all Errors of the ESCON Module, with a disabled to enable event.
chrigelburri 36:4226e50a0bcd 159 */
chrigelburri 1:6cd533a712c6 160 robotControl.setEnable(false);
chrigelburri 16:b5d949136a21 161 wait(0.01);
chrigelburri 1:6cd533a712c6 162 robotControl.setEnable(true);
chrigelburri 6:48eeb41188dd 163 wait(0.1);
chrigelburri 28:b3e195e80439 164 robotControl.setEnable(false);
chrigelburri 12:235e318a414f 165
chrigelburri 29:937c74ff040e 166 /**
chrigelburri 29:937c74ff040e 167 * Initialise the ADB subsystem.
chrigelburri 32:767044a3e421 168 * Set Theta for to go to Startloop.
chrigelburri 29:937c74ff040e 169 */
chrigelburri 28:b3e195e80439 170 init();
chrigelburri 28:b3e195e80439 171 setDesiredTheta(400.0f);
chrigelburri 28:b3e195e80439 172
chrigelburri 28:b3e195e80439 173 while(getDesiredTheta() < (4 * PI)) {
chrigelburri 36:4226e50a0bcd 174
chrigelburri 28:b3e195e80439 175 if (getDesiredTheta() > (2 * PI)) {
chrigelburri 29:937c74ff040e 176 /**
chrigelburri 33:ac39982fd3b2 177 * Runs at first till the Startbutton has pressed.
chrigelburri 29:937c74ff040e 178 */
chrigelburri 36:4226e50a0bcd 179
chrigelburri 28:b3e195e80439 180 state.startTimerFromZero();
chrigelburri 28:b3e195e80439 181 robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
chrigelburri 28:b3e195e80439 182 robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
chrigelburri 30:c32fc6174efe 183 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 184 } else {
chrigelburri 28:b3e195e80439 185 robotControl.setEnable(true);
chrigelburri 28:b3e195e80439 186 robotControl.setDesiredPositionAndAngle(getDesiredX(), getDesiredY(), getDesiredTheta());
chrigelburri 30:c32fc6174efe 187 state.savePlotFile(s);
chrigelburri 30:c32fc6174efe 188 wait(PERIOD_ANDROID/2);
chrigelburri 28:b3e195e80439 189 state.savePlotFile(s);
chrigelburri 28:b3e195e80439 190 }
chrigelburri 28:b3e195e80439 191 writeActualPosition(robotControl.getxActualPosition(),
chrigelburri 28:b3e195e80439 192 robotControl.getyActualPosition(),
chrigelburri 28:b3e195e80439 193 robotControl.getActualTheta(),
chrigelburri 28:b3e195e80439 194 s.state&STATE_UNDER,
chrigelburri 28:b3e195e80439 195 s.state&STATE_LEFT,
chrigelburri 28:b3e195e80439 196 s.state&STATE_RIGHT,
chrigelburri 28:b3e195e80439 197 s.voltageBattery);
chrigelburri 30:c32fc6174efe 198 wait(PERIOD_ANDROID/2);
chrigelburri 36:4226e50a0bcd 199
chrigelburri 36:4226e50a0bcd 200 ADB::poll();
chrigelburri 28:b3e195e80439 201 }
chrigelburri 6:48eeb41188dd 202
chrigelburri 22:bfec16575c91 203 /**
chrigelburri 29:937c74ff040e 204 * Sets the acutal value for a fast stop.
chrigelburri 33:ac39982fd3b2 205 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm.
chrigelburri 22:bfec16575c91 206 */
chrigelburri 28:b3e195e80439 207 robotControl.setDesiredPositionAndAngle(robotControl.getxActualPosition(),
chrigelburri 28:b3e195e80439 208 robotControl.getyActualPosition(),
chrigelburri 28:b3e195e80439 209 robotControl.getActualTheta());
chrigelburri 26:a201dcd4e618 210 robotControl.stop();
chrigelburri 26:a201dcd4e618 211 leftMotor.setVelocity(0.0f);
chrigelburri 26:a201dcd4e618 212 rightMotor.setVelocity(0.0f);
chrigelburri 34:62996eed658a 213 wait(2);
chrigelburri 34:62996eed658a 214
chrigelburri 21:48248c5b8992 215 /**
chrigelburri 33:ac39982fd3b2 216 * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm.
chrigelburri 21:48248c5b8992 217 */
chrigelburri 10:09ddb819fdcb 218 state.closePlotFile();
chrigelburri 10:09ddb819fdcb 219 state.stop();
chrigelburri 10:09ddb819fdcb 220 robotControl.setEnable(false);
chrigelburri 24:08241be546ba 221
chrigelburri 24:08241be546ba 222 /**
chrigelburri 33:ac39982fd3b2 223 * Fast PWM sample for the end.
chrigelburri 24:08241be546ba 224 */
chrigelburri 24:08241be546ba 225 while(1) {
chrigelburri 24:08241be546ba 226 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 227 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 228 led[i] = state.dim( i, f );
chrigelburri 24:08241be546ba 229 }
chrigelburri 24:08241be546ba 230 wait_ms(5);
chrigelburri 24:08241be546ba 231 }
chrigelburri 24:08241be546ba 232 wait(0.1);
chrigelburri 24:08241be546ba 233 for (float f = 0.1f; f < 6.3f; f += 0.1f) {
chrigelburri 24:08241be546ba 234 for(int i = 0; i <= 3; i ++) {
chrigelburri 24:08241be546ba 235 led[i] = state.dim( 3-i, f );
chrigelburri 24:08241be546ba 236 }
chrigelburri 24:08241be546ba 237 wait_ms(5);
chrigelburri 24:08241be546ba 238 }
chrigelburri 24:08241be546ba 239 wait(0.05);
chrigelburri 24:08241be546ba 240 }
chrigelburri 10:09ddb819fdcb 241 }