1) if commanded_speed = 0, go to 17 (no change needed)
2) if abs(commanded_speed) > XXX, go to 5 (need high gear)
3) if abs(commanded_speed) < YYY, go to 12 (need low gear)
4) go to 17 (in overlap region, can use either gear) (note - this is used to implement some hystersis... if the shift point was a single speed, for example 2500 rpm, then a command that changes from 2499 to 2501 and back would result in multiple shifts - having an overlap of some tens or even a few hundred RPM avoids unneccessary shifts)
5) if "HIGH_GEAR" input is active, go to 17 (already in high gear, no change needed)
6) send (zero) to spindle drive, wait until spindle stops
7) de-energise "LOW_GEAR" output, energize "HIGH_GEAR" output (this attempts to mesh the gears)
8) send (slow) to spindle drive (helps the gears to engage)
9) wait for "HIGH GEAR" input (this means the gears are engaged)
10) go to 17
11) if "LOW_GEAR" input is active, go to 17 (already in low gear, no changed needed)
12) send (zero) to spindle drive, wait until spindle stops
13) de-energise "HIGH_GEAR" output, energize "LOW_GEAR" output (this attempts to mesh the gears)
14) send (slow) to spindle drive (helps the gears to engage)
15) wait for "LOW GEAR" input (this means the gears are engaged)
16) go to 17
17) if HIGH_GEAR input is active, set GEAR_RATIO to XXXX
18) if LOW_GEAR input is active, set GEAR_RATIO to YYYY
19) send (commanded_speed * GEAR_RATIO) to spindle drive
20) wait until drive indicates AT_SPEED
21) done