Hi, I'm having some troubles in creating ssc file where I need to use while loop (or maybe for). Here is my code:
parameters
gain = { [0 0 1/3], '1' }; % Gain
max={[0.3 0.1 0.25],'1'} %Maximum pressures
end
parameters
stop = { 0, '1' };
k={1,'1'};
end
equations
while stop<1
if I<=sum(max(1:k))
stop=1;
coef=gain(k);
end
k=k+1;
end
O == coef * I;
end
And when I try to build library with ssc_build I get message like this:
Illegal flow control construct 'while' in equation block
Am I doing something wrong, or there is no possibility in simscape language to use "while" and "for" statements (although conditional "if" is allowed)?
Thanks in advance.

 採用された回答

Arnaud Miege
Arnaud Miege 2011 年 6 月 7 日

1 投票

while and for loops are not allowed in the Simscape language, see the equations documentation ("Supported Functions" section) and Defining Component Equations in the Simscape documentation. What are you trying to do?
Arnaud

5 件のコメント

Tomas Iesmantas
Tomas Iesmantas 2011 年 6 月 8 日
First, as parameters I supply two vectors gain and max. And I want to modify "Gain" block from simscape pysical signals. To simplify, I want to while loop to check whether incoming signal I is greater than sum of first ith elements of max vector or not. And depending on the results I take value from vector "gain" and multiply it by incoming signal.
For example: gain=[1 1/2 1/3], max=[0.3 0.1 0.25]. Suppose I have while loop, and index k=1. Then I check whether incoming signal I<sum(max(1:k))=0.3 or not. And loop stops when condition is satisfied.
I hope that it is clear of what I want to do in simscape.
Arnaud Miege
Arnaud Miege 2011 年 6 月 8 日
OK, but what's the application? What are you trying to model?
Tomas Iesmantas
Tomas Iesmantas 2011 年 6 月 8 日
I have several flow rate sources (Controlled Pneumatic Flow Rate Source) and want to controll them according to the incomming signal. Suppose those flow rate sources can't generate flow rates higher than some max value. If incomming signal does not exceed thirst flow rate source max value, than other sources produce 0 value flow rates and thirst source produce flow rate identical to incomming signal. When incomming signal exceeds first source max flow value than first and second sources produce flow rates equal to half the incomming signal (sum is still equal to incomming signal). If signal exceeds flow rate equal to sum of first and second source max values then third source is activated and produced flow rates are equal to one third of original signal and so on. And I need component which could at the same time monitor incomming singla and depending on those conditions it selects of what factor should signal be multiplied (0 if sources is not activated, 1/2 if two sources have to be activated, 1/3 if three sources are needed).
Arnaud Miege
Arnaud Miege 2011 年 6 月 8 日
I would suggest doing this in Simulink/Stateflow or Embedded MATLAB and using a Simulink->PS Converter block to feed to the flow rate sources. Alternatively, if you want to stay within the Simscape environment, you could probably use the PS Switch block in conjunction with the PS Max and PS Min blocks.
Andreas
Andreas 2015 年 11 月 6 日
Hi Arnaud,
while and for would be helpful, to create parameter-driven discretisations of simscape-blocks (like in Modelica language) for any type of lumped models.

サインインしてコメントする。

その他の回答 (1 件)

Vishnu Teja Vithala
Vishnu Teja Vithala 2018 年 7 月 9 日

2 投票

I agree, Simscape not supporting while and for loops is pretty big limitation

カテゴリ

ヘルプ センター および File ExchangeFoundation and Custom Domains についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by