Stateflow is not working with Matlab - matlab

I cannot run state flow diagram from Matlab. I am using Matlab 2013b. Whenever I try to run it it gives a warning:
Warning: The model 'xyz' does not have continuous states, hence
Simulink is using the solver'FixedStepDiscrete' instead of solver
'ode4'. You can disable this diagnostic by explicitly specifying a
discrete solver in the solver tab of the Configuration Parameters
dialog, or by setting the 'Automatic solver parameter selection'
diagnostic to 'none' in the Diagnostics tab of the Configuration
Parameters dialog
However I have modified the above mentioned two requirement from configuration setup. But it is still showing problem. Do I need to set up some additional software to fix this problem?

This is just a warning, not an error message, your model will run just fine as is. If you want to get rid of the message, change the solver in the model to FixedStepDiscrete instead of ode4 and it will go away, but it won't change anything in the actual running of the model.

Related

Dymola model not initializing with auxiliary variables turned off in output

I am trying to run a model in Dymola 2019 FD01 with auxiliary outputs turned off (to improve simulation speed). I've also set the flag:
Advanced.AutoRemoveAuxiliaries = true;
When I try to run the model, I get:
Error: Integrator failed to start model.
I am able to run the same model with Auxiliary Variable outputs turned on and the flag set to true.
I was wondering if someone else had this issue before and how to go about troubleshooting this problem.
The dymola user manual states this about the flag:
Advanced.AutoRemoveAuxiliaries - Removes code for auxiliary variables that neither influence the simulation state nor the outputs. This improves performance a bit. If the auxiliary code is used to assert correct behaviour or to generate external outputs, that code will not be run.
I am able to run some other models which have assert statements with the same settings (aux outputs off), so it seems like there is something else essential to the model removed during initialization.
I am trying to replicate the issue with a simple model but i have no idea where to even start.

How to update variable in From workspace block during runtime

I have a sample model(shown below) which consist of a from workspace block. It contains a workspace variable variable1(timeseries signal). I am changing the data of variable1 during simulation but model is not updating the current value of variable1. It's update only when I stop and restart the simulation but I want it to update during runtime only. Can anyone help me in handling this problem?
This is not really how Simulink is designed to work, so there's no easy way to do this. Simulink only checks only checks the workspace for values during model initialization at the start of the simulation. The best thing to do is to use set_param, as in:
set_param('untitled/From Workspace',' VariableName','variable1'); % put the correct path to your block
This is not changing anything in how the block is parameterised, but forces Simulink to parameterise the block with the new values of variable1. Because variable1 is a timeseries object, I am not sure how well this will work, but it's worth a try.
For more details, see this discussion on MATLAB Central.

How can I pass Bus signal input to simulink model during runtime

I have a simulink model which takes Bus signal as input. I have passed the bus signal data using Configuration->Data import/export ->input
Now I want to vary this signal from workspace when model is running and see the output during runtime.
But model is taking new data from workspace only when you stop the model and run again. Is there any way to feed the input to model during runtime?
By default Simulink looks in the Workspace for data at initialization, not at every time step. Hence the behaviour you are seeing.
To make it look in the workspace during the simulation you need to force it to do so. This can be done by using set_param to change a dialog parameter.
Once you've made a change to the variable in the workspace, in your case, something like set_param(gcs,'ExternalInput',get_param(gcs,'ExternalInput')) should work.
This is just getting the string that is in the dialog box and poking the (same) string back into the dialog.
This tells Simulink that something has changed and it'll go and re-read the variables.

My simple Stateflow model shows error

I'm almost new to Simulink and Stateflow. I am trying to model some simple state machines. But when trying to run the model, it shows errors (on the main Matlab screen).
Warning: Input port 1 of 'sample/If' is not connected.
Warning: Output port 1 of 'sample/If' is not connected.
Parsing failed for machine: "sample"(#90)
1) Is there anything wrong with this?
2) One more question: How can I add a timer on S2? e.g. we can not stay more than 2 minutes on S2. So as soon as we enter S2, a timer starts, and when it reaches 2 minutes, then should transition to S3.
P.S. For some reasons, the stateflow thumbnail on simulink scheme is not showing the updated model; there is no condition and if_outfput variables anymore!
Well, the error message is pretty self-explanatory: you haven't connected the input Condition of your Stateflow chart to anything, hence the error. Connect it to a signal in your Simulink (whatever represents your condition signal). Likewise, you haven't connected the output of the chart to anything either. You say these variables aren't there anymore, but Stateflow doesn't seem to think so. Have you deleted them from the Model Explorer? If not, Stateflow will still think they're part of the chart. See Use the Model Explorer with Stateflow Objects in the documentation for more details.
For the timer, yes it's possible. At the moment, you exit S2 to S3 when input ==1. You can change the transition to be [input == 1] || after(2000,sec) (I think). You may need to enable support for absolute time in the model configuration parameters. See Control Chart Execution Using Temporal Logic in the documentation for more details.

Is is possible to programmatically play a Simulink model and measure its states?

I am looking to set up a test set for an existing Simulink model. Ideally I could take full control of the model, explicitly stepping it and measuring the state of any signal on any bus in the model.
As might have been gleaned, this is the precursor of a unit testing system for the model. Being so, I can't really justify changing the model to suit the test, the test must accommodate the model as-is.
The furthest I've got so far is using load_model() to return a handle to the model. From there there seems to be a quite obscure set of functions for accessing the model. I can't see any that relate to accessing states and can't see any further commands that relate to accessing a loaded model.
The easiest way is to use the Data Import/Export function within the Simulink Preferences.
Set the checkbox States and it will store every state of your system for every time step in your workspace, also when you pause the simulation or execute it step by step.
Be aware not to set Save simulation output as single object, in this case the access would be more complicated and you need to follow the instructions here.
To add to the other answer, you probably want to check this page in the documentation: Control Simulation Using the set_param Command. Of interest are the following commands:
set_param(<model_name>, 'SimulationCommand', 'start')
set_param(<model_name>, 'SimulationCommand', 'pause')
set_param(<model_name>, 'SimulationCommand', 'WriteDataLogs')
set_param(<model_name>, 'SimulationCommand', 'continue')
Replace <model_name> by the path to your model file.