- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Generate C Code
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.
- sjoelund.se
- 1700 Posts
Re: Generate C Code
Current working directory.
- sjoelund.se
- 1700 Posts
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).
- sjoelund.se
- 1700 Posts
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).
- sjoelund.se
- 1700 Posts
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).
- sjoelund.se
- 1700 Posts
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;
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Generate C Code