[637] | 1 | #include "diabolo.h"
|
---|
| 2 | #include "synchro.h"
|
---|
| 3 | #include "carte.h"
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | #define indicemax 1000
|
---|
| 8 |
|
---|
| 9 | double taille_carte,pas,vitesse;
|
---|
| 10 | int bolo_carte,indice,ind_moy,debut_ligne,moy,sens_ligne;
|
---|
| 11 | double dynamique;
|
---|
| 12 | double seuil;
|
---|
| 13 |
|
---|
| 14 | double carte[nb_max_bolo][indicemax];
|
---|
| 15 | double xx[indicemax];
|
---|
| 16 | double yy[indicemax];
|
---|
| 17 | int flag_fin[indicemax],flag_sens[indicemax];
|
---|
| 18 |
|
---|
| 19 | double xx0,yy0;
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | //-------------------- fonction exec de la fenetre : trace_carte -------------------------------
|
---|
| 23 | void echelles(void);
|
---|
| 24 | void retrace_carte(void);
|
---|
| 25 |
|
---|
| 26 | void exec_carte(int fen,int item,double valeur,...)
|
---|
| 27 | {
|
---|
| 28 | if(item>1000) item-=1000; // pour appeler le case pour tous les cara d'un edit texte
|
---|
| 29 |
|
---|
| 30 | switch(item)
|
---|
| 31 | {
|
---|
| 32 | case ouverture : gg->trace_ouvert=gg->trace_ouvert | 16 ;
|
---|
| 33 | selectgra(fen);
|
---|
| 34 | graph->taille_graduations=7;
|
---|
| 35 |
|
---|
| 36 | case cart_debut : echelles();
|
---|
| 37 | indice=0;ind_moy=0;sens_ligne=1;debut_ligne=1; // premier point a venir
|
---|
| 38 | xx0=-0.5*(taille_carte-0.5*pas);yy0=-0.5*taille_carte;
|
---|
| 39 | break;
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | case fermeture : gg->trace_ouvert=gg->trace_ouvert & (255-16); // enleve le 16
|
---|
| 44 | break;
|
---|
| 45 |
|
---|
| 46 | case cart_taille_carte :
|
---|
| 47 | case cart_pas :
|
---|
| 48 | case cart_dynamique :
|
---|
| 49 | case cart_bolo :
|
---|
| 50 | case cart_vitesse : echelles();
|
---|
| 51 |
|
---|
| 52 | break;
|
---|
| 53 |
|
---|
| 54 | case cart_retrace : retrace_carte();
|
---|
| 55 | break;
|
---|
| 56 |
|
---|
| 57 | default : break;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | void echelles(void)
|
---|
| 63 | {
|
---|
| 64 | double moyenne_double;
|
---|
| 65 | taille_carte=litD(fenetre_annexe,cart_taille_carte,0);
|
---|
| 66 | pas=litD(fenetre_annexe,cart_pas,0);
|
---|
| 67 | vitesse=litD(fenetre_annexe,cart_vitesse,0);
|
---|
| 68 | dynamique=litD(fenetre_annexe,cart_dynamique,0);
|
---|
| 69 | bolo_carte=litD(fenetre_annexe,cart_bolo,0);
|
---|
| 70 | selectgra(fenetre_annexe);
|
---|
| 71 | graph->ymin=-0.5*(taille_carte+2*pas);
|
---|
| 72 | graph->ymax=0.5*(taille_carte+2*pas);
|
---|
| 73 | graph->ypas=pas;
|
---|
| 74 | graph->xmin=-0.5*(taille_carte+2*pas);
|
---|
| 75 | graph->xmax=0.5*(taille_carte+2*pas);
|
---|
| 76 | graph->xpas=pas;
|
---|
| 77 | graph->graduations=0;
|
---|
| 78 | graph->grille=1;
|
---|
| 79 | graph->aspect=-1;
|
---|
| 80 | efface(fenetre_annexe);
|
---|
| 81 | // moyennes par demi pas en x
|
---|
| 82 | moyenne_double= pas * 0.5 /( gg->periode_echantillonage * vitesse );
|
---|
| 83 |
|
---|
| 84 | if(gg->trace_ouvert&32) moyenne_double/=(double)synchro_periode; // pour mesure avec Detection synchrone
|
---|
| 85 | moy=(int)(moyenne_double+0.5);
|
---|
| 86 | if(moy<1) moy=1;
|
---|
| 87 | printf("moyennes calculee sur %6.2f points soit m=%d \n",moyenne_double,moy);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | void trace_carte(double * y)
|
---|
| 91 | {
|
---|
| 92 | int j;
|
---|
| 93 | // calculer le nombre de points de mesure dans un pas a la vitesse
|
---|
| 94 | // gg->periode_echantillonage contient la duree entre deux points de mesure (pour diabolo)
|
---|
| 95 |
|
---|
| 96 | if( (!(gg->don.sync[sync_scan]&&gg->don.sync[sync_subscan])) && (indice==0) ) return;
|
---|
| 97 |
|
---|
| 98 | if( (!gg->don.sync[sync_subscan]) && (indice>2) && (debut_ligne<3) ) debut_ligne=2; // entre deux subscan
|
---|
| 99 |
|
---|
| 100 | if(ind_moy==0) for(j=0;j<nb_max_bolo;j++) carte[j][indice]=0;
|
---|
| 101 | if(ind_moy<moy) for(j=0;j<nb_max_bolo;j++) carte[j][indice]+=y[j];
|
---|
| 102 | if(ind_moy<moy+10) ind_moy++; // pour ne pas continuer a l'infini
|
---|
| 103 |
|
---|
| 104 | if( (ind_moy>=moy) && (indice<indicemax) )
|
---|
| 105 | {
|
---|
| 106 | if(ind_moy==moy)
|
---|
| 107 | {
|
---|
| 108 | int couleur_degrade;
|
---|
| 109 | xx[indice]=xx0;
|
---|
| 110 | yy[indice]=yy0;
|
---|
| 111 | flag_fin[indice]=debut_ligne;
|
---|
| 112 | flag_sens[indice]=sens_ligne;
|
---|
| 113 | for(j=0;j<nb_max_bolo;j++) carte[j][indice]/=(double)moy;
|
---|
| 114 |
|
---|
| 115 | // if(debut_ligne==1) seuil=carte[bolo-1][indice]; // premier point d'une ligne : seuil pour la suite
|
---|
| 116 | seuil=0; // pas de seuil: utiliser le filtrage en mode puissance totale
|
---|
| 117 | // et raz parasite en mode detection synchrone
|
---|
| 118 | couleur_degrade=1050+(50.*(carte[bolo_carte-1][indice]-seuil)/dynamique);
|
---|
| 119 | if(sens_ligne>0)rectangle(fenetre_annexe,xx0-0.25*pas,yy0-0.5*pas,xx0+0.25*pas,yy0,couleur_degrade);
|
---|
| 120 | else rectangle(fenetre_annexe,xx0-0.25*pas,yy0,xx0+0.25*pas,yy0+0.5*pas,couleur_degrade);
|
---|
| 121 | if(debut_ligne==1)
|
---|
| 122 | {
|
---|
| 123 | debut_ligne=0; // premier point
|
---|
| 124 | printf(" debut_ligne indice=%d : x=%g y=%g valeur=%g couleur=%d \n",indice,xx0,yy0,carte[8][indice],couleur_degrade);
|
---|
| 125 | }
|
---|
| 126 | indice++;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | if( (debut_ligne==2) && (!gg->don.sync[sync_scan]) )
|
---|
| 131 | {
|
---|
| 132 | debut_ligne=3; // fin de carte
|
---|
| 133 | son(133);
|
---|
| 134 | printf("fin de carte \n\n");
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | if(gg->don.sync[sync_subscan])
|
---|
| 138 | {
|
---|
| 139 | if(debut_ligne==2) // prepare pour mesure premier point
|
---|
| 140 | {
|
---|
| 141 | sens_ligne=-sens_ligne;
|
---|
| 142 | if(sens_ligne>0) yy0+=pas;
|
---|
| 143 | xx0=-0.5*sens_ligne*(taille_carte-0.5*pas);
|
---|
| 144 | debut_ligne=1; ind_moy=0; // premier point
|
---|
| 145 | }
|
---|
| 146 | if(!debut_ligne) // prepare pour mesure point suivant
|
---|
| 147 | {
|
---|
| 148 | xx0+=sens_ligne*0.5*pas;
|
---|
| 149 | if( (xx0<0.5*taille_carte) && (xx0>-0.5*taille_carte) ) ind_moy=0;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | void retrace_carte(void)
|
---|
| 158 | {
|
---|
| 159 | int i,k,kk,couleur_degrade;
|
---|
| 160 | double sx,sy,sx2,sxy,n,a,b; // pour le fit lineaire
|
---|
| 161 | efface(fenetre_annexe);
|
---|
| 162 | // calcul dynamique automatique
|
---|
| 163 | dynamique=0.000000001;
|
---|
| 164 |
|
---|
| 165 | for(i=0;i<indice;i+=kk)
|
---|
| 166 | { // une ligne commence en indice==i
|
---|
| 167 | // fit lineaire avec un poid null au milieu : y= ax+b
|
---|
| 168 | //
|
---|
| 169 | // calcule la droite a soustraire
|
---|
| 170 | sx=0;sy=0;sx2=0;sxy=0;n=0;
|
---|
| 171 | k=0;
|
---|
| 172 | do {
|
---|
| 173 | // printf(" i=%d k=%d carte=%g \n",i,k,carte[bolo-1][i+k]);
|
---|
| 174 | if( (xx[i+k]>0.25*taille_carte) ou (xx[i+k]<-0.25*taille_carte) )
|
---|
| 175 | {
|
---|
| 176 | n++;
|
---|
| 177 | sx+=xx[i+k];
|
---|
| 178 | sy+=carte[bolo_carte-1][i+k];
|
---|
| 179 | sx2+=xx[i+k]*xx[i+k];
|
---|
| 180 | sxy+=xx[i+k]*carte[bolo_carte-1][i+k];
|
---|
| 181 | }
|
---|
| 182 | k++;
|
---|
| 183 | }
|
---|
| 184 | while ( (k<indice-i) && (flag_fin[i+k]!=1) );
|
---|
| 185 |
|
---|
| 186 | kk=k; // kk = longueur de ligne
|
---|
| 187 | a=(sxy*n-sx*sy)/(sx2*n-sx*sx); b=(sy-a*sx)/n;
|
---|
| 188 | // printf(" une ligne indice i=%d ligne de %d points a=%g b=%g \n\n",i,kk,a,b);
|
---|
| 189 |
|
---|
| 190 | // soustrait la droite fittée sur la ligne et calcule la dynamique
|
---|
| 191 | for(k=0;k<kk;k++)
|
---|
| 192 | {
|
---|
| 193 | carte[bolo_carte-1][i+k]-=a*xx[i+k]+b;
|
---|
| 194 |
|
---|
| 195 | // printf(" k=%d carte/fittee=%g \n",k,carte[bolo_carte-1][i+k]);
|
---|
| 196 |
|
---|
| 197 | if(dynamique<carte[bolo_carte-1][i+k]) dynamique=carte[bolo_carte-1][i+k];
|
---|
| 198 | if(dynamique<-carte[bolo_carte-1][i+k]) dynamique=-carte[bolo_carte-1][i+k];
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | ecritD( fenetre_annexe,cart_dynamique,"%g",dynamique);
|
---|
| 203 |
|
---|
| 204 | for(i=0;i<indice;i++)
|
---|
| 205 | {
|
---|
| 206 | couleur_degrade=1050+(50.*carte[bolo_carte-1][i]/dynamique);
|
---|
| 207 | // printf(" retrace : debut_ligne=%d i=%d : x=%g y=%g valeur=%g couleur=%d \n",debut_ligne,i,xx0,yy0,carte[8][i],couleur_degrade);
|
---|
| 208 | if(flag_sens[i]>0) rectangle(fenetre_annexe,xx[i]-0.25*pas,yy[i]-0.5*pas,xx[i]+0.25*pas,yy[i],couleur_degrade);
|
---|
| 209 | else rectangle(fenetre_annexe,xx[i]-0.25*pas,yy[i],xx[i]+0.25*pas,yy[i]+0.5*pas,couleur_degrade);
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 |
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 |
|
---|