0

I want to know how I can visualise the results of a Modelica simulation in the form of an animation.

Imagine I have a simple simulation as below:

model test
  //parameters
  parameter Real m_1 = 1;
  parameter Real m_2 = 10;
  parameter Real K_c = 100000;
  //variables
  Real x_1;
  Real v_1;
  Real x_2;
  Real v_2;
  Real f_1;
  Real f_12;
initial equation
  x_1 = 0;
  v_1 = 0;
  x_2 = 0.2;
  v_2 = 0;
equation
  v_1 = der(x_1);
  m_1 * der(v_1) = f_1 - f_12;
  v_2 = der(x_2);
  m_2 * der(v_2) = f_12;
  f_12 = if x_2 >= x_1 then 0 else K_c * (x_1 - x_2);
  f_1 = 1;
end test;

(it is actually a very simple elastic collision)

and I have part1.obj and part2.obj (or other possible formats rather than .obj), designed in other CAD software, which I want to import and assign to x_1 and x_2 and then animate. OpenModelica 1.11.0 is already installed on Ubuntu using these instructions.

What I have found so far and the problems I have encountered:

  1. From this page I have learned that Modelica3D should also be installed. However I couldn't find this library using apt or aptitude.

    Do I still need to install this library separately or it has already been integrated into the latest stable OpenModelica release? if yes how can I install it? what other libraries/packages might be needed?

    Edit: It seems that Modelica3D has been depreciated (same for OMVisualize). Now the ModelicaServices is being used for animation. more information here

  2. This post gives a very simple example of animating using Wolfram SystemModeller. When I open it into the OpenModelica, it does compile and shows the results. I tried exporting the model as FMU and XML and then use animation icon from the top menus to import the model.

    enter image description here

    but when tried to import the .mat file I got the error:

    Scripting Error Could not find the visual XML file /tmp/OpenModelica_user/OMEdit/SimpleCarModel_visual.xml.

    Is this example compatible with OpenModelica? and if yes what is the problem and how I can solve it? (you can also download the example from this Github gist)

    Edit: This example is compatible with OpenModelica. I was doing it wring. I had to choose the "simulate with Animation" instead of "Simulate". I still can't assign an external CAD object to the simulation and a cylinder is being shown instead.

  3. I also tried to learn using OMShell scripting to run the Modelica3D example from this page. However it seems that the code is wrong because I get many errors running it in my OMShell.

  4. One of the linked websites has mentioned that it is possible to use blender for animated results however the author hadn't succeed to do so. I would appreciate if you could help learn this in simple and clear steps.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
  • 2
    Modelica3D is deprecated. We have 3D animation support via the ModelicaServices. See the examples in the MultiBody library for example: Modelica.Mechanics.Examples.Elementary.DoublePendulum (click on Simulate with Animation in OMEdit). You will need to add bodies in your model and link your variables to them. – Adrian Pop Feb 14 '17 at 19:38
  • See also Modelica.Mechanics.Examples.UsersGuide and Modelica.Mechanics.Examples.UsersGuide.Tutorial on how to use the MultiBody library. – Adrian Pop Feb 14 '17 at 20:16
  • Dear @AdrianPop, thanks a lot for your reply. 1. I took a look at examples in Modelica.Mechanics.Examples.Elementary library. I didn't know that I have to use the "Simulate with Animation" icon. now I'm able to run the examples. but it seems to me that there some built in drawing fucntions of OpenModelica has been used to make basic objects like cylinder and boxes. what I want is to link some variables to the pose of some objects I have made in other CAD software. I ran the example from Wolfram website and it also runs, but uses a cylinder instead of the CAD I put in that folder. – Foad S. Farimani Feb 15 '17 at 09:20
  • 2. secondly, all of these examples use prebuilt OpenModelica blocks. What I'm looking for is pure Modelica code which I can understand and modify, in the form of example I have mentioned in the question above. I'm looking for a function which assigns a homogeneous matrix or quaternions to the pose of a 3D object. is that a possibilty – Foad S. Farimani Feb 15 '17 at 09:21

1 Answers1

0

Visualizing CAD-files is currently only possible for .stl and .dxf. You can specify the URI of your CAD-file in the shapeType-parameter of your shape. Please use the following notation:

"modelica://packageName/relativePath/To/Your/CADfile.stl"

It is also possible to set the absolute path in the *_visual.xml that has been generated with your simulation results(and should be in the same directory if you want to load simulation from OMEdit).

If you want to move your animation shapes, simply assign variables to i.e. the position vector

r = {x,0,0};
Slava.K
  • 3,073
  • 3
  • 17
  • 28
vwaurich
  • 1
  • 1