Post up them handmade G-codes

Hey All, Thought it might be fun and educational if we share what we do for simple programming needs.
You know - when you need a circle cut - but don’t want to fire up the CAM software just for that!

Yah - that’s what I mean - HAND WRITTEN G-CODE

Do you have any keeper files for generic shapes that you use over and over by just changing a few parameters?
Maybe we can learn from each other - what to do and not to do.

In the next post I’ll show what I learned today about improving generic circles.

Just learned this!
In order to maintain original formating of your code in posts on this forum (indenting etc.) just ad this before your code - without the “(” and “)”

(```none)

and this at the end - without the “(” and “)”

(```)

I used to just copy and paste and change the Z value to make a circle program like this:

%
G53 G0 G90 Z0
G0 G90 X2.625 Y0
Z0
G2 X2.625 Y0 I-2.625 J0 Z-.125 F70
G2 X2.625 Y0 I-2.625 J0 Z-.25
G2 X2.625 Y0 I-2.625 J0 Z-.375
G2 X2.625 Y0 I-2.625 J0 Z-.5
G2 X2.625 Y0 I-2.625 J0 Z-.625
G2 X2.625 Y0 I-2.625 J0 Z-.72
G2 X2.625 Y0 I-2.625 J0
G53 G0 G90 Z0
M30
%

But today I learned the Buildbotics controller can do variables and control structures so this is my new generic circle program.
Just fill in variables number 1 to 4 at the top for your circle and away you go.
The origin does have to be set to the circle center.

