VeriStand

cancel
Showing results for 
Search instead for 
Did you mean: 

[BUG] Exporting a Simulink model to Veristand, that uses legacy_code, with code containing N-dimensional variables

Steps successfully completed :

- Built a model from Simulink and exported it into Verisdand, with the expected behavior.
- Same, but with C code re-use using the legacy_code tool

 

Current objective :

- Same, with the additionnal condition that my legacy code must allow the output of :

   * Variables with two dimensions

   * Array of structures.

 

Bug description :

While the simulation runs fine, the last step of building the model into a Veristand usable model fails under said conditions. The generated code gives the follwing message for multidimentional variables and 'sometimes' arrays of structures : "too many initializers". This issue is confirmed because when I reduce the dimentionnality of my variables of reduce the number of elements in the structure to 1, then there is no error.

 

Configuration :

- MATLAB 2015b

- NIVS 2015 SP1

 

Please let me know if you have any idea or suggestion on which approach I should try to solve this issue.

 

0 Kudos
Message 1 of 7
(3,482 Views)

Steps to reproduce :

- Create a Simulink model and use a legacy_code block

- Wrap a piece of code that outputs a structure with a multidimentional variable

- Build for Veristand using the NIVS Builder

- The error message 'too many initializers' shows up in the build log

0 Kudos
Message 2 of 7
(3,461 Views)


Steps to reproduce the bug

1. Execute the script "PR_1_INIT.m"
      -> Buses are initiliazed in the workspace
2. Execute the script "PR_2_GenLegacyCode.m"
      -> The legacy_code code is generated
3. Open the model "PR_3_Model.slx"
4. Run the simulation
      -> No error.
5. Build
      -> "PR_3_Model_data.c(167) : error C2078: too many initializers"
.

When going to the line associated to the error in the generated code, we see that it is due to a bad parallelisation of the 2 dimensionnal structure.

By changing the dimensions of the variables so that they are 1-D, then there is no error and the model build fine.
To do this, comment / uncomment lines :
- 7 and 10 of PR_1_INIT.m
- 5 and 8 of PR_legacy_code.h
Then run steps 1 to 5 again.

0 Kudos
Message 3 of 7
(3,416 Views)

My interpretation of the observed behavior: the code generation NIVS plugin processes the declaration of arrays in a way that MyStruct StructTab[2][3] and MyStruct StructTab[2*3] are seen are identical.

 

This is observable in the  generated code because if we suppose that MyStruct is a type containing 5 integers, then we see:

StructTab = {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};

while it should be:

StructTab = {{{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},{{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}};

 

The way I see it, the solution could be to find a trick -which I don't know how at the moment- in the way I declare variables in Simulink.

Additionnal info: I'm using .net4.0 because .net4.4 induces a linking error with my configuration Matlab2015b and NIVeriStand2015SP1.

0 Kudos
Message 4 of 7
(3,393 Views)

About the "and sometimes user defined structures of structures" that I mention in the top post, I reproduced that behavior on my original project but I'm unable to locate the exact point that triggers the error. As far as I understand, the same error message should appear in the sample project I posted due to the SubStruct1 and SubStruct2 inside of Struct, even when DIMENSION is set to 1.

0 Kudos
Message 5 of 7
(3,379 Views)

Thank you for the detailed report, Franck. I've documented the bug for further investigation. Please note that I'm unable to provide you with a guaranteed fix date. Rest assured that your detailed steps will expedite the investigation. 

Nestor
Message 6 of 7
(3,337 Views)

Thank you Nestor,

I have bypassed the issue for now by making all the incriminated variables of the shape a(M,N) into a(M*N).

Also the issue mentioned in my previous post (about multi element structure) was a design induced bug by me. So the only bug remaining is the one described in the small project I posted.

Message 7 of 7
(3,330 Views)