Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of autonomousRobotAndroid by
main.cpp@17:f0a973f17917, 2013-05-03 (annotated)
- Committer:
- chrigelburri
- Date:
- Fri May 03 06:30:46 2013 +0000
- Revision:
- 17:f0a973f17917
- Parent:
- 16:b5d949136a21
bastel mit adb
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chrigelburri | 10:09ddb819fdcb | 1 | /*! \mainpage Index Page |
| chrigelburri | 2:d8e1613dc38b | 2 | * @author Christian Burri |
| chrigelburri | 11:775ebb69d5e1 | 3 | * @author Arno Galliker |
| chrigelburri | 2:d8e1613dc38b | 4 | * |
| chrigelburri | 11:775ebb69d5e1 | 5 | * @copyright Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe |
| chrigelburri | 1:6cd533a712c6 | 6 | * All rights reserved. |
| chrigelburri | 2:d8e1613dc38b | 7 | * |
| chrigelburri | 11:775ebb69d5e1 | 8 | * @brief |
| chrigelburri | 2:d8e1613dc38b | 9 | * |
| chrigelburri | 15:cb1337567ad4 | 10 | * This program is for an autonomous robot for the competition |
| chrigelburri | 4:3a97923ff2d4 | 11 | * at the Hochschule Luzern. |
| chrigelburri | 3:92ba0254af87 | 12 | * We are one of the 32 teams. In the team #1 is: |
| chrigelburri | 11:775ebb69d5e1 | 13 | * - Bauernfeind Julia <B>WI</B> <a href="mailto:julia.bauernfeind@stud.hslu.ch">julia.bauernfeind@stud.hslu.ch</a> |
| chrigelburri | 11:775ebb69d5e1 | 14 | * - Büttler Pirmin <B>WI</B> <a href="mailto:pirmin.buetler@stud.hslu.ch">pirmin.buetler@stud.hslu.ch</a> |
| chrigelburri | 11:775ebb69d5e1 | 15 | * - Amberg Reto <B>I</B> <a href="mailto:reto.amberg@stud.hslu.ch">reto.amberg@stud.hslu.ch</a> |
| chrigelburri | 11:775ebb69d5e1 | 16 | * - Galliker Arno <B>I</B> <a href="mailto:arno.galliker@stud.hslu.ch">arno.galliker@stud.hslu.ch</a> |
| chrigelburri | 11:775ebb69d5e1 | 17 | * - Amrein Marcel <B>M</B> <a href="mailto:marcel.amrein@stud.hslu.ch">marcel.amrein@stud.hslu.ch</a> |
| chrigelburri | 11:775ebb69d5e1 | 18 | * - Flühler Ramon <B>M</B> <a href="mailto:ramon.fluehler@stud.hslu.ch">ramon.fluehler@stud.hslu.ch</a> |
| chrigelburri | 11:775ebb69d5e1 | 19 | * - Burri Christian <B>ET</B> <a href="mailto:christian.burri@stud.hslu.ch">christian.burri@stud.hslu.ch</a> |
| chrigelburri | 4:3a97923ff2d4 | 20 | * |
| chrigelburri | 13:a7c30ee09bae | 21 | * The postition control is based on this Documentation: Control of Wheeled Mobile Robots: |
| chrigelburri | 13:a7c30ee09bae | 22 | * An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli. |
| chrigelburri | 15:cb1337567ad4 | 23 | * 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 | 24 | * |
| chrigelburri | 15:cb1337567ad4 | 25 | * The connection to an android smartphone is realise with the library AndroidAccessory from Rich Bayliss. |
| chrigelburri | 15:cb1337567ad4 | 26 | * For more information see here: <a href="https://mbed.org/users/richbayliss/code/AndroidAccessory/docs/tip/">https://mbed.org/users/richbayliss/code/AndroidAccessory/docs/tip/</a> |
| chrigelburri | 17:f0a973f17917 | 27 | * |
| chrigelburri | 13:a7c30ee09bae | 28 | * The rest of the classes are only based on standard library from mbed. |
| chrigelburri | 15:cb1337567ad4 | 29 | * 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 | 30 | */ |
| chrigelburri | 1:6cd533a712c6 | 31 | |
| chrigelburri | 11:775ebb69d5e1 | 32 | /** |
| chrigelburri | 11:775ebb69d5e1 | 33 | * @file main.cpp |
| chrigelburri | 11:775ebb69d5e1 | 34 | */ |
| chrigelburri | 11:775ebb69d5e1 | 35 | |
| chrigelburri | 1:6cd533a712c6 | 36 | #include "defines.h" |
| chrigelburri | 1:6cd533a712c6 | 37 | #include "State.h" |
| chrigelburri | 1:6cd533a712c6 | 38 | #include "RobotControl.h" |
| chrigelburri | 17:f0a973f17917 | 39 | |
| chrigelburri | 17:f0a973f17917 | 40 | #include "androidADB.h" |
| chrigelburri | 11:775ebb69d5e1 | 41 | |
| chrigelburri | 11:775ebb69d5e1 | 42 | /** |
| chrigelburri | 11:775ebb69d5e1 | 43 | * @name Hallsensor |
| chrigelburri | 11:775ebb69d5e1 | 44 | * @{ |
| chrigelburri | 11:775ebb69d5e1 | 45 | */ |
| chrigelburri | 12:235e318a414f | 46 | |
| chrigelburri | 12:235e318a414f | 47 | /** |
| chrigelburri | 12:235e318a414f | 48 | * @brief <code>hallsensorLeft</code> object with pin15, pin17 and pin16 |
| chrigelburri | 12:235e318a414f | 49 | */ |
| chrigelburri | 11:775ebb69d5e1 | 50 | Hallsensor hallLeft(p18, p17, p16); |
| chrigelburri | 12:235e318a414f | 51 | |
| chrigelburri | 11:775ebb69d5e1 | 52 | /** |
| chrigelburri | 11:775ebb69d5e1 | 53 | * @brief <code>hallsensorLeft</code> object with pin17, pin28 and pin29 |
| chrigelburri | 11:775ebb69d5e1 | 54 | */ |
| chrigelburri | 11:775ebb69d5e1 | 55 | Hallsensor hallRight(p27, p28, p29); |
| chrigelburri | 11:775ebb69d5e1 | 56 | /*! @} */ |
| chrigelburri | 1:6cd533a712c6 | 57 | |
| chrigelburri | 10:09ddb819fdcb | 58 | /** |
| chrigelburri | 11:775ebb69d5e1 | 59 | * @name Motors and Robot Control |
| chrigelburri | 12:235e318a414f | 60 | * @{ |
| chrigelburri | 10:09ddb819fdcb | 61 | */ |
| chrigelburri | 12:235e318a414f | 62 | |
| chrigelburri | 12:235e318a414f | 63 | /** |
| chrigelburri | 12:235e318a414f | 64 | * @brief <code>leftMotor</code> object with pin26, pin25, pin24, |
| chrigelburri | 12:235e318a414f | 65 | * pin19 and <code>hallsensorLeft</code> object |
| chrigelburri | 12:235e318a414f | 66 | */ |
| chrigelburri | 1:6cd533a712c6 | 67 | MaxonESCON leftMotor(p26, p25, p24, p19, &hallLeft); |
| chrigelburri | 12:235e318a414f | 68 | |
| chrigelburri | 11:775ebb69d5e1 | 69 | /** |
| chrigelburri | 12:235e318a414f | 70 | * @brief <code>rightMotor</code> object with pin23, pin22, pin21, |
| chrigelburri | 12:235e318a414f | 71 | * pin20 and <code>hallsensorRight</code> object |
| chrigelburri | 11:775ebb69d5e1 | 72 | */ |
| chrigelburri | 1:6cd533a712c6 | 73 | MaxonESCON rightMotor(p23, p22, p21, p20, &hallRight); |
| chrigelburri | 1:6cd533a712c6 | 74 | |
| chrigelburri | 11:775ebb69d5e1 | 75 | /** |
| chrigelburri | 12:235e318a414f | 76 | * @brief <code>robotControl</code> object with <code>leftMotor</code>, |
| chrigelburri | 12:235e318a414f | 77 | * <code>rightMotor</code> and the sampling rate for the run method |
| chrigelburri | 11:775ebb69d5e1 | 78 | */ |
| chrigelburri | 11:775ebb69d5e1 | 79 | RobotControl robotControl(&leftMotor, &rightMotor, PERIOD_ROBOTCONTROL); |
| chrigelburri | 11:775ebb69d5e1 | 80 | /*! @} */ |
| chrigelburri | 1:6cd533a712c6 | 81 | |
| chrigelburri | 11:775ebb69d5e1 | 82 | /** |
| chrigelburri | 11:775ebb69d5e1 | 83 | * @name Logging & State |
| chrigelburri | 11:775ebb69d5e1 | 84 | * @{ |
| chrigelburri | 11:775ebb69d5e1 | 85 | */ |
| chrigelburri | 12:235e318a414f | 86 | |
| chrigelburri | 12:235e318a414f | 87 | /** |
| chrigelburri | 12:235e318a414f | 88 | * @brief Define the struct for the State and the Logging |
| chrigelburri | 12:235e318a414f | 89 | */ |
| chrigelburri | 11:775ebb69d5e1 | 90 | state_t s; |
| chrigelburri | 12:235e318a414f | 91 | |
| chrigelburri | 11:775ebb69d5e1 | 92 | /** |
| chrigelburri | 12:235e318a414f | 93 | * @brief <code>state</code> object with <code>robotControl</code>, |
| chrigelburri | 12:235e318a414f | 94 | * <code>rightMotor</code>, <code>leftMotor</code>, <code>battery</code> |
| chrigelburri | 12:235e318a414f | 95 | * and the sampling rate for the run method |
| chrigelburri | 11:775ebb69d5e1 | 96 | */ |
| chrigelburri | 11:775ebb69d5e1 | 97 | State state(&s, &robotControl, &leftMotor, &rightMotor, p15, PERIOD_STATE); |
| chrigelburri | 11:775ebb69d5e1 | 98 | /*! @} */ |
| chrigelburri | 1:6cd533a712c6 | 99 | |
| chrigelburri | 14:6a45a9f940a8 | 100 | /** |
| chrigelburri | 14:6a45a9f940a8 | 101 | * @name Communication |
| chrigelburri | 14:6a45a9f940a8 | 102 | * @{ |
| chrigelburri | 14:6a45a9f940a8 | 103 | */ |
| chrigelburri | 14:6a45a9f940a8 | 104 | |
| chrigelburri | 14:6a45a9f940a8 | 105 | /** |
| chrigelburri | 14:6a45a9f940a8 | 106 | * @brief <code>adkTerm</code> object is for the communication with a smartphone. |
| chrigelburri | 14:6a45a9f940a8 | 107 | * The operation system must be a android. |
| chrigelburri | 14:6a45a9f940a8 | 108 | */ |
| chrigelburri | 16:b5d949136a21 | 109 | //AdkTerm adkTerm(&robotControl, &s, PERIOD_ANDROID); |
| chrigelburri | 14:6a45a9f940a8 | 110 | /*! @} */ |
| chrigelburri | 14:6a45a9f940a8 | 111 | |
| chrigelburri | 14:6a45a9f940a8 | 112 | |
| chrigelburri | 12:235e318a414f | 113 | // @todo PC USB communications DAs wird danach gelöscht |
| chrigelburri | 16:b5d949136a21 | 114 | //Serial pc(USBTX, USBRX); |
| chrigelburri | 1:6cd533a712c6 | 115 | |
| chrigelburri | 12:235e318a414f | 116 | /** |
| chrigelburri | 12:235e318a414f | 117 | * @brief Main function. Start the Programm here. |
| chrigelburri | 12:235e318a414f | 118 | */ |
| chrigelburri | 1:6cd533a712c6 | 119 | int main() |
| chrigelburri | 1:6cd533a712c6 | 120 | { |
| chrigelburri | 12:235e318a414f | 121 | |
| chrigelburri | 12:235e318a414f | 122 | /** |
| chrigelburri | 12:235e318a414f | 123 | * Initialze the filt PLOTS.txt, |
| chrigelburri | 12:235e318a414f | 124 | * start the timer for the Logging to the file |
| chrigelburri | 12:235e318a414f | 125 | * and start the Task for logging |
| chrigelburri | 12:235e318a414f | 126 | **/ |
| chrigelburri | 16:b5d949136a21 | 127 | state.initPlotFile(); |
| chrigelburri | 12:235e318a414f | 128 | state.startTimerFromZero(); |
| chrigelburri | 12:235e318a414f | 129 | state.start(); |
| chrigelburri | 12:235e318a414f | 130 | |
| chrigelburri | 12:235e318a414f | 131 | /** |
| chrigelburri | 12:235e318a414f | 132 | * Clear all Errors of the ESCON Module, with a disabled to enable event |
| chrigelburri | 12:235e318a414f | 133 | */ |
| chrigelburri | 1:6cd533a712c6 | 134 | robotControl.setEnable(false); |
| chrigelburri | 16:b5d949136a21 | 135 | wait(0.01); |
| chrigelburri | 1:6cd533a712c6 | 136 | robotControl.setEnable(true); |
| chrigelburri | 6:48eeb41188dd | 137 | wait(0.1); |
| chrigelburri | 12:235e318a414f | 138 | |
| chrigelburri | 12:235e318a414f | 139 | /** |
| chrigelburri | 12:235e318a414f | 140 | * Set the startposition and start the Task for controlling the roboter. |
| chrigelburri | 12:235e318a414f | 141 | */ |
| chrigelburri | 16:b5d949136a21 | 142 | //robotControl.setAllToZero(0, 0, PI/2 ); |
| chrigelburri | 16:b5d949136a21 | 143 | robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 ); |
| chrigelburri | 8:696c2f9dfc62 | 144 | robotControl.start(); |
| chrigelburri | 8:696c2f9dfc62 | 145 | |
| chrigelburri | 17:f0a973f17917 | 146 | init(); |
| chrigelburri | 6:48eeb41188dd | 147 | |
| chrigelburri | 17:f0a973f17917 | 148 | //pc.printf("connection isOpen\n"); |
| chrigelburri | 5:48a258f6335e | 149 | |
| chrigelburri | 17:f0a973f17917 | 150 | while(1) { |
| chrigelburri | 6:48eeb41188dd | 151 | |
| chrigelburri | 17:f0a973f17917 | 152 | ADB::poll(); |
| chrigelburri | 4:3a97923ff2d4 | 153 | |
| chrigelburri | 17:f0a973f17917 | 154 | //robotControl.setDesiredPositionAndAngle(androidx, androidy, androidt); |
| chrigelburri | 17:f0a973f17917 | 155 | robotControl.setDesiredPositionAndAngle(androidx, 1.4, 1.3); |
| chrigelburri | 11:775ebb69d5e1 | 156 | |
| chrigelburri | 17:f0a973f17917 | 157 | char str[32]; |
| chrigelburri | 11:775ebb69d5e1 | 158 | |
| chrigelburri | 17:f0a973f17917 | 159 | // to mbed |
| chrigelburri | 17:f0a973f17917 | 160 | sprintf( str, "%f;%f;%f;", robotControl.getxActualPosition(), robotControl.getyActualPosition(), robotControl.getDesiredTheta()); |
| chrigelburri | 17:f0a973f17917 | 161 | //pc.printf("Sending: %s\n\r",str); |
| chrigelburri | 17:f0a973f17917 | 162 | connection->write(sizeof(str),(unsigned char*)&str); |
| chrigelburri | 9:d3cdcdef9719 | 163 | |
| chrigelburri | 17:f0a973f17917 | 164 | wait(1); |
| chrigelburri | 12:235e318a414f | 165 | |
| chrigelburri | 17:f0a973f17917 | 166 | } |
| chrigelburri | 8:696c2f9dfc62 | 167 | |
| chrigelburri | 12:235e318a414f | 168 | /** |
| chrigelburri | 17:f0a973f17917 | 169 | * Close the File PLOTS.txt to read the file after with the computer and draw a diagramm |
| chrigelburri | 17:f0a973f17917 | 170 | */ |
| chrigelburri | 10:09ddb819fdcb | 171 | state.savePlotFile(s); |
| chrigelburri | 10:09ddb819fdcb | 172 | state.closePlotFile(); |
| chrigelburri | 10:09ddb819fdcb | 173 | state.stop(); |
| chrigelburri | 10:09ddb819fdcb | 174 | robotControl.setEnable(false); |
| chrigelburri | 17:f0a973f17917 | 175 | |
| chrigelburri | 10:09ddb819fdcb | 176 | } |
