Hello Guest it is December 21, 2024, 07:22:07 AM

Author Topic: Macro generated GCode hesitation  (Read 4093 times)

0 Members and 1 Guest are viewing this topic.

Offline rbjem

*
  •  15 15
Macro generated GCode hesitation
« on: January 10, 2013, 05:18:32 PM »
I have made a macro (only after I found out I couldn't do it solely with gcode) to create some gcode, and have an issue with stuttering that I am wondering if anyone could shed some light on. 

First background info...

I am trying to create a helical toolpath so that I can quickly change parameters for different situations.  I have it coded to the macro to: (starting from the bottom of the cut) make a vertical move, helix around at a desired pitch and radius until I reach a certain z height, then exit the cut vertically.  This then repeats after increasing the cut radius by a small stepover. So far I have gotten this all to work.



My issue is that when executing the macro, the machine moves like it is in absolute stop (G61) mode rather than constant velocity.   I am guessing the issue is due to the way the code is calculated for each step, but am unsure if it is due to my code, or if this is a limitation of mach3. When the angle increment is set to a low value motion slows to a crawl. 

Here is the snippit of code that I am having an issue with:
(I made the program in polar coordinates (G16), so Y is equivalent to angle)
Quote
        Do   'Begin helical interpolation
           CURRENT_Z_HEIGHT = (CURRENT_Z_HEIGHT +(PITCH * ANGLE_INCREMENT / 360))  'increment height for this move
           CURRENT_ANGLE = (CURRENT_ANGLE + ANGLE_INCREMENT)   'increment angle for this move 

                CODE "G1 Y" & CURRENT_ANGLE & "Z" & CURRENT_Z_HEIGHT
              
   
           If CURRENT_Z_HEIGHT >= (TOTAL_HEIGHT - FLAT_LENGTH) THEN   'stop at top of helix
                 Exit Do
      
           Else
                 End If

        Loop

This portion executes then is looped back up to the top after incrementing the cut radius.  So essentially I am trying to program a loop in a loop.  Maybe there is a method to do this entriely in a gcode file, but so far it has eluded me. 

Any suggestions, insight, or alternative methods would be appreciated.
Re: Macro generated GCode hesitation
« Reply #1 on: January 10, 2013, 06:11:21 PM »
Why not simply use G2/G3?  What you're doing will be very slow, because you're generating lots of very short, straight lines, which is a terribly inefficient way to generate any circular move.

Regards,
Ray L.
Regards,
Ray L.

Offline rbjem

*
  •  15 15
Re: Macro generated GCode hesitation
« Reply #2 on: January 10, 2013, 06:14:33 PM »
More testing.... same stuttering :-\

I have rewritten the offending part of the macro so now the helix loop has no calculations and does not check to see if the z height is at the max.  I set it so it now uses a FOR loop in incremental coordinates. Now, before the loop, it calculates how much to increase the z per angle increment and how many steps needed to get to the correct height.  There should be a lot less computation going on now since nothing is changing.

This is what that section now looks like:
Quote
Z_INCREMENT= (PITCH * ANGLE_INCREMENT / 360)
Steps =  Round((HEIGHT - (2 * FLAT_LENGTH)) / Z_INCREMENT)

        For i=0 to STEPS   'Begin helical interpolation
         CODE "G91 Y" & ANGLE_INCREMENT
         CODE "Z" & Z_INCREMENT
        Next i

Offline rbjem

*
  •  15 15
Re: Macro generated GCode hesitation
« Reply #3 on: January 10, 2013, 06:17:24 PM »
I agree about the inefficiency. I thought about G2/G3 and didnt initially think of a way to do it easily in Gcode. I guess now that Im writing a macro, that should be more doable.  I'll think about it more tonight.

Offline rbjem

*
  •  15 15
Re: Macro generated GCode hesitation
« Reply #4 on: January 10, 2013, 06:20:55 PM »
That brings up another question.  Although it should be quite easy to do in what I want using cartesian coordinates, I was wondering yesterday if it is possible to do a circular move (like a G2 or G3) while in polar coordinates.

Offline BR549

*
  •  6,965 6,965
Re: Macro generated GCode hesitation
« Reply #5 on: January 10, 2013, 07:27:15 PM »
IF you mean G15/16 then no is the answer. The big question would be WHY? As Ray stated G2/G3 is your answer and using parameteric Gcode with subs is the answer for a programable helix. Of any diameter, pitch or height.  Mach3 macros are never going to be the fast solution especially when you mix VB and Gcode.

Just a thought, (;-)

Offline rbjem

*
  •  15 15
Re: Macro generated GCode hesitation
« Reply #6 on: January 11, 2013, 10:56:20 AM »
Thanks for the replies.  This is the first time I've written a macro that generates gcode, so I wasnt sure if the stuttering was fixable or not. 

Anyways, I'll make a new version using arc moves, I'm confident that will work better.