# Linuxcnc - g-code - gcode sequence to change origin to machine multiple patterns



## dansawyer (Oct 14, 2021)

The project is to cut two patterns from a piece of bar stock on a BOSS 5. I have the subroutine to create pattern debuged, it seems to work as required. I have the setup in place for the origin for the first pattern and the move to the start of the second. However I am unable to reset the origen for the start of the second pattern.
I am not running the mill directly but watching the display on the GUI. I have the move to the origin in place. I have tired G10 commands, G53 commands, and G54 commands to reset the origin. However the simulation always retruns to the original origin.
When the process starts the position is 0,0, the first pattern is run from that position. If the the start of the second pattern is 1,1 what is the g commnad sequence to move the bed to the start of the second pattern and set to working origin to that location? The patterns are written to assume they start at a 0,0 offset.
Thanks in advance, Dan


----------



## JimDawson (Oct 15, 2021)

Maybe you will find this helpful https://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g10-l2

But the way we many times do it is to just have both parts on the CAM setup and handle it like a single part with only one 0,0 point.


----------



## dansawyer (Oct 15, 2021)

JimDawson said:


> Maybe you will find this helpful https://linuxcnc.org/docs/html/gcode/g-code.html#gcode:g10-l2
> 
> But the way we many times do it is to just have both parts on the CAM setup and handle it like a single part with only one 0,0 point.


Jim, I was wondering how you were doing. It has been a while. The first pattern cuts correctly, and the tool positions to the base of the seconf pattern. However attempts to reset the origin do not appear to set the new origin relative to the part. I will keep you informed.


----------



## JimDawson (Oct 15, 2021)

It has been awhile.  I'm still alive and kicking. 

Can you post a picture of what you are trying to do.  I'm a bit confused.  But I have never used LinuxCNC before so maybe setting the G54, G55 does not act as I would expect.


----------



## RJSakowski (Oct 15, 2021)

I use Tormach's PathPilot which is a Linux CNC derivative.  Can you furnish some examples of your code?  I haven't used work offsets for some time and when I did, it was in Mach 3.  As I recall, you had to set the G54,55,etc. offsets prior to running the program.  IIRC, I accomplished this by setting my G54 origin to 0,0,0 on DRO, moving to my offset position, changing to G55 and zeroing my DRO.  In your program, you just call out the desired coordinate system for that part.


----------



## dansawyer (Oct 15, 2021)

Thank you, the code is below. The code is trying to cut two arc loops. The arcs are cut based on the while loops. The zeroing code segments are the segments before the while loops; that code is being tested. If you load the code into the linuxcnc gui it the trace shows the first pattern starting at the origin, however it does not start the second pattern from the start of second pattern. 
Dan


/ cut arc for telescope support 
#1 = 0
#<_tool_dia> = .25
#<_dia> = 14.625
#<_radius> = [#<_dia>/2]
#<_length> = 12
#<_width> = .75
#<_offset> = .1 
#<_d1> = 4
#<_d2> = 6
#<_theta1> = [asin[#<_d1>/#<_radius>]]
#<_theta2> = [asin[#<_d2>/#<_radius>]]
/#<_theta> = 24.22094
#<_g> = [#<_radius> - [cos[#<_theta1>] * #<_radius>]]
#<_g2> = [#<_radius> - [cos[#<_theta2>] * #<_radius>]]

