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

Interfacing OpenModelica

Interfacing OpenModelica

Hi everyone,

I am new to OpenModelica but I will try not to make to many mistakes about it.

So I would like to know if there is an already existing way to communicate with OpenModelica but from an another software.
I will explain. I have seen that there is a way to import C code inside Modelica but this is a static method.

I would like to send some udp packet or else from my software (here a rock-orocos project) TO openModelica, to change some very simple inputs as a value of a resistor for example.

And the good thing also will be to have the same kind of link the other way around !

Thanks to the comunity

regards

V.v

Re: Interfacing OpenModelica

Write an example session of what you would like to do. To me it's not clear if you want to communicate with a running OpenModelica simulation or simply set some values and start a simulation.

Re: Interfacing OpenModelica

Actually what I want to achieve is that I would like that all this softwares are running at the same time, and exchange informations.
I would like to test for example the control laws in my Orocos software and send these values to a running OpenModelica model of a motor and get a value back from my OpenModelica model  to my Orocos software.
See the schematic attached http://hpics.li/ae2012c

Re: Interfacing OpenModelica

Yeah, you will need to write your own code in external C functions. Depending on what you want, you either sample the system at certain intervals and exchange information. Or you have something that calculates the value in every time step.

inValue = getFromOrocos(...);
outValue = f(inValue, ...); // 1 or more equations
sendToOrocos(outValue, ...);

Re: Interfacing OpenModelica

Hello sjoelund.se

In my case there is a main GUI program that:
- Calls OMC to compile the .mos and .mo files
- Change some parameters in the XML
- and call the exe to get the results

However I would like to get some communication between the OMC compiled .exe and the main program, because the simulations sometimes take a long time.

What is the best way to do it? Is there a simple sample?

Best regards
Koldo

Re: Interfacing OpenModelica

Open up a socket and send a message. Use when sample() to do it periodically. Use a UDP socket if you don't care about lost messages. What information do you need the main program to get?

Re: Interfacing OpenModelica

Hello sjoelund.se

I want the OpenModelica program to periodically send host program:
- the simulation time: To follow the simulation speed.
- some variables: SImulation time is not fixed and stops when some variables are stable

I will try to learn TCP sockets that seem to be the reliable way. It does not seem to be simple but it seems to be the only way.

Thank you
Koldo

Re: Interfacing OpenModelica

OMEdit can do that, and so can you. Use the -port=X option of the simulation executable (seems to have been broken for beta3 but should work in beta4 again).
To test it in Linux, launch nc and the simulation in two different terminals

Code:

$ nc -l 10356

$ ./M -port=10356

While it actually doesn't print the simulation time, it print the progress as an integer 0-10000 (0.00-100.00%).

Re: Interfacing OpenModelica

Hello sjoelund.se

I have seen that nc listen TCP connection in Linux. In my case I am in Windows and the simulation duration is variable: the model decides when to stop.

Anyway sockets do not seem so difficult. I have collected a couple of samples and I will try them.

Best regards
Koldo

Re: Interfacing OpenModelica

Koldo wrote:


Hello sjoelund.se

I have seen that nc listen TCP connection in Linux. In my case I am in Windows and the simulation duration is variable: the model decides when to stop.

Anyway sockets do not seem so difficult. I have collected a couple of samples and I will try them.

Best regards
Koldo

Dear Koldo,
I am trying to do the same thing but you are using Orcos and I have to use 4DIAC. I am trying to send message to my control application and also trying to receive it. But still not able to make it work.

I would like to get help from anyone from here. I am new to all these things.

Edited by: m.akram040@gmail.com - May-13-15 11:24:00
There are 0 guests and 0 other users also viewing this topic