How can a Simulink State Space block state be periodically reset?
Show older comments
In Simulink, can a State Space block's states be periodically reset, ie not just set on startup?
If not, what alternative is there to accomplish the same thing?
I'm looking to periodically (every T sec) reset the states of a State Space block (say, called "R" for reset), and reset them to a set of passed parameters (states); ie not static constants from the workspace that only act on sim initialization.
These passed reset-value states might come from another continuously-run State Space block (say, the block is "C" for continuous, and its states are the "Good" states), as one example...
At each n*T tick i'd look to update the states of R to the Good states, so that R somewhat matches C as time goes on. Yes, these updates could lead to discontinuous behavior from R, but that's okay.
The question is, how can I periodically update R's states?
7 Comments
Hi @John
I want to make sure I understand the 'reset' problem correctly. Are you looking to update the matrices in the state-space periodically, as shown? If that's the case, the Varying State Space block might be a suitable option for you. It provides the flexibility to update the matrices based on your desired schedule.

State equations

Output equations

Sam Chak
on 24 Feb 2024
Hi @John
Thank you for describing your problem clearly. Mathematically, I believe you can manipulate the state vector
to track
at some time t, using the input signal
, which is a function of the state vectors
and
. However, you will need to creatively find the mathematical equation for
. It is important to note that the dynamics in the original System R remain unchanged. However, the closed-loop feedback System R may behave similarly to System C.
System C

System R

where
John
on 24 Feb 2024
Sam Chak
on 25 Feb 2024
Don't mention it, @John. I perceive the issue akin to a Mathematical Tracking Problem. The task lies in ingeniously deriving an equation to guide the state
of System R to closely follow the state
of System C.
However, the approach you desire involves manually updating the state
to synchronize with
every 3 seconds, ensuring the reset mechanism doesn't disrupt System R's natural state evolution.
In this context, @Paul's programmatic approach seems most fitting. However, I'm skeptical about the practicality of correcting the state
without addressing its underlying system dynamics. See demo below.


John
on 8 Mar 2024
Answers (1)
i think you'll have to use an Integrator and other native blocks to implement
xdot = A*x + B*u
y = C*x + D*u
Use the external initial condition option and the external reset option to reset the integrator states to the signal on the initial condition line based on whatever your reset logic is. The signal on the IC line should be the IC of the integrator at t = 0 and then the values to reset to at the resets as t moves forward.
Make sure to have appropriate solver settings (solver type, zero crossing detection).
Here's an example that resets the state of the integrator to 1 every time the sine wave crosses zero in either direction, i.e., every pi seconds.

3 Comments
Paul
on 3 Mar 2024
Though it doesn't solve this problem, which requires that the states be reset to values provided from an external source, it may be of interest that the states of State Space block and can be reset to the Initial Conditions block parameter if the state space block is inside a Resettable Subsystem.
John
on 8 Mar 2024
Paul
on 8 Mar 2024
Just like any other block parameter, the Initial Conditions parameter of the State Space block can be any expression that evaluates to a valid value for the parameter, in this can a vector (of initial conditions). So you can use, for example, X0 as the parameter value, and then Simulink will evaluate X0 using the normal workspace hierarchy. I assume that works the same way at the resets if the State Space block resides inside a Resettable Subsystem, but I didn't test it.
Based on the context of this thread I assume you're considering putting the State Space block inside a Resettable Subsystem, using a variable, e.g., X0, for the Initial Condition, and then changing the value of X0 in the workspace in which it resides while the simuluation is running (or paused) before the next reset. I don't know if that's feasible, particularly if the new value of X0 isn't known until the time of the reset. It might be feasible, but I just don't know.
Categories
Find more on Programmatic Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
