How to the change the C++ class interface created by Simulink Coder

2 views (last 30 days)
Hi all,
I have a huge Simulink model which I need to integrate inside an application under development in Visual Studio C++. I´d like to integrate my Simulink model as a .dll . As you know, the Simulink Coder Toolbox cam translate a Simulink model in C/C++ code. Below is the C++ class declaration for my scheme.
/* Class declaration for model isar */
class isarModelClass
{
/* public data and function members */
public:
/* Model entry point functions */
/* model initialize function */
void initialize();
/* model step function */
void step();
/* model terminate function */
void terminate();
/* Constructor */
isarModelClass();
/* Destructor */
~isarModelClass();
/* Real-Time Model get method */
RT_MODEL_isar_T * getRTM();
/* private data and function members */
private:
/* Block signals */
B_isar_T isar_B;
/* Block states */
DW_isar_T isar_DW;
X_isar_T isar_X; /* Block continuous states */
PrevZCX_isar_T isar_PrevZCX; /* Triggered events */
/* Real-Time Model */
RT_MODEL_isar_T isar_M;
/* Continuous states update member function*/
void rt_ertODEUpdateContinuousStates(RTWSolverInfo *si );
/* Derivatives member function */
void isar_derivatives();
};
Let me highlight some points:
• The three public class methods are void function with no inputs. • All the simulation state information are stored in the private members of the model class. Every simulation they are updated.
The present class interface is actually a black box, you cannot access the simulation state. You cannot initialize the simulation with a generic state, you cannot: • stop the simulation at a certain point, • restart later the simulation when you want (like with “SimState”, available with the Simulink Normal or Rapid Accelerator simulation modes).
More specifically, I have to perform a forward-forward lap time simulation. The simulation has to be forward in time both in acceleration and in braking. To find the suboptimum braking point, I am planning to repeat the braking phase many times. Therefore I need to: • Save the state at the beginning of the braking phase (state n. 1_init) • Carried out one braking phase and save the final state. (state n.1_final) • Restart the simulation from the begininning of the braking phase (so from state n.1_init) , continue accelerating for a while (for instance one ten of second) and then brake again and saving the new initial and final simulation states (state n.2_init and state n.2_final) • Iterate the process until the corner apex is approached with the target speed.
I tried to configure the Simulink Coder Configuration in a way that the generated C++ Class: • Allows initializing its member variables where all the simulation states are stored with a generic state. • Has a step method which takes as input the simulation state at the previous step and returns the state at the current step.
I´m thinking about possible workarounds I could use, but it would be better to set properly the options available in the Simulink Code Generation UI (which System Target File, which Interface …) Is that possible?
Thanks in advance and best regards,
Michele Mambrini
  2 Comments
Benjamin Thompson
Benjamin Thompson on 31 Aug 2017
I have a related interest in this. I need the getRTM function to be a constant member function (i.e. guaranteeing that the returned buffer is not overwritten by the caller), or to have getRTM return a reference to the RTM structure instead of the address of it, or to allow a buffer size check.
Security scanning tools like CheckMarx will flag source code containing a definition of getRTM as Simulink Coder is currently generating as a medium vulnerability.
Vighnesh
Vighnesh on 16 Aug 2022
Hello. Were you able to succeed in this? I have a similar requirement and could use some help. In my case, I'm just trying to convert a simple transfer function or state space model into a dll that I can import into Unity.

Sign in to comment.

Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!