Main Content

Troubleshooting Memory Limitations for MAT-file Logging

If you deploy the Simulink model configured for MAT-File logging by clicking Build, Deploy & Start in the Hardware tab of Simulink toolstrip, the Diagnostic Viewer sometimes displays the following RAM overflow errors towards the end of the build process:

  • This error occurs if the static memory allocated for all the signals marked for logging exceeds the RAM size for Pixhawk board.

  • This error occurs if the entire PX4 application along with the PX4 stack and integrated Simulink code takes up more than 50% of the available board RAM. With less than 50% of the RAM available, the chances of a hard fault because of Stack/Heap collision increases.

Action

Reduce the memory by following any one of these steps, or a combination of these steps:

  • Reduce the number of signals to be logged.

  • Change the data type of the signal to be logged to achieve a smaller size for data. By default, the data type of signals in Simulink is double, which takes twice the amount of memory compared to a signal with single data type. Additionally, the double data type takes 8 times the amount of memory compared to an int8 signal.

  • Increase the sample time at which the signals are logged by using the Rate Transition block. The memory required to log a signal at the rate of 5ms is twice the amount of memory required to log the same signal at 10ms.

  • Increase the rate at which the signal is logged by increasing the decimation of the signal. The memory required to log a signal with decimation set to 1 is twice the amount of memory required to log the same signal with its decimation set to 2.

  • If there are multiple signals selected for logging at the same Sample time, it is recommended that the time variable is logged for only one signal. For the other blocks that support MAT-file logging, choose the Save Format as either Structure or Array, instead of Structure with Time.

    For each signal with Structure with Time format, the time variable is duplicated (the Structure with Time format logs both the signal data and the time stamp).

    However, if you choose the format as either Structure or Array, only the signal values are logged.

    The timestamp from the first signal with Structure with Time format can be used for other signals that are logged in the same Sample time, so that the same time variable is not logged repeatedly.

  • Te reduce memory overhead, consider combining signals with the same Sample Time using a Mux block, and then feeding the values to To Workspace or Scope blocks. Each signal, which is sent to the To Workspace or Scope block for logging, has a memory overhead apart from the memory required for signal values and timestamp. Combining the signals using a Mux block reduces this overhead.

Continue to modify the model according to the above suggestions, and execute the px4PrepareModelForMATFileLogging function until this warning message no longer appears:

Note

It may take multiple iterations to reduce the memory footprint. You need to call the px4PrepareModelForMATFileLogging function repeatedly until the warning goes away. This process for optimizing the memory footprint needs to be done every time you make these specific changes to the model:

  • Change in the number of signals being logged

  • Change to the sample time of signals being logged