Is is possible to switch the model which is being referred by model referencing block with variants enabled by changing the value of variant object at run time (while model is simulating).
MATLAB: Can model variants be switched while model is running (simulating)
model referencing blocksimulinkvariants
Related Solutions
Hi!
I think we are close to the solution! In what follows I performed all the simulations by using the fixed-step solver Ode3(Bogacki-Shampine) to all the models. Moreover, let me say that the model 'SingleWheelTEST/LocalCtrlFL' is composed by 4 input ports, 1 output port, 2 gains, one switch, one product block and one scope(so the model is very simple, I would even upload an image but I do not know if it is possible here in the forum).
Anyway, I tried to put a sample time "0" to a randomly chosen block in the 'SingleWheelTEST/LocalCtrlFL' model (for instance, I set sample time "0" to an Inport). I tried to run the simulation and I got this error
"Root Inport 'LocalController/Is Braking' has a sample time of [0 0] which does not match the sample time [0.4 0] of its destination: input port 1 of block 'LocalController/Scope'. Root inports must have the same sample time as their destinations for model reference. Please correct this situation by changing one of the two sample times or inserting a Rate Transition block. This error message is related to a hidden Inport block."
So I argued that the problem is in the Scope block. In addition, I don't want to add additional blocks in the model (otherwise is not the same model as in the case with variable-step solver, where everything works fine without additional blocks.) Then, with the same setting as above (i.e. sample time "0" to an Inport), I removed the Scope block and this time everything worked out perfectly, but with these warnings:
"Warning: Unable to determine a fixed step size based on the sample times in the model 'SingleWheelTEST', because the model does not have any discrete sample times. Picking a fixed step size of (0.4) based on simulation start and stop times. You can disable this diagnostic by explicitly specifying a fixed step size in the Solver pane of the Configuration Parameters dialog box, or setting the 'Automatic solver parameter selection' diagnostic to 'none' in the Solver group on the Diagnostics pane of the Configuration Parameters dialog box.
Warning: The model 'SingleWheelTEST' has continuous states and is referencing (via the Model block 'SingleWheelTEST/LocalCtrlFL') the fixed-step model 'LocalController' which has blocks with continuous sample time. The solver 'ode3' used to simulate model 'SingleWheelTEST', will execute the referenced model 'LocalController' in minor time steps, where as during standalone simulation the model 'LocalController' uses a discrete solver which does not have minor time steps. This can cause results from the Model block and results obtained from standalone simulation of the referenced model to be different. You can disable this diagnostic by setting 'Automatic solver parameter selection' diagnostic to 'none' in the Diagnostics page of the configuration parameters dialog."
Honestly, I was surprised that the problem could be the Scope block. Could you please explain me what happened with that block? And could you also tell me more about the warnings I get?
Finally, just for the sake of completeness, I also tried to run a simulation by setting sample time "-1" to all the blocks in 'SingleWheelTEST/LocalCtrlFL'and by deleting the Scope block. The result is that the sample time of this referenced model became again Discrete1 0.4.
I wonder what trick the variable-step solvers use to adapt all the sample times of all the blocks...
The issue occurred primarily because the Switch block is being used before the Counter block in your Simulink model. In order to switch the input signal based on the number of counts, the switch block should be used after the count block as shown below. To reset the number of counts depending on the cycles counted, select the Reset Input port check box in Counterblock. When you enable the Rst port, the block resets the counter to its initial value each time a trigger event occurs at the Rst port.The type of trigger event is based on the Count event parameter in the counter block. The Period of the input signal should be specified as a value greater than the fixed value (i.e. “5”) selected to reset the input signal. In the given model, the Period is selected as “6”.
For more information refer to the documentation given below:
Best Answer