Simulink function in Stateflow error - matlab

I have multiple subsystems each of which have State machines "Stateflow". One subsystem has FSM, inside one state there is a simulink function that is supposed to start "simulink model representing an ODE" when in that state , a solution is observed until it reaches a threshold , the value of which shall trigger a transition of a state in a different subsystem
I used the Simulink function inside the stateflow as indicated in numerous tutorial, but the error I'm getting is the following:
'MatlabFunInChart/Chart/VelocityProfile/Cart/Integrator' has sample time '0'. Only constant (inf) or inherited (-1) sample times are allowed in 'function call' subsystem 'MatlabFunInChart/Chart/VelocityProfile'.
It looks like I'm missing something inside the simulink model that has to do with the integration.
Any ideas ?

Related

configure entry points in simulink model to make it callable

I've been handed a simulink model. I'd like to use simulink's code generation features to compile it into a binary and then run it on an embedded system (a beaglebone black). From there, I want to query it for output as a stand-alone component of a more complicated system.
I am having trouble finding where to specify the interface behavior to the compiled model.
I want to start the simulink model (with a python os.system() call, probably) with some default arguments (like starting parameter values for the model blocks), and then capture its output, which should be the values reported at each outport at each tick (the model has an internal clock and reports values at given intervals).
I have been able to blindly compile it into an *.elf binary and deploy it to the embedded device, and it runs, but the only thing that happens is i get the string **** model running **** on STDOUT.
What's the easiest way to specify command line arguments into this compiled binary?
If the answer is "generate the code and then edit it by hand to pass arguments in", how do I persist the hand edits between re-generations of the code when the simulink model changes?
How do i make simulink outports report on STDOUT ?

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.

How to export simulink data to workspace during simulation?

I want to retrieve the data from simulink during simulation, and use serial network function to send these data to another program. Because I need to use another program to do some tricks and send command back to simulink, so I have to get data from simulink during runtime so that another program can make the right command.
I've tried using To Workspace block to export the data.
However, I can only got value in the very beginning of the simulation.
And I've also tried using scope and change some properties: check Save Data To Workspace and Uncheck Limite data to Last.
First, I started simulation, and I found the ScopeData didn't appear in the Workspace. Only when I stop simulation, ScopeData would appear in workspace.
And after that, I can use ScopeData.signals.values to get values.
But what I want is: when I start simulation, ScopeData would appear in workspace so that I can send these data to other program.
Does anyone know how to achieve this?
I found this page might be helpful, but I still don't know how to continuously export data during simulation.
Use get_param to read data from just at the current time. Also to send the data back to Simulink with set_param of a gain or another block.
An example of get_param
First load and start the simulation:
load_system('myModel')
set_param('myModel','SimulationCommand','Start');
To read data on any line of your simulink model:
Get a simulink block object (let's try a Clock with the name Clock):
block = 'myModel/Clock';
rto = get_param(block, 'RuntimeObject');
Then get the data on its first (or any) output port (or input) of that block.
time = rto.OutputPort(1).Data;
You could do the reading, in a timer callback.
Also this might be helpful: Command Line Functionality for Simulink
During simulation Simulink stores logged data in an internal buffer and only writes the data to the Workspace when the simulation is paused or stopped.
It sounds as if you really need to write an S-function (which will get signal values on a timestep-by-timestep basis) and communicate with Proteus that way.
Of course Simulink is a non-realtime simulator, so if you are talking about doing anything resembling real-time control then you are most likely taking the wrong approach altogether.
At any time during simulation you can force Simulink to write the simulation output data to the workspace:
set_param(bdroot,'SimulationCommand','WriteDataLogs');
I've found that this command is quite unstable in my Matlab 2010a for Win64. In particular I have to avoid it when simulation is stopped (i.e. first check
get_param(bdroot,'SimulationStatus') ), otherwise Matlab shows an error and asks to be restarted.

1]Change variable value during script is running 2] while running Script in loop does not update variable value in workspace

I am controlling a pilot plant of boiler through Matlab using modbus RTU (serial communication).
I am running my control program (in editor) for 45 mins through a loop but I am facing two problems :
1] I can't change any variable value while running program which is deadly needed.
2] I am unable to see real time data in workspace while running script.
It updates all variables after finishing execution time. For my application I want data to appear for every iteration.
I couldn't solve them so I switched to simulink but that was even more frustrating.
In simulink I used user defined blocks (embedded Matlab function) to generate modbus address PDU which does not support to in-built matlab functions (like dec2hex).
Will please someone let me know in simulink, serial send/receive support which data format?(ASCII/HEX/DEC)
If you want to see the status of your system after each iteration this can be solved by putting a breakpoint there. If required you can even change the value of variables then.