Pour Marc la mignonne
Dependencies: BSP_DISCO_F429ZI LCD_DISCO_F429ZI TS_DISCO_F429ZI mbed
automatique.cpp@0:fcce18d01987, 2018-05-31 (annotated)
- Committer:
- Alex_mln
- Date:
- Thu May 31 06:11:25 2018 +0000
- Revision:
- 0:fcce18d01987
Tiens pd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Alex_mln | 0:fcce18d01987 | 1 | #include "mbed.h" |
Alex_mln | 0:fcce18d01987 | 2 | #include "LCD_DISCO_F429ZI.h" |
Alex_mln | 0:fcce18d01987 | 3 | #include "commandes.h" |
Alex_mln | 0:fcce18d01987 | 4 | #include "TS_DISCO_F429ZI.h" |
Alex_mln | 0:fcce18d01987 | 5 | #include <stdlib.h> |
Alex_mln | 0:fcce18d01987 | 6 | #include "screen.h" |
Alex_mln | 0:fcce18d01987 | 7 | #include "automatique.h" |
Alex_mln | 0:fcce18d01987 | 8 | #include "Capteurs.h" |
Alex_mln | 0:fcce18d01987 | 9 | |
Alex_mln | 0:fcce18d01987 | 10 | //typedef int tab[3]; |
Alex_mln | 0:fcce18d01987 | 11 | int capteur1,capteur2,capteur3; //gauche, centre, droit |
Alex_mln | 0:fcce18d01987 | 12 | //tab ligne; |
Alex_mln | 0:fcce18d01987 | 13 | float delai=1.0; |
Alex_mln | 0:fcce18d01987 | 14 | |
Alex_mln | 0:fcce18d01987 | 15 | |
Alex_mln | 0:fcce18d01987 | 16 | LCD_DISCO_F429ZI lcda; |
Alex_mln | 0:fcce18d01987 | 17 | TS_DISCO_F429ZI tsa; |
Alex_mln | 0:fcce18d01987 | 18 | TS_StateTypeDef tsStatea; |
Alex_mln | 0:fcce18d01987 | 19 | uint16_t xa, ya; |
Alex_mln | 0:fcce18d01987 | 20 | |
Alex_mln | 0:fcce18d01987 | 21 | |
Alex_mln | 0:fcce18d01987 | 22 | |
Alex_mln | 0:fcce18d01987 | 23 | void detectiona(){ |
Alex_mln | 0:fcce18d01987 | 24 | xa = tsStatea.X; |
Alex_mln | 0:fcce18d01987 | 25 | ya = tsStatea.Y; |
Alex_mln | 0:fcce18d01987 | 26 | int8_t text[7]; |
Alex_mln | 0:fcce18d01987 | 27 | sprintf((char*)text, "%d; %d", xa, ya); |
Alex_mln | 0:fcce18d01987 | 28 | lcda.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); |
Alex_mln | 0:fcce18d01987 | 29 | } |
Alex_mln | 0:fcce18d01987 | 30 | |
Alex_mln | 0:fcce18d01987 | 31 | |
Alex_mln | 0:fcce18d01987 | 32 | void traitement(){ |
Alex_mln | 0:fcce18d01987 | 33 | if(capteur1==0 && capteur2==1 && capteur3==0){ |
Alex_mln | 0:fcce18d01987 | 34 | avancer(); |
Alex_mln | 0:fcce18d01987 | 35 | wait(delai); |
Alex_mln | 0:fcce18d01987 | 36 | } |
Alex_mln | 0:fcce18d01987 | 37 | else if(capteur1==1 && capteur2==0 && capteur3==0){ |
Alex_mln | 0:fcce18d01987 | 38 | tournerDroitVite(); |
Alex_mln | 0:fcce18d01987 | 39 | wait(delai); |
Alex_mln | 0:fcce18d01987 | 40 | } |
Alex_mln | 0:fcce18d01987 | 41 | else if(capteur1==1 && capteur2==1 && capteur3==0){ |
Alex_mln | 0:fcce18d01987 | 42 | tourner_droite(); |
Alex_mln | 0:fcce18d01987 | 43 | wait(delai); |
Alex_mln | 0:fcce18d01987 | 44 | } |
Alex_mln | 0:fcce18d01987 | 45 | else if(capteur1==0 && capteur2==0 && capteur3==1){ |
Alex_mln | 0:fcce18d01987 | 46 | tournerGaucheVite(); |
Alex_mln | 0:fcce18d01987 | 47 | wait(delai); |
Alex_mln | 0:fcce18d01987 | 48 | } |
Alex_mln | 0:fcce18d01987 | 49 | else if(capteur1==0 && capteur2==1 && capteur3==1){ |
Alex_mln | 0:fcce18d01987 | 50 | tourner_gauche(); |
Alex_mln | 0:fcce18d01987 | 51 | wait(delai); |
Alex_mln | 0:fcce18d01987 | 52 | } |
Alex_mln | 0:fcce18d01987 | 53 | else if(capteur1==1 && capteur2==1 && capteur3==1){ |
Alex_mln | 0:fcce18d01987 | 54 | arreter(); |
Alex_mln | 0:fcce18d01987 | 55 | wait(delai); |
Alex_mln | 0:fcce18d01987 | 56 | } |
Alex_mln | 0:fcce18d01987 | 57 | } |
Alex_mln | 0:fcce18d01987 | 58 | |
Alex_mln | 0:fcce18d01987 | 59 | void go_automatique(){ |
Alex_mln | 0:fcce18d01987 | 60 | |
Alex_mln | 0:fcce18d01987 | 61 | uint8_t status = tsa.Init(lcda.GetXSize(), lcda.GetYSize()); |
Alex_mln | 0:fcce18d01987 | 62 | tsa.GetState(&tsStatea); |
Alex_mln | 0:fcce18d01987 | 63 | detectiona(); |
Alex_mln | 0:fcce18d01987 | 64 | |
Alex_mln | 0:fcce18d01987 | 65 | |
Alex_mln | 0:fcce18d01987 | 66 | while((xa>225 || xa<12) || (ya<78-20 || ya>288-20)){ |
Alex_mln | 0:fcce18d01987 | 67 | tsa.GetState(&tsStatea); |
Alex_mln | 0:fcce18d01987 | 68 | detectiona(); |
Alex_mln | 0:fcce18d01987 | 69 | int* ligne=detectionLigne(); |
Alex_mln | 0:fcce18d01987 | 70 | capteur1=*ligne; |
Alex_mln | 0:fcce18d01987 | 71 | capteur2=*(ligne+1); |
Alex_mln | 0:fcce18d01987 | 72 | capteur3=*(ligne+2); |
Alex_mln | 0:fcce18d01987 | 73 | traitement(); |
Alex_mln | 0:fcce18d01987 | 74 | wait(delai); |
Alex_mln | 0:fcce18d01987 | 75 | } |
Alex_mln | 0:fcce18d01987 | 76 | } |
Alex_mln | 0:fcce18d01987 | 77 | |
Alex_mln | 0:fcce18d01987 | 78 | |
Alex_mln | 0:fcce18d01987 | 79 | |
Alex_mln | 0:fcce18d01987 | 80 | |
Alex_mln | 0:fcce18d01987 | 81 | |
Alex_mln | 0:fcce18d01987 | 82 | |
Alex_mln | 0:fcce18d01987 | 83 |