If a state machine is called periodically (in MatLAB Simulink or PLC program), is it possible to transition between states during the same plc cycle/simulink step?.
In Twincat 3 (PLC) there is such an option "Cycle-internal" as in link below: https://infosys.beckhoff.com/content/1033/tf1910_tc3_uml/63050395607969163.html
are there any constraints to use such option? would the system still be real time capable?
Edited as I can't write a long comment:
1- In your example, If the state is an In-Cycle state and is responsible for generating set points for the motor till it reaches the required set point (hence taking a lot of time). The program can be "stuck" in this state causing a task overrun, and violating the real time constraints. Suggested solution: Control the max. number of calls for this state with the variable "Max. DO cycle calls" : https://infosys.beckhoff.com/english.php?content=../content/1033/tf1910_tc3_uml/63050395607969163.html&id=, or is it possible/better to implement this task in a separate PLC task?
2- For a state chart with no In-Cycle states, the program stops excuting the chart, saves the states, and execute the rest of the program after ONE evaluation of the current active state(s). If all states in the chart are In-Cycle, where does the program stops excuting the chart to execute the rest of the program?
Is the only solution is to have some states that are not In-Cycle and making sure they are reached fast enough not to cause a task overrun?
A PLC is made to be real time capable, so to answer your last question, yes the system is real time capable regardless of the programming language you are using.
When you use the tf1910 extension, code for the Beckhoff runtime is generated in the background, which will run cyclically every x ms depending on your configurations.
Translating the Cycle-Internal operation to a structured language could look like this:
Imagine you have a software-component Motor which extends a software-component StateMachine.
StateMachine defines different (primitive) states like Init, Ready, Busy, Idle, Error etc.
V Boot()
|
|
<Init>
|
|
| Start()
|
|
<Ready> -----------<--------------+-------------<-----------+
| | |
| | |
| Execute() | |
| | |
| | |
| | Reset() |
<Prepare> | |
| | |
| | |
| | |
Wait() | Fault() | |
<Waiting> ---<-------->--- <Busy> ----------->----------- <Error> |
EndWait() | |
| |
| |
| |
| Done() |
| |
| |
| |
<Idle> ---------------------->------------------------------+
As a consequence Motor also inherits those states.
Now, if Motor is in the Init state, calling the Start() method will change the state from Init to Ready.
Depending on the architecture of your program this change can have an immediate effect on the program flow (this means in the current cycle) or in the next cycle.
Let's say, our StateMachine Function Block implements Cycle-Internal as a boolean input variable: bCycleInternal and it's current state as an enumaration variable: eStateMachine
Let's also say that, depending on the value of eStateMachine (thus the current state of the state machine), StateMachine calls a specific method (e.g. for Init Init(), for Ready Ready() etc.)
When bCycleInternal is true and the Start() method changes the current state from Init to Ready, Ready() is called directly after Init() in the same cycle. Otherwise, if bCycleInternal is false, when changing the state of the state machine (or the value of eStateMachine) from Init to Ready with the Start() method, Ready() is called not before the next cycle.