Code covered by the BSD License  

Highlights from
Logiciels temps réel

Logiciels temps réel

by

 

Real-time software concerning the domains of the signal processing, feedback and regulation

lance_modele_les_2.m
function [MOG,DEF,G]=lance_modele_les_2(MOGi,DEFi,Gi)


MOG=MOGi;
DEF=DEFi;
G=Gi;
% On efface ventuellement le bouton STOP
if MOG(10,2)~=0
    delete(MOG(10,2));
    MOG(10,2)=0;
end;
repertoire=pwd;
cd ..
A=load('parametres_carte.mat');
cd(repertoire)
etat=get_param(gcs,'simulationstatus');
if strcmp(etat,'stopped')
      modele=get_param(gcs,'name');
    if DEF(5)    %*******synchro*********
        constante=[modele,'/Constant9'];
        set_param(constante,'value','1');
        niveau=get(MOG(1,4),'string');
        DEF(6)=str2double(niveau);
        constante=[modele,'/Constant8'];
        set_param(constante,'value',niveau);
        sens=get(MOG(1,5),'string');
        DEF(7)=str2double(sens);
        constante=[modele,'/Constant7'];
        set_param(constante,'value',sens);
        retard=[modele,'/Bloc_synchro/Unit Delay'];
        if DEF(7)>0
            set_param(retard,'X0',num2str(A.S.entree.val_max));
        else
            set_param(retard,'X0',num2str(A.S.entree.val_min));
        end;
        set_param(gcs,'extmodetrigtype','signal')
        set_param(gcs,'extmodetrigport','1')
         set_param(gcs,'extmodetrigdirection','rising')
        set_param(gcs,'extmodetriglevel','0.5')
    
    else
        constante=[modele,'/Constant9'];
        set_param(constante,'value','0');
        set_param(gcs,'extmodetrigtype','manual')
    end;   
    calibre_y=[2,1,0.5,0.2,0.1,0.05,0.02,1];
    for k=1:1:DEF(1)
            cal_y=get(MOG(1+k,2),'value');
            if cal_y==1
                cal_y=9;
            end;
            if cal_y~=9
                G(k)=1/calibre_y(cal_y-1);
                bloc=[get_param(gcs,'name'),'/Gain'];
                if k~=1
                    bloc=[bloc,num2str(k-1)];
                end;
                set_param(bloc,'Gain',num2str(G(k)));
            end;
    end;
    bdt=[20e-3,50e-3,0.1,0.2,0.5,1,2,5,10,20];
    cal_bdt=get(MOG(1,2),'value')-1;
    if cal_bdt<=5
        DEF(4)=1e-3;
    else
        DEF(4)=50e-3;
    end;
    if cal_bdt==1
        DEF(2)=1;
        DEF(3)=1001;
    else
        DEF(2)=bdt(cal_bdt)*20;
        DEF(3)=DEF(2)/DEF(4)+1;
    end;
    set_param(gcs,'fixedstep',num2str(DEF(4)))
    set(MOG(6,1),'Xlim',[0,DEF(2)])
    oscillo=[modele,'/Scope'];
    set_param(oscillo,'timerange',num2str(DEF(2)));
    set_param(oscillo,'sampletime',num2str(DEF(4)));
    for k=1:1:9
     
            constante=[modele,'/Constant',num2str(k)];
            set_param(constante,'sampletime',num2str(DEF(4)));
      
    end;
    constante1=[modele,'/Constant1'];
    set_param(constante1,'value',num2str(DEF(3)));
    filtre=[modele,'/Filtre'];
    set_param(filtre,'te',num2str(DEF(4)));
    for k=2:1:4
        filtre=[modele,'/Filtre',num2str(k-1)];
        set_param(filtre,'te',num2str(DEF(4)));
    end;
    bloc=[modele,'/Bloc_synchro'];
    set_param(bloc,'te',num2str(DEF(4)));
    for k=1:1:3
        bloc=[modele,'/Analog Input'];
        if k~=1
            bloc=[bloc,num2str(k-1)];
        end;
        set_param(bloc,'sampletime',num2str(DEF(4)));
    end;
    for k=1:1:DEF(1)
        v=get(MOG(12,2+k),'value');
        if v==3
            Nb=get(MOG(11,2+k),'string');
        else
            Nb='1';
        end;
        filtre=[modele,'/Filtre'];
        if k~=1
            filtre=[filtre,num2str(k-1)];
        end;
        set_param(filtre,'N',Nb);
    end;
    bloc=[modele,'/Modele'];
 %******************************************
 % Lecture de NUM et DEN
 %****************************************
    sn=get(MOG(6,7),'string');
    sd=get(MOG(8,7),'string');
    if sn(end)~=';'
        sn=[sn,';'];
    end;
    if sd(end)~=';'
        sd=[sd,';'];
    end;
    test1=findstr(sn,'NUM=');
    if isempty(test1)
        MOG(9,7)=uicontrol(gcf,'style','text',...
            'unit','normalized',...
           'position',[0.1 0.5 0.8 0.05],...
           'backgroundcolor','w',...
           'foregroundcolor','r',...
           'string','DEFINIR LES COEFFICIENTS PAR NUM=...',...
           'fontunits','normalized','fontsize',0.5,'fontweight','bold');
        pause(5)
        delete(MOG(9,7)); 
        return;
    else
        try
            eval(sn);
        catch
            MOG(9,7)=uicontrol(gcf,'style','text',...
                'unit','normalized',...
                'position',[0.1 0.5 0.8 0.05],...
                'backgroundcolor','w',...
                 'foregroundcolor','r',...
                 'string','ERREUR DE PROGRAMMATION !',...
                 'fontunits','normalized','fontsize',0.5,'fontweight','bold'); 
            pause(5)
            delete(MOG(9,7)); 
            return;
        end;
    end;
    test2=findstr(sd,'DEN=');
    if isempty(test2)
        MOG(10,7)=uicontrol(gcf,'style','text',...
            'unit','normalized',...
             'position',[0.1 0.3 0.8 0.05],...
             'backgroundcolor','w',...
             'foregroundcolor','r',...
             'string','DEFINIR LES COEFFICIENTS PAR DEN=...',...
             'fontunits','normalized','fontsize',0.5,'fontweight','bold');
        pause(5)
        delete(MOG(10,7)); 
        return;
    else
        try
            eval(sd);
        catch
            MOG(10,7)=uicontrol(gcf,'style','text',...
                'unit','normalized',...
                'position',[0.1 0.3 0.8 0.05],...
                'backgroundcolor','w',...
                 'foregroundcolor','r',...
                 'string','ERREUR DE PROGRAMMATION !',...
                 'fontunits','normalized','fontsize',0.5,'fontweight','bold'); 
            pause(5)
            delete(MOG(10,7)); 
            return;
        end;
    end;
