Can classes or class variables be used in stateflow charts / test sequences

I'm creating a test sequence for a test harness and would like to use an object in the steps. However, I receive a message that Data type of '<initialized object variable name>' is not supported in Stateflow charts. I know I can perform function calls, but I need some state maintenance to drive function behavior and would like to use an object's methods instead of raw functions.
Is this possible?

 Accepted Answer

It is not possible to directly use object methods in Stateflow charts. Stateflow charts only support basic data types and cannot directly handle objects. However, you can work around this limitation by using function calls instead of object methods. You can define functions that encapsulate the desired behavior and call these functions from your Stateflow chart. This way, you can still achieve the state maintenance and drive the desired behavior using functions.
Here's an example to illustrate this approach,
% Define a function that encapsulates the desired behavior
function myFunction(obj)
% Perform state maintenance and drive behavior using object methods
obj.method1();
obj.method2();
% ...
end
Then, in your Stateflow chart, you can call this function:
chart MyChart
properties
obj; % Initialized object variable
end
methods
function entry(obj)
% Call the function that encapsulates the desired behavior
myFunction(obj);
end
end
end
By using this approach, you can achieve the desired state maintenance and behavior while still working within the limitations of Stateflow charts.
Hope this helps!

4 Comments

I'm using a test sequence form of stateflow chart and there is no way for me to include an object as a property. It will only accept base data types as Local or Constant values. While I can make a function that could accept an object as a passed parameter, I have no way to initialize an object in the test sequence that could then be passed to the function. What am I missing? How would you initialize the object in the stateflow chart / test sequence? I get errors anytime i try to include an initialized object.
Stateflow, depending on the version you're using and its capabilities, might have constraints on what types of data can be initialized directly within test sequences.
Here are a few potential workarounds you might consider,
  • If your version of Stateflow allows it, you could utilize MATLAB Function Blocks within your Stateflow chart. This would enable you to write MATLAB code directly within the Stateflow environment, including object initialization.
  • Initialize the object in the MATLAB workspace before running the test sequence. Then, in your test sequence, you can refer to this pre-initialized object.
  • As you mentioned, you can create functions that accept objects as parameters. While you can't directly initialize objects within the test sequence, you could have a setup function outside of the Stateflow environment that initializes objects and passes them into your Stateflow chart via function calls.
Without more specific information about your setup and constraints, it's a bit challenging to provide a tailored solution, but hopefully, these suggestions give you some ideas on how to proceed.
Thanks again for the inputs. Test sequences don't have access to the base workspace and don't appear to allow usage of evalin / assignin calls. I tried working around that by using an evalin call from a function called in a test sequence, but the test sequence then tried to add the object variable from the function's evalin call to the local variables in the test sequence and it could not do so b/c of the inability to handle object data types.
My setup is an intentionally simple 1-step test sequence in MATLAB 2023b that just seeks to find some way to call a method from an object in the base workspace or somehow get that object reference accessible to the test sequence.
The workaround I went with is using a MATLAB function block to hold the object and its state, then I use the test sequence to drive ports on the MATLAb function block to support multiple test cases and state changes.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023b

Asked:

on 25 Apr 2024

Commented:

on 8 May 2024

Community Treasure Hunt

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

Start Hunting!