Real-time workshop - using external time management

13 Ansichten (letzte 30 Tage)
Luca Goldoni
Luca Goldoni am 17 Feb. 2011
I'm quite new to Matlab/Simulink. I am studying all the documentation but still can not find solution.
I am using Simulink to create a model and Real-Time Workshop to convert it to C++ code. Then, I have to integrate this code automatically generated, within other existing code. I can do it.
The existing C++ code can properly handle the inputs and outputs of the model. To do this I set the storage class of those signals such as ImportedExtern.
But now I need to use in the Simulink model an externally generated clock presented in the existing C++ code. I can do this? I'm trying to understand how time is handled in the simulation and which blocks can be involved.
Perhaps the question has a simple answer, most of what I think. I hope I was clear enough.
Thank you in advance.

Antworten (2)

Guy Rouleau
Guy Rouleau am 18 Feb. 2011
RTW will generate a "step" function. You just need to use your external clock to call this "step" function in your C/C++ application at the right time.
Typically, you need to call the "step" function at the same rate as the one specified in the model. That way, the "step" function will automatically increase its time internally.
If you want to call the "step" function asynchrounously, or at non-constant intervals, you should ensure that your model is sample time independant, as explained here:
http://www.mathworks.com/help/toolbox/simulink/gui/bq7cmsp-1.html#bq990zm-1
  2 Kommentare
Luca Goldoni
Luca Goldoni am 23 Feb. 2011
Thanks for your reply. But I'm not sure I've correctly understood. RTW generates files including one called model.cpp. Inside that, there is the grt interfaces. Now the external code follows these steps to use the model:
* MdlStart ();
* initializes input signals (I use StorageClass ImportedExtern)
* MdlOutputs ();
* save the outputs of the model in the local varible of the external code
* MdlTerminate ();
I think that the "step" function to call in the interface is indicated as MdlUpdates. Is it? Is what I have to rely on the same frequency of the clock in my existing code?
Is there a way to pass to the model a specific timestep? Or a time variable?
Thanks again.
Kaustubha Govind
Kaustubha Govind am 23 Feb. 2011
The step function is generated as rt_OneStep, which you can tie in to your clock. I'm not sure what you mean by passing in a time variable - is this just something that the function must use as any other parameter, or do you want the model to somehow act upon this input by automatically running at the given frequency? AFAIK, the latter is not possible.

Melden Sie sich an, um zu kommentieren.


Luca Goldoni
Luca Goldoni am 20 Feb. 2011
Thanks for your reply. But I'm not sure I've correctly understood. RTW generates files including one called model.cpp. Inside that, there is the grt interfaces. Now the external code follows these steps to use the model:
  • MdlStart ();
  • initializes input signals (I use StorageClass ImportedExtern)
  • MdlOutputs ();
  • save the outputs of the model in the local varible of the external code
  • MdlTerminate ();
I think that the "step" function to call in the interface is indicated as MdlUpdates. Is it? Is what I have to rely on the same frequency of the clock in my existing code?
Is there a way to pass to the model a specific timestep? Or a time variable?
Thanks again.

Kategorien

Mehr zu Simulink Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by