modelicaderivativeopenmodelica

Why Modelica.Blocks.Continuous.Derivative input can't take Modelica.Blocks.Sources.CombiTimeTable as input?


I'm new to Modelica.

I did this with OpenModelica Connection Editor.

graph

with the following code

model chariot_portique
  Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint, table = [0, 0; 4, 3; 8, 3; 12, 0; 16, 0; 20, -3; 24, -3; 28, 0], tableOnFile = false) annotation(
    Placement(transformation(extent = {{-80, 20}, {-60, 40}})));
  Modelica.Blocks.Continuous.Derivative derivative(T = 1, k = 1)  annotation(
    Placement(visible = true, transformation(origin = {-26, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(combiTimeTable.y, derivative.u) annotation(
    Line(points = {{-58, 30}, {-38, 30}}, color = {0, 0, 127}));
  annotation(
    experiment(StopTime = 20),
    uses(Modelica(version = "4.0.0")));
end chariot_portique;

Unfortunately verifying this model raises

The type of variables combiTimeTable.y and derivative.u are inconsistent in connect equations.

How can it be fixed?

I tried to insert between CombiTimeTable and Derivative a SISO or a DiscreteSISO block. But it didn't work.


Solution

  • The output y of the CombiTimeTable is a vector, but the derivative block expects a scalar input. You must add an index to the connect statement and specify which element of the output vector shall be used.

    You have a table with 2 columns, so the size of y is 1 (the first column is always the time, all other columns are for output values). Therefore, you must add [1] in the connection.

      connect(combiTimeTable.y[1], derivative.u) annotation (...);
    

    When you create the connection graphically, OMEdit opens a dialog, asking which index of y shall be used:

    OMEdit - index selection in create connection dialog

    Here you can select the index to use on creation, so you don't have to edit the code of the connections manually.