
Proponents of text based languages often point to the ease of developing / debugging their code; “I put a breakpoint on a line(1) and…” while at first blush it may seem easier to debug textual models today I am going to walk you through(2) how to debug graphical models.
What is debugging?

First let us come to an agreement on what it means to “debug” a model / code. A model has a “bug” when the model either
- Fails to run:
or - Runs producing incorrect results:
it is not - Excessive memory use, slow execution…(3)
Failure to run is easy to detect, incorrect results may be more difficult to detect if unit tests for regression do not exist.
Sometimes…

You get lucky and a simple differencing of your model against recent versions can determine where the error crept in.(4) To do this, you need to…

- Review the blocks added to the model
- Review block parameter changes
- Review the changes to connections
- Review changes to data
Breakpoints and probes

In textual debugging there is often enough “printf” statements to make you think you are in Project Gutenberg;(5) graphical models use probes and scopes to accomplish the same objective.

Breakpoints can be inserted into the model in any location; for advanced debugging techniques, conditional breakpoints can be used e.g., break when signal > MyVal

Break it down

Finally, a powerful method available in Simulink is the ability to create test harnesses for subsystems, e.g. once you have isolated the issue to a given subsystem you can create a test harness that will run that section of the model independently, enabling a faster debugging experience
Final thoughts

Once you have gone through your debugging exercise…
- Check any models that you have created to prevent regression to this bug
- Note any incorrect block usage for future best practices
Footnotes
- Why yes, that is MATLAB code with simple breakpoints; it is the “text” portion of the Simulink / Stateflow / MATLAB triumvirate.
- After a month of video posts walking you through Model-Based Design this will be a short walk in the park.
- Many of the techniques for debugging a model can be used for these situations; however those are optimization problems, not function problems. The general best practice is to ensure full system compliance with requirements before starting to optimize your system.
- As a side bar, the phrase “low hanging fruit” is an interesting phrase. It covers the “things that are easy to get”. However, if you talk to people who climb into trees to pick fruit they will tell you that you grab the low hanging fruit last so you do not climb up the tree with extra weight. Like many things in life if your long term objectives should shape your short term actions.
- The Project Gutenberg brings public domain books to electronic format.
- Point-Break ==> reverse Break-Point