Clear Filters
Clear Filters

How to initialise Goto variables used in enabled subsystems

21 views (last 30 days)
How can I initialise Goto variables in an enabled or switch case action subsystem?
I use the Goto blocks to reinitialize the integration variable when one subsystem is enabled, as described here: Building a Clutch Lock-Up Model
Now I can't find a clean way to initialize the goto variables when the model is started. As there is no previously active subsystem, no value can be passed to initialize the variable.

Accepted Answer

Jim Riggs
Jim Riggs on 29 Nov 2022
You should not need to "initialize" the Goto variables. The "Goto / from" blocks are simply a way to connect a signal without showing the connecting line. The Goto block gets its value from the signal line that is the input to the block.
  3 Comments
Jim Riggs
Jim Riggs on 30 Nov 2022
Edited: Jim Riggs on 30 Nov 2022
I am still not sure if I understand your question, but it sounds like you want to initialize an integrator block which is inside an enabled subsystem. The subsystem may be called for a period of time, and then not. You want to perform this initialization upon the first of a series of calls to the enabled subsystem.
To initialize the integrator, you will need to create a logical signal outside of the enabled subsystem which indiates that the call to the subsystem is an initilizing one. This logic signal is passed into the enabled subsystem and is connected to the "reset" port of the integrator. The initial vaue for the integrator is connected to the "initial condition" port of the integrator. This is where you need to get creative.
Here is an example using two enabled subsystems.
The "Trigger Signal" (in blue) is a logical signal which is used to select Subsystem 1. the "NOT" operator insures that Subsystem 2 is not selected when subsystem 1 is active, and it also insures that one of the subsystems will always be active. (i.e. If subsystem 1 is not on, subsystem 2 is on)
Each Subsystem outputs a unique ID number (1 or 2) to identify which subsystem is active. The switch block selects only the active output from the two subsystems, i.e. the output of the switch block (signal "ID") has the value of the current active subsystem. Each subsystem compares the output of the switch ("ID") block to it's own ID. When they are the same, then the "reset" signal is "false", and the integrator continues operating. Only when they are different (i.e. the last pass throu the loop, a different subsystem was active) then the "reset" signal is "true" which is used to reset the integrator inside the subsystem. The initial condition for the integrator reset is also passed in from outside the subsystem. This can be an output from the other subsystem. (Note that, in this diagram, I am only showing the signals required for the integrator reset logic. Each subsystem will obviously have other inputs and outputs).
Note that the integrator blocks inside both subsystems have their parameters set as follows: "External reset = rising" and "Initial Condition source = external".
I hope that this helps.
Daniel
Daniel on 1 Dec 2022
First of all, thank you very much for your answer and the work you put into it.
My model is a periodical one, that has three operation states where one of them is active at a time. Sorry that I didn't describe that sufficiently, but your assumption is still leading to my key problem.
My problem is based on my use of the 'Goto' and 'From' blocks. In each subsystem, a 'Goto' block is connected to the 'State' port of the integrator. This 'Goto' block is transmitting the last state of this integrator block to the one in the next subsystem active. In this new subsystem the 'From' block is providing the initialization value for the integrator block of this new subsystem. This procedure is done every time the active subsystem changes to pass on the integration value. Now the problem arised, that I had to provide a general initialization for the integration value when the simulation starts. I couldn't easily provide a initialization value, as this would have been used every time the subsystem is reactivated. I hope that is a better description of my problem.
However, I thought I am just missing the setting for this initialization somewhere. Till now I was using an external signal to solve my problem, but my implementation of this solution was problematic in some ways.
So now I'm using parts of your answer as a solution to my problem that work much better for me.
Thank you very much and sorry again for the badly described problem.

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!