Transition not executed despite true condition
27 次查看(过去 30 天)
显示 更早的评论
Hello Community,
I have a simple Stateflow chart with two empty states (see image). To switch between those states I have two conditional transitions. In those transitions, I compare two fixed-point values (signed, 16 bit, fraction length 7). One of them is an input to the chart and the other one is a parameter in the MATLAB workspace. My Problem is that the transitions never become valid.
So my two transition conditions are:
input > parameter
input <= parameter
If I use the debugger to stop the simulation when the transitions is checked, I can see that the values should lead to a true result. Entering the condition in the MATLAB command line also shows that the result is true.
Nonetheless Stateflow doesn't execute the transition and I'm stuck in one of those states.
BUT: If I convert both variables to unsigned (the variables are always positive) it suddenly starts working.
What's the cause for this behaviour?
Thanks for your help!
0 个评论
回答(3 个)
Nirja Mehta
2017-2-6
How are you providing input to the chart? I made a Stateflow chart according to your description, and with signed fixed point data, it works fine. Attach your model if this is not what you meant.
Scherer Gábor
2022-7-29
编辑:Scherer Gábor
2022-7-29
The same issue is persistent in MATLAB 2022a.
Even after debugging, the output indicates that this should never happen but it does.
0 个评论
Andy Bartlett
2022-8-1
编辑:Andy Bartlett
2022-8-1
Hi,
I did a quick spot check of the functionality
I've attached a model showing transitions based on relational operators in Stateflow MATLAB and Stateflow C.
The relational operators are all using the fixed-point data type fixdt( 1, 16, 7 ) as described in the original post.
All the transitions are happening as expected.
Unfortunately, it is unclear what issue you observed.
To clarify things, two suggestions.
1) Set breakpoints on all the Stateflow states of interest. When the breakpoint triggers, inspect the values of the two variables being compared as shown in the attached screenshot.
2) If your debugging reproduces the incorrect behavior, please provide full reproduction information, so we can help you solve it. Ideally, your reproduction information would include simplified models and all supported data needed for those models to simulate.
If a hard constraint is preventing you from providing the simplified model and supporting data, then we could try to work with a textual description of the specifics, but that carries high risk that information was lost. Due to lost information, the specific issue you are observing might never get reproduced.
A key risk with textual communication of values is that default displays hide some details that are important especially for the finer behaviors of relational operators. For example,
a = fi(3+2^-25,1,32,27);
b = fi(3+2^-27,1,32,27);
a, b
If you look at the default displays, the values look equal
a =
3.0000
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 32
FractionLength: 27
b =
3.0000
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 32
FractionLength: 27
but the values are not equal
yEqual = a == b
yEqual =
logical
0
Displaying with 17 digits, we'll reveal the truth for doubles and fixed-point up to ~53 bits.
num2str(a,17)
num2str(b,17)
This shows the values are really not the same
ans =
'3.0000000298023224'
ans =
'3.0000000074505806'
FYI, fi objects provide a Value method that makes it is to see a textual display of the exact value they represent (not an approximation).
a.Value
b.Value
ans =
'3.0000000298023223876953125'
ans =
'3.000000007450580596923828125'
To provide text to reproduce a value in its original data type, mat2str with two extra arguments is great
mat2str(a,17,'class')
ans =
'fi('numerictype',numerictype(1,32,27),'Value','3.0000000298023224')'
Evaluating that text (up to doubles or 53 bit fixed-point) should give lossless round trip
aRoundTrip = fi('numerictype',numerictype(1,32,27),'Value','3.0000000298023224')
cEqual = a == aRoundTrip
aRoundTrip =
3.0000
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 32
FractionLength: 27
cEqual =
logical
1
Looking forward to clearing up the issue you observed.
Again, a model with all necessary supporting data is the safest and most efficient way to communicate your reproduction steps.
If the information must be provided textually, please try to avoid information loss.
Andy
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!