How to integrate generated simulink model code into own project

5 visualizaciones (últimos 30 días)
mikemodanoxxx
mikemodanoxxx el 24 de En. de 2013
Comentada: Sahana B S el 12 de En. de 2017
Hi there,
i am working on an application which is currently doing the following:
1. I have a SimMechanics model and a controller which is written in cpp. The model reads the input variables from the workspace and writes the output into other workspace variables. 2. I am using the matlab engine to set some workspace variables and to simulate the model for a time step (using the sim-command). Then i am using the results to generate new input values and start the simulation again (and so on).
This works fine but is very slow. That's why I would like to generate code from my model and use this instead of the model itself.
Is it possible to generate the code, call a function to set the input variables, start the simulation and use the results? I can't find any information about the api of the generated code. At the moment the model is built and i can run the object file. The output is written into a mat-file and the input seems to be hardcoded in the Model.c-file.
To sum it up, i would like to.. -have some information about the api of the generated code -know which target file is the best for my purpose (rapid simulation target?!) -know how i can build the code by myself (to integrated it in my project).
I am using 32bit ubuntu 12.04 and matlab r2012a.
I would be glad if someone knew the answer to any of my questions.
Greetings, Simon.

Respuestas (1)

Ryan G
Ryan G el 28 de En. de 2013
It sounds like your controller is the portion outside of simulink here. How are you interacting with it? S-function?
I would first try to generate an s-function for the controller. Once this is done you can use simulink for the whole process and speed things up a bit by removing the overhead of reading/writing to the workspace.
Second, what solver are you using? Try using a stiff solver to speed things up like ODE15s or ODE23t
Finally, once you figure all this out and it's running smoother, you can try using accelerator or rapid accelerator mode.
  4 comentarios
mikemodanoxxx
mikemodanoxxx el 28 de En. de 2013
The controller normal works with a real robot. The goal is to test it against the model without rewritting the code in matlab (i want to use my normal c++ code which is integrated in a certain environment -> you can't port the code that easily).
The problem is that i have to use the "sim" command for simulation with the matlab engine. There is no possibility to run simulation for a while, pause it, update some variables and continue simulation. You have to use "sim" which starts the simulation every time. This is very slow and you can't overcome that bottleneck by optimization of the model itself.
I think i have to look in the generated source code to see how i can change the data. In the Configuration Parameters Dialog is a "Generate C API" option in the Interface Tab (Code Generation), maybe that is something that i could use...
Sahana B S
Sahana B S el 12 de En. de 2017
Hi, I am trying to implement something similar to your project. I have developed a wireless bridge for ECU communication, there are few parameters which needs to be given by the user during run time using keyboard. I have generated C api for my model to access of the addresses of the paramaters along with the c code. But I dont know how to develop program to write into these memory locations of the paramater using C api. Can you please tell me how I can use matlab generated C api to develop my front end application code to write values into the parameter memory in real-time.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by