% Transformation T(p) en H(z)    
    H=tf(NUM,DEN);
    Hd=c2d(H,DEF(4),'tustin');
    [NUMZ,DENZ]=tfdata(Hd,'v');
    set_param(bloc,'NUMZ',['[',num2str(NUMZ,'%24.15e'),']']);
    set_param(bloc,'DENZ',['[',num2str(DENZ,'%24.15e'),']']);
% Lecture valeur initiale    
       VI=get(MOG(4,7),'string');
       set_param(bloc,'VI',VI)
% Affichage T(p) dans bloc analogique       
    set_param(bloc,'NUM',['[',num2str(NUM),']']);
    set_param(bloc,'DEN',['[',num2str(DEN),']']);
    bloc_vi=[bloc,'/Constant'];
    set_param(bloc_vi,'sampletime',num2str(DEF(4)));
% lecture du retard    
    bloc=[modele,'/Retard'];
    R=get(MOG(2,7),'string');
    set_param(bloc,'T',R);
    VO=get(MOG(10,7),'string');
    set_param(bloc,'VO',VO)
    bloc_vo=[bloc,'/Constant'];
    set_param(bloc_vo,'sampletime',num2str(DEF(4)));
    bloc=[modele,'/Transport Delay'];
% lecture valeur initiale sortie      
      set_param(bloc,'InitialOutput',VO);
       set_param(bloc,'DelayTime',R);
  
    if faut_il_recompiler
                 MOG(7,1)=uicontrol(MOG(1,6),'style','text',...
                     'unit','normalized',...
		            'position',[0.1,0.01,0.8,0.05],...
                    'backgroundcolor','w',...
	                'foregroundcolor','r',...
                    'fontunits','normalized','fontsize',0.4,'fontweight','bold',...
                    'string','COMPILATION EN COURS');
                rtwbuild(gcs);
                delete(MOG(7,1))
    end;
    set_param(gcs,'SimulationCommand','connect');  
