mmm

Dependencies:   mbed StrategieLib BrasLib AnalyseDistanceLib BrasPousserLib EcranLib PompeLib DemarreurLib Asservissment_robot2_v16_05 AnalyseArcLib

Committer:
JimmyAREM
Date:
Mon May 20 23:26:02 2019 +0000
Revision:
0:712c30640b31
Child:
5:10193f156c3f
maj du feu

Who changed what in which revision?

UserRevisionLine numberNew 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 0:712c30640b31 7 * @brief Implementation file to communicate with the screen
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 0:712c30640b31 30
JimmyAREM 0:712c30640b31 31
JimmyAREM 0:712c30640b31 32 /* Global Variables ---------------------------------------------------------*/
JimmyAREM 0:712c30640b31 33
JimmyAREM 0:712c30640b31 34 //I2CSlave i2c(PIN_SDA, PIN_SCL);
JimmyAREM 0:712c30640b31 35 extern Serial serial;
JimmyAREM 0:712c30640b31 36 Serial capteursUART(A0,A1,2000000);
JimmyAREM 0:712c30640b31 37 //Ticker lectureI2C;
JimmyAREM 0:712c30640b31 38 extern event_callback_t afficherEcranCallback;
JimmyAREM 0:712c30640b31 39 event_callback_t afficherCapteursCallback;
JimmyAREM 0:712c30640b31 40
JimmyAREM 0:712c30640b31 41 bool newOrder = false;
JimmyAREM 0:712c30640b31 42 bool detectionUltrasons = false;
JimmyAREM 0:712c30640b31 43
JimmyAREM 0:712c30640b31 44 /* Public Functions ------------------------------------------------------------------*/
JimmyAREM 0:712c30640b31 45
JimmyAREM 0:712c30640b31 46 //void afficherI2C();
JimmyAREM 0:712c30640b31 47 void recupererCapteurs(int events);
JimmyAREM 0:712c30640b31 48
JimmyAREM 0:712c30640b31 49 /* Main ------------------------------------------------------------------*/
JimmyAREM 0:712c30640b31 50
JimmyAREM 0:712c30640b31 51 int main()
JimmyAREM 0:712c30640b31 52 {
JimmyAREM 0:712c30640b31 53 Pompe pompe(PIN_POMPE);
JimmyAREM 0:712c30640b31 54 Demarreur demarreur(PIN_DEMARREUR);
JimmyAREM 0:712c30640b31 55 Bras brasGauche(PIN_SERVO_BRAS_GAUCHE, GAUCHE);
JimmyAREM 0:712c30640b31 56 Bras brasDroit(PIN_SERVO_BRAS_DROIT, DROIT);
JimmyAREM 0:712c30640b31 57 BrasPousser brasPousserGauche(PIN_SERVO_PALETS_GAUCHE, GAUCHE);
JimmyAREM 0:712c30640b31 58 BrasPousser brasPousserDroit(PIN_SERVO_PALETS_DROIT,DROIT);
JimmyAREM 0:712c30640b31 59 deplacement robot;
JimmyAREM 0:712c30640b31 60
JimmyAREM 0:712c30640b31 61 robot.initialisation();
JimmyAREM 0:712c30640b31 62
JimmyAREM 0:712c30640b31 63 AnalogIn Ain(A5);
JimmyAREM 0:712c30640b31 64 if(Ain.read() < 0.68f)
JimmyAREM 0:712c30640b31 65 {
JimmyAREM 0:712c30640b31 66 return 0;
JimmyAREM 0:712c30640b31 67 }
JimmyAREM 0:712c30640b31 68
JimmyAREM 0:712c30640b31 69 //pc.printf("SystemCoreClock is %d Hz\r\n", SystemCoreClock);
JimmyAREM 0:712c30640b31 70
JimmyAREM 0:712c30640b31 71 afficherEcranCallback.attach(afficherEcran);
JimmyAREM 0:712c30640b31 72 afficherCapteursCallback.attach(recupererCapteurs);
JimmyAREM 0:712c30640b31 73
JimmyAREM 0:712c30640b31 74 serial.read((uint8_t*)buffer, TAILLE, afficherEcranCallback, SERIAL_EVENT_RX_COMPLETE);
JimmyAREM 0:712c30640b31 75 capteursUART.read((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, afficherCapteursCallback, SERIAL_EVENT_RX_COMPLETE);
JimmyAREM 0:712c30640b31 76
JimmyAREM 0:712c30640b31 77 setEmplacementDepartViolet();
JimmyAREM 0:712c30640b31 78 init_odometrie();
JimmyAREM 0:712c30640b31 79 wait(10);
JimmyAREM 0:712c30640b31 80 robot.va_au_point(200000,30000,0.0);
JimmyAREM 0:712c30640b31 81
JimmyAREM 0:712c30640b31 82 while(1)
JimmyAREM 0:712c30640b31 83 {
JimmyAREM 0:712c30640b31 84 if(detectionUltrasons)
JimmyAREM 0:712c30640b31 85 {
JimmyAREM 0:712c30640b31 86 detectionUltrasons = false;
JimmyAREM 0:712c30640b31 87 writeCapteurs();
JimmyAREM 0:712c30640b31 88 //LectureI2CCarteCapteur(robot);
JimmyAREM 0:712c30640b31 89 }
JimmyAREM 0:712c30640b31 90 if(newOrder)
JimmyAREM 0:712c30640b31 91 {
JimmyAREM 0:712c30640b31 92 newOrder = false;
JimmyAREM 0:712c30640b31 93 executeOrderInit(robot, pompe, demarreur, brasGauche, brasDroit, brasPousserGauche, brasPousserDroit);
JimmyAREM 0:712c30640b31 94 }
JimmyAREM 0:712c30640b31 95 }
JimmyAREM 0:712c30640b31 96 return 0;
JimmyAREM 0:712c30640b31 97 }
JimmyAREM 0:712c30640b31 98
JimmyAREM 0:712c30640b31 99
JimmyAREM 0:712c30640b31 100 void recupererCapteurs(int events)
JimmyAREM 0:712c30640b31 101 {
JimmyAREM 0:712c30640b31 102 //pc.write((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, NULL);
JimmyAREM 0:712c30640b31 103 detectionUltrasons = true;
JimmyAREM 0:712c30640b31 104 capteursUART.read((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, afficherCapteursCallback, SERIAL_EVENT_RX_COMPLETE);
JimmyAREM 0:712c30640b31 105
JimmyAREM 0:712c30640b31 106 }
JimmyAREM 0:712c30640b31 107 /*
JimmyAREM 0:712c30640b31 108 void afficherI2C()
JimmyAREM 0:712c30640b31 109 {
JimmyAREM 0:712c30640b31 110 //On coupe la lecture écran lorsqu'on lit l'I2C pour éviter les conflits avec le ticker (on le coupe aussi)
JimmyAREM 0:712c30640b31 111 serial.abort_read();
JimmyAREM 0:712c30640b31 112 lectureI2C.detach();
JimmyAREM 0:712c30640b31 113
JimmyAREM 0:712c30640b31 114 i2c.read((char*)bufferCapteurs, TAILLEBUFFERCAPTEURS);
JimmyAREM 0:712c30640b31 115 pc.printf("%s\n", bufferCapteurs);
JimmyAREM 0:712c30640b31 116
JimmyAREM 0:712c30640b31 117 //On renvoit ce qui est lu vers l'écran par liaison série
JimmyAREM 0:712c30640b31 118 writeCapteurs();
JimmyAREM 0:712c30640b31 119
JimmyAREM 0:712c30640b31 120 //On réactive le ticker et la lecture des ordres de l'écran
JimmyAREM 0:712c30640b31 121 serial.read((uint8_t*)buffer, TAILLE, afficherEcranCallback, SERIAL_EVENT_RX_COMPLETE);
JimmyAREM 0:712c30640b31 122 lectureI2C.attach(&afficherI2C, 0.02);
JimmyAREM 0:712c30640b31 123 }
JimmyAREM 0:712c30640b31 124
JimmyAREM 0:712c30640b31 125 //main
JimmyAREM 0:712c30640b31 126
JimmyAREM 0:712c30640b31 127 //i2c.address(0x90);
JimmyAREM 0:712c30640b31 128 //i2c.read((char*)bufferCapteurs, TAILLEBUFFERCAPTEURS);*/
JimmyAREM 0:712c30640b31 129 //Réception des ordres écran : on attache la fonction afficherEcran qui est appelée lorsque le buffer de 11 est plein
JimmyAREM 0:712c30640b31 130
JimmyAREM 0:712c30640b31 131 //Première initialisation du ticker
JimmyAREM 0:712c30640b31 132 //lectureI2C.attach(&afficherI2C, 0.02);
JimmyAREM 0:712c30640b31 133
JimmyAREM 0:712c30640b31 134