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

Generate C Code

Generate C Code

Hey

I have simulated a basic DC motor in Modelica with a PID controller. I want to generate a C code for it. How to do that?
Also, I only need the code for a specific part of the model( i.e. the PID controller). How should I proceed?


Thanks

Re: Generate C Code

https://openmodelica.org/doc/OpenModeli … buildmodel

Or translateModel, which does the same thing except does not run the makefile to compile the simulation executable. If you only want to generate code for the PID-controller, run the command on the PID-controller instead of the motor.

Re: Generate C Code

Thanks for the answer.

I just wanna know how can i access this file? Will it be saved in some directory?

Re: Generate C Code

Current working directory.

Re: Generate C Code

Hey

Somehow i cannot run OM SHell on my PC . Can this thing be done using OM EDit??

Re: Generate C Code

It can be done using mos-scripts and command-line omc. Or you could unblock OMShell from the firewall (which I assume is what is hindering you).

Re: Generate C Code

When I try to open OMShell, i get the following message
"The application has requested the Runtime to terminate it in an unusual way"

Can you help me regarding this?

Thanks

Re: Generate C Code

Also,
Let me know if there is any other method to get the C code from a modelica model? (maybe another software etc.)

Thanks

Re: Generate C Code

Well, just simulating in OMEdit will generate the C code (it is used to compile the executable). It should be in whatever temp directory OMEdit uses on Windows. You could also do an FMI Export to get the C-code in a different format.

Any other software will generate different C-code for a Modelica model. And they might generate different C-code depending on which solvers and optimization flags were set (OpenModelica does this as well).

Re: Generate C Code

Hey,
Thanks for all your help.
You mentioned that if I want to obtain the code for only the PID, I should run the simulation on the PID.

For my model, i simply put a DC motor, a PID block, a Voltage Source etc. for the inbuilt Modelica Library. I cannot simulate a standalone PID block because it requires input. Thus I have to simulate the whole model together. Can you help me how to get the C code for this part.

Re: Generate C Code

Modelica.Blocks.Continuous.PID does generate code. If you have top-level inputs in a model, you can generate code for it even if the input is not specified (assumed to be given by the user at run-time).

Re: Generate C Code

Can you please tell me how to give top level input??
(I'm really new at Modelica and I don't know much)

Re: Generate C Code

Code:

model M

  input Real r; // top-level input
end M;

model N
  M m; // m.r is not a top-level input
end N;

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