roll back slbuild genrated model by one step

24 views (last 30 days)
E_C
E_C on 10 Nov 2025 at 16:54
Commented: E_C on 18 Nov 2025 at 16:34
I have generated a Simscape model to c excutable and code using slbuild and it has produced a main code rt_malloc_main in C which I am editing. I will eventually build that executable with gcc (and where needed g++) and use in Ubuntu 22.04.
For various reasons I need to roll back the model, i.e. reject all the progress made during the last call to rt_OneStep(S). This is a large model with many simscapep multibody library blocks, but also simulink blocks, and some matlab function blocks which use global variables through the persistent command.
What I ideally want would look like this:
save model S
advance one step: rt_OneStep(S)
if condition is not achieved completely roll back everything to how they where before rt_OneStep was called, or in the very least time and states so that a new call to rt_OneStep would give the exact same results: restore(S)
I currently have some ad-hoc lines of code to do save and restore and various efforts have also led me to use the rt_terminate (S) and rt_Init(S) to avoid bad memory allocation problems, and then use restore(S) in the hope that I also change my time and all states in the various blocks.
Is there a formal way to go back one step and cancel the effects of rt_OneStep(S) without starting the simulation from t=0?
The reason behind this roll back is that I am coupling this code with another code that needs the roll-back
  3 Comments
E_C
E_C on 17 Nov 2025 at 17:10
Thanks for teh suggestion I believe I am restoring almost all of the above but I am not sure what is the name to use for saving and restoring Simscape internal runtime structures
e.g. for continuoustates I can for example access them as: S->contStates (S is my model)
E_C
E_C on 18 Nov 2025 at 16:34
And perhaps if there is some guidance of what elements of DW (dwork) need to be saved and restored or how to configure slbuild to group them in a conveninent way to do so that would be very useful as a shallow copy of those doesn't seem to work (memcpy)

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!