Why do I get this error 'Code generation does not support changing types through assignment' in Stateflow?

166 vues (au cours des 30 derniers jours)
I am implementing a logic using stateflow and I need to change the value of the input if one of the entry conditions get satisfied so as to not get caught in a loop. for example in the picture the inputs are color1 and color2 which are enums of the class Color. I am assigning color1 and color2 to temporary variables. Inside the subchart the first condition will be tested and if that is satisfied it will enter codn1 and assign the temporary variable with another value so that the condn2 can be tested. If the temporary variable is not used the input can't be assigned a value during simulation. The idea here is to assign values to a and b in the same simulation time. However I end up having this error if I initiate the inputs from MATLAB workspace:
This assignment writes a 'Color' value into a 'double' type. Code generation does not support changing types through assignment. Check preceding assignments or input type specifications for type mismatches.
State 'Codn1'
"y1"
Figure1:
Example.JPG
But this error doesn't occur if I initate the inputs inside the simulink file using constant blocks as shown in Figure 2.
Figure 2:
Eample2.JPG

Réponses (1)

Raghav Singhal
Raghav Singhal le 20 Fév 2019
I believe you currently have the default datatype for the local variable you’ve assigned is set to double, whereas it should have been set to enum datatype as the variable you are referring to in the Stateflow Chart seems to be an enum datatype. This mismatch may be causing the aforementioned error during code generation
One way to resolve this would be to try changing the local variable type to enum <class> type within the Stateflow block. Once you explicitly change it, it should work fine.
Please refer to the following documentation link for further information:

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by