Hello Guest it is December 26, 2024, 01:00:13 PM

Author Topic: Advanced G Code Programming - Advise or Alternatives Needed  (Read 4295 times)

0 Members and 1 Guest are viewing this topic.

Offline rbjem

*
  •  15 15
Advanced G Code Programming - Advise or Alternatives Needed
« on: March 02, 2013, 01:58:16 PM »
Hi everyone,  I am looking for advise on how to go about programming some files to make them easy to change at the machine. My parts typically have 1-4 holes in them and a slot (this is extremely simplified, but will serve well for the example). Each piece is usually custom so I end up having to make a separate file for, 1 hole and a slot, 3 holes and a slot, 2 holes and no slot, etc... This gets tedious when you have 30+ similar parts that all need multiple configurations.  I could program a file for exery permutation, but would love to have a single file capable of making any configuration of that part.

Essentially, I would like to be able to have a provision to individually enable/disable hole 1, hole 2, 3,  4 and the slot. I was originally planning on using GOTO or IF/THEN statements in the G Code, but then found out Mach3 cant do that.   :'(

I was thinking I could set variables at the start of the code that I can edit to be 1 or 0 (on/off). Then write a macro that calls a variable, checks if true or false and enables/disables block delete to turn off the next bit of code.  I would run the macro before each hole or slot.  

Here is a basic eaxmple of that:
Quote from: G Code
#120=1  (hole 1 toggle)
#121=0  (hole 2 toggle)
#122=1 (slot toggle)

(Cut Profile)
... gcode...
... more gcode...

(DRILL HOLE 1)
#200=#120 (set blockskip toggle for next subprogram call)
M26 (call blockskip macro)
/ G0 X1.5 Y2. (move to hole location)
/ G1 Z0.
/ G2 I-.25
/ G1 Z1.

(DRILL HOLE 2)
#200=#121 (set blockskip toggle  for next subprogram call)
M26 (call blockskip macro)
/ G0 X1.5 Y3. (move to hole location)
/ G1 Z0.
/ G2 I-.25
/ G1 Z1.

(CUT SLOT)
#200=#122 (set blockskip toggle for next subprogram call)
M26 (call blockskip macro)
/ G0 X.5 Y1. (move to location)
/ G98 (slot.nc)

M30


Corresponding Macro:
Quote from: M26
trigger = GetVar (200)   'block skip enable disable variable

IF [trigger = 1]  then turn off blockskip  <-- I know this is not the right command...  have not figured it out yet.
End IF

I tested this out this morning (well not the macro, only the code by manually toggling Block Delete at M0 stops) and found out that I cant enable/disable block skip delete in the middle of a file. It can only be toggled before you start running the code.  So this method seems like it wont work like i had hoped.  :-\

Does anyone have any other ideas on how to individually toggle or skip past different portions of the code in a way that is easily modifiable from the machine? In the above example, I used holes and slots, but the portion I want to toggle could just as easily be a chamfer or a 3d contour.

Maybe I need to go a totally different route, but I am running out of ideas...   Any suggestions would be greatly appreciated.


Regards,
rbjem

Please note that I am not a gcode expert by any means, I know just enough to be dangerous. >:D
Re: Advanced G Code Programming - Advise or Alternatives Needed
« Reply #1 on: March 02, 2013, 02:17:35 PM »
You could assign parameters that specify the depth of each hole.  Since you are doing a single plunge for each hole, if you set the depth using a variable, and set the corresponding variable to the Z clearance height, the machine will rapid to that position, *not* drill the hole, then immediately rapid on to the next position.  There may well be a better solution, but this is simple and will work.

Regards,
Ray L.
Regards,
Ray L.

Offline BR549

*
  •  6,965 6,965
Re: Advanced G Code Programming - Advise or Alternatives Needed
« Reply #2 on: March 02, 2013, 02:47:35 PM »
One of the best ways to do this (and there are many) is to use a combination of #vars and sub programming.

You can create a Macro that runs at the start of the program to program the #vars as needed.  A window pops up asking questions and the OP answers them. The macro then programs the values of the associated #vars.

Next the Operations are done as SUBs that can be called or ignored based on the #var values.

#1=1
M98 P#1

This calls the SUB o001 and runs it 1 time

#1=0
M98 P#1

This calls NO sub to be run and simple ignors the call and preceeds on with the rest of the program.

The same can be done with the Lvalue

#1=1
#2=1
M98 P#1 L#2

This runs the o001 sub 1 time

#1=1
#2=0
M98 P#1 L#2

This SEES the sub BUT does it ZERO times.

Just a thought, (;-) TP

Offline rbjem

*
  •  15 15
Re: Advanced G Code Programming - Advise or Alternatives Needed
« Reply #3 on: March 02, 2013, 05:05:20 PM »
Thanks for the replies.  I like both of these ideas quite a bit.  The way I look at it now, I will probably use a little of both of those tricks.  In order to get the L parameter to work as I want, I need the subprogram to not execute if I turn it off (ie. if the toggle variable  = 0).

Thanks to bobeson and his thread (link below), I was able to setup an equation to set any non-zero value to 1, and 0 always equates to 0. 
Link:http://www.machsupport.com/forum/index.php?topic=13329.0

Quote
#1=1 (hole1 toggle)
#2=1 (slot toggle)

 (Cut Hole)
#11=#1
#11=[ 1- [ 1 xor #11 ]]
M98 P1 L[ #11 ]

(Cut Slot)
#11=#2
#11=[ 1- [ 1 xor #11 ]]
M98 (slot.nc) L[ #11 ]

M30

O1
g1 x3 F100
x0
M99

Amazingly that code works!! Now I'm wondering how will a slightly modified version of that equation will work if I tie it in with HimyKabibble's suggestion of using variables for the z depth.... some very interesting stuff could be done with this.

I'll have to play around with it a little more to figure out which will work better for my situation. Maybe there's an even simpler method still, but this gives me something to think about.