Beckhoff-USA-Community / SPT-Libraries

MIT License
86 stars 20 forks source link

Using state machines in components' implementation. #66

Open achimlucian opened 3 months ago

achimlucian commented 3 months ago

The control systems are mostly meant to perform a small or a large number of steps either they are in linear sequence or not. Non linear sequences are taking the decisions based on a set of data available in the current state. The decision moves the sequence into the next state based on the decision taken (Transitions).

In the SPT library, when implementing sequences I see 2 approaches. One is implementing state machines (SMs) in a simplified way using Switch/Case statement (in OOP languages - C++ or C# - is used State Design Pattern). The onther way I see is using flags to control the states.

PackML standards are meant to introduce a set of predefined state machines into the control systems of various scales.

The use of flags in more complex sequences becomes very hard to read, maintain and document. On the other hand, the SMs can be very easy described in UML State Diagrams (flow diagrams) and code can be much easier to read.

To keep implementation consistent is better implementing SMs in all layers, including in components (e.g. cylinder actuators).

Implementing SMs in the components might need customization in terms of naming of the states, but documentation and readability of the code is always esential. Use of Enums to describe states instead of numbers can be a great approach.

This will improve consistency in the implementation of the entire system.

AB#5170