Again, thanks all for the help.
Turns out the Probe Basic 'standard' logic works for what I want when edited to control an ATC as an axis. Any problems were simply due to my lack of understanding and atrocious math skills.
Frankly, I wasn't able to keep track - mentally - of the variable values as they changed until I set up a spreadsheet which showed each value change during the whole sequence. Once I did that I could test all the combinations of origin->destination pocket commands and check the result.
So what I've wound up with is, basically, the original PB sequence & logic just edited a bit. Unsurprisingly, the math is mostly a duplicate of what @rmu and @cadpete have suggested.
(in English, for those like me that have a hard time following g-code parameter gymnastics)
- M10
- Homes ATC if not already homed
- Called by the main toolchange.ngc
- Determines shortest-path direction
- Calculates number of steps from origin to destination along shortest path
- Selects M11 or M12 depending on CW or CCW
- If steps to move is negative, converts to positive number
- M11 (CW)
- Homes ATC if not already homed
- If called without a step value (no #<P> passed) [to manually jog ATC one pocket]
- Assigns a value of "1" to steps
- If called with step value passed from M10
- Assigns value passed from M10
- Moves/updates Probe Basic ATC screen widget to match reality (the "DEBUG, EVAL" comment)
- Moves ATC correct number of pockets (G91 incremental move: steps x degrees/pocket)
- Modulo formula updates a persistent parameter which represents current pocket
- M12 (CCW)
- Same as M11, except
- G91 move is negative
- Formula to update current pocket parameter is reversed
Maybe still needed: error handling so if the sequence is interrupted the current pocket parameter doesn't get out of sync with reality.
I'm attaching the files for future reference. The logic is no different than what's already in the Probe Basic sim config, but these are an example of when an ATC is controlled as a step/direction axis (B, U, V, W, etc.) instead of with a 'dumb' motor and geneva mechanism.
NOTE: ignore the silly amount of commenting in the files - think of them as electronic sticky notes for the memory-challenged.
As usual, if anyone spots an error or has questions, feel free to chime in.
-R