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