![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mmm
Dependencies: mbed StrategieLib BrasLib AnalyseDistanceLib BrasPousserLib EcranLib PompeLib DemarreurLib Asservissment_robot2_v16_05 AnalyseArcLib
main.cpp@7:cf7f06f57d40, 2019-05-29 (annotated)
- Committer:
- GuillaumeCH
- Date:
- Wed May 29 06:37:40 2019 +0000
- Revision:
- 7:cf7f06f57d40
- Parent:
- 6:4f7f2d8a7cf8
mmmm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimmyAREM | 0:712c30640b31 | 1 | /** |
JimmyAREM | 0:712c30640b31 | 2 | **************************************************************************** |
JimmyAREM | 0:712c30640b31 | 3 | * @file main.cpp |
JimmyAREM | 0:712c30640b31 | 4 | * @author Jimmy MAINGAM |
JimmyAREM | 0:712c30640b31 | 5 | * @version V0.0.1 |
JimmyAREM | 0:712c30640b31 | 6 | * @date 20/03/2019 |
JimmyAREM | 5:10193f156c3f | 7 | * @brief Implementation file main |
JimmyAREM | 0:712c30640b31 | 8 | **************************************************************************** |
JimmyAREM | 0:712c30640b31 | 9 | *This software has been developed to be used in AREM's robot for the cdfr 2019 |
JimmyAREM | 0:712c30640b31 | 10 | **/ |
JimmyAREM | 0:712c30640b31 | 11 | |
JimmyAREM | 0:712c30640b31 | 12 | /* Includes ------------------------------------------------------------------*/ |
JimmyAREM | 0:712c30640b31 | 13 | |
JimmyAREM | 0:712c30640b31 | 14 | #include "mbed.h" |
JimmyAREM | 0:712c30640b31 | 15 | #include "pinMap.hpp" |
JimmyAREM | 0:712c30640b31 | 16 | |
JimmyAREM | 0:712c30640b31 | 17 | #include "hardware.h" |
JimmyAREM | 0:712c30640b31 | 18 | #include "odometrie.h" |
JimmyAREM | 0:712c30640b31 | 19 | #include "reglages.h" |
JimmyAREM | 0:712c30640b31 | 20 | #include "deplacement.h" |
JimmyAREM | 0:712c30640b31 | 21 | |
JimmyAREM | 0:712c30640b31 | 22 | #include "BrasPousser.h" |
JimmyAREM | 0:712c30640b31 | 23 | #include "Bras.h" |
JimmyAREM | 0:712c30640b31 | 24 | #include "Pompe.h" |
JimmyAREM | 0:712c30640b31 | 25 | #include "demarreur.h" |
JimmyAREM | 0:712c30640b31 | 26 | #include "Ecran.h" |
JimmyAREM | 0:712c30640b31 | 27 | |
JimmyAREM | 0:712c30640b31 | 28 | #include "Strategie.h" |
JimmyAREM | 0:712c30640b31 | 29 | #include "AnalyseDistance.h" |
JimmyAREM | 5:10193f156c3f | 30 | #include "AnalyseArcLib.h" |
JimmyAREM | 0:712c30640b31 | 31 | |
JimmyAREM | 0:712c30640b31 | 32 | |
JimmyAREM | 0:712c30640b31 | 33 | /* Global Variables ---------------------------------------------------------*/ |
JimmyAREM | 0:712c30640b31 | 34 | |
JimmyAREM | 0:712c30640b31 | 35 | //I2CSlave i2c(PIN_SDA, PIN_SCL); |
JimmyAREM | 0:712c30640b31 | 36 | extern Serial serial; |
JimmyAREM | 5:10193f156c3f | 37 | extern bool typeEvitement; |
JimmyAREM | 0:712c30640b31 | 38 | Serial capteursUART(A0,A1,2000000); |
JimmyAREM | 0:712c30640b31 | 39 | //Ticker lectureI2C; |
JimmyAREM | 0:712c30640b31 | 40 | extern event_callback_t afficherEcranCallback; |
JimmyAREM | 0:712c30640b31 | 41 | event_callback_t afficherCapteursCallback; |
JimmyAREM | 0:712c30640b31 | 42 | |
JimmyAREM | 0:712c30640b31 | 43 | bool newOrder = false; |
JimmyAREM | 0:712c30640b31 | 44 | bool detectionUltrasons = false; |
JimmyAREM | 0:712c30640b31 | 45 | |
JimmyAREM | 0:712c30640b31 | 46 | /* Public Functions ------------------------------------------------------------------*/ |
JimmyAREM | 0:712c30640b31 | 47 | |
JimmyAREM | 0:712c30640b31 | 48 | //void afficherI2C(); |
JimmyAREM | 0:712c30640b31 | 49 | void recupererCapteurs(int events); |
JimmyAREM | 0:712c30640b31 | 50 | |
JimmyAREM | 5:10193f156c3f | 51 | /* Main -----------------------------------------------------------------------------*/ |
JimmyAREM | 0:712c30640b31 | 52 | |
JimmyAREM | 0:712c30640b31 | 53 | int main() |
JimmyAREM | 0:712c30640b31 | 54 | { |
JimmyAREM | 0:712c30640b31 | 55 | Pompe pompe(PIN_POMPE); |
JimmyAREM | 0:712c30640b31 | 56 | Demarreur demarreur(PIN_DEMARREUR); |
JimmyAREM | 0:712c30640b31 | 57 | Bras brasGauche(PIN_SERVO_BRAS_GAUCHE, GAUCHE); |
JimmyAREM | 0:712c30640b31 | 58 | Bras brasDroit(PIN_SERVO_BRAS_DROIT, DROIT); |
JimmyAREM | 0:712c30640b31 | 59 | BrasPousser brasPousserGauche(PIN_SERVO_PALETS_GAUCHE, GAUCHE); |
JimmyAREM | 0:712c30640b31 | 60 | BrasPousser brasPousserDroit(PIN_SERVO_PALETS_DROIT,DROIT); |
JimmyAREM | 0:712c30640b31 | 61 | deplacement robot; |
JimmyAREM | 0:712c30640b31 | 62 | |
JimmyAREM | 0:712c30640b31 | 63 | robot.initialisation(); |
JimmyAREM | 0:712c30640b31 | 64 | |
JimmyAREM | 0:712c30640b31 | 65 | AnalogIn Ain(A5); |
JimmyAREM | 0:712c30640b31 | 66 | if(Ain.read() < 0.68f) |
JimmyAREM | 0:712c30640b31 | 67 | { |
JimmyAREM | 0:712c30640b31 | 68 | return 0; |
JimmyAREM | 0:712c30640b31 | 69 | } |
JimmyAREM | 0:712c30640b31 | 70 | |
JimmyAREM | 6:4f7f2d8a7cf8 | 71 | pc.printf("SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
JimmyAREM | 0:712c30640b31 | 72 | |
JimmyAREM | 0:712c30640b31 | 73 | afficherEcranCallback.attach(afficherEcran); |
JimmyAREM | 0:712c30640b31 | 74 | afficherCapteursCallback.attach(recupererCapteurs); |
JimmyAREM | 0:712c30640b31 | 75 | |
JimmyAREM | 0:712c30640b31 | 76 | serial.read((uint8_t*)buffer, TAILLE, afficherEcranCallback, SERIAL_EVENT_RX_COMPLETE); |
JimmyAREM | 0:712c30640b31 | 77 | capteursUART.read((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, afficherCapteursCallback, SERIAL_EVENT_RX_COMPLETE); |
JimmyAREM | 0:712c30640b31 | 78 | |
JimmyAREM | 6:4f7f2d8a7cf8 | 79 | /*setEmplacementTest(); |
JimmyAREM | 0:712c30640b31 | 80 | init_odometrie(); |
JimmyAREM | 5:10193f156c3f | 81 | typeEvitement = ARC; |
JimmyAREM | 0:712c30640b31 | 82 | wait(10); |
JimmyAREM | 6:4f7f2d8a7cf8 | 83 | robot.va_au_point(100000,30000,0.0);*/ |
JimmyAREM | 0:712c30640b31 | 84 | while(1) |
JimmyAREM | 0:712c30640b31 | 85 | { |
JimmyAREM | 0:712c30640b31 | 86 | if(detectionUltrasons) |
JimmyAREM | 0:712c30640b31 | 87 | { |
JimmyAREM | 0:712c30640b31 | 88 | detectionUltrasons = false; |
JimmyAREM | 0:712c30640b31 | 89 | writeCapteurs(); |
JimmyAREM | 0:712c30640b31 | 90 | //LectureI2CCarteCapteur(robot); |
JimmyAREM | 0:712c30640b31 | 91 | } |
JimmyAREM | 0:712c30640b31 | 92 | if(newOrder) |
JimmyAREM | 0:712c30640b31 | 93 | { |
JimmyAREM | 0:712c30640b31 | 94 | newOrder = false; |
JimmyAREM | 0:712c30640b31 | 95 | executeOrderInit(robot, pompe, demarreur, brasGauche, brasDroit, brasPousserGauche, brasPousserDroit); |
JimmyAREM | 0:712c30640b31 | 96 | } |
JimmyAREM | 0:712c30640b31 | 97 | } |
JimmyAREM | 0:712c30640b31 | 98 | return 0; |
JimmyAREM | 0:712c30640b31 | 99 | } |
JimmyAREM | 0:712c30640b31 | 100 | |
JimmyAREM | 0:712c30640b31 | 101 | |
JimmyAREM | 0:712c30640b31 | 102 | void recupererCapteurs(int events) |
JimmyAREM | 0:712c30640b31 | 103 | { |
JimmyAREM | 0:712c30640b31 | 104 | //pc.write((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, NULL); |
JimmyAREM | 0:712c30640b31 | 105 | detectionUltrasons = true; |
JimmyAREM | 0:712c30640b31 | 106 | capteursUART.read((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, afficherCapteursCallback, SERIAL_EVENT_RX_COMPLETE); |
JimmyAREM | 0:712c30640b31 | 107 | |
JimmyAREM | 0:712c30640b31 | 108 | } |
JimmyAREM | 0:712c30640b31 | 109 | /* |
JimmyAREM | 0:712c30640b31 | 110 | void afficherI2C() |
JimmyAREM | 0:712c30640b31 | 111 | { |
JimmyAREM | 0:712c30640b31 | 112 | //On coupe la lecture écran lorsqu'on lit l'I2C pour éviter les conflits avec le ticker (on le coupe aussi) |
JimmyAREM | 0:712c30640b31 | 113 | serial.abort_read(); |
JimmyAREM | 0:712c30640b31 | 114 | lectureI2C.detach(); |
JimmyAREM | 0:712c30640b31 | 115 | |
JimmyAREM | 0:712c30640b31 | 116 | i2c.read((char*)bufferCapteurs, TAILLEBUFFERCAPTEURS); |
JimmyAREM | 0:712c30640b31 | 117 | pc.printf("%s\n", bufferCapteurs); |
JimmyAREM | 0:712c30640b31 | 118 | |
JimmyAREM | 0:712c30640b31 | 119 | //On renvoit ce qui est lu vers l'écran par liaison série |
JimmyAREM | 0:712c30640b31 | 120 | writeCapteurs(); |
JimmyAREM | 0:712c30640b31 | 121 | |
JimmyAREM | 0:712c30640b31 | 122 | //On réactive le ticker et la lecture des ordres de l'écran |
JimmyAREM | 0:712c30640b31 | 123 | serial.read((uint8_t*)buffer, TAILLE, afficherEcranCallback, SERIAL_EVENT_RX_COMPLETE); |
JimmyAREM | 0:712c30640b31 | 124 | lectureI2C.attach(&afficherI2C, 0.02); |
JimmyAREM | 0:712c30640b31 | 125 | } |
JimmyAREM | 0:712c30640b31 | 126 | |
JimmyAREM | 0:712c30640b31 | 127 | //main |
JimmyAREM | 0:712c30640b31 | 128 | |
JimmyAREM | 0:712c30640b31 | 129 | //i2c.address(0x90); |
JimmyAREM | 0:712c30640b31 | 130 | //i2c.read((char*)bufferCapteurs, TAILLEBUFFERCAPTEURS);*/ |
JimmyAREM | 0:712c30640b31 | 131 | //Réception des ordres écran : on attache la fonction afficherEcran qui est appelée lorsque le buffer de 11 est plein |
JimmyAREM | 0:712c30640b31 | 132 | |
JimmyAREM | 0:712c30640b31 | 133 | //Première initialisation du ticker |
JimmyAREM | 0:712c30640b31 | 134 | //lectureI2C.attach(&afficherI2C, 0.02); |
JimmyAREM | 0:712c30640b31 | 135 | |
JimmyAREM | 0:712c30640b31 | 136 |