How to integrate generated simulink model code into own project
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (1)
Ryan G
il 28 Gen 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 Commenti
Sahana B S
il 12 Gen 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.
Vedere anche
Categorie
Scopri di più su Simulink Coder in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!