Automatic c++ code generation with simulink coder

10 ビュー (過去 30 日間)
Markus Neumeier
Markus Neumeier 2019 年 8 月 23 日
コメント済み: Francesco M 2020 年 3 月 20 日
Two questions:
Question One: How can I avoid the initialize function and introduce the initialize code into the constructor?
Example:
instead of
void PIDModelClass::initialize()
{ rt_InitInfAndNaN(sizeof(flt64));
(void) memset((void *)(&PID_M), 0, sizeof(RT_MODEL_PID_T));
(void) memset((void *)&PID_DW, 0, sizeof(DW_PID_T));
}
// Constructor
PIDModelClass::PIDModelClass()
{
// Currently there is no constructor body generated.
}
I want this to see
// Constructor
PIDModelClass::PIDModelClass()
{ rt_InitInfAndNaN(sizeof(flt64));
(void) memset((void *)(&PID_M), 0, sizeof(RT_MODEL_PID_T));
(void) memset((void *)&PID_DW, 0, sizeof(DW_PID_T));
}
Question Two: How can the class declartion for the model include inheritance from a parent class (here Filter)?
// Class declaration for model PID
class PIDModelClass : public Filter
{
// public data and function members
public:
// model initialize function
void initialize();
// model step function
void step();
// model terminate function
void terminate();
// Constructor
PIDModelClass();
// Destructor
~PIDModelClass();
// Real-Time Model get method
RT_MODEL_PID_T * getRTM();
// private data and function members
private:
// Block states
DW_PID_T PID_DW;
// Real-Time Model
RT_MODEL_PID_T PID_M;
};
  1 件のコメント
Francesco M
Francesco M 2020 年 3 月 19 日
Hi Markus,
I have the same problem as Klocwork generates an error when it does not find the input / state / output variables initialized in the constructor.
Have you found a solution in the meanwhile?
Thank you!
Francesco

サインインしてコメントする。

回答 (1 件)

Markus Neumeier
Markus Neumeier 2020 年 3 月 20 日
I talked to various technicians during a seminar in Munich and couldn't get a solution from the matlab coder itself.
The only workaround was a parser script that alters the generated code. But this is not an appropiate solution for
our development team.
  1 件のコメント
Francesco M
Francesco M 2020 年 3 月 20 日
Thank you for your reply. In this case the only other solution looks TLC code customization.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by