Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q mbed xbee_lib
Fork of Programme_course by
traitement_image.cpp
00001 #include "Mlib.h" 00002 00003 /**********TRAITEMENT_IMG************/ 00004 00005 void F_TraitementImage() 00006 { 00007 unsigned char i; 00008 signed short save_a; 00009 signed short save_b; 00010 int tempo = 0; 00011 char mem_a, mem_b; 00012 char tab[3]; 00013 char tab2[3]; 00014 mem_a = 100; 00015 mem_b = 100; 00016 save_b = MARGE_LIGNE; 00017 save_a = MARGE_LIGNE; 00018 somme_derivee = 0; 00019 for(i = 0; i < 62-4; i++) 00020 { 00021 tab[0] = cam_data[AMIDTAB+i]; 00022 tab[1] = cam_data[AMIDTAB+i+1]; 00023 tab[2] = cam_data[AMIDTAB+i+2]; 00024 tab2[0] = cam_data[AMIDTAB+i+3]; 00025 tab2[1] = cam_data[AMIDTAB+i+4]; 00026 tab2[2] = cam_data[AMIDTAB+i+5]; 00027 tempo = middle_3(tab)-middle_3(tab2); 00028 if(tempo < 0) tempo = 0; 00029 somme_derivee+= tempo; 00030 if(save_a < tempo) 00031 { 00032 save_a = tempo; 00033 mem_a = i; 00034 } 00035 } 00036 for(i = 1; i < 63-4; i++) 00037 { 00038 tab[0] = cam_data[AMIDTAB-i]; 00039 tab[1] = cam_data[AMIDTAB-i-1]; 00040 tab[2] = cam_data[AMIDTAB-i-2]; 00041 tab2[0] = cam_data[AMIDTAB-i-3]; 00042 tab2[1] = cam_data[AMIDTAB-i-4]; 00043 tab2[2] = cam_data[AMIDTAB-i-5]; 00044 tempo = middle_3(tab)-middle_3(tab2); 00045 if(tempo < 0) tempo = 0; 00046 somme_derivee+= tempo; 00047 if(save_b < tempo) 00048 { 00049 save_b = tempo; 00050 mem_b = i; 00051 } 00052 } 00053 00054 00055 if (mem_b == 100 && mem_a == 100) 00056 { 00057 baricentre = 0; 00058 } 00059 else if (mem_b == 100) 00060 { 00061 //baricentre = (mem_a-MARGE_DISTANCE_LIGNE); 00062 baricentre = (64-mem_a); 00063 } 00064 else if (mem_a == 100) 00065 { 00066 //baricentre = (MARGE_DISTANCE_LIGNE-mem_b); 00067 baricentre = (64-mem_b); 00068 } 00069 else 00070 { 00071 baricentre = (mem_b - mem_a); 00072 //baricentre = -baricentre; 00073 } 00074 } 00075 00076 void F_BalanceBlancs() 00077 { 00078 static unsigned char moy = 0; 00079 moy = Moyenne(cam_data); 00080 tempsInte+=100*(LUMI_MOYENNE-moy); 00081 if(tempsInte>MAX_INTE) tempsInte = MAX_INTE; 00082 if(tempsInte<MIN_INTE) tempsInte = MIN_INTE; 00083 somme_derivee = somme_derivee/(moy/10.0); 00084 } 00085 00086 00087 void T_image() 00088 { 00089 static int last_bari = 0, bari_bis = 0; 00090 static int retiens = 0; 00091 F_TraitementImage();//donne une valeur au baricentre 00092 00093 bary_tab[2] = bary_tab[1];//décalage du tableau des 3 derniers bari 00094 bary_tab[1] = bary_tab[0]; 00095 bary_tab[0] = baricentre; 00096 00097 for(int i = 0; i < 3; i++)//on rentre le tableau dans un autre tableau 00098 { 00099 bary_tab_bis[i] = bary_tab[i]; 00100 } 00101 00102 bari_bis = middle_3U(bary_tab_bis);//On calcul la médianne des 3 derniers bari 00103 integral += bari_bis; 00104 new_bari = (KI*integral+KP*bari_bis+KD*(bari_bis-last_bari))/1000;//On applique un KP et un KD (proportionnel et dérivé) au bari 00105 last_bari = bari_bis; 00106 00107 led4 = ralentire; 00108 if(S3)//gestion des lignes droites 00109 { 00110 if(abs(new_bari) < 15 && ligne_droite < 10 && ralentire == 0) 00111 { 00112 if(ligne_droite == 0) 00113 { 00114 t_ligne.reset(); 00115 } 00116 ligne_droite++; 00117 } 00118 if(abs(new_bari) >= 15 && ligne_droite > 0 && ralentire == 0) 00119 { 00120 ralentire = 1; // ralentire???????? 00121 retiens = t_ligne.read_ms(); 00122 t_ligne.reset(); 00123 if(retiens > 3000) retiens = 3000; 00124 retiens = retiens /3; 00125 } 00126 if(ralentire) 00127 { 00128 ligne_droite = (t_ligne.read_ms()-retiens)/4; 00129 ligne_droite = -100; 00130 if(t_ligne.read_ms()-retiens > 0) 00131 { 00132 ralentire = 0; 00133 ligne_droite = 0; 00134 } 00135 } 00136 } 00137 } 00138 00139 void init_bary() 00140 { 00141 for(int i = 0; i < 3; i++) 00142 { 00143 bary_tab[i] = 0; 00144 bary_tab_bis[i] = 0; 00145 } 00146 }
Generated on Tue Jul 12 2022 21:30:22 by
