Hi Emmanuel Bastar Torres,
I understand you want to integrate a stateflow block into your simulink model which triggers a reference point when the error constraint is satisfied. You may refer to the workflow below that can help your use case:
1-In the Stateflow Editor, go to the 'Model's explorer' or 'Symbol's pane" and define two variables:
- 'index' (scope: Local Variable, initial value: 1)
- 'matrixArray' (scope: Input/Constant Variable, size: [2, N] where “N” is the number of reference points)
'matrixArray' can be the reference points matrix containing time stamps and coordinate values that can be taken as input values in the stateflow chart or defined with a constant/local scope.
The above illustration is an example view of 'model explorer' where the variables are enlisted. Please note instead of 2D matrix ‘matrixArray’, the variable 'points' is a 1-D array described as an local scope variable which is used for example purpose.
2- You can create three states in the stateflow chart for handling the error values which will be received as an input.
- InitialState : To perform input handling and handle edges cases(for ex- out of index) if any
- Intial0State : A state to handle where error is less than specified threshold(for ex:0.5)
- Intial1State : A state to handle where error is more than specified threshold.
The above illustration is an example stateflow where 3 states are constructed to show expected functionality. Please note, error condition statements are specified as 0 and 1 for example purpose and 'InitialState' state is currently empty for simplicity and can be modified. The operations happening in each of the state blocks can be explained in the next step.
3- Define appropriate state actions:
- The aim is to increase the index whenever error is within a specified threshold and define reference output as the updated value fetched from that index from the array.(Initial0State).
- Similarly, whenever error is more than the specified threshold, the index value will not increase, and reference output will not be updated, returning the old value.(Initial1State).
- The example above implements this on an array, but this methodology can also be applied when working with matrix type data.
This stateflow achieves the task of generating new set of reference only when error threshold is satisfied.
For more information on stateflow data and actions, please refer to following documentation:
Hope this helps.