carte esclave petit robot
Dependencies: mbed Herkulex_Library_2019 actions_Gr ident_crac actions_Pr
Capteurs/dt.cpp@8:8aeb718824ea, 2019-05-16 (annotated)
- Committer:
- Artiom
- Date:
- Thu May 16 11:58:17 2019 +0000
- Revision:
- 8:8aeb718824ea
- Child:
- 9:9833e788942b
ajout de la mediane sur les telemetres!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Artiom | 8:8aeb718824ea | 1 | #include "mbed.h" |
Artiom | 8:8aeb718824ea | 2 | #include "dt.h" |
Artiom | 8:8aeb718824ea | 3 | //RawSerial pc(USBTX, USBRX,9600);//serie pour debug |
Artiom | 8:8aeb718824ea | 4 | |
Artiom | 8:8aeb718824ea | 5 | AnalogIn DT1(PB_0); |
Artiom | 8:8aeb718824ea | 6 | AnalogIn DT2(PC_5); |
Artiom | 8:8aeb718824ea | 7 | AnalogIn DT3(PC_4); |
Artiom | 8:8aeb718824ea | 8 | AnalogIn DT4(PA_5); |
Artiom | 8:8aeb718824ea | 9 | |
Artiom | 8:8aeb718824ea | 10 | DigitalIn DT1_isr(PB_1); |
Artiom | 8:8aeb718824ea | 11 | DigitalIn DT2_isr(PA_7); |
Artiom | 8:8aeb718824ea | 12 | DigitalIn DT3_isr(PA_6); |
Artiom | 8:8aeb718824ea | 13 | DigitalIn DT4_isr(PA_4); |
Artiom | 8:8aeb718824ea | 14 | |
Artiom | 8:8aeb718824ea | 15 | double DT1_mes[256]= {0}; |
Artiom | 8:8aeb718824ea | 16 | double DT1_trait[256]= {0}; |
Artiom | 8:8aeb718824ea | 17 | double DT1_trait_Ex; |
Artiom | 8:8aeb718824ea | 18 | |
Artiom | 8:8aeb718824ea | 19 | double DT2_mes[256]= {0}; |
Artiom | 8:8aeb718824ea | 20 | double DT2_trait[256]= {0}; |
Artiom | 8:8aeb718824ea | 21 | double DT2_trait_Ex; |
Artiom | 8:8aeb718824ea | 22 | |
Artiom | 8:8aeb718824ea | 23 | double DT3_mes[256]= {0}; |
Artiom | 8:8aeb718824ea | 24 | double DT3_trait[256]= {0}; |
Artiom | 8:8aeb718824ea | 25 | double DT3_trait_Ex; |
Artiom | 8:8aeb718824ea | 26 | |
Artiom | 8:8aeb718824ea | 27 | double DT4_mes[256]= {0}; |
Artiom | 8:8aeb718824ea | 28 | double DT4_trait[256]= {0}; |
Artiom | 8:8aeb718824ea | 29 | double DT4_trait_Ex; |
Artiom | 8:8aeb718824ea | 30 | |
Artiom | 8:8aeb718824ea | 31 | unsigned char n = 0; |
Artiom | 8:8aeb718824ea | 32 | |
Artiom | 8:8aeb718824ea | 33 | void f_mesure() |
Artiom | 8:8aeb718824ea | 34 | { |
Artiom | 8:8aeb718824ea | 35 | n++; |
Artiom | 8:8aeb718824ea | 36 | DT1.read();//lecture dans le vide le temp que l'adc switch |
Artiom | 8:8aeb718824ea | 37 | wait_us(100);//attente du switch de l'adc |
Artiom | 8:8aeb718824ea | 38 | DT1_mes[n]= DT1.read() * A + B; |
Artiom | 8:8aeb718824ea | 39 | DT1_trait[n] = mediane(DT1_mes, 10); |
Artiom | 8:8aeb718824ea | 40 | DT1_trait_Ex = DT1_trait[n]; |
Artiom | 8:8aeb718824ea | 41 | |
Artiom | 8:8aeb718824ea | 42 | DT2.read();//lecture dans le vide le temp que l'adc switch |
Artiom | 8:8aeb718824ea | 43 | wait_us(100);//attente du switch de l'adc |
Artiom | 8:8aeb718824ea | 44 | DT2_mes[n]= DT2.read() * A + B; |
Artiom | 8:8aeb718824ea | 45 | DT2_trait[n] = mediane(DT2_mes, 10); |
Artiom | 8:8aeb718824ea | 46 | DT2_trait_Ex = DT2_trait[n]; |
Artiom | 8:8aeb718824ea | 47 | |
Artiom | 8:8aeb718824ea | 48 | DT3.read();//lecture dans le vide le temp que l'adc switch |
Artiom | 8:8aeb718824ea | 49 | wait_us(100);//attente du switch de l'adc |
Artiom | 8:8aeb718824ea | 50 | DT3_mes[n]= DT3.read() * A + B; |
Artiom | 8:8aeb718824ea | 51 | DT3_trait[n] = mediane(DT3_mes, 10); |
Artiom | 8:8aeb718824ea | 52 | DT3_trait_Ex = DT3_trait[n]; |
Artiom | 8:8aeb718824ea | 53 | |
Artiom | 8:8aeb718824ea | 54 | DT4.read();//lecture dans le vide le temp que l'adc switch |
Artiom | 8:8aeb718824ea | 55 | wait_us(100);//attente du switch de l'adc |
Artiom | 8:8aeb718824ea | 56 | DT4_mes[n]= DT4.read() * A + B; |
Artiom | 8:8aeb718824ea | 57 | DT4_trait[n] = mediane(DT4_mes, 10); |
Artiom | 8:8aeb718824ea | 58 | DT4_trait_Ex = DT4_trait[n]; |
Artiom | 8:8aeb718824ea | 59 | |
Artiom | 8:8aeb718824ea | 60 | wait_ms(4); |
Artiom | 8:8aeb718824ea | 61 | } |
Artiom | 8:8aeb718824ea | 62 | |
Artiom | 8:8aeb718824ea | 63 | double mediane(double* buff_med, int size_med) |
Artiom | 8:8aeb718824ea | 64 | { |
Artiom | 8:8aeb718824ea | 65 | double DT_med[30]= {0}; |
Artiom | 8:8aeb718824ea | 66 | for(unsigned char i =0; i< size_med; i++)DT_med[i] = buff_med[(unsigned char)(n-i)]; |
Artiom | 8:8aeb718824ea | 67 | |
Artiom | 8:8aeb718824ea | 68 | tri(DT_med, size_med); |
Artiom | 8:8aeb718824ea | 69 | return DT_med[(int)(size_med/2)]; |
Artiom | 8:8aeb718824ea | 70 | } |
Artiom | 8:8aeb718824ea | 71 | |
Artiom | 8:8aeb718824ea | 72 | void tri(double* tab, int size) |
Artiom | 8:8aeb718824ea | 73 | { |
Artiom | 8:8aeb718824ea | 74 | for (int i=0; i<size; i++) { |
Artiom | 8:8aeb718824ea | 75 | for(int j=i; j<size; j++) { |
Artiom | 8:8aeb718824ea | 76 | if(tab[j]<tab[i]) { |
Artiom | 8:8aeb718824ea | 77 | double temp = tab[i]; |
Artiom | 8:8aeb718824ea | 78 | tab[i] = tab[j]; |
Artiom | 8:8aeb718824ea | 79 | tab[j] = temp; |
Artiom | 8:8aeb718824ea | 80 | } |
Artiom | 8:8aeb718824ea | 81 | } |
Artiom | 8:8aeb718824ea | 82 | } |
Artiom | 8:8aeb718824ea | 83 | } |