[637] | 1 | #include "diabolo.h"
|
---|
| 2 | #include "bolo.h"
|
---|
| 3 | #include "auto.h"
|
---|
| 4 | #include "tm.h"
|
---|
| 5 |
|
---|
| 6 | //#define bon_type(j) ( (litD(fen,auto_thermo,0)&&(parametres.bolo_type[j]==0)) ou(litD(fen,auto_voie1,0)&&(parametres.bolo_type[j]==1)) ou(litD(fen,auto_voie2,0)&&(parametres.bolo_type[j]==2)) ou(litD(fen,auto_voie3,0)&&(parametres.bolo_type[j]==3)) )
|
---|
| 7 | #define bon_type(j) 1
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | int vg[nb_max_bolo]; // 0 ou vieux gain pour remonter le gain
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | //-------------------- fonction exec de la fenetre : auto -------------------------------
|
---|
| 14 |
|
---|
| 15 | void exec_auto(int fen,int item,double valeur,...)
|
---|
| 16 | {
|
---|
| 17 | int j;
|
---|
| 18 | if(item>1000) item-=1000; // pour appeler le case pour tous les cara d'un edit texte
|
---|
| 19 |
|
---|
| 20 | switch(item)
|
---|
| 21 | {
|
---|
| 22 | case ouverture :
|
---|
| 23 | /* case auto_bolo_couleur :
|
---|
| 24 | case auto_bolo_couleur+1 :
|
---|
| 25 | case auto_bolo_couleur+2 :
|
---|
| 26 | case auto_bolo_couleur+3 :
|
---|
| 27 | case auto_bolo_couleur+4 :
|
---|
| 28 | case auto_bolo_couleur+5 :
|
---|
| 29 | case auto_bolo_couleur+6 :
|
---|
| 30 | case auto_bolo_couleur+7 :
|
---|
| 31 | case auto_bolo_couleur+8 :
|
---|
| 32 | case auto_bolo_couleur+9 :
|
---|
| 33 | case auto_bolo_couleur+10 :
|
---|
| 34 | case auto_bolo_couleur+11 :
|
---|
| 35 | case auto_bolo_couleur+12 :
|
---|
| 36 |
|
---|
| 37 | for(i=0;i<max_couleur;i++)
|
---|
| 38 | {
|
---|
| 39 | bolo_couleur[i]=litD(fen,auto_bolo_couleur+i,0L);
|
---|
| 40 | if( (bolo_couleur[i]<1) ou (bolo_couleur[i]>nb_max_bolo) ) bolo_couleur[i]=0;
|
---|
| 41 | printf(" i=%d bolo=%d ",i,bolo_couleur[i]);
|
---|
| 42 | }
|
---|
| 43 | printf("\n");
|
---|
| 44 | */ break;
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | case caseferme : cache(fen); infos(fen)->action=0; break;
|
---|
| 50 |
|
---|
| 51 | case auto_tout_auto :
|
---|
| 52 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 53 | if( fenetre(j+1) && (!litD(j+1,b_bloq,0L)) && bon_type(j) )
|
---|
| 54 | {ecritD(j+1,b_auto,1);auto_control(j,auto_force);}
|
---|
| 55 | break;
|
---|
| 56 |
|
---|
| 57 | case auto_rien_auto :
|
---|
| 58 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 59 | if( fenetre(j+1) && (!litD(j+1,b_bloq,0L)) && bon_type(j))
|
---|
| 60 | ecritD(j+1,b_auto,0);
|
---|
| 61 | break;
|
---|
| 62 |
|
---|
| 63 | case auto_transitoire_auto :
|
---|
| 64 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 65 | if( fenetre(j+1) && (!litD(j+1,b_bloq,0L)) && bon_type(j) )
|
---|
| 66 | exec_bolo(j+1,b_auto_trans,0);
|
---|
| 67 | break;
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | case auto_fixe_gain :
|
---|
| 71 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 72 | if( fenetre(j+1) && bon_type(j))
|
---|
| 73 | if(!litD(j+1,b_bloq,0L)) exec_bolo(j+1,b_gain,litD(fen,auto_gain,0L));
|
---|
| 74 | break;
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | case auto_fixe_courant :
|
---|
| 78 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 79 | if( fenetre(j+1) && bon_type(j))
|
---|
| 80 | if(!litD(j+1,b_bloq,0L)) exec_bolo(j+1,b_tri,litD(fen,auto_courant,0L));
|
---|
| 81 | break;
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | case auto_auto_val : break;
|
---|
| 85 | case auto_gain : break;
|
---|
| 86 | default : break;
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | void auto_transitoire(int bolo,int ct)
|
---|
| 92 | {
|
---|
| 93 | int i;
|
---|
| 94 | double a,tt,dd;
|
---|
| 95 | int n=gg->reglage.horloge.nb_mesures;
|
---|
| 96 | static double coef[nb_max_bolo]={0,0};
|
---|
| 97 | static double val_p[nb_max_bolo];
|
---|
| 98 | def_gains
|
---|
| 99 | if(ct%4!=0) return;
|
---|
| 100 |
|
---|
| 101 | if(coef[0]==0) for(i=0;i<nb_max_bolo;i++) coef[i]=0.05;
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | tt=0;for(i=0;i<n;i++)
|
---|
| 105 | {
|
---|
| 106 | a=(double) ((gg->bol_per[bolo-1][i]&0x7fff)-0x4000); // 16 bit utiles dans gg->bol_per
|
---|
| 107 | // FONCTION : 3 -1 -1 -1 -3 1 1 1
|
---|
| 108 | switch(8*i/n)
|
---|
| 109 | {
|
---|
| 110 | case 0 : tt += 3*a; break;
|
---|
| 111 | case 1 : tt -= a; break;
|
---|
| 112 | case 2 : tt -= a; break;
|
---|
| 113 | case 3 : tt -= a; break;
|
---|
| 114 | case 4 : tt -= 3*a; break;
|
---|
| 115 | case 5 : tt += a; break;
|
---|
| 116 | case 6 : tt += a; break;
|
---|
| 117 | case 7 : tt += a; break;
|
---|
| 118 | default : break;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | tt/=0.01*(double)parametr.bolo[bolo-1].bolo_gain*gain_ampli(gg->reglage.bolo[bolo-1]);
|
---|
| 122 |
|
---|
| 123 | printf("transitoire auto ct=%d bolo %d : ",ct,bolo);
|
---|
| 124 | printf(" valeur tt=%g ",tt);
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | if(ct==16) // premiere mesure en 20 : change le coef en 16
|
---|
| 128 | {
|
---|
| 129 | double rr;
|
---|
| 130 | /* correction faite = ( tt - val_p[bolo-1] )
|
---|
| 131 | correction qu'il falait faire = - val_p[bolo-1]
|
---|
| 132 |
|
---|
| 133 | la correction en valeur de dac faite = val_p[bolo-1] * coef[bolo-1]
|
---|
| 134 |
|
---|
| 135 | la correction dac qu'il aurait fallu faire val_p[bolo-1] * coef[bolo-1] * (- val_p[bolo-1]) / ( tt - val_p[bolo-1] )
|
---|
| 136 | */
|
---|
| 137 | if(val_p[bolo-1] -tt ) rr = ( val_p[bolo-1]) / ( val_p[bolo-1]-tt );
|
---|
| 138 | if(rr<0.2) rr=0.2;
|
---|
| 139 | if(rr>4) rr=4;
|
---|
| 140 | coef[bolo-1]= coef[bolo-1] * rr;
|
---|
| 141 | printf(" calcul du coef = coef=%g \n", coef[bolo-1]);
|
---|
| 142 |
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | val_p[bolo-1]=tt;
|
---|
| 147 | //dd=(double)gg->reglage.dac[d_trans][bolo-1] + tt * coef[bolo-1] ; // nouvelle valeur de transitoire
|
---|
| 148 | dd=(double)dac_T(gg->reglage.bolo[bolo-1]) + tt * coef[bolo-1] ; // nouvelle valeur de transitoire
|
---|
| 149 |
|
---|
| 150 | while( (dd<-10) ou (dd>4010) ) {coef[bolo-1]*=0.8;dd=(double)dac_T(gg->reglage.bolo[bolo-1]) + tt * coef[bolo-1] ;}
|
---|
| 151 |
|
---|
| 152 | printf(" coef=%g : valeur nouvelle du DAC =%g \n",coef[bolo-1],dd);
|
---|
| 153 |
|
---|
| 154 | exec_bolo(bolo,b_trans,dd);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | int test_saturation(int bolo)
|
---|
| 160 | {
|
---|
| 161 | int i,sat;
|
---|
| 162 | int n=gg->reglage.horloge.nb_mesures;
|
---|
| 163 |
|
---|
| 164 | sat=0;for(i=0;i<n;i++)
|
---|
| 165 | {
|
---|
| 166 | if ( ((gg->bol_per[bolo-1][i]&0x7fff)<0x400)
|
---|
| 167 | ou ((gg->bol_per[bolo-1][i]&0x7fff)>0x7c00) ) sat++;// 16 bit utiles dans gg->bol_per
|
---|
| 168 | }
|
---|
| 169 | return(sat);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | void auto_control(int bolo,int mode) // voir les modes
|
---|
| 176 | {
|
---|
| 177 | static int ct[nb_max_bolo],cg[nb_max_bolo]; // static compteur pour changement carre et gain auto
|
---|
| 178 | static int at[nb_max_bolo]; // attente pour ne pas changer plusieurs fois a la suite
|
---|
| 179 | double nseuil;
|
---|
| 180 | double y;int yi;
|
---|
| 181 | int cc;
|
---|
| 182 | double r,coef; // point convert. / µV
|
---|
| 183 | def_gains;
|
---|
| 184 | //printf("autocontrole de bolo%d en mode %d \n",bolo,mode);
|
---|
| 185 |
|
---|
| 186 | coef=pt_micV(bolo); // point convert. / µV
|
---|
| 187 | coef=coef*litD(fenetre_auto,auto_correct,0L); // correction augmentée artificiellement
|
---|
| 188 | nseuil=litD(fenetre_auto,auto_auto_val,0L); // seuil defini dans la fenetre violette
|
---|
| 189 | cc=xbolbrut(bolo-1)*coef; // correction exacte
|
---|
| 190 |
|
---|
| 191 | if( (ct[bolo-1]>10) ou (ct[bolo-1]<-10) ) {ct[bolo-1]=0;cg[bolo-1]=0;} // initialisation si n'importe quoi
|
---|
| 192 | if( (at[bolo-1]>20) ou (at[bolo-1]<0) ) at[bolo-1]=0; // initialisation si n'importe quoi
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 | //____________ test de depassement : change ct ++ ou -- : change le carré si ct > 2 en module
|
---|
| 196 |
|
---|
| 197 | if (xbolbrut(bolo-1)>nseuil) ct[bolo-1]++;
|
---|
| 198 | else {
|
---|
| 199 | if (xbolbrut(bolo-1)<-nseuil) ct[bolo-1]--;
|
---|
| 200 | else ct[bolo-1]=0;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | //printf("bolo %d : moyenne=%g valeur=%g ct=%d cg=%d \n",bolo,gg->xx[bolo-1][1],gg->xx[bolo-1][0],ct[bolo-1],cg[bolo-1]);
|
---|
| 205 |
|
---|
| 206 | //_____________ action de correction
|
---|
| 207 |
|
---|
| 208 | if(((longueur_table_tm+tt->tm.pos_ecrit-tt->tm.pos_lit)%longueur_table_tm)>2) return;
|
---|
| 209 |
|
---|
| 210 | if ( (litD(fenetre_auto,auto_verouille,0)==1) && gg->scan_en_cours && (mode==auto_val) ) return; // pas de corrections pendant le scan
|
---|
| 211 | if ( (litD(fenetre_auto,auto_verouille,0)==2) && (gg->don.sync[sync_subscan] && gg->don.sync[sync_scan]) && (mode==auto_val) ) return; // pas de corrections pendant les subscan
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 | if(litD(bolo,b_bloq,0L)) return; // sort si blocqué
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | if(test_saturation(bolo)>5) //***************************** baisse le gain si sature
|
---|
| 219 | {
|
---|
| 220 | printf("bolo %d sature (sat=%d) cg=%d \n",bolo,test_saturation(bolo),cg[bolo-1]);
|
---|
| 221 | if(!vg[bolo-1]) vg[bolo-1]=gainbrut(gg->reglage.bolo[bolo-1]);
|
---|
| 222 | cg[bolo-1]++;
|
---|
| 223 | at[bolo-1]=5; // ne va pas changer le carre avant 5 sec
|
---|
| 224 | if(cg[bolo-1]>2)
|
---|
| 225 | {
|
---|
| 226 | yi=gainbrut(gg->reglage.bolo[bolo-1]);
|
---|
| 227 | if (yi>=16) yi=yi&3;
|
---|
| 228 | yi--;
|
---|
| 229 | if(yi<0) yi=0;
|
---|
| 230 | // exec_bolo(bolo,b_gain,yi);
|
---|
| 231 | ecritD(bolo,b_gain,yi);ecritgain(bolo);
|
---|
| 232 | cg[bolo-1]=0;
|
---|
| 233 | son(130);
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 | if(at[bolo-1]) {at[bolo-1]--;return;}
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | if( (mode==auto_carre) ou (mode==auto_force) ou (ct[bolo-1]>2) ou (ct[bolo-1]<-2) )//************************* change le carre
|
---|
| 242 | {
|
---|
| 243 | at[bolo-1]=5; // attend 5 coups avant de changer une seconde fois // change le carre apres 3 fois depassement
|
---|
| 244 | if( (r=litD(bolo,b_auto_R,0L)) ==0 )
|
---|
| 245 | {
|
---|
| 246 | y=(double)dac_V(gg->reglage.bolo[bolo-1])-cc;
|
---|
| 247 | exec_bolo(bolo,b_carre,y);
|
---|
| 248 | }
|
---|
| 249 | else // ************ mesure a resistance donnee
|
---|
| 250 | {
|
---|
| 251 | cc=cc*2; // correction double pour converger plus vite
|
---|
| 252 | y=(double)dac_V(gg->reglage.bolo[bolo-1])-cc; // nouvelle valeur de tension
|
---|
| 253 | exec_bolo(bolo,b_carre,y);
|
---|
| 254 |
|
---|
| 255 | r = 1e-6 * ( y / pt_micV(bolo) ) /r ; // y/pt_micV donne des microvolts
|
---|
| 256 | // I = V / R (V en volt, R en MOhm) -> I en µA
|
---|
| 257 |
|
---|
| 258 | printf(" carre=%g I=V/r =%g nA ",y,r*1000); // V en pts, I en nA
|
---|
| 259 |
|
---|
| 260 | r *= pt_micA(bolo); // changement i en valeur triangle
|
---|
| 261 | printf(" triangle=%g \n",r);
|
---|
| 262 | exec_bolo(bolo,b_tri,r);
|
---|
| 263 | }
|
---|
| 264 | ct[bolo-1]=0;
|
---|
| 265 | son(130);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | //if(bolo==3) printf(" vg=%d at=%d \n",vg[bolo-1],at[bolo-1]);
|
---|
| 269 | if(at[bolo-1]) return;
|
---|
| 270 |
|
---|
| 271 | if(vg[bolo-1]) // ********************* remonte le gain
|
---|
| 272 | {
|
---|
| 273 | yi=gainbrut(gg->reglage.bolo[bolo-1]);
|
---|
| 274 | if (yi>=16) yi=yi&3;
|
---|
| 275 | if(yi>=vg[bolo-1]) vg[bolo-1]=0;
|
---|
| 276 | else {
|
---|
| 277 | // exec_bolo(bolo,b_gain,yi+1);
|
---|
| 278 | printf("remonte gain\n");
|
---|
| 279 | ecritD(bolo,b_gain,yi+1);ecritgain(bolo);
|
---|
| 280 | son(130);
|
---|
| 281 | at[bolo-1]=5; // attend 5 coups avant de rechanger le carre ou le gain
|
---|
| 282 | }
|
---|
| 283 | cg[bolo-1]=0;
|
---|
| 284 | son(130);
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 |
|
---|
| 293 | //-----------------------------------------------------------------------------------------
|
---|
| 294 | //-----------------------------------------------------------------------------------------
|
---|
| 295 | //-------------------- fonction exec de la fenetre : automatismes -------------------
|
---|
| 296 | //-----------------------------------------------------------------------------------------
|
---|
| 297 | //-----------------------------------------------------------------------------------------
|
---|
| 298 |
|
---|
| 299 |
|
---|
| 300 |
|
---|
| 301 | void exec_automatismes(int fen,int item,double valeur,...)
|
---|
| 302 | {
|
---|
| 303 | int i,a;
|
---|
| 304 | long ll;
|
---|
| 305 | if(item>0) for(i=0;i<nombre_de_voies;i++)
|
---|
| 306 | {
|
---|
| 307 | ll=(long)(&(gg->reglage.autom[i].mode))-(long)(&(gg->reglage.autom[0]));
|
---|
| 308 | a=litD(fenetre_automatismes,atm_auto+i,0L)-1;
|
---|
| 309 | if( (a!=gg->reglage.autom[i].mode) ou ( /*clavier(touche_alt) et*/ (item==atm_auto+i) ) )
|
---|
| 310 | emission_tc_reduite(tc2_auto_bolo,ll,a);
|
---|
| 311 |
|
---|
| 312 | ll=(long)(&(gg->reglage.autom[i].gain))-(long)(&(gg->reglage.autom[0]));
|
---|
| 313 | a=litD(fenetre_automatismes,atm_gain+i,0L)-1+20;
|
---|
[643] | 314 | if( (a!=gg->reglage.autom[i].gain) ou ( /*clavier(touche_alt) et*/ (item==atm_gain+i) ) )
|
---|
[637] | 315 | emission_tc_reduite(tc2_auto_bolo,ll,a);
|
---|
| 316 |
|
---|
| 317 | ll=(long)(&(gg->reglage.autom[i].courant))-(long)(&(gg->reglage.autom[0]));
|
---|
| 318 | a=litD(fenetre_automatismes,atm_courant+i,0L)-1;
|
---|
[643] | 319 | if( (a!=gg->reglage.autom[i].courant) ou ( /*clavier(touche_alt) et*/ (item==atm_courant+i) ) )
|
---|
[637] | 320 | emission_tc_reduite(tc2_auto_bolo,ll,a);
|
---|
| 321 |
|
---|
| 322 | ll=(long)(&(gg->reglage.autom[i].delai))-(long)(&(gg->reglage.autom[0]));
|
---|
| 323 | a=litD(fenetre_automatismes,atm_delai+i,0L);
|
---|
[643] | 324 | if( (a!=gg->reglage.autom[i].delai) ou ( /*clavier(touche_alt) et*/ (item==atm_delai+i) ) )
|
---|
[637] | 325 | emission_tc_reduite(tc2_auto_bolo,ll,a);
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 |
|
---|