samedi 26 décembre 2015

CodeSys 2.3 State Machine

What is the best way to make efficient and flexible state state machine(SM) in IEC61131-3 / CodeSyS v2.3? Are there any good examples of SM realizations on CodeSys V2.3?

As far as I understand, there are 3 different types of SM:

1.Case logic SM - simple, just change states based on if logic, not flexible at all, hard to maintain.

2.Table driven SM - better, but without function pointers there is need in additional conditional instructions to run some actions based on current state.

3.State Design Pattern SM - best option, flexible, no huge CASE statements, no duplication.

I am trying to adopt C State Design Patter by Adam Tornhill: http://ift.tt/1R16o4J But it is quite hard to translate from plain C to Structural Text. CodeSys has support for Function Block pointers but I can't figure out how to declare incomplete pointer type in ST (is it even possible?):

/*C-style incomplite state pointer*/
typedef struct State* StatePtr;

struct State
{
   EventFunc exampleFunc1;
   EventFunc exampleFunc2;
}

{ST-style incomplite state pointer ???}
TYPE Sm_state_t :
STRUCT
State:POINTER TO ???;
END_STRUCT
END_TYPE

Aucun commentaire:

Enregistrer un commentaire