MATLAB Answers

Code generation continuous time

3 views (last 30 days)
Richard Koch
Richard Koch on 12 Feb 2019
Answered: Munish Raj on 25 Feb 2019
MatlabHello,
I am pretty new to Simulink and to programming general.
For the Simulation of a vertical axis wind turbine I am trying to integrate a control system into the open source program QBlade.
Therefor I am creating the control in Simulink. Afterwards I create the C++ Code and embed it into the source code of QBlade.
For the PI-Controller and Rate Limiter I use continuous time.
Generally I am wondering how the control gets the time /time-step when running the simulation. It seems to work fine for a while. But after about 400 Timesteps the simulation aborts. But I don't know if the error is related to the mentioned problem.
Should I choose a fixed time step to create the code? And adapt the time step in the wind turbine simulation tool QBlade? Or is the Simulink Code able to get the time out of the Simulation tool QBlade without transferring it manually?
A second question: Should I create and initialize (.initialize()) the Simulink Control Class Object in the simulation loop? Or is it necessary to create and initialize it outside the loop? And only put the input parameters, the function .step() and the output parameters inside the loop?
I am really looking forward to your answer!
Best Regards
Richard

Answers (1)

Munish Raj
Munish Raj on 25 Feb 2019
When a C++ code is generated, the timestep is not defined by the embedded coder.
The time step should ideally be defined in the Qblade environment.
The error does not seem to occur because of the timestep.
Please provide more information about the error.
For your second part of the question, it is recommended that you initialize and configure outside the loop and use the parameters in the loop as it would be unnecessary to configure it at every iteration of the loop.

Community Treasure Hunt

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

Start Hunting!

Translated by