[SOLVED] Modulo formula for ATC shortest-path

More
01 Mar 2023 21:28 #265674 by spumco
[MODS - this is related to PB, but it's basic LCNC & G-code formula. Prolly not right to bury it in the qtpyvcp sub, but move if you think appropriate]

I'm switching my ATC control from carousel.comp to treating it like an axis (B).  Could use some help writing the shortest-path formula for my NGC files.

This sequencing is roughly based on the Probe Basic M-codes, but I can't just copy-paste everything over as the PB scheme is based on a geneva mechanism and my ATC is based on a stepper + reducer.  Basically, I need a distance to move, and the PB scheme moves until a parameter value decrements to zero (essentially a velocity * time move).

Right now I've got three basic files to rotate the platter:
  • M10
    • Calculates steps to move (pockets)
    • Calculates shortest path direction
    • Outputs M11 P[#<steps>] or M12[#<steps>] depending on CW or CCW
  • M11
    • Commands B-axis incremental move (positive) based on [ABS[#<P>]] * [degrees/pocket from INI]
    • Updates current pocket number after move
  • M12
    • Same as M11, only negative incremental move
So what I need is some formula that picks a direction and then sends a number of steps value out.

I'm lost at the steps to move and shortest path part.  The original PB math doesn't seem to work out for me (though certainly possible I'm being dense) when I try to verify the calculations.

If anyone wants to take a stab at this, I've got 18 pockets.

M10 (original PB)
NOTE - #5170 is the current pocket at start of sequence & #<p> is next pocket passed from remap
#<steps> = [#5170 - #<p>]
(print, o<M10> P#<p>, steps=#<steps>)

o1000 if [#<steps> GT 9]
    #<steps>=[#<steps> - 18]
o1000 endif

o1001 if [#<steps> LT -9]
    #<steps>=[#<steps> + 18]
o1001 endif

o1003 if [#<steps> GT 0]
    M12 P[#<steps>]

o1003 elseif [#<steps> LT 0]
    #<steps>=[#<steps> * -1]
    M11 P[#<steps>]
o1003 endif

Thanks in advance for any guidance.
-R

Please Log in or Create an account to join the conversation.

More
02 Mar 2023 10:28 #265708 by rmu
Replied by rmu on topic Modulo formula for ATC shortest-path?
first, calculate number of steps: #steps = #5170 - #p

second, if #steps is negative add 18

third look if #steps > 9, subtract 18.

example1: current 18, new pocket 2: 18 - 2 = 16, subtract 18, result -2
example2: current 2, new 18: 2 - 18 = -16, add 18, result 2.
The following user(s) said Thank You: spumco

Please Log in or Create an account to join the conversation.

More
02 Mar 2023 14:04 #265721 by spumco
Replied by spumco on topic Modulo formula for ATC shortest-path?
Thank you, the text translation of the math is just what I needed.

However, the formula fails under certain conditions:

Current=1, new=5;
1-5=-4 (add 18), result 14

Is there an additional step I need to do to get shortest-path?

Please Log in or Create an account to join the conversation.

More
03 Mar 2023 05:59 #265760 by cadpete
Replied by cadpete on topic Modulo formula for ATC shortest-path?
You have not applied the third step -
if #steps > 9 then subtract 18

However I think this should maybe read as the absolute value, eg the -4 should be +4
The following user(s) said Thank You: spumco

Please Log in or Create an account to join the conversation.

More
03 Mar 2023 10:08 #265771 by rmu
Replied by rmu on topic Modulo formula for ATC shortest-path?
current=1 new=5

(1) 1 - 5 = -4
(2) -4 + 18 = 14
(3) 14 - 18 = -4

so move 4 positions into "-" direction. sign is a convention, maybe it would be more logical to define going from 1->5 as the "+" direction, then just change order in step 1.
The following user(s) said Thank You: spumco

Please Log in or Create an account to join the conversation.

More
03 Mar 2023 17:16 #265785 by spumco
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
Attachments:

Please Log in or Create an account to join the conversation.

Time to create page: 0.063 seconds
Powered by Kunena Forum