%(CUT A CIRCLE COUNTERCLOCKWISE - ORIGIN IS CIRCLE CENTER, Z0 IS TOP)
(RADIUS OF CIRCLE - YOU MUST COMPENSATE FOR CUTTER RADIUS)
#<_radius> = .188
(DEPTH TO GO DOWN IN ONE REVOLUTION)
#<_depth_per_rev> = -.05
(FINAL DEPTH)
#<_final_depth> = -.43
(FEEDRATE)
#<_feedrate>= 30
(DONT CHANGE ANYTHING BELOW THIS)
G0 G90 G17 G20        
G53 G0 Z0             
X#<_radius> Y0       
Z0.1                   
G1 Z0 F#<_feedrate>                                        
#<_current_depth> = #<_depth_per_rev>                ; SET TO FIRST PASS DEPTH                      
O101 WHILE [#<_current_depth> GT #<_final_depth>]          
  G3 X#<_radius> Y0 Z#<_current_depth> I-#<_radius> J0       
  #<_current_depth> = [#<_current_depth> + #<_depth_per_rev>]
O101 ENDWHILE                                              
#<_current_depth> = #<_final_depth>                     ; SET TO FINAL DEPTH            
G3 X#<_radius> Z#<_current_depth> I-#<_radius>      
G3 X#<_radius> I-#<_radius>                          
G1 Z0.1                                                    
G53 G0 Z0                                                   
M30                                                         
%
1 Like

Depending on your machine, you can probably eliminate a lot of it since g2 is modal. If I had to write your first example by hand for a quick circle toolpath, I do this…

%
G (yadda yadda etc…)
G90 G0 X2.625 Y0
Z0
G2 X2.625 Y0 I-2.625 Z-.125 F*** (J not needed for full circle)
I-2.625 Z-.25
I-2.625 Z-.375
I-2.625 Z-.5
I-2.625 Z-.625
I-2.625 Z-.72
I-2.625
G1 Z0
G (yadda yadda)
M30

1 Like

Yeh you are right, that is more elegant - but it’s all just copy and paste anyway.
That’s why I put the Z at the end 'cause that is the only thing that gets changed.

Otherwise, I sometimes use a repeating sub program. I have several “skeleton” programs that I use for profiles of different shapes and sizes.

Would love to see 'em!
I just think it would be helpful for those who ( like me before today ) just don’t know what is able to be done with a few lines of code.
I know a lot of people think they have to start the cam software for everything.

I agree. Although I just bought my first home cnc, I’ve been a cnc machinist for over 30 years. And I think one of THE main reasons I bought one (other than someone FINALLY making one with a proper controller and made of something besides aluminum extrusion) is seeing so many people making REAL money by just downloading files and pressing play, but have no idea how to make something without software. Not punching down on them for what they don’t know but holy cow! Imagine what I’ll be able to do…if the damn thing ever gets here!

I don’t think that’s actually happening. I was not a CNC expert when I got my 1F 2 years ago, and I still f’ up more cuts than I get right. I don’t believe the youtube hype.

1 Like

Unfortunately, it’s not just youtube. Around here, you can’t walk 3 feet without seeing a “punisher flag” or a piece of pallet wood with “live laugh love” v-carved into it. The craft markets and craigslist are full of murica merch and catch-all trays. People will buy that stuff all day long. It makes me ill, but more power to the folks who make a profit from it. With 30+ years of cad/cam and cnc experience, I shouldn’t have a problem retiring early now that I’ll have a machine in my garage making things that have some quality.

2 Likes

But today I learned the Buildbotics controller can do variables and control structures so this is my new generic circle program.

Do you have a link to the docs for that? I checked their github org and didn’t find it - but I might be searching for the wrong thing. TIA!

I found it! I was definitely looking in the wrong place.

1 Like

Hey Gabe,

the variables in g-code are called “parameters”. There are numbered parameters, named parameters and subroutine parameters. See G-Code overview.

The user parameters are the number #31#5000, available for free use.

The subroutine parameters are #1#30, which correspond to the parameters following a subroutine call.

2 Likes

This is excellent information. Thanks for the detailed response!

I see that there are some python scripts for LinuxCNC, and I will have to see how that works. Seems like there are some real simple options for common tasks like flattening a workpiece and such.

ref: GitHub - LinuxCNC/simple-gcode-generators: Simple LinuxCNC G-Code Generators written in Python

Blockquote

1 Like

Hey Gabe,

the buildbotics-derived Onefinity controller is not based on LinuxCNC. It’s just that its g-code is patterned after the LinuxCNC g-code dialect, so it supports a subset of LinuxCNC G-code.

Further information

See here for the g-code commands supported by the buildbotics-derived Onefinity Controller.

1 Like

I was thinking more about the similarity of the output rather than the provenance of the original source.

My thought process is more that if the gcode used by my 1f is similar (with the caveats provided) to what is created by the LinuxCNC scripts then it seems reasonable to me that I could fork those scripts and convert those to a “1f compliant” gcode, so to speak.

That sounds like a fun learning project, if nothing else. I like the idea of having a higher level of abstraction than gcode, and I do some python programming for my day job. If anyone else has some code that fulfills a similar function for the onefinity I would be happy to learn from that as well.

Thanks for the further clarification!

Hey Gabe,

I am sure that the Onefinity Community will appreciate it if you share your experiences with this.

I asked ChatGPT to add comments in English to the gcode you provided and to use named parameters instead of the numbered ones. What it initially provided did not quite work, but it only took a couple of tries for me (a complete newbie to gcode) to get it into this shape:

% (CUT A CIRCLE COUNTERCLOCKWISE - ORIGIN IS CIRCLE CENTER, Z0 IS TOP)
; (RADIUS OF CIRCLE - YOU MUST COMPENSATE FOR CUTTER RADIUS)
#<_radius> = .188
; (DEPTH TO GO DOWN IN ONE REVOLUTION)
#<_depth_per_rev> = -.05
; (FINAL DEPTH)
#<_final_depth> = -.43
; (FEEDRATE)
#<_feedrate>= 30
; (DON’T CHANGE ANYTHING BELOW THIS)
G0 G90 G17 G20 ; Rapid move, absolute positioning, XY plane select, inches as units
G53 G0 Z0 ; Move to machine coordinate system's Z0
G0 G90 X#<_radius> Y0 ; Rapid move to the starting position at X = 0.188, Y = 0
Z0.1 ; Move to Z = 0.1
G1 Z0 F#<_feedrate>; Linear interpolation to Z = 0 at feed rate #feedrate
#<_current_depth> = #<_depth_per_rev> ; Assign the value of #<_depth_per_rev> to a variable #<_current_depth>
O101 WHILE [#<_current_depth> GT #<_final_depth>] ; Start of a loop until #<_current_depth> is greater than #<_final_depth>
G3 X#<_radius> Y0 Z#<_current_depth> I-#<_radius> J0 ; Circular interpolation, cutting a circle counterclockwise with center at (0.188, 0), radius 0.188, and depth determined by #<_current_depth>
#<_current_depth> = [#<_current_depth> + #<_depth_per_rev>] ; Increment #<_current_depth> by #<_depth_per_rev>
O101 ENDWHILE ; End of the loop
#<_current_depth> = #<_final_depth> ; Set #<_current_depth> to #<_final_depth>
G3 X#<_radius> Y0 Z#<_current_depth> I-#<_radius> J0 ; Circular interpolation to reach the final depth determined by #<_final_depth>
G3 X#<_radius> Y0 I-#<_radius> J0 ; Circular interpolation to return to the starting position
G1 Z0.1 ; Linear interpolation to Z = 0.1
G53 G0 Z0 ; Return to machine coordinate system's Z0
M30 ; End of program
%

Here is the description that ChatGPT provided:

This program is designed to cut a circle counterclockwise. The circle is centered at (0.188, 0) with a radius of 0.188 inches. The cutting depth per revolution is -0.05 inches, and the final depth is -0.43 inches. The feed rate is 30 inches per minute. The program starts by setting up the machine parameters, then moves to the starting position, cuts the circle, and returns to the starting position before ending the program.

I find it interesting to see that the onefinity can show a preview, but that it also has a text message saying:

{“message”:“Unable to read file - doesn’t appear to be GCode.”,“code”:400}

I haven’t tried to run that yet, but will see how it goes later.

I had every line commented to start with but it just looked too messy … especially here in the forum - it does not respect tabs.

That is not correct. The circle is centered on X0 Y0.
Other than that it’s correct.

As I said, I just discovered all this yesterday and have since learned it is best to use named parameters. So I will update the original to use them. Thanks Gabe.

1 Like

Ok, I just found out that you cannot have an apostrophe in a comment.
This will not load.
It gives {“code”:400,“message”:“Unable to read file - doesn’t appear to be GCode.”}

(DON’T CHANGE ANYTHING BELOW THIS)

This will load:

(DONT CHANGE ANYTHING BELOW THIS)

The thing is - I cannot load the code as Gabe updated it.
I have been deleting it line by line to find the line that causes it to say it does not look like g-code. Still have not found the problem.

Update:
So I took out all comment lines that have “()” and it loads fine.
I put this comment back in

(DON’T CHANGE ANYTHING BELOW THIS)

and it will not load.
( It turns out that comment was originally from me not Gabe )

Another update:
Yep, it loads if you take the apostrophe out.
I’m sure anything between the ( ) should not matter but trial and error seems to indicate otherwise.

Another update:
More testing sometimes it works with the apostrope in there.
It seems to be buggy. I have never got the error message when the apostrophe was out, but sometimes I get the error when it is in.

So the moral of the story is DONT USE APOSTROPHIES

Hey Chris, hey Gabe,

I don’t understand why you don’t simply add the comments the way I do, by typing them in on my keyboard and observing the g-code syntax rules. For what do you need a stupid machine learning statistical engine? You don’t expect to learn g-code from a stupid algorithm that does not (and never will) understand what it outputs?

What would be nice would be pretty-print g-code, e.g. with indentation on “o” commands for increased legibility.

1 Like