For a motionPLC project written in ST, I use a lot of stepper structured functions like this:
stepNum := 1;
CASE stepNum OF
1: (* Move axis to upper positon *)
axis.in.position := 0;
axis.start := true;
IF(axis.out.position = 0) THEN
stepNum := 2;
END_IF
2: (* Do something else *)
The goal behind this approach is to be able to wait for the drive to complete its task, before moving to the next task.
This works, but as programs grow more complex, and steps don't always need to be sequential (you can go from waiting state, to operating state, to fault state and back to waiting state), the code starts to look more like spaghetti code as written in the days of qBASIC.
Are there other styles to write this program that enable me to wait for the drive to finish its task, but that don't get so convoluted?
Please let me know if this question is 'too broad', I didn't know where else to ask.
Honestly the case
statement is the best way I have found to accomplish what you are talking about. However you can combine functionality in a function
or function block
to reduce the amount of code written in each step... or perhaps have mini case
statements within function blocks
to reduce the amount of code in one place to make it more "readable".