Strange error hybrid system?

8 posts / 0 new
Last post
janpeter
Offline
Joined: 2010-09-11
Strange error hybrid system?

Hi
I try to simulate a simple example to illustate the role of integrator anti wind-up, taken from Karl Johan Åström-
The process is continuous time and the PI-regulator is discrete time.
The simulatation works fine if I provide a DUMMY input signal to the block for the PID-regulator.
If the dummy variable is commented away the simiulation just becomes a straight line.
 
(Note, the anti-windup is illustrated by setting the ul and uh of the regulator to -0.1 and 0.1 the same as for the process).
 
I attach the appropriate files to run the simulation. I ran JModelica ver 1.8 in Windowx XP (in VBox 4.22 on a Mac 10.7.5).
 
I would appreciate your help.
 
Jan Peter
 
 

jakesson
Offline
Joined: 2009-03-14
Initial equations

Hi Jan-Peter
 
I can repeat the problem - I think that it is due to the use of the Signal connector class. If I replace instances of this class with Modelica.Blocks.Interfaces.RealInput and Modelica.Blocks.Interfaces.RealOutput, respectivly, then the model compiles also without the dummy input. This also has the benefit of eliminating the need for using var.val notation.
 
The profiles are still constant, however. The reason is that there are no initial equations generated, so even if the value process.x_0 is set in the FMU, it is not propagated to process.x upon initialization. If I set the value of the parameter process.x_0 to 0.0 in the Modelica code, I get more interesting curves, the wind-up seems to be working.
 
As for the first issue, I suggest that you go with the connectors in the Modelica Standard Library, this is the recommended way of modeling connectors. In the second case, we will have to look at this, this is a bug, meanwhile, I suggest you use the workaround above.
 
Best regards
/Johan

jakesson
Offline
Joined: 2009-03-14
Hi,   I checked the model

Hi,
 
I checked the model again, and verified that there is only one issue, issue 2. The fact that there are constant profiles is not due to issue 1 - if the script and model are kept intact except for the change of the change of process.x_0 in the Modelica code, things are working.
 
Never the less, I would suggest using the MSL RealInput/RealOutputs.
 
Best regards
/Johan 

janpeter
Offline
Joined: 2010-09-11
Good that we have identified

Good that we have identified a bug!
 
However, I am not sure I understand the scope of the bug nor the possible workaround.
To me it looks like that if I connect a discrete time system with a continuous time system, the initial state of the continuos time will not be set but reamin zero. Is that right - or an over-generalization?
 
The workaround you suggest is to just consider intial values equal to zero, right?
 
Would appreciate if you document the ticet for this bug here.
 
Do you plan to fix this bug by next update 1.9 due in about two weeks - or it need to wait?
 
Best regards
 
Jan Peter
 
 
 
 

janpeter
Offline
Joined: 2010-09-11
By the way, am I also

By the way, am I also uncertain about how to use Modelica.Blocks.Interface.RealInput and RealOutput, that you recomend.
 
1) Can these concepts be used both in Blocks and in Models?
 
2) For discrete time systems should I declare "discrete Modelica.Bloks.Interface.RealOutput"... of for some reason I do not need to declare discrete?
 
3) I see that I gain in convenience of notation -  but do I gain something else? speed?
 
Perhaps you could post the code?
 
Jan Peter
 
 
 
 

jakesson
Offline
Joined: 2009-03-14
RealInput/RealOutput
janpeter wrote:

By the way, am I also uncertain about how to use Modelica.Blocks.Interface.RealInput and RealOutput, that you recomend.
 
1) Can these concepts be used both in Blocks and in Models?
 
2) For discrete time systems should I declare "discrete Modelica.Bloks.Interface.RealOutput"... of for some reason I do not need to declare discrete?
 
3) I see that I gain in convenience of notation -  but do I gain something else? speed?
 
Perhaps you could post the code?
 
Jan Peter
 
 
 
 

janpeter wrote:

By the way, am I also uncertain about how to use Modelica.Blocks.Interface.RealInput and RealOutput, that you recomend.
1) Can these concepts be used both in Blocks and in Models?

Yes.
 

janpeter wrote:

2) For discrete time systems should I declare "discrete Modelica.Bloks.Interface.RealOutput"... of for some reason I do not need to declare discrete?
 

That is not necessary, the compiler automatically infer that variable assigned in when-statements have discrete variability.
 

janpeter wrote:

 
3) I see that I gain in convenience of notation -  but do I gain something else? speed?

It is mainly about clarity, and if you use RealInput/RealOutput in a graphical Modelica editor they come with icons.
 
 

janpeter wrote:

 
Perhaps you could post the code?
 

 
Here it comes:

package PID_regulators

 

    // Package for simulation of PID regulators.

 

    // Author: Jan Peter Axelsson

    // Created: 2012-10-31

    // Modified: 2012-10-31

 

    // Issues:

    // Problems with anti-windup in continuous time

    // Need also discrete time implementation

 

    connector Signal

        Real val;            // electrical signal

    end Signal;

    

    model ProcType

        Modelica.Blocks.Interfaces.RealInput u;

        Modelica.Blocks.Interfaces.RealOutput y;

        parameter Real x_0=1.0;

        Real x(start=x_0,fixed=true);

        Real upr;

    equation

        upr=if u<=-0.1 then -0.1 else (if u<0.1 then u else 0.1);

        der(x)=upr;

        y=x;      

    end ProcType;

        

    block PIDregType1

        Modelica.Blocks.Interfaces.RealInput y,yr,ul,uh;

        discrete Modelica.Blocks.Interfaces.RealOutput u;       

        parameter Real K=1.0;

        parameter Real Ti=1.0;

        parameter Real sample_interval=0.5;

        Real I(start=0,fixed=true);

        Real e,v;

    equation

        when sample(0,sample_interval) then

            e=yr-y;

            v=K*e+pre(I);

            u=if v<ul then ul else (if v<uh then v else uh); 

            I=pre(I)+K*e*sample_interval/Ti+u-v;

        end when;

    end PIDregType1;

 

    model test1

        PIDregType1 PIreg;

        ProcType process;

        parameter Real yr=1.0;

        parameter Real ulow=-0.1;

        parameter Real uhigh=0.1;

    equation

        connect(PIreg.u,process.u);

        connect(PIreg.y,process.y);

        PIreg.yr=yr;

        PIreg.ul=ulow;

        PIreg.uh=uhigh;

    end test1;

        

end PID_regulators;

 
 
 
Best regards
/Johan

jakesson
Offline
Joined: 2009-03-14
Initial equations
janpeter wrote:

Good that we have identified a bug!
 
However, I am not sure I understand the scope of the bug nor the possible workaround.
To me it looks like that if I connect a discrete time system with a continuous time system, the initial state of the continuos time will not be set but reamin zero. Is that right - or an over-generalization?
 
The workaround you suggest is to just consider intial values equal to zero, right?
 
Would appreciate if you document the ticet for this bug here.
 
Do you plan to fix this bug by next update 1.9 due in about two weeks - or it need to wait?
 
Best regards
 
Jan Peter
 
 
 
 

 
There is a bug in the code generation, which we are addressing, once there is a ticket, we'll post it in the thread. Surely, this fix will be included in JModelica.org-1.9, although we will have to push this release until the end of the year.
 
The workaround is to simply change the value of the parameter process.x_0 to 1.0 in the Modelica code, rather than in the Python, script.
 
Best regards
/Johan
 

janpeter
Offline
Joined: 2010-09-11
Good. I think I understand. /

Good. I think I understand. / Jan Peter

Login or register to post comments