end;


for k=1:1:min(DEF(1),4)
    y1=0.26;
    y2=0.23;
    d=1;
   
   p_p=[0.175*(k-d)+0.125,y1,0.05,0.03]; 
   cal_y=get(MOG(1+k,2),'value');
   if cal_y==9
        MOG(7,2+k)=uicontrol(MOG(1,6),'style','push',...
            'unit','normalized','position',p_p,'userdata',k,...
             'backgroundcolor','w','string','+10%',...
             'foregroundcolor','r',...
             'fontunits','normalized','fontsize',0.5,'fontweight','bold',...
             'callback','K=get(gco,''userdata'');G=regle_gain(7,K,G);'); 
        p_p=[0.175*(k-d)+0.125,y2,0.05,0.03]; 
        MOG(8,2+k)=uicontrol(MOG(1,6),'style','push',...
            'unit','normalized','position',p_p,'userdata',k,...
             'backgroundcolor','w','string','-10%',...
             'foregroundcolor','r',...
             'fontunits','normalized','fontsize',0.5,'fontweight','bold',...
             'callback','K=get(gco,''userdata'');G=regle_gain(8,K,G);');   
        p_p=[0.175*(k-d)+0.175,y1,0.05,0.03]; 
        MOG(9,2+k)=uicontrol(MOG(1,6),'style','push',...
            'unit','normalized','position',p_p,'userdata',k,...
            'backgroundcolor','w','string','+0,5%',...
            'foregroundcolor','r',...
            'fontunits','normalized','fontsize',0.5,'fontweight','bold',...
             'callback','K=get(gco,''userdata'');G=regle_gain(9,K,G);'); 
        p_p=[0.175*(k-d)+0.175,y2,0.05,0.03]; 
        MOG(10,2+k)=uicontrol(MOG(1,6),'style','push',...
            'unit','normalized','position',p_p,'userdata',k,...
             'backgroundcolor','w','string','-0,5%',...
             'foregroundcolor','r',...
             'fontunits','normalized','fontsize',0.5,'fontweight','bold',...
             'callback','K=get(gco,''userdata'');G=regle_gain(10,K,G);');
         p_p=[0.175*(k-d)+0.075,0.23,0.05,0.03];
        MOG(5+k,2)=uicontrol(MOG(1,6),'style','text',...
            'unit','normalized','position',p_p,...
            'backgroundcolor','w','string','Calibre',...
            'foregroundcolor','b',...
            'fontunits','normalized','fontsize',0.5,'fontweight','bold');
   else
       if MOG(7,2+k)~=0
           for kp=7:1:10
                delete(MOG(kp,2+k))
                MOG(kp,2+k)=0;
           end;
            p_p=[0.175*(k-d)+0.05,0.23,0.05,0.03];
        MOG(5+k,2)=uicontrol(MOG(1,6),'style','text',...
            'unit','normalized','position',p_p,...
             'backgroundcolor','w','string','Calibre',...
             'foregroundcolor','w',...
             'fontunits','normalized','fontsize',0.5,'fontweight','bold');
       end;
   end;
   MOG(7,1)=uicontrol(MOG(1,6),'style','text',...
       'unit','normalized',...
		'position',[0.1,0.01,0.8,0.05],...
        'backgroundcolor','w',...
	    'foregroundcolor','r',...
        'fontunits','normalized','fontsize',0.4,'fontweight','bold',...
        'string','POUR LANCER L''ENREGISTREMENT APPUYER SUR LA BARRE ESPACE');          
end;



Contact us