0
votes

Context: I have a huge Simulink Model that is going to be used for automated simulations on a Debian 10. Therefore it has to be built as standalone C-Code using the Matlab Coder. This code is then called to start the simulation.

What I need: I need to find a way to initialize my built model with ~500 parameters. These change with each simulation run and are stored in a SQLite file. The goal is to have parameters written to the database, then start the Model which reads the parameters from SQLite during initialization (presumably using the InitFcn Model Callback, although I'm open to alternatives).

What I have tried:

  1. Direct SQL interface: I tried to use a direct Matlab-SQL interface such as JDBC (since I don't have access to the Database-toolbox) but those are not supported for Code generation.

  2. Write a C-function that reads the SQLite file, then call the function during initialization in the InitFcn Callback using coder.ceval like this:

   data = 0;
   err = coder.ceval('read_function',4, 2, 12, coder.wref(data));
   parameter = data;
  • Problem here is that coder.wref is not supported in Matlab and therefore doesn't work in the InitFcn. (Please correct me if I'm wrong) This only seems to work inside a Matlab-Function-Block:
   Error evaluating 'InitFcn' callback of block_diagram 'Model'.
   Caused by:
   The coder.wref function is not supported in MATLAB.

So my problem with the second approach is, that I can't call the C-function during initialization.

  1. Using a Matlab-function-Block to read the parameters isn't really an option, since I would have to route all the signals out which makes maintaining and further development of the model really hard. Also my suggestion is, that the model would not even run because the parameters are needed to initialize the model.

Questions:

  1. Is there a way to make one of the above approaches work? If yes, how? Where is my mistake?
  2. Is there another (simpler) option to pass the data as an array or struct to my model?

Database looks like this:

Identifier               Default         
latitude                    52.5
longitude                   13.4
electricity_consumption   4000.0
ventilation_stream          50.0
PV_peak                     30.0
PV_orientation               0.0
no_vessels                  28.0
heatpump_exists              1.0
hotwater_consumption      1000.0
.
.
.
1

1 Answers

0
votes

After having spent so much time on this issue, I would like to share my experience on this problem:

SQLite: This approach did not work out for me because the direct SQL-Matlab interfaces are not supported for code generation. It is in fact possible to write a C-function, that reads from SQLite and call that function in a Matlab-function-block via coder.ceval wich allows to read in a signal during simulation. This works for code generation (Simulink coder) as well. However this will not work for initialization (see question).

So none of my original approaches ended up working.

Workaround: I ended up switching to an approach based on the Simulink RSIM-target wich generates code (also for Linux) and can be parametrized via a .mat file wich contains all the parameters. The .mat file can be modified to update parameters. This required some additional code wich automates this step. Also the model configuration for RSIM is a bit tricky.