carte esclave petit robot

Dependencies:   mbed Herkulex_Library_2019 actions_Gr ident_crac actions_Pr

Committer:
Artiom
Date:
Sat May 25 15:15:30 2019 +0000
Revision:
41:832128353732
Parent:
27:9627700d989f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Artiom 8:8aeb718824ea 1 #include "dt.h"
Artiom 8:8aeb718824ea 2 //RawSerial pc(USBTX, USBRX,9600);//serie pour debug
Artiom 8:8aeb718824ea 3
Artiom 8:8aeb718824ea 4 AnalogIn DT1(PB_0);
Artiom 8:8aeb718824ea 5 AnalogIn DT2(PC_5);
Artiom 8:8aeb718824ea 6 AnalogIn DT3(PC_4);
Artiom 8:8aeb718824ea 7 AnalogIn DT4(PA_5);
Artiom 8:8aeb718824ea 8
Artiom 10:48c0d1b8aed9 9 InterruptIn DT1_isr(PB_1);
Artiom 10:48c0d1b8aed9 10 InterruptIn DT2_isr(PA_7);
Artiom 10:48c0d1b8aed9 11 InterruptIn DT3_isr(PA_6);
Artiom 10:48c0d1b8aed9 12 InterruptIn DT4_isr(PA_4);
Artiom 8:8aeb718824ea 13
Artiom 9:9833e788942b 14 Timer t;
Artiom 9:9833e788942b 15
Artiom 8:8aeb718824ea 16 double DT1_mes[256]= {0};
Artiom 8:8aeb718824ea 17 double DT1_trait[256]= {0};
Artiom 8:8aeb718824ea 18 double DT1_trait_Ex;
Artiom 8:8aeb718824ea 19
Artiom 8:8aeb718824ea 20 double DT2_mes[256]= {0};
Artiom 8:8aeb718824ea 21 double DT2_trait[256]= {0};
Artiom 8:8aeb718824ea 22 double DT2_trait_Ex;
Artiom 8:8aeb718824ea 23
Artiom 8:8aeb718824ea 24 double DT3_mes[256]= {0};
Artiom 8:8aeb718824ea 25 double DT3_trait[256]= {0};
Artiom 8:8aeb718824ea 26 double DT3_trait_Ex;
Artiom 8:8aeb718824ea 27
Artiom 8:8aeb718824ea 28 double DT4_mes[256]= {0};
Artiom 8:8aeb718824ea 29 double DT4_trait[256]= {0};
Artiom 8:8aeb718824ea 30 double DT4_trait_Ex;
Artiom 8:8aeb718824ea 31
Artiom 41:832128353732 32 unsigned char DT1_interrupt_Ex;
Artiom 41:832128353732 33 unsigned char DT2_interrupt_Ex;
Artiom 41:832128353732 34 unsigned char DT3_interrupt_Ex;
Artiom 41:832128353732 35 unsigned char DT4_interrupt_Ex;
Artiom 10:48c0d1b8aed9 36
Artiom 8:8aeb718824ea 37 unsigned char n = 0;
Artiom 9:9833e788942b 38 bool flag_t=0;
Artiom 8:8aeb718824ea 39
Artiom 8:8aeb718824ea 40 void f_mesure()
Artiom 8:8aeb718824ea 41 {
Artiom 9:9833e788942b 42 if(!flag_t) {
Artiom 9:9833e788942b 43 t.start();
Artiom 9:9833e788942b 44 flag_t=1;
Artiom 9:9833e788942b 45 }
Artiom 9:9833e788942b 46
Artiom 9:9833e788942b 47 if (t.read_ms() >= 4) {
Artiom 9:9833e788942b 48 n++;
Artiom 9:9833e788942b 49 DT1.read();//lecture dans le vide le temp que l'adc switch
Artiom 9:9833e788942b 50 wait_us(100);//attente du switch de l'adc
Artiom 9:9833e788942b 51 DT1_mes[n]= DT1.read() * A + B;
Artiom 9:9833e788942b 52 DT1_trait[n] = mediane(DT1_mes, 10);
Artiom 9:9833e788942b 53 DT1_trait_Ex = DT1_trait[n];
Artiom 8:8aeb718824ea 54
Artiom 9:9833e788942b 55 DT2.read();//lecture dans le vide le temp que l'adc switch
Artiom 9:9833e788942b 56 wait_us(100);//attente du switch de l'adc
Artiom 9:9833e788942b 57 DT2_mes[n]= DT2.read() * A + B;
Artiom 9:9833e788942b 58 DT2_trait[n] = mediane(DT2_mes, 10);
Artiom 9:9833e788942b 59 DT2_trait_Ex = DT2_trait[n];
Artiom 9:9833e788942b 60
Artiom 9:9833e788942b 61 DT3.read();//lecture dans le vide le temp que l'adc switch
Artiom 9:9833e788942b 62 wait_us(100);//attente du switch de l'adc
Artiom 9:9833e788942b 63 DT3_mes[n]= DT3.read() * A + B;
Artiom 9:9833e788942b 64 DT3_trait[n] = mediane(DT3_mes, 10);
Artiom 9:9833e788942b 65 DT3_trait_Ex = DT3_trait[n];
Artiom 9:9833e788942b 66
Artiom 9:9833e788942b 67 DT4.read();//lecture dans le vide le temp que l'adc switch
Artiom 9:9833e788942b 68 wait_us(100);//attente du switch de l'adc
Artiom 9:9833e788942b 69 DT4_mes[n]= DT4.read() * A + B;
Artiom 9:9833e788942b 70 DT4_trait[n] = mediane(DT4_mes, 10);
Artiom 9:9833e788942b 71 DT4_trait_Ex = DT4_trait[n];
Artiom 9:9833e788942b 72
Artiom 9:9833e788942b 73 t.reset();
Artiom 9:9833e788942b 74 }
Artiom 9:9833e788942b 75
Artiom 8:8aeb718824ea 76 }
Artiom 8:8aeb718824ea 77
Artiom 8:8aeb718824ea 78 double mediane(double* buff_med, int size_med)
Artiom 8:8aeb718824ea 79 {
Artiom 8:8aeb718824ea 80 double DT_med[30]= {0};
Artiom 8:8aeb718824ea 81 for(unsigned char i =0; i< size_med; i++)DT_med[i] = buff_med[(unsigned char)(n-i)];
Artiom 8:8aeb718824ea 82
Artiom 8:8aeb718824ea 83 tri(DT_med, size_med);
Artiom 8:8aeb718824ea 84 return DT_med[(int)(size_med/2)];
Artiom 8:8aeb718824ea 85 }
Artiom 8:8aeb718824ea 86
Artiom 8:8aeb718824ea 87 void tri(double* tab, int size)
Artiom 8:8aeb718824ea 88 {
Artiom 8:8aeb718824ea 89 for (int i=0; i<size; i++) {
Artiom 8:8aeb718824ea 90 for(int j=i; j<size; j++) {
Artiom 8:8aeb718824ea 91 if(tab[j]<tab[i]) {
Artiom 8:8aeb718824ea 92 double temp = tab[i];
Artiom 8:8aeb718824ea 93 tab[i] = tab[j];
Artiom 8:8aeb718824ea 94 tab[j] = temp;
Artiom 8:8aeb718824ea 95 }
Artiom 8:8aeb718824ea 96 }
Artiom 8:8aeb718824ea 97 }
Artiom 8:8aeb718824ea 98 }
Artiom 10:48c0d1b8aed9 99
Artiom 10:48c0d1b8aed9 100 void interrupt()
Artiom 10:48c0d1b8aed9 101 {
Artiom 10:48c0d1b8aed9 102 DT1_interrupt_Ex = DT1_isr.read();
Artiom 10:48c0d1b8aed9 103 DT2_interrupt_Ex = DT2_isr.read();
Artiom 10:48c0d1b8aed9 104 DT3_interrupt_Ex = DT3_isr.read();
Artiom 10:48c0d1b8aed9 105 DT4_interrupt_Ex = DT4_isr.read();
Artiom 10:48c0d1b8aed9 106 }
Artiom 10:48c0d1b8aed9 107
Artiom 10:48c0d1b8aed9 108