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.
Dependencies: mbed StrategieLib BrasLib AnalyseDistanceLib BrasPousserLib EcranLib PompeLib DemarreurLib Asservissment_robot2_v16_05 AnalyseArcLib
main.cpp
00001 /** 00002 **************************************************************************** 00003 * @file main.cpp 00004 * @author Jimmy MAINGAM 00005 * @version V0.0.1 00006 * @date 20/03/2019 00007 * @brief Implementation file main 00008 **************************************************************************** 00009 *This software has been developed to be used in AREM's robot for the cdfr 2019 00010 **/ 00011 00012 /* Includes ------------------------------------------------------------------*/ 00013 00014 #include "mbed.h" 00015 #include "pinMap.hpp" 00016 00017 #include "hardware.h" 00018 #include "odometrie.h" 00019 #include "reglages.h" 00020 #include "deplacement.h" 00021 00022 #include "BrasPousser.h" 00023 #include "Bras.h" 00024 #include "Pompe.h" 00025 #include "demarreur.h" 00026 #include "Ecran.h" 00027 00028 #include "Strategie.h" 00029 #include "AnalyseDistance.h" 00030 #include "AnalyseArcLib.h" 00031 00032 00033 /* Global Variables ---------------------------------------------------------*/ 00034 00035 //debug 00036 extern BrasPousser brasPousserGauche; 00037 extern BrasPousser brasPousserDroit; 00038 extern Pompe pompe; 00039 00040 //I2CSlave i2c(PIN_SDA, PIN_SCL); 00041 extern Serial serial; 00042 extern int typeEvitement; 00043 Serial capteursUART(A0,A1,2000000); 00044 //Ticker lectureI2C; 00045 extern event_callback_t afficherEcranCallback; 00046 event_callback_t afficherCapteursCallback; 00047 00048 bool newOrder = false; 00049 bool detectionUltrasons = false; 00050 00051 /* Public Functions ------------------------------------------------------------------*/ 00052 00053 //void afficherI2C(); 00054 void recupererCapteurs(int events); 00055 00056 /* Main -----------------------------------------------------------------------------*/ 00057 00058 int main() 00059 { 00060 Pompe pompe(PIN_POMPE); 00061 Demarreur demarreur(PIN_DEMARREUR); 00062 Bras brasGauche(PIN_SERVO_BRAS_GAUCHE, GAUCHE); 00063 Bras brasDroit(PIN_SERVO_BRAS_DROIT, DROIT); 00064 BrasPousser brasPousserGauche(PIN_SERVO_PALETS_GAUCHE, GAUCHE); 00065 BrasPousser brasPousserDroit(PIN_SERVO_PALETS_DROIT,DROIT); 00066 deplacement robot; 00067 00068 robot.initialisation(); 00069 00070 /*AnalogIn Ain(A5); 00071 if(Ain.read() < 0.68f) 00072 { 00073 return 0; 00074 }*/ 00075 00076 pc.printf("SystemCoreClock is %d Hz\r\n", SystemCoreClock); 00077 00078 afficherEcranCallback.attach(afficherEcran); 00079 afficherCapteursCallback.attach(recupererCapteurs); 00080 00081 serial.read((uint8_t*)buffer, TAILLE, afficherEcranCallback, SERIAL_EVENT_RX_COMPLETE); 00082 capteursUART.read((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, afficherCapteursCallback, SERIAL_EVENT_RX_COMPLETE); 00083 //pompe.activer(); 00084 /*setEmplacementTest(); 00085 init_odometrie(); 00086 typeEvitement = RECTANGLE; 00087 wait(2); 00088 robot.va_au_point(130000,30000,0);*/ 00089 //robot.pente_combo(0, brasPousserGauche,brasPousserDroit, pompe); 00090 while(1) 00091 { 00092 if(detectionUltrasons) 00093 { 00094 detectionUltrasons = false; 00095 writeCapteurs(); 00096 //LectureI2CCarteCapteur(robot); 00097 } 00098 if(newOrder) 00099 { 00100 newOrder = false; 00101 executeOrderInit(robot, pompe, demarreur, brasGauche, brasDroit, brasPousserGauche, brasPousserDroit); 00102 } 00103 } 00104 return 0; 00105 } 00106 00107 00108 void recupererCapteurs(int events) 00109 { 00110 //pc.write((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, NULL); 00111 detectionUltrasons = true; 00112 capteursUART.read((uint8_t*)bufferCapteurs, TAILLEBUFFERCAPTEURS, afficherCapteursCallback, SERIAL_EVENT_RX_COMPLETE); 00113 00114 } 00115 /* 00116 void afficherI2C() 00117 { 00118 //On coupe la lecture écran lorsqu'on lit l'I2C pour éviter les conflits avec le ticker (on le coupe aussi) 00119 serial.abort_read(); 00120 lectureI2C.detach(); 00121 00122 i2c.read((char*)bufferCapteurs, TAILLEBUFFERCAPTEURS); 00123 pc.printf("%s\n", bufferCapteurs); 00124 00125 //On renvoit ce qui est lu vers l'écran par liaison série 00126 writeCapteurs(); 00127 00128 //On réactive le ticker et la lecture des ordres de l'écran 00129 serial.read((uint8_t*)buffer, TAILLE, afficherEcranCallback, SERIAL_EVENT_RX_COMPLETE); 00130 lectureI2C.attach(&afficherI2C, 0.02); 00131 } 00132 00133 //main 00134 00135 //i2c.address(0x90); 00136 //i2c.read((char*)bufferCapteurs, TAILLEBUFFERCAPTEURS);*/ 00137 //Réception des ordres écran : on attache la fonction afficherEcran qui est appelée lorsque le buffer de 11 est plein 00138 00139 //Première initialisation du ticker 00140 //lectureI2C.attach(&afficherI2C, 0.02); 00141 00142
Generated on Sat Aug 13 2022 17:42:11 by
1.7.2