carte esclave Petit Robot
Dependencies: mbed Herkulex_Library_2019 actions_Gr ident_crac actions_Pr
Diff: Capteurs/dt.cpp
- Revision:
- 8:8aeb718824ea
- Child:
- 9:9833e788942b
diff -r 553f3f1c2c53 -r 8aeb718824ea Capteurs/dt.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Capteurs/dt.cpp Thu May 16 11:58:17 2019 +0000 @@ -0,0 +1,83 @@ +#include "mbed.h" +#include "dt.h" +//RawSerial pc(USBTX, USBRX,9600);//serie pour debug + +AnalogIn DT1(PB_0); +AnalogIn DT2(PC_5); +AnalogIn DT3(PC_4); +AnalogIn DT4(PA_5); + +DigitalIn DT1_isr(PB_1); +DigitalIn DT2_isr(PA_7); +DigitalIn DT3_isr(PA_6); +DigitalIn DT4_isr(PA_4); + +double DT1_mes[256]= {0}; +double DT1_trait[256]= {0}; +double DT1_trait_Ex; + +double DT2_mes[256]= {0}; +double DT2_trait[256]= {0}; +double DT2_trait_Ex; + +double DT3_mes[256]= {0}; +double DT3_trait[256]= {0}; +double DT3_trait_Ex; + +double DT4_mes[256]= {0}; +double DT4_trait[256]= {0}; +double DT4_trait_Ex; + +unsigned char n = 0; + +void f_mesure() +{ + n++; + DT1.read();//lecture dans le vide le temp que l'adc switch + wait_us(100);//attente du switch de l'adc + DT1_mes[n]= DT1.read() * A + B; + DT1_trait[n] = mediane(DT1_mes, 10); + DT1_trait_Ex = DT1_trait[n]; + + DT2.read();//lecture dans le vide le temp que l'adc switch + wait_us(100);//attente du switch de l'adc + DT2_mes[n]= DT2.read() * A + B; + DT2_trait[n] = mediane(DT2_mes, 10); + DT2_trait_Ex = DT2_trait[n]; + + DT3.read();//lecture dans le vide le temp que l'adc switch + wait_us(100);//attente du switch de l'adc + DT3_mes[n]= DT3.read() * A + B; + DT3_trait[n] = mediane(DT3_mes, 10); + DT3_trait_Ex = DT3_trait[n]; + + DT4.read();//lecture dans le vide le temp que l'adc switch + wait_us(100);//attente du switch de l'adc + DT4_mes[n]= DT4.read() * A + B; + DT4_trait[n] = mediane(DT4_mes, 10); + DT4_trait_Ex = DT4_trait[n]; + + wait_ms(4); +} + +double mediane(double* buff_med, int size_med) +{ + double DT_med[30]= {0}; + for(unsigned char i =0; i< size_med; i++)DT_med[i] = buff_med[(unsigned char)(n-i)]; + + tri(DT_med, size_med); + return DT_med[(int)(size_med/2)]; +} + +void tri(double* tab, int size) +{ + for (int i=0; i<size; i++) { + for(int j=i; j<size; j++) { + if(tab[j]<tab[i]) { + double temp = tab[i]; + tab[i] = tab[j]; + tab[j] = temp; + } + } + } +}