AI suggestions for writing G-code

All things related to the Centroid Acorn CNC Controller

Moderator: cnckeith

Post Reply
RJS100
Posts: 748
Joined: Tue Oct 20, 2020 8:41 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Arizona

AI suggestions for writing G-code

Post 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
Attachments
Trim Top CHAT Numbers.txt
(325 Bytes) Downloaded 17 times
Trim Right CHAT Numbers.txt
(323 Bytes) Downloaded 18 times
Trim Front CHAT Numbers.txt
(319 Bytes) Downloaded 18 times


suntravel
Community Expert
Posts: 3618
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: AI suggestions for writing G-code

Post 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


RJS100
Posts: 748
Joined: Tue Oct 20, 2020 8:41 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Arizona

Re: AI suggestions for writing G-code

Post 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!


suntravel
Community Expert
Posts: 3618
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: AI suggestions for writing G-code

Post 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


cncsnw
Community Expert
Posts: 4578
Joined: Wed Mar 24, 2010 5:48 pm

Re: AI suggestions for writing G-code

Post by cncsnw »

Let us know how that custom M101 macro and Q parameter work out for you....


suntravel
Community Expert
Posts: 3618
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: AI suggestions for writing G-code

Post 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


suntravel
Community Expert
Posts: 3618
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: AI suggestions for writing G-code

Post by suntravel »

By the way, the best AI tool for Centroid I know is Paper Tools with Camera support....

Uwe


RJS100
Posts: 748
Joined: Tue Oct 20, 2020 8:41 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Arizona

Re: AI suggestions for writing G-code

Post 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


suntravel
Community Expert
Posts: 3618
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: AI suggestions for writing G-code

Post 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


Post Reply