Page 1 of 1

AI suggestions for writing G-code

Posted: Sun Jun 29, 2025 12:04 am
by RJS100
I recently started writing a few small g-code routines. For fun, I told CHATGPT what I wanted to do, and it wrote the code perfectly. I found it extremely helpful, as I knew what commands I wanted to use, but it helped with the syntax and added notes for each line in a fraction of time it would take me to do the same. I believe, it is helping me learn g-code faster than without it.

Just curious, is anyone else using AI to write code? Is there an even better mouse trap than CHATGPT?

For fun, I attached the simple routines that took about 3 minutes to create.

Thanks... Richard

Re: AI suggestions for writing G-code

Posted: Sun Jun 29, 2025 2:32 am
by suntravel
I can write this in under a minute, or for a full functional code with spindle, tool change and Z moves Iet Intercon dot it ;)

I use AI for Phyton and Java Script, but for g-gode specific to CNC12 or other systems I prefer to use my head.

Uwe

Re: AI suggestions for writing G-code

Posted: Sun Jun 29, 2025 1:33 pm
by RJS100
To my surprise, CHATGPT appears to be able to write g-code specific to CNC12. Here is an example of where I wanted add the use of variables to the previous code:

Great! Below is a fully working example of a parameterized “Trim Top” routine for Centroid CNC12, using:
• A main G-code file that calls a macro (M101 Q7.85)
• A macro file (mfunc101.mac) that does the actual trimming using the Q value
________________________________________
✅ 1. Main G-code File (calls macro)
You can name this file something like trim_top.cnc:
gcode
CopyEdit
%
; TRIM TOP using macro with variable distance

M101 Q7.85 ; Call trim macro, passing 7.85 as trim distance

%
This sends Q7.85 (the trim distance) to macro M101.
________________________________________
✅ 2. Macro File: mfunc101.mac
Place this file in the CNC12 macro folder (usually c:\cncm\mill\mfunc or similar for milling machines).
Filename: mfunc101.mac
gcode
CopyEdit
; mfunc101.mac - Trim Top Edge using Q as trim distance

G91 ; Relative positioning
G1 X[-#1] F30 ; Move left by trim distance
G1 Z0.2 F20 ; Raise Z
G1 X[#1] F120 ; Move right by trim distance
G1 Z-0.2 F20 ; Lower Z
G90 ; Return to absolute positioning
#1 is the system variable that receives the Q value from the G-code call.
________________________________________
🛠 How to Use It
1. Save the macro as mfunc101.mac in your Centroid macro directory.
2. Call M101 Qxxx in any G-code file with the trim distance you want (e.g., Q7.85).
3. The macro handles all the relative motion based on the passed-in value.
________________________________________
✅ Why This Works:
Centroid CNC12 doesn't allow math expressions like X[#100] in the G-code file, but it does support macros with passed parameters, so this setup is the clean, maintainable way to parameterize distances.

Inspiring!

Re: AI suggestions for writing G-code

Posted: Sun Jun 29, 2025 2:24 pm
by suntravel
RJS100 wrote: Sun Jun 29, 2025 1:33 pm To my surprise, CHATGPT appears to be able to write g-code specific to CNC12. Here is an example of where I wanted add the use of variables to the previous code:

....
✅ Why This Works:
Centroid CNC12 doesn't allow math expressions like X[#100] in the G-code file, but it does support macros with passed parameters, so this setup is the clean, maintainable way to parameterize distances.

Inspiring!
IMHO this is bullshit

X[#100]

is not a math expression but x with a value of #100 user variable

#100 = 1
X[#100]
will be the same like X 1

Read and understand chapter 8 in the manual and you will outsmart ChatGPT in no time

Uwe

Re: AI suggestions for writing G-code

Posted: Tue Jul 01, 2025 2:25 pm
by cncsnw
Let us know how that custom M101 macro and Q parameter work out for you....

Re: AI suggestions for writing G-code

Posted: Tue Jul 01, 2025 2:44 pm
by suntravel
Hi KI

here is a link to my cncm folder of my 6 axis mill: ....

pls make some g code to grind drills with 4 facets so that I have only to touch off the drill in Z

As you can see, I would use the D75mm Diamond wheel in T04

If this would work, I would be impressed ;) :mrgreen:

And I have not asked for thinning out the tip :lol:



Uwe

Re: AI suggestions for writing G-code

Posted: Tue Jul 01, 2025 3:09 pm
by suntravel
By the way, the best AI tool for Centroid I know is Paper Tools with Camera support....

Uwe

Re: AI suggestions for writing G-code

Posted: Tue Jul 01, 2025 11:50 pm
by RJS100
Hello Uwe,

You mentioned that reading chapter 8 of the manual for programming g-code. From what I can see, chapter 8 is on digitizing. Did you mean chapter 12 for g-code?

Richard

Re: AI suggestions for writing G-code

Posted: Wed Jul 02, 2025 2:50 am
by suntravel
RJS100 wrote: Tue Jul 01, 2025 11:50 pm Hello Uwe,

You mentioned that reading chapter 8 of the manual for programming g-code. From what I can see, chapter 8 is on digitizing. Did you mean chapter 12 for g-code?

Richard
ups. 8 is CNC Programm Codes in the lathe Manual, it is 11 in the mill manual.
Next two chapters G-codes and M-functions are also important to learn Centroid g code

Uwe