how to model a switch with two different conditions for activation and deactivation

Hello:
I have a problem modeling a dynamic system. Now I understand the problem and know a possible solution. My problem is to transform the thought logic into Simulink language.
Let's describe what I want to do:
I want to activate or deactivate a subsystem based on a signal value (0 or 1) in a discrete subsystem. The activation is conditioned by another two conditions: condition A must be ON and does not matter the value of condition B. At this point, if condition A turns to off, the subsystem must be active until condition B is ON (How to maintain this value?). Finally the subsystem is deactivated and it will wait for another instant when condition A is ON again.
Thank you in advance for your help!!

 採用された回答

Arnaud Miege
Arnaud Miege 2011 年 5 月 9 日

0 投票

Can you use Stateflow? Something like this should do it:
where A_in and B_in are defined as boolean inputs to the chart and out as an output from the chart that can be used to enable a subsystem.
HTH,
Arnaud

6 件のコメント

Javier Guiterrez
Javier Guiterrez 2011 年 5 月 9 日
That is correct but my problem is that i do not have Stateflow license. So i have to do it with Simulink blocks.
Thank you anyway
Arnaud Miege
Arnaud Miege 2011 年 5 月 9 日
OK, then use an Embedded MATLAB Function block (http://www.mathworks.com/help/releases/R2010b/toolbox/simulink/slref/embeddedmatlabfunction.html) with some MATLAB code:
function out = mylogic(A_in,B_in)
%#eml
persistent out_last
% Initialise output previous value
if isempty(out_last)
out_last = 1;
end
if out_last == 1; % in state A
if ~A_in && B_in % transition to state B
out = 0;
else % stay in state A
out = 1;
end
else % in state B
if A_in % transition to state A
out = 1;
else % stay in state B
out = 0;
end
end
% Update value of the last output
out_last = out;
Javier Guiterrez
Javier Guiterrez 2011 年 5 月 9 日
Thank you again!!
I will try and comment to you tomorrow
Javier Guiterrez
Javier Guiterrez 2011 年 5 月 10 日
I have written the next code:
function ind_presion = ABS_incp_logic(ABS_ON,PABS_cdyc)
%#eml
persistent ind_presion_last
% Initialise output previous value for the first time it is run
if isempty(ind_presion_last)
ind_presion_last = 0;
end
if ABS_ON; % ACTIVATION
ind_presion = 1;
else
if PABS_cdyc && ind_presion_last==1 % DEACTIVATION
ind_presion = 0;
end
if ~PABS_cdyc && ind_presion_last==1
ind_presion = 1;
end
if ind_presion_last==0
ind_presion = 0;
end
end
% Update value of the last output
ind_presion_last = ind_presion;
I have no previous experience with embedded functions, and I have several error. What I have done: first write the code, execute mex -setup and finally try to build the embedded function. Is this process correct?
The error are the following:
1.- Variable 'ind_presion' is undefined on some execution paths.
Function 'ABS + TCS (Longitudinal Slip Controller)/Proportional ABS+TCS Controller/FL_ABS_Torque_increment/Embedded MATLAB Function' (#31.599.610), line 25, column 20:
"ind_presion" (When we do the Update value of the last output)
Launch diagnostic report.
2.- Errors occurred during parsing of Embedded MATLAB function 'ABS + TCS
(Longitudinal Slip Controller)/Proportional ABS+TCS
Controller/FL_ABS_Torque_increment/Embedded MATLAB Function'(#31)
3.- Code Directory :
"C:\Documents and Settings\javgut\Escritorio\Sim_Control\Straight_braking\slprj\_sfprj\ABS_TCS_ESP_31_PID_ABS_BOSCH_low_mu\_self\sfun\src"
Machine (#29): "ABS_TCS_ESP_31_PID_ABS_BOSCH_low_mu" Target : "sfun"
Chart "Embedded MATLAB Function" (#31):
.
Code generation failed Errors occurred during parsing of Embedded MATLAB function 'ABS + TCS
(Longitudinal Slip Controller)/Proportional ABS+TCS
Controller/FL_ABS_Torque_increment/Embedded MATLAB Function'(#31)
4.- Errors occurred during parsing of Embedded MATLAB function 'ABS + TCS
(Longitudinal Slip Controller)/Proportional ABS+TCS
Controller/FL_ABS_Torque_increment/Embedded MATLAB Function'(#31)
5.- Parsing successful for machine: "ABS_TCS_ESP_31_PID_ABS_BOSCH_low_mu"(#29)
Maybe solving the first error the rest are solved at the same time.
Thank you in advance
Arnaud Miege
Arnaud Miege 2011 年 5 月 10 日
This is because you haven't defined what ind_presion is in all cases (execution path). For example when you have:
if PABS_cdyc && ind_presion_last==1 % DEACTIVATION
ind_presion = 0;
end
you need an else to define ind_presion when 'PABS_cdyc && ind_presion_last == 1' isn't true.
I would suggest trying to combine all the logic into one if...else statement, possibly with some additional nested if...else statements if necessary.
Javier Guiterrez
Javier Guiterrez 2011 年 5 月 10 日
Thank you very much!!
Now is already fixed. This was the problem, every option was not contemplated.

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

その他の回答 (1 件)

Javier Guiterrez
Javier Guiterrez 2011 年 5 月 9 日

0 投票

I have no experience with stateflow. Is it possible to create this logic in Stateflow at university (they have stateflow license) and then convert it into simulink blocks automatically to be able to run it in my job computer?
Or maybe to combine stateflow diagrams with simulink programs? Thank you in advance

カテゴリ

ヘルプ センター および File ExchangeSimulation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by