Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different programming styles for motion PLC

Tags:

plc

motion

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.

like image 552
DrDonut Avatar asked Mar 19 '26 21:03

DrDonut


1 Answers

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".

like image 76
mrsargent Avatar answered Mar 21 '26 13:03

mrsargent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!