o1                             ; Main program 1
  G01 X [#<_offset>]   Y [#<_offset>] F25.0  ; reposition 
  g01 z .1
  G01 x0 y-[#<_tool_dia>/2] f25 ; change from offset tool to cutting tool 
  m0
  G10 L20 P1 x0 y0 z0           ; zero out offset
  m0
  g10 l2 p1 x0 y0 z0    
  m0
  g53 x0 y0 z0
  m0
  G01 Z0.3 f10            ; clear cutting tool
  o2 while [#1 gt -0.7]
     #1 = [#1 -0.1]
     M98 p100                   ; Call subprogram 100
  o2 endwhile  
  g01 z .5 f10        ; lift tool 
  g01 x0 y0   f20        ; return to center
  m0                ;pause before continuing 
  g1 x [#<_d2> - #<_d1> - 1] y[2.5 + #<_tool_dia>]    ; set tool to start of pattern 2
  #1 = 0
  g10 l20 p1 x0 y0
  m0
  g10 l2 p1 x0 y0
  m0
  g55 x0 y0 
  g01 z.3 f3
  o3 while [#1 gt -0.7]
     #1 = [#1 -0.1]
     M98 p200                   ; Call subprogram 100
  o3 endwhile  
  g01 z .999 f10        ; lift tool to clear work 
  g01 x0 y0                     ; return to starting point
M2                              ; End main program
/
/
/ Cut Arc 1
o100                            ; starting position - left 
 G01 z 0.2 f5        ; clear cutting tool 
/ G01 x3 y[#<_radius> -[cos[#<_theta>] * #<_radius>]] f25       ; move to starting position 
 g01 x[#<_d2> - #<_d1>] y[#<_g2> - #<_g>] f20          ; position on edge for start of cut 
 G01 Z#1 f3            ; reposition 
 G03 X0.00 y0.0  f5 I[ #<_d1> ]  J-[#<_radius> -#<_g>] 
M99
/
/ Cut Arc 2
o200                            ; starting position - left 
 G01 z 0.2 f5        ; clear cutting tool 
 g01 x-[#<_d2> - #<_d1>] y-[#<_g2> - #<_g>] f20          ; position on edge for start of cut 
 G01 Z#1 f3            ; reposition 
 G03 X0.00 y0.0  f5 I-[ #<_d1> ]  J[#<_radius> -#<_g>] 
M99


----------



## RJSakowski (Oct 15, 2021)

It'll take me a while to figure out what you are doing.  One thing that I noticed is that you are using G53.  I never use G53 but rather, G54,, G55, etc.  How are you defining G55?  My machine starts up with G54 which is modal.  When I set my work origin to 0,0,0 it is in G54  If I wanted to machine a second part 5 inches to the right, after zeroing my G54 work coordinate, I would move X5 and then G55 and zero my X axis.  Switching back to G54, the DRO should read X as 5.


----------



## JimDawson (Oct 15, 2021)

If I'm reading the code correctly I think the line g10 l20 *p1* x0 y0 maybe should be g10 l20 *p2* x0 y0.  I think this sets the G54 position.  I think you would have to assign that position in the start of the code, maybe in the main program.  But I'm not sure about that.

Having said that, I have never seen G code with that many variables in it before.  That code is horribly complicated.

Can you post a drawing or a sketch of the part you are trying to make?


----------



## dansawyer (Oct 15, 2021)

After wearing out 11 typewriters and driving 14 monkies to exhaustion the following code works to move the relative origin to the base of the second pattern:
  m0
  g53 x [#<_d2> - #<_d1> - 1] y[2.5 + #<_tool_dia>]                ; use g53 to move to new origin
  m0
  g10 l20 p1 x0 y0                                                                     ; use g10 to bias on new origin.
  m0

The only part of this I feel confident about is once the machine is homed an absolute origin is set. The 'g10 l2 p1 x0 y0' command appears to reset the origin to the original origin.
Conversly after the above code the 'relative' origin is set to the g53 offset. The above sequence sets the G54 offset. I have not figured that part out.


----------



## dansawyer (Oct 15, 2021)

I have done additional testing. It seems as though the G53, G54 commands are redundant with tthe G10 command. I have not been able to create a case where those commands actually changed the G5x values. On the other hand the L10 commands do change those values. The L2 value appears to reset the origin and the L20 value appears to create an offset. I have only tried P1 values. More on P2 etc late.


----------



## RJSakowski (Oct 15, 2021)

Thanks for the insight @JimDawson . In the past I have not tried to use G10 to set the work offsets.  I just moved to the new work origin and zeroed my coordinates.

I  tried them in PathPIlot  this morning and the G10 L2 P2 X~ Y~Z~ command does set the the offsets from the machine coordinates to the X~ Y~ Z~ values in the work offset table.  Another tool in the arsenal.  I haven't done any conditional programming in PathPIlot yet.  Most of the programs that I run are through the CAM processor so there hasn't been a need.


----------



## JimDawson (Oct 15, 2021)

RJSakowski said:


> Thanks for the insight @JimDawson .


 My pleasure.  I can't take too much credit there, I just looked at the LinuxCNC G code list and read the documentation. I have never seen a G10 before.   

Like you, I just do everything in CAM, I've never done any conditional G code programming, makes my head hurt to think about how that code works.


----------



## RJSakowski (Oct 15, 2021)

JimDawson said:


> My pleasure.  I can't take too much credit there, I just looked at the LinuxCNC G code list and read the documentation. I have never seen a G10 before.
> 
> Like you, I just do everything in CAM, I've never done any conditional G code programming, makes my head hurt to think about how that code works.


I did some about twenty years ago. It actually wasn't too bad.  The program involved cutting degree lines on a large disk with every fifth line longer and every tenth line longer yet.  The final part was cutting the numbers for every tenth line.  I work in polar coordinates which made the programming much simpler.  I don't recall the flavor of the CNC but we didn't have a CAM processor then.  The machinist didn't do any programming  and only used conversational control or canned programs.  I didn't actually do the machining.  He gave me the user manual and I wrote the G code.  My first experience with CNC programs.  Here was the final product.


----------

