Dynamic control of variant blocks during simulation
Show older comments
I am trying to control physical connections in simscape/simulink with variant connectors. This is pretty easy to do using the base workspace, and initializing the conditional variables prior to the execution of the simulink simulation. See the test model below:

The variant assemblies are active when A==1 or B==1 are true, which I initialize in the base workspace through following script:
clear all
clc
%parameters
M1=1;
M2=2;
M3=3;
K=10;
C=5;
%conditional varibles
A=1;
B=0;
sim('TestModel.slx');
%extracting data
VelOutVec=VelOut.Data(:,1);
TimeVec=VelOut.Time(:,1);
What I would like to do is dynamically control the variant connections based on a signal output during the simulation - such as if VelOut is less than zero, the variant conditions would then change. To my knowledge, the base workspace only updates after the simulink simulation has completed. I have tried to incorporate a MATLAB function block to implement logic to control the variant connectors, but cannot seem to do it dynamically. See MATLAB function block code below:
function [A,B] = condition(yout)
if yout <= 0
B=1;
A=0;
else
A=1;
B=0;
end
end
It seems that yout is the default variable for any sensor output, but I'm not sure how to access that variable, as it is not in the base or model workspace.
Is it possible to control the variant connections dynamically in Simulink? What I am trying to model (the above model is a test, not the actual system that I am modeling) is a system who's contacts/dynamics change based on certain physical parameters.
Any help is greatly appreciated, I apologize if any of the above information is difficult to understand. I am new to simulink/simscape but will do my best to clarify. The .slx file has been attached to aid in troubleshooting.
Thank you.
Answers (1)
Jacob Seifert
on 17 Apr 2021
0 votes
2 Comments
Paul
on 18 Apr 2021
I haven't used variants much, but my basic understanding of them is that they aren't intended to be used in the way you want. Have you tried pausing the simulation, changing the variables in the base workspace, and updating the diagram just to see if you can even change the variant in the model during the run? If you can, maybe you can set something up within the simulation to do this. But it really sounds like instead of using variants you want to just implement the dynamic logic in the block diagram to select the desired subsystem, like maybe with Enabled subsystems or an If type of construct.
Jacob Seifert
on 18 Apr 2021
Categories
Find more on General Applications 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!