Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

State space identification

State space identification

Hi,

I'm working on the design of linear optimal controller for Modelica-based systems.
In order to do that, I need to get a linearized model of my system which is modeled using OpenModelica.
I want to get the state-space representation of this model.

I would like to know if it is a way to get all dynamic equations of my Modelica model (created using the Standard Library) or link OpenModelica with symbolic solver softwares like Maxima.

Another question: I am using Scilab for designing my optimal controller. Is it possible to link the OM compiler and Scilab (I know there is the OpenModelica Toolbox for Scilab which only works on Linux OS but I am using Windows!)

Thanks in advance for your replies.

Best,
DC

Re: State space identification

Hi,

Actually, you can just generate a linearize model of your OpenModelica model on every point in time you want.
The only thing is that it isn't activated by default, so you need to activate a flag.
You can do it like that:

Code:


setCommandLineOptions("+d=linearization");
loadFile("VanDerPol.mo");
buildModel(VanDerPol);
system("./VanDerPol -l 0");

With that code you will get a linearized model to point in time "0" in your directory.
The model will called "linear_VanDerPol.mo".
This model could be loaded to OpenModelica and used for your controller.

Regarding your Scilab issues I have no idea.


so long.
Willi

Re: State space identification

Hi,
Thank you for your reply.

I tried your proposal using my own model (I used the standard library) but the size of my C matrix seems to be null.
This maybe is because I didn't set any parameter as input or output.
In my model, input variables should be force1.f and force.f and outputs positionSensor.s and positionSensor1.s.

How can I set these parameters as input or output without setting the whole block as input or output (if I do this I get errors).
I tried to use the realinput/realoutput blocks but I can't connect them to the force.f port.

Thanks in advance.

Best,

Re: State space identification

Hi,

yes, you need set input and output variables for the top-level variables.
actually, parameter couldn't be input or output. you need to select some variable.
Maybe you need also to add additional variables for that.

so long.
Willi

Re: State space identification

Hi,

Thanks for your help.

Is it possible to write something like that ?

Code:


input Real u1;
...
Modelica.Mechanics.Translational.Sources.Force force1(useSupport = false);
...
connect(u1, force1.f);
...

A last question : is it possible to specify which variables should be set as my state vector?
I want to get A, B, C and D state matrixes where dX = AX+Bu // Y=CX+Du, and specify my X vector.

Thanks in advance,

Best,
DC

Re: State space identification

Hi,

I change my .mo file in order to specify my states and my input/output.
Here is the code:

Code:

class Systeme_MRA3 "Systeme_MRA3.mo"

  input Real u1(start = 2);
  input Real u2(start = 10);
  output Real y1;
  output Real y2;
  Real x1(stateSelect = StateSelect.always);
  Real x2(stateSelect = StateSelect.always);
  Real x3(stateSelect = StateSelect.always);
  Real x4(stateSelect = StateSelect.always);
  annotation(Diagram());
  Modelica.Mechanics.Translational.Sources.Force force1(useSupport = false) annotation(Placement(visible = true, transformation(origin = {-61,1}, extent = {{-10,-10},{10,10}}, rotation = 0)));
  Modelica.Mechanics.Translational.Sources.Force force(useSupport = true) annotation(Placement(visible = true, transformation(origin = {-61,-69}, extent = {{-10,-10},{10,10}}, rotation = 0)));
  Modelica.Mechanics.Translational.Components.Fixed fixed annotation(Placement(visible = true, transformation(origin = {-6,81}, extent = {{10,10},{-10,-10}}, rotation = 180)));
  Modelica.Mechanics.Translational.Components.SpringDamper springDamper(stateSelect = StateSelect.never, s_nominal = 0.1, c = 5, d = 1300, s_rel0 = 0) annotation(Placement(visible = true, transformation(origin = {-6,51}, extent = {{-10,10},{10,-10}}, rotation = 270)));
  Modelica.Mechanics.Translational.Components.SpringDamper springDamper1(stateSelect = StateSelect.never, s_nominal = 0.1, c = 3, d = 1000, s_rel0 = 0) annotation(Placement(visible = true, transformation(origin = {-6,-29}, extent = {{-10,10},{10,-10}}, rotation = 270)));
  Modelica.Mechanics.Translational.Components.Mass mass(m = 120, stateSelect = StateSelect.never, L = 0.2) annotation(Placement(visible = true, transformation(origin = {-6,11}, extent = {{-10,10},{10,-10}}, rotation = 270)));
  Modelica.Mechanics.Translational.Components.Mass mass1(m = 70, stateSelect = StateSelect.never, L = 0.2) annotation(Placement(visible = true, transformation(origin = {-6,-59}, extent = {{-10,10},{10,-10}}, rotation = 270)));
  Modelica.Mechanics.Translational.Sensors.PositionSensor positionSensor annotation(Placement(visible = true, transformation(origin = {49,-4}, extent = {{10,10},{-10,-10}}, rotation = 180)));
  Modelica.Mechanics.Translational.Sensors.PositionSensor positionSensor1 annotation(Placement(visible = true, transformation(origin = {44,-74}, extent = {{10,10},{-10,-10}}, rotation = 180)));

equation
  connect(positionSensor1.flange,mass1.flange_b) annotation(Line(points = {{54,-74},{29,-74},{-6,-74},{-6,-69}}));
  connect(positionSensor.flange,mass.flange_b) annotation(Line(points = {{59,-4},{34,-4},{-6,-4},{-6,1}}));
  connect(force.flange,mass1.flange_b) annotation(Line(points = {{-51,-69},{-6,-69}}));
  connect(mass1.flange_a,springDamper1.flange_b) annotation(Line(points = {{-6,-49},{-6,-39}}));
  connect(force1.flange,mass.flange_b) annotation(Line(points = {{-51,1},{-6,1}}));
  connect(mass.flange_b,springDamper1.flange_a) annotation(Line(points = {{-6,1},{-6,-19}}));
  connect(springDamper.flange_b,mass.flange_a) annotation(Line(points = {{-6,41},{-6,21}}));
  connect(force.support,springDamper1.flange_a) annotation(Line(points = {{-61,-79},{-59,-79},{-59,-19},{-6,-19}}));
  connect(fixed.flange,springDamper.flange_a) annotation(Line(points = {{-6,81},{-6,61}}));
  force.f = u1;
  force1.f = u2;
  y1 = positionSensor.s;
  y2 = positionSensor1.s;
  x1 =  positionSensor.s;
  x2 = positionSensor1.s;
  x3 = der(positionSensor.s);
  x4 = der(positionSensor1.s);
end Systeme_MRA3;

The simulation runs perfectly, but when I linearize my model using the "-l 0" arguments, I get the following state matrix:

Code:


model linear_Systeme_MRA3
  parameter Integer n = 4; // states
  parameter Integer k = 2; // top-level inputs
  parameter Integer l = 2; // top-level outputs
  parameter Real x0[4] = {0,0,0,0};
  parameter Real u0[2] = {0,0};
  parameter Real A[4,4] = [1.654246805958327e-307,7.000521832679948e-307,3.097696738820614e-317,0;0,7.435092989896573e-307,0,2.121995790965272e-314;0,0,1.086461844974219e-311,0;0,3.13092364163473e-317,0,7.050757112236943e-307];
  parameter Real B[4,2] = [1.653832599999293e-307,NaN;NaN,NaN;8.487983163367024e-314,NaN;NaN,7.0885689109885e-251];
  parameter Real C[2,4] = [1.653832592379931e-307,0,0,0;0,0,0,0];
  parameter Real D[2,2] = [2.54639495098637e-313,0;0,0];
  Real x[4](start=x0);
  input Real u[2](start= u0);
  output Real y[2];

  Real x_Px1 = x[1];
  Real x_Px2 = x[2];
  Real x_Px3 = x[3];
  Real x_Px4 = x[4];
    Real u_Pu1 = u[1];
  Real u_Pu2 = u[2];
    Real y_Py1 = y[1];
  Real y_Py2 = y[2];
 
equation
  der(x) = A * x + B * u;
  y = C * x + D * u;
end linear_Systeme_MRA3;

I can see that there's something wrong because my C matrix should be [1,0,0,0;0,1,0,0].

What's wrong in my model?

Thanks for your reply.

Best regards,
DC

Re: State space identification

Hello dcasner,

which version of OpenModelica do you use?
If I linearize your model with the current trunk, I get following linear model:

Code:


model linear_Systeme_MRA3
  parameter Integer n = 4; // states
  parameter Integer k = 2; // top-level inputs
  parameter Integer l = 2; // top-level outputs
  parameter Real x0[4] = {0,0,0,0};
  parameter Real u0[2] = {0,0};
  parameter Real A[4,4] = [0,0,1,0;
0,0,0,1;
-0.06666666666666667,0.025,-19.16666666666667,8.333333333333334;
0.04285714285714286,-0.04285714285714286,14.28571428571429,-14.28571428571429];
  parameter Real B[4,2] = [0,0;0,0;
-0.008333333333333333,0.008333333333333333;
0.01428571428571429,0];
  parameter Real C[2,4] = [1,0,0,0;0,1,0,0];
  parameter Real D[2,2] = [0,0;0,0];
  Real x[4](start=x0);
  input Real u[2](start= u0);
  output Real y[2];

  Real x_Px1 = x[1];
  Real x_Px2 = x[2];
  Real x_Px3 = x[3];
  Real x_Px4 = x[4];
  Real u_Pu1 = u[1];
  Real u_Pu2 = u[2];
  Real y_Py1 = y[1];
  Real y_Py2 = y[2];
 
equation
  der(x) = A * x + B * u;
  y = C * x + D * u;
end linear_Systeme_MRA3;

so long.
Willi

There are 0 guests and 0 other users also viewing this topic