Pass bus signals to a function as an array (Stateflow)

5 visualizaciones (últimos 30 días)
Noah Stormonth
Noah Stormonth el 14 de En. de 2022
Editada: Purvaja el 2 de Abr. de 2025
Hello!
I'm working within stateflow and defining a transition check:
[checkInRange(User_CMDs.r,0,1)==1]
Check In range is a simple function as follows and returns true if all inputs are true (In Range):
function result = checkInRange(input,request,tolerance)
result = abs(request - input) <= tolerance;
result = all(result(:));
end
Ive been able to pass arrays as input to the function, however i am trying to define a transition and for a state within simulink. The User_CMD.r is a bus with 4 singals called X1, X2, X3 and X4. I need all of these to be in range for state transition. Is there a way of doing this without doing it as below?
[checkInRange([User_CMDs.r.X1,User_CMDs.r.X1,User_CMDs.r.X1,User_CMDs.r.X1], 0,1)==1]

Respuestas (1)

Purvaja
Purvaja el 2 de Abr. de 2025
Editada: Purvaja el 2 de Abr. de 2025
I understand that you want to pass array as input to the function in Stateflow diagram as transition condition to next state. To simulate given diagram in your question, I combined three different signals generated by “Signal Generator” block in Simulink using a “Bus Selector” and passed it to the “Stateflow” block as inputs.
To access a particular signal in combined signals, we must mention its index in the array instead of dot operator, since a MATLAB function accepts scalar or array values. The state also needs a condition back to initial state when the signal at that time instant does not meet the tolerance. This allows us to check only a single value of signal at a particular time instant and not entire signal.
Refer to the below diagrams for results achieved using the user-defined tolerance function i.e. “checkInRange” function as given in the question:
  • Simulink Model consisting of dummy signals, showing input and output of “Stateflow” block:
  • Stateflow diagram to determine tolerance for combined signal:
  • Stateflow diagram to determine tolerance for a particular signal, where “User_CMDs(2)”, denotes 2nd signal of input and it is closed inside “[]” to translate it into array:
For more details, kindly refer to the following MathWorks documentation:
  1. Stateflow: https://www.mathworks.com/help/stateflow/getting-started.html
  2. Bus Selector: https://www.mathworks.com/help/simulink/slref/busselector.html
To access the documentation for the MATLAB release you are using, please execute the following command in the MATLAB command window:
web(fullfile(docroot, 'stateflow/getting-started.html'))
web(fullfile(docroot, 'simulink/slref/busselector.html'))
Let me know in case you expected a different answer and try to provide your model so that I have correct measurements and block parameters, that you intend to work with.

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by