carte esclave petit robot
Dependencies: mbed Herkulex_Library_2019 actions_Gr ident_crac actions_Pr
Capteurs/Capteur.cpp@0:bc74da1c502f, 2019-05-06 (annotated)
- Committer:
- Artiom
- Date:
- Mon May 06 11:18:47 2019 +0000
- Revision:
- 0:bc74da1c502f
- Child:
- 7:553f3f1c2c53
Z
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Artiom | 0:bc74da1c502f | 1 | #include "Capteur.h" |
Artiom | 0:bc74da1c502f | 2 | #include "mbed.h" |
Artiom | 0:bc74da1c502f | 3 | #include "Actionneurs.h" |
Artiom | 0:bc74da1c502f | 4 | #define NOMBRE_TELEMETRE 4 |
Artiom | 0:bc74da1c502f | 5 | #define precision 5 |
Artiom | 0:bc74da1c502f | 6 | #define CONSTANTE_TIR 0.639f |
Artiom | 0:bc74da1c502f | 7 | |
Artiom | 0:bc74da1c502f | 8 | ///////////////////////////////////////Capteurs de Contact/////////////////////// |
Artiom | 0:bc74da1c502f | 9 | DigitalIn capteur_contact_block(PB_15); |
Artiom | 0:bc74da1c502f | 10 | DigitalIn capteur_contact1(PB_4); |
Artiom | 0:bc74da1c502f | 11 | DigitalIn capteur_contact2(PB_5); |
Artiom | 0:bc74da1c502f | 12 | DigitalIn capteur_contact3(PH_1); |
Artiom | 0:bc74da1c502f | 13 | |
Artiom | 0:bc74da1c502f | 14 | /////////////////////////////////////Lecture Batterie//////////////////////////// |
Artiom | 0:bc74da1c502f | 15 | AnalogIn Val_batterie(PC_2); |
Artiom | 0:bc74da1c502f | 16 | |
Artiom | 0:bc74da1c502f | 17 | ////////////////////////////////////////Télémètres/////////////////////////////// |
Artiom | 0:bc74da1c502f | 18 | AnalogIn telemetre1(PB_0); |
Artiom | 0:bc74da1c502f | 19 | AnalogIn telemetre2(PC_5); |
Artiom | 0:bc74da1c502f | 20 | AnalogIn telemetre3(PC_4); |
Artiom | 0:bc74da1c502f | 21 | AnalogIn telemetre4(PA_5); |
Artiom | 0:bc74da1c502f | 22 | ///////////////////////////////////Capteurs multiCouleurs//////////////////////// |
Artiom | 0:bc74da1c502f | 23 | |
Artiom | 0:bc74da1c502f | 24 | |
Artiom | 0:bc74da1c502f | 25 | |
Artiom | 0:bc74da1c502f | 26 | /////////////////////////////////////Capteurs monocouleur//////////////////////// |
Artiom | 0:bc74da1c502f | 27 | DigitalIn monocouleur1(PC_15); |
Artiom | 0:bc74da1c502f | 28 | DigitalIn monocouleur2(PC_14); |
Artiom | 0:bc74da1c502f | 29 | DigitalIn monocouleur3(PB_10); |
Artiom | 0:bc74da1c502f | 30 | DigitalIn monocouleur4(PC_3); |
Artiom | 0:bc74da1c502f | 31 | |
Artiom | 0:bc74da1c502f | 32 | /////////////////////////////////////Capteurs industriels//////////////////////// |
Artiom | 0:bc74da1c502f | 33 | /*AnalogIn Capteur_indus1(PA_7); |
Artiom | 0:bc74da1c502f | 34 | AnalogIn Capteur_indus2(PA_6); |
Artiom | 0:bc74da1c502f | 35 | AnalogIn Capteur_indus3(PA_5); |
Artiom | 0:bc74da1c502f | 36 | AnalogIn Capteur_indus4(PA_4); |
Artiom | 0:bc74da1c502f | 37 | AnalogIn Capteur_indus5(PC_1); |
Artiom | 0:bc74da1c502f | 38 | AnalogIn Capteur_indus6(PC_0);*/ |
Artiom | 0:bc74da1c502f | 39 | |
Artiom | 0:bc74da1c502f | 40 | short distance_moyenne; |
Artiom | 0:bc74da1c502f | 41 | |
Artiom | 0:bc74da1c502f | 42 | short lecture_telemetre(char numero_telemetre){ // DEGUEUX MAIS FONCTIONNEL :') |
Artiom | 0:bc74da1c502f | 43 | //wait(1); |
Artiom | 0:bc74da1c502f | 44 | float telemetre_distance=0; |
Artiom | 0:bc74da1c502f | 45 | short distance; |
Artiom | 0:bc74da1c502f | 46 | long long distance_moyenne_somme=0; |
Artiom | 0:bc74da1c502f | 47 | for (unsigned char i=0; i<precision;i++){ |
Artiom | 0:bc74da1c502f | 48 | if(numero_telemetre==1) |
Artiom | 0:bc74da1c502f | 49 | { |
Artiom | 0:bc74da1c502f | 50 | telemetre_distance=telemetre1.read(); |
Artiom | 0:bc74da1c502f | 51 | distance=(((telemetre_distance)-0.2)*4671)+45; |
Artiom | 0:bc74da1c502f | 52 | wait_us(100); |
Artiom | 0:bc74da1c502f | 53 | telemetre_distance=telemetre1.read(); |
Artiom | 0:bc74da1c502f | 54 | distance=(((telemetre_distance)-0.2)*4671)+50; |
Artiom | 0:bc74da1c502f | 55 | distance+=86; |
Artiom | 0:bc74da1c502f | 56 | distance=(distance*0.98)+16.6; |
Artiom | 0:bc74da1c502f | 57 | } |
Artiom | 0:bc74da1c502f | 58 | else if (numero_telemetre==2) |
Artiom | 0:bc74da1c502f | 59 | { |
Artiom | 0:bc74da1c502f | 60 | telemetre_distance=telemetre2.read(); |
Artiom | 0:bc74da1c502f | 61 | distance=(((telemetre_distance)-0.2)*4671)+45; |
Artiom | 0:bc74da1c502f | 62 | wait_us(100); |
Artiom | 0:bc74da1c502f | 63 | telemetre_distance=telemetre2.read(); |
Artiom | 0:bc74da1c502f | 64 | distance=(((telemetre_distance)-0.2)*4671)+50; |
Artiom | 0:bc74da1c502f | 65 | distance+=86; |
Artiom | 0:bc74da1c502f | 66 | distance=(distance*0.975)+25.7; |
Artiom | 0:bc74da1c502f | 67 | } |
Artiom | 0:bc74da1c502f | 68 | else if (numero_telemetre==3) |
Artiom | 0:bc74da1c502f | 69 | { |
Artiom | 0:bc74da1c502f | 70 | telemetre_distance=telemetre3.read(); |
Artiom | 0:bc74da1c502f | 71 | distance=(((telemetre_distance)-0.2)*4671)+45; |
Artiom | 0:bc74da1c502f | 72 | wait_us(100); |
Artiom | 0:bc74da1c502f | 73 | telemetre_distance=telemetre3.read(); |
Artiom | 0:bc74da1c502f | 74 | distance=(((telemetre_distance)-0.2)*4671)+50; |
Artiom | 0:bc74da1c502f | 75 | distance+=86; |
Artiom | 0:bc74da1c502f | 76 | distance=(distance*0.98)+15.6; |
Artiom | 0:bc74da1c502f | 77 | } |
Artiom | 0:bc74da1c502f | 78 | else if (numero_telemetre==4) |
Artiom | 0:bc74da1c502f | 79 | { |
Artiom | 0:bc74da1c502f | 80 | telemetre_distance=telemetre4.read(); |
Artiom | 0:bc74da1c502f | 81 | distance=(((telemetre_distance)-0.2)*4671)+45; |
Artiom | 0:bc74da1c502f | 82 | wait_us(100); |
Artiom | 0:bc74da1c502f | 83 | telemetre_distance=telemetre4.read(); |
Artiom | 0:bc74da1c502f | 84 | distance=(((telemetre_distance)-0.2)*4671)+50; |
Artiom | 0:bc74da1c502f | 85 | distance+=86; |
Artiom | 0:bc74da1c502f | 86 | distance=(distance*0.98)+11.15; |
Artiom | 0:bc74da1c502f | 87 | } |
Artiom | 0:bc74da1c502f | 88 | distance_moyenne_somme+=distance; |
Artiom | 0:bc74da1c502f | 89 | } |
Artiom | 0:bc74da1c502f | 90 | distance_moyenne=(distance_moyenne_somme/precision); |
Artiom | 0:bc74da1c502f | 91 | wait_us(100); |
Artiom | 0:bc74da1c502f | 92 | return distance_moyenne; |
Artiom | 0:bc74da1c502f | 93 | } |
Artiom | 0:bc74da1c502f | 94 | |
Artiom | 0:bc74da1c502f | 95 | |
Artiom | 0:bc74da1c502f | 96 | |
Artiom | 0:bc74da1c502f | 97 | float Val_puissance(char zone_tir){ |
Artiom | 0:bc74da1c502f | 98 | float voltage=Val_batterie.read()*3.3f; |
Artiom | 0:bc74da1c502f | 99 | float puissance_tir=CONSTANTE_TIR/voltage; |
Artiom | 0:bc74da1c502f | 100 | return puissance_tir; |
Artiom | 0:bc74da1c502f | 101 | } |
Artiom | 0:bc74da1c502f | 102 | int capteur_contact(void){ |
Artiom | 0:bc74da1c502f | 103 | if(capteur_contact_block.read()==1){ |
Artiom | 0:bc74da1c502f | 104 | return 1; |
Artiom | 0:bc74da1c502f | 105 | } |
Artiom | 0:bc74da1c502f | 106 | else{ |
Artiom | 0:bc74da1c502f | 107 | return 0; |
Artiom | 0:bc74da1c502f | 108 | } |
Artiom | 0:bc74da1c502f | 109 | } |