Christian Burri / Mbed 2 deprecated autonomous Robot Android

Dependencies:   mbed

Fork of autonomous Robot Android by Christian Burri

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 
00002 /*! \mainpage Index Page
00003  * @author Christian Burri
00004  * @author Arno Galliker
00005  *
00006  * @copyright Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe
00007  * All rights reserved.
00008  *
00009  * @brief
00010  *
00011  * This program is for an autonomous robot for the competition
00012  * at the Hochschule Luzern.
00013  * We are one of the 32 teams. In the team #1 is:
00014  * - Bauernfeind Julia <B>WI</B>
00015  * - Büttler Pirmin <B>WI</B>
00016  * - Amberg Reto <B>I</B>
00017  * - Galliker Arno <B>I</B>
00018  * - Amrein Marcel <B>M</B>
00019  * - Flühler Ramon <B>M</B>
00020  * - Burri Christian <B>ET</B>
00021  *   Or see: <a href="http://cruisingcrepe.wordpress.com/">http://cruisingcrepe.wordpress.com/</a>
00022  *
00023  * The postition control is based on this Documentation: Control of Wheeled Mobile Robots:
00024  * An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli.
00025  * 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>
00026  *
00027  * The connection to an android smartphone is realise with the library MicroBridge(Android ADB) from Junichi Katsu.
00028  * For more information see here: <a href="http://mbed.org/users/jksoft/code/MicroBridge/">http://mbed.org/users/jksoft/code/MicroBridge/</a>
00029  *
00030  * The rest of the classes are only based on standard library from mbed.
00031  * For more information see here: <a href="http://mbed.org/users/mbed_official/code/mbed/">http://mbed.org/users/mbed_official/code/mbed/</a>
00032  * 
00033  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00034  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00035  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00036  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00037  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00038  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00039  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00040  */
00041 
00042 /**
00043  * @file main.cpp
00044  */
00045 
00046 #include "defines.h"
00047 #include "State.h"
00048 #include "RobotControl.h"
00049 #include "androidADB.h"
00050 
00051 PwmOut led[4] = {LED1, LED2, LED3, LED4};
00052 
00053 /**
00054  * @name Hallsensor
00055  * @{
00056  */
00057 
00058 /**
00059 * @brief <code>hallsensorLeft</code> object with pin15, pin17 and pin16
00060 */
00061 Hallsensor hallLeft(p18, p17, p16);
00062 
00063 /**
00064  * @brief <code>hallsensorLeft</code> object with pin17, pin28 and pin29
00065  */
00066 Hallsensor hallRight(p27, p28, p29);
00067 /*! @} */
00068 
00069 /**
00070  * @name Motors and Robot Control
00071  * @{
00072  */
00073 
00074 /**
00075 * @brief <code>leftMotor</code> object with pin26, pin25, pin24,
00076 * pin19 and <code>hallsensorLeft</code> object
00077 */
00078 MaxonESCON leftMotor(p26, p25, p24, p19, &hallLeft);
00079 
00080 /**
00081  * @brief <code>rightMotor</code> object with pin23, pin22, pin21,
00082  * pin20 and <code>hallsensorRight</code> object
00083  */
00084 MaxonESCON rightMotor(p23, p22, p21, p20, &hallRight);
00085 
00086 /**
00087  * @brief <code>robotControl</code> object with <code>leftMotor</code>,
00088  * <code>rightMotor</code> and the sampling rate for the run method
00089  */
00090 RobotControl robotControl(&leftMotor, &rightMotor, PERIOD_ROBOTCONTROL);
00091 /*! @} */
00092 
00093 /**
00094  * @name Logging & State
00095  * @{
00096  */
00097 
00098 /**
00099  * @brief Define the struct for the State and the Logging
00100  */
00101 state_t s;
00102 
00103 /**
00104  * @brief <code>state</code> object with <code>robotControl</code>,
00105  * <code>rightMotor</code>, <code>leftMotor</code>, <code>battery</code>
00106  * and the sampling rate for the run method
00107  */
00108 State state(&s, &robotControl, &leftMotor, &rightMotor, p15, PERIOD_STATE);
00109 /*! @} */
00110 
00111 /**
00112  * @name Communication
00113  * @{
00114  */
00115 
00116 /*! @} */
00117 
00118 /**
00119 * @brief Main function. Start the Programm here.
00120 */
00121 int main()
00122 {
00123 
00124     /**
00125      * Check at first the Battery voltage. Starts when the voltage
00126      * is greater than the min is.
00127      * start the timer for the Logging to the file
00128      * and start the Task for logging.
00129      **/
00130     state.start();
00131 
00132     while(s.voltageBattery < BAT_MIN) {
00133         for (float f = 0.1f; f < 6.3f; f += 0.1f) {
00134             for(int i = 0; i <= 3; i  ++) {
00135                 led[i] = state.dim( i, f );
00136             }
00137             wait_ms(20);
00138         }
00139         wait(0.05);
00140         for (float f = 0.1f; f < 6.3f; f += 0.1f) {
00141             for(int i = 0; i <= 3; i  ++) {
00142                 led[i] = state.dim( 3-i, f );
00143             }
00144             wait_ms(20);
00145         }
00146         wait(0.05);
00147     }
00148     for(int i = 0; i <= 3; i  ++) {
00149         led[i] = state.dim( 0, 0.0f );
00150     }
00151 
00152     wait(0.5);
00153     state.initPlotFile();
00154     state.startTimerFromZero();
00155     robotControl.start();
00156     /*
00157         /**
00158          * Clear all Errors of the ESCON Module, with a disabled to enable event.
00159          */
00160     robotControl.setEnable(false);
00161     wait(0.01);
00162     robotControl.setEnable(true);
00163     wait(0.1);
00164     robotControl.setEnable(false);
00165 
00166     /**
00167     * Initialise the ADB subsystem.
00168     * Set Theta for to go to Startloop.
00169     */
00170     init();
00171     setDesiredTheta(400.0f);
00172 
00173     while(getDesiredTheta() < (4 * PI)) {
00174 
00175         if (getDesiredTheta() > (2 * PI)) {
00176             /**
00177             * Runs at first till the Startbutton has pressed.
00178             */
00179             
00180             state.startTimerFromZero();
00181             robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 );
00182             robotControl.setDesiredPositionAndAngle(START_X_OFFSET, START_Y_OFFSET, PI/2);
00183             wait(PERIOD_ANDROID/2);
00184         } else {
00185             robotControl.setEnable(true);
00186             robotControl.setDesiredPositionAndAngle(getDesiredX(), getDesiredY(), getDesiredTheta());
00187             state.savePlotFile(s);
00188             wait(PERIOD_ANDROID/2);
00189             state.savePlotFile(s);
00190         }
00191         writeActualPosition(robotControl.getxActualPosition(),
00192                             robotControl.getyActualPosition(),
00193                             robotControl.getActualTheta(),
00194                             s.state&STATE_UNDER,
00195                             s.state&STATE_LEFT,
00196                             s.state&STATE_RIGHT,
00197                             s.voltageBattery);
00198         wait(PERIOD_ANDROID/2);
00199         
00200         ADB::poll();
00201     }
00202 
00203     /**
00204      * Sets the acutal value for a fast stop.
00205      * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm.
00206      */
00207     robotControl.setDesiredPositionAndAngle(robotControl.getxActualPosition(),
00208                                             robotControl.getyActualPosition(),
00209                                             robotControl.getActualTheta());
00210     robotControl.stop();
00211     leftMotor.setVelocity(0.0f);
00212     rightMotor.setVelocity(0.0f);
00213     wait(2);
00214 
00215     /**
00216      * Close the File PLOTS.txt to read the file with the computer afterwards and draw a diagramm.
00217      */
00218     state.closePlotFile();
00219     state.stop();
00220     robotControl.setEnable(false);
00221 
00222     /**
00223     * Fast PWM sample for the end.
00224     */
00225     while(1) {
00226         for (float f = 0.1f; f < 6.3f; f += 0.1f) {
00227             for(int i = 0; i <= 3; i  ++) {
00228                 led[i] = state.dim( i, f );
00229             }
00230             wait_ms(5);
00231         }
00232         wait(0.1);
00233         for (float f = 0.1f; f < 6.3f; f += 0.1f) {
00234             for(int i = 0; i <= 3; i  ++) {
00235                 led[i] = state.dim( 3-i, f );
00236             }
00237             wait_ms(5);
00238         }
00239         wait(0.05);
00240     }
00241 }