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
Fork of autonomous Robot Android by
main.cpp@4:3a97923ff2d4, 2013-03-08 (annotated)
- Committer:
- chrigelburri
- Date:
- Fri Mar 08 09:54:34 2013 +0000
- Revision:
- 4:3a97923ff2d4
- Parent:
- 3:92ba0254af87
- Child:
- 5:48a258f6335e
f?hrt bis zum qr code und dannach vor garage 4;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chrigelburri | 2:d8e1613dc38b | 1 | /** |
chrigelburri | 3:92ba0254af87 | 2 | * @file main.cpp |
chrigelburri | 2:d8e1613dc38b | 3 | * @author Christian Burri |
chrigelburri | 2:d8e1613dc38b | 4 | * |
chrigelburri | 2:d8e1613dc38b | 5 | * @section LICENSE |
chrigelburri | 2:d8e1613dc38b | 6 | * |
chrigelburri | 2:d8e1613dc38b | 7 | * Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe |
chrigelburri | 1:6cd533a712c6 | 8 | * All rights reserved. |
chrigelburri | 2:d8e1613dc38b | 9 | * |
chrigelburri | 2:d8e1613dc38b | 10 | * @section DESCRIPTION |
chrigelburri | 2:d8e1613dc38b | 11 | * |
chrigelburri | 3:92ba0254af87 | 12 | * This Programm is for a autonomous robot for the competition |
chrigelburri | 4:3a97923ff2d4 | 13 | * at the Hochschule Luzern. |
chrigelburri | 3:92ba0254af87 | 14 | * We are one of the 32 teams. In the team #1 is: |
chrigelburri | 4:3a97923ff2d4 | 15 | * - Bauernfeind Julia <B>WI</B> <a href="julia.bauernfeind@stud.hslu.ch">julia.bauernfeind@stud.hslu.ch</a> |
chrigelburri | 4:3a97923ff2d4 | 16 | * - Büttler Pirmin <B>WI</B> <a href="pirmin.buetler@stud.hslu.ch">pirmin.buetler@stud.hslu.ch</a> |
chrigelburri | 4:3a97923ff2d4 | 17 | * - Amberg Reto <B>I</B> <a href="reto.amberg@stud.hslu.ch">reto.amberg@stud.hslu.ch</a> |
chrigelburri | 4:3a97923ff2d4 | 18 | * - Galliker Arno <B>I</B> <a href="arno.galliker@stud.hslu.ch">arno.galliker@stud.hslu.ch</a> |
chrigelburri | 4:3a97923ff2d4 | 19 | * - Amrein Marcel <B>M</B> <a href="marcel.amrein@stud.hslu.ch">marcel.amrein@stud.hslu.ch</a> |
chrigelburri | 4:3a97923ff2d4 | 20 | * - Flühler Ramon <B>M</B> <a href="ramon.fluehler@stud.hslu.ch">ramon.fluehler@stud.hslu.ch</a> |
chrigelburri | 3:92ba0254af87 | 21 | * - Burri Christian <B>ET</B> <a href="christian.burri@stud.hslu.ch">christian.burri@stud.hslu.ch</a> |
chrigelburri | 4:3a97923ff2d4 | 22 | * |
chrigelburri | 4:3a97923ff2d4 | 23 | * The postition control is based on polar coordiantes. |
chrigelburri | 3:92ba0254af87 | 24 | * For more information see here: <a href="http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf">a href="http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf</a> |
chrigelburri | 2:d8e1613dc38b | 25 | * |
chrigelburri | 1:6cd533a712c6 | 26 | */ |
chrigelburri | 1:6cd533a712c6 | 27 | |
chrigelburri | 1:6cd533a712c6 | 28 | #include "mbed.h" |
chrigelburri | 1:6cd533a712c6 | 29 | #include "math.h" |
chrigelburri | 1:6cd533a712c6 | 30 | #include "defines.h" |
chrigelburri | 1:6cd533a712c6 | 31 | #include "State.h" |
chrigelburri | 1:6cd533a712c6 | 32 | #include "HMC5883L.h" |
chrigelburri | 1:6cd533a712c6 | 33 | #include "HMC6352.h" |
chrigelburri | 1:6cd533a712c6 | 34 | #include "RobotControl.h" |
chrigelburri | 1:6cd533a712c6 | 35 | #include "Ping.h" |
chrigelburri | 1:6cd533a712c6 | 36 | #include "PowerControl/EthernetPowerControl.h" |
chrigelburri | 1:6cd533a712c6 | 37 | |
chrigelburri | 1:6cd533a712c6 | 38 | // LiPo Batterie |
chrigelburri | 1:6cd533a712c6 | 39 | AnalogIn battery(p15); // Battery check |
chrigelburri | 1:6cd533a712c6 | 40 | |
chrigelburri | 1:6cd533a712c6 | 41 | // compass |
chrigelburri | 1:6cd533a712c6 | 42 | //HMC5883L compass(p9, p10, PERIOD_COMPASS); // sda, sdl (I2C) |
chrigelburri | 1:6cd533a712c6 | 43 | //HMC6352 compass(p9, p10, PERIOD_COMPASS); // sda, sdl (I2C) |
chrigelburri | 1:6cd533a712c6 | 44 | |
chrigelburri | 1:6cd533a712c6 | 45 | //Hallsensor |
chrigelburri | 1:6cd533a712c6 | 46 | //hall1, hall2, hall3 |
chrigelburri | 1:6cd533a712c6 | 47 | Hallsensor hallLeft(p18, p17, p16); |
chrigelburri | 1:6cd533a712c6 | 48 | //hall1, hall2, hall3 |
chrigelburri | 1:6cd533a712c6 | 49 | Hallsensor hallRight(p27, p28, p29); |
chrigelburri | 1:6cd533a712c6 | 50 | |
chrigelburri | 1:6cd533a712c6 | 51 | // Motors |
chrigelburri | 1:6cd533a712c6 | 52 | //enb, ready, pwm, actualSpeed, Hallsensor object |
chrigelburri | 1:6cd533a712c6 | 53 | MaxonESCON leftMotor(p26, p25, p24, p19, &hallLeft); |
chrigelburri | 1:6cd533a712c6 | 54 | //enb, ready, pwm, actualSpeed, Hallsensor object |
chrigelburri | 1:6cd533a712c6 | 55 | MaxonESCON rightMotor(p23, p22, p21, p20, &hallRight); |
chrigelburri | 1:6cd533a712c6 | 56 | |
chrigelburri | 1:6cd533a712c6 | 57 | // Robot Control |
chrigelburri | 1:6cd533a712c6 | 58 | RobotControl robotControl (&leftMotor, &rightMotor, /*&compass,*/ PERIOD_ROBOTCONTROL); |
chrigelburri | 1:6cd533a712c6 | 59 | |
chrigelburri | 1:6cd533a712c6 | 60 | // Logging & State |
chrigelburri | 1:6cd533a712c6 | 61 | state_t s; // stuct state |
chrigelburri | 1:6cd533a712c6 | 62 | State state(&s, &robotControl, &leftMotor, &rightMotor, /*&compass,*/ &battery, PERIOD_STATE); |
chrigelburri | 1:6cd533a712c6 | 63 | |
chrigelburri | 1:6cd533a712c6 | 64 | // PC USB communications |
chrigelburri | 1:6cd533a712c6 | 65 | Serial pc(USBTX, USBRX); |
chrigelburri | 1:6cd533a712c6 | 66 | |
chrigelburri | 1:6cd533a712c6 | 67 | DigitalOut myled(LED1); |
chrigelburri | 1:6cd533a712c6 | 68 | |
chrigelburri | 1:6cd533a712c6 | 69 | //float magout[3] = {0}; |
chrigelburri | 1:6cd533a712c6 | 70 | |
chrigelburri | 1:6cd533a712c6 | 71 | // LiPo Batterie |
chrigelburri | 1:6cd533a712c6 | 72 | float batterie_voltage; |
chrigelburri | 1:6cd533a712c6 | 73 | |
chrigelburri | 1:6cd533a712c6 | 74 | int main() |
chrigelburri | 1:6cd533a712c6 | 75 | { |
chrigelburri | 1:6cd533a712c6 | 76 | /** Normal mbed power level for this setup is around 690mW |
chrigelburri | 1:6cd533a712c6 | 77 | * assuming 5V used on Vin pin |
chrigelburri | 1:6cd533a712c6 | 78 | * If you don't need networking... |
chrigelburri | 1:6cd533a712c6 | 79 | * Power down Ethernet interface - saves around 175mW |
chrigelburri | 1:6cd533a712c6 | 80 | * Also need to unplug network cable - just a cable sucks power |
chrigelburri | 1:6cd533a712c6 | 81 | */ |
chrigelburri | 1:6cd533a712c6 | 82 | PHY_PowerDown(); |
chrigelburri | 2:d8e1613dc38b | 83 | |
chrigelburri | 2:d8e1613dc38b | 84 | // robotControl.start(); |
chrigelburri | 1:6cd533a712c6 | 85 | // compass.setOpMode(HMC6352_CONTINUOUS, 1, 20); |
chrigelburri | 1:6cd533a712c6 | 86 | // compass.start(); |
chrigelburri | 4:3a97923ff2d4 | 87 | |
chrigelburri | 2:d8e1613dc38b | 88 | state.initPlotFile(); |
chrigelburri | 2:d8e1613dc38b | 89 | |
chrigelburri | 1:6cd533a712c6 | 90 | robotControl.start(); |
chrigelburri | 1:6cd533a712c6 | 91 | robotControl.setEnable(false); |
chrigelburri | 1:6cd533a712c6 | 92 | wait(0.01); |
chrigelburri | 1:6cd533a712c6 | 93 | robotControl.setEnable(true); |
chrigelburri | 1:6cd533a712c6 | 94 | wait(0.01); |
chrigelburri | 4:3a97923ff2d4 | 95 | robotControl.setAllToZero(START_X_OFFSET, START_Y_OFFSET, PI/2 ); |
chrigelburri | 2:d8e1613dc38b | 96 | |
chrigelburri | 1:6cd533a712c6 | 97 | leftMotor.setPulses(0); |
chrigelburri | 1:6cd533a712c6 | 98 | rightMotor.setPulses(0); |
chrigelburri | 2:d8e1613dc38b | 99 | |
chrigelburri | 2:d8e1613dc38b | 100 | state.startTimerFromZero(); |
chrigelburri | 1:6cd533a712c6 | 101 | state.start(); |
chrigelburri | 2:d8e1613dc38b | 102 | |
chrigelburri | 4:3a97923ff2d4 | 103 | robotControl.setPositionAngle(-1.20f, 1.50f, 3*PI/4); |
chrigelburri | 4:3a97923ff2d4 | 104 | while(!(robotControl.getDistanceError() <= 0.4)) { |
chrigelburri | 1:6cd533a712c6 | 105 | state.savePlotFile(s); |
chrigelburri | 1:6cd533a712c6 | 106 | }; |
chrigelburri | 2:d8e1613dc38b | 107 | |
chrigelburri | 4:3a97923ff2d4 | 108 | robotControl.setPositionAngle(-1.20f, 2.6f, PI/4); |
chrigelburri | 4:3a97923ff2d4 | 109 | while(!(robotControl.getDistanceError() <= 0.4)) { |
chrigelburri | 4:3a97923ff2d4 | 110 | state.savePlotFile(s); |
chrigelburri | 4:3a97923ff2d4 | 111 | }; |
chrigelburri | 4:3a97923ff2d4 | 112 | |
chrigelburri | 4:3a97923ff2d4 | 113 | robotControl.setPositionAngle(-0.45f, 3.4f, PI/2); |
chrigelburri | 4:3a97923ff2d4 | 114 | while(!(robotControl.getDistanceError() <= 0.4)) { |
chrigelburri | 1:6cd533a712c6 | 115 | state.savePlotFile(s); |
chrigelburri | 2:d8e1613dc38b | 116 | }; |
chrigelburri | 2:d8e1613dc38b | 117 | |
chrigelburri | 4:3a97923ff2d4 | 118 | robotControl.setPositionAngle(-1.0f, 3.6f, PI); |
chrigelburri | 4:3a97923ff2d4 | 119 | while(!(robotControl.getDistanceError() <= 0.4)) { |
chrigelburri | 2:d8e1613dc38b | 120 | state.savePlotFile(s); |
chrigelburri | 1:6cd533a712c6 | 121 | }; |
chrigelburri | 2:d8e1613dc38b | 122 | |
chrigelburri | 4:3a97923ff2d4 | 123 | robotControl.setPositionAngle(-1.5f, 3.9f, PI); |
chrigelburri | 4:3a97923ff2d4 | 124 | while(!(robotControl.getDistanceError() <= 0.03)) { |
chrigelburri | 2:d8e1613dc38b | 125 | state.savePlotFile(s); |
chrigelburri | 2:d8e1613dc38b | 126 | }; |
chrigelburri | 4:3a97923ff2d4 | 127 | |
chrigelburri | 4:3a97923ff2d4 | 128 | robotControl.setPositionAngle(-2.5f, 3.0f, -PI/2); |
chrigelburri | 4:3a97923ff2d4 | 129 | while(!(robotControl.getDistanceError() <= 0.4)) { |
chrigelburri | 4:3a97923ff2d4 | 130 | state.savePlotFile(s); |
chrigelburri | 4:3a97923ff2d4 | 131 | }; |
chrigelburri | 4:3a97923ff2d4 | 132 | |
chrigelburri | 4:3a97923ff2d4 | 133 | robotControl.setPositionAngle(-1.75f, 1.30f, -PI/2); |
chrigelburri | 4:3a97923ff2d4 | 134 | while(!(robotControl.getDistanceError() <= 0.04)) { |
chrigelburri | 4:3a97923ff2d4 | 135 | state.savePlotFile(s); |
chrigelburri | 4:3a97923ff2d4 | 136 | }; |
chrigelburri | 4:3a97923ff2d4 | 137 | |
chrigelburri | 2:d8e1613dc38b | 138 | |
chrigelburri | 2:d8e1613dc38b | 139 | state.savePlotFile(s); |
chrigelburri | 1:6cd533a712c6 | 140 | state.closePlotFile(); |
chrigelburri | 1:6cd533a712c6 | 141 | state.stop(); |
chrigelburri | 1:6cd533a712c6 | 142 | robotControl.setEnable(false); |
chrigelburri | 1:6cd533a712c6 | 143 | } |