roll back slbuild genrated model by one step
Mostrar comentarios más antiguos
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 comentarios
sneha
el 14 de Nov. de 2025
Hello,
there is no formal MathWorks-supported API to roll back a Simscape model one step in generated C code, because SimState and operating-point features are not supported for code generation with Simscape; the only reliable approach is to manually save and restore all simulation state memory before calling rt_OneStep(S), including continuous states (X), discrete work vectors (DW), mode vectors, zero-crossing signals, solver workspaces, timing fields, and Simscape internal runtime structures.
relevant MathWorks documentation:
Data Structures in the Generated Code: https://www.mathworks.com/help/rtw/ug/data-structures-in-the-generated-code.html
Access Block Data During Simulation: https://www.mathworks.com/help/simulink/ug/accessing-block-data-during-simulation.html
About Simscape Run-Time Parameters: https://www.mathworks.com/help/simscape/ug/about-simscape-run-time-parameters.html
Save State Information (Simulink): https://www.mathworks.com/help/simulink/ug/save-state-information.html
E_C
el 17 de Nov. de 2025
E_C
el 18 de Nov. de 2025
Respuestas (0)
Categorías
Más información sobre Run-Time Parameters en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!