CNC Programming with AI: Exploring Google Bard and ChatGPT for Improved Machining

At Mechutopia.com, we understand the importance of AI technologies in the CNC programming and machining industry. I always wanted to generate codes in a better way in my work. I was waiting to write this for a long time, eventually, it is time deep dive into CNC Programming With AI technologies like Google Bard and ChatGPT.

I wrote more about AI CNC machining and programming technologies, they can be help full to understand better;

This article talks about he exiting future of CNC machinists.

A general overview of AI CNC machining and programming technologies.

AI Language Models: Google Bard and ChatGPT

I had an e-mail that confirmed that I am able to use Google Bard. I was waiting for this so I could try it against the CNC programming prompts. As ChatGPT was early than Google Bard I played with it already before. So, you will also see ChatGPT and Google Bard results compared side by side.

Both of them are free, and you can subscribe to either of them at no cost. We will test the capability of two of them also prompts will be the same for the two language models as they are claiming to be a conversational AI model.

It is so exciting that we may soon have a free CAM system for easy CNC programming tasks. Let`s go for it.

Testing AI Capabilities: Icebreaker Questions

I have decided to ask them if they can generate a program for me or not. Let’s ask them about their capabilities and limitations:

Prompt-Question-1:Can you write CNC programs?

Answer-1 from Google Bard;

Answer-1 from ChatGPT-3.5;

My thoughts on the results from ChatGPT and Bard:

ChatGPT and Google Bard seem ready to take on this task, providing confident answers without showing any fear of incapability. Also, Google Bard offered to create CAM files. It was impressive, we will test it too. Let’s go next question.

Before continuing you must know that you should provide as much information as you can about the task you want to order. So AI models will not generate not defined values for themselves. Not well-designed prompts can lead to generating wrong results on AI conversation models.

Generating the First Program

Now we are ready to use the famous AI power. I am gonna select a very easy task for them, it is a spot drilling operation on 4 holes and I am gonna be clear about my requirements.

Prompt-2_Command: “I need to drill 2 holes with 90 Degree Countersink, hole diameter 8mm, countersink diameter 9mm, hole straight depth is 50mm, hole`s coordinates=[50,50][-50,50], the material is 4140 select suitable feed rate and speed, Tool_Carousel=[T1-12mm dia._90DEG_spot Carbide Drill + T2-8mm dia Carbide Drill],controller=fanuc_generic, go for it!”

I will check the results against the code quality, Quality of feed and speeds, and self-determination of the program.

Comparing Code Quality, Feeds, and Speeds

ChatGPT results on below:

Code Quality: ChatGpt messed up a lot. Using G81 and G83 without changing tools and canceling cycles is not possible in G-Code language. Moving to the Z0. with rapid movement would be the last thing a machinist can do with a CNC machine. Also, it drills full-depth holes with a spot drill. Funny right?

Quality of Feeds and Speeds: ChatGPT selected very conservative feed rates against the high spindle speed, due to the qualities of the carbide drill it could select a feed rate around F300 at least.

self-determination: It selected tools correctly from the tool changer but it changed tools for every hole coordinate, in real life it is a reason to lose your job in a modern machine shop if you drill holes like this.

% O0001 (Drill and Countersink Program)
G90 (Absolute programming)
G54 (Workpiece coordinate system)
G00 G40 G49 G80 G94 (Safe start-up)
(TOOL CHANGE)
T1 M06 (Select T1 - 12mm dia. 90 DEG spot Carbide Drill)
S1500 M03 (Spindle speed 1500 RPM)
(*** First hole ***)
G00 X50 Y50 (Rapid move to the first hole position)
Z0 (Move to the workpiece surface)
G83 Z-50 R2 Q0.1 F100 (Peck drilling cycle)
G81 X50 Y50 Z-50 R9 F100 (Drilling cycle)
G80 (Cancel drilling cycle)
G90 G00 Z10 (Move away from the workpiece)
G94 (Feedrate per minute)
(*** First countersink ***)
T2 M06 (Select T2 - 8mm dia. Carbide Drill)
S2000 M03 (Spindle speed 2000 RPM)
G00 X50 Y50 (Rapid move to the first countersink position)
Z0 (Move to the workpiece surface)
G83 Z-50 R2 Q0.1 F50 (Peck drilling cycle for countersink)
G81 X50 Y50 Z-50 R9 F50 (Countersinking cycle)
G80 (Cancel countersinking cycle)
G90 G00 Z10 (Move away from the workpiece)
G94 (Feedrate per minute)
(*** Second hole ***)
T1 M06 (Select T1 - 12mm dia. 90 DEG spot Carbide Drill)
S1500 M03 (Spindle speed 1500 RPM)
G00 X-50 Y50 (Rapid move to the second hole position)
Z0 (Move to the workpiece surface)
G83 Z-50 R2 Q0.1 F100 (Peck drilling cycle)
G81 X-50 Y50 Z-50 R9 F100 (Drilling cycle)
G80 (Cancel drilling cycle)
G90 G00 Z10 (Move away from the workpiece)
G94 (Feedrate per minute)
(*** Second countersink ***)
T2 M06 (Select T2 - 8mm dia. Carbide Drill)
S2000 M03 (Spindle speed 2000 RPM)
G00 X-50 Y50 (Rapid move to the second countersink position)
Z0 (Move to the workpiece surface)
G83 Z-50 R2 Q0.1 F50 (Peck drilling cycle for countersink)
G81 X-50 Y50 Z-50 R9 F50 (Countersinking cycle)
G80 (Cancel countersinking cycle)
G90 G00 Z10 (Move away from the workpiece)
G94 (Feedrate per minute)
M30 (End of program)

Google Bard results on below:

Code Quality: Code quality on Google Bard`s CNC program result is much worse than ChatGPT. No tool changing at all and there is no sign of any drilling cycle usage. No spindle command like M03.

Quality of Feeds and Speeds: Google Bard failed on selecting feed and speeds too.

self-determination: Unexpectedly It put the time to dwell on the bottom of the hole but generally no consistent results.

G90 G21
(T1)
G0 X50 Y50
G1 Z-10 F1000
G3 X50 Y50 Z-50 I0 J0 K9
G0 X-50 Y50
G1 Z-10 F1000
G3 X-50 Y50 Z-50 I0 J0 K9
(T2)
G0 X50 Y50
G1 Z-50 F500
G4 P1
G3 X50 Y50 Z-50.5 I0 J0 K9
G0 X-50 Y50
G1 Z-50 F500
G4 P1
G3 X-50 Y50 Z-50.5 I0 J0 K9
M30

Final Test with More Information

I decided to provide more information for last time let`s see results;

Final Prompt Try

Generate G&M code CNC machining program for Fanuc.
Operation: Drilling
Units: Metric
Material: 4140
Geometry: a hole on 50,50 and another hole on -50,-50 and two of them has 50mm depth.
Tools on changer pockets:(T1-12mmdia.90Deg. Carbide spot drill),(T2-8mmDia. Carbide Drill)
Retract distance above part:5
commands:(Drill these 2 holes and put 10mm countersink, Select suitable feedrates, add tip compansation
to 8mm hole drilling operation.)
Go for it!

Google Bard Result on below;

It got better but still 90% non-sense G-Code

G90 G21 (Set units to millimeters and absolute mode)

T1 M06 (Change to tool T1)

G00 X50 Y50 Z0 (Rapid to the start position)

G01 Z-50 F100 (Drill the hole at 100mm/min feedrate)

G00 Z5 (Rapid to clear the hole)

G01 Z-10 F10 (Countersink the hole at 10mm/min feedrate)

G00 Z5 (Rapid to clear the hole)

T2 M06 (Change to tool T2)

G00 X-50 Y-50 Z0 (Rapid to the start position)

G01 Z-50 F100 (Drill the hole at 100mm/min feedrate)

G00 Z5 (Rapid to clear the hole)

G01 Z-10 F10 (Countersink the hole at 10mm/min feedrate)

G00 Z5 (Rapid to clear the hole)

M05 Spindle off (Turn off the spindle)

M09 Coolant off (Turn off the coolant)

M30 End of program (End the program)

ChatGPT results on below;

It got much better but still too much dangerous mistakes in the code, you wouldn`t want to put this on your machine.

% O1234 (CNC Machining Program)
N10 G90 G94 G54 (Absolute coordinates, feedrate per minute, coordinate system)
N15 G21 (Units: Metric)
N20 G40 G80 G49 (Cancel tool radius compensation, cancel canned cycle, cancel tool length offset)
N25 G91 G28 Z0 (Return to machine zero in Z-axis)
N30 T1 M06 (Select tool T1 – 12mm dia. 90° carbide spot drill)
N35 S2000 M03 (Spindle speed: 2000 RPM, start spindle clockwise)
N40 G00 X50. Y50. Z5. (Rapid move to hole position 1)
N45 G81 Z-50. R5. F100. (Drill hole 1 with retract of 5mm, feedrate: 100mm/min)
N50 G00 Z5. (Rapid retract above part)
N55 X-50. Y-50. (Move to hole position 2)
N60 G81 Z-50. R5. F100. (Drill hole 2 with retract of 5mm, feedrate: 100mm/min)
N65 G00 Z5. (Rapid retract above part)
N70 T2 M06 (Select tool T2 – 8mm dia. carbide drill)
N75 S3000 M03 (Spindle speed: 3000 RPM, start spindle clockwise)
N80 G00 X50. Y50. Z5. (Rapid move to hole position 1)
N85 G83 Z-50. R5. Q10. F200. (Peck drilling hole 1 with 10mm countersink, retract: 5mm, feedrate: 200mm/min)
N90 G00 Z5. (Rapid retract above part)
N95 X-50. Y-50. (Move to hole position 2)
N100 G83 Z-50. R5. Q10. F200. (Peck drilling hole 2 with 10mm countersink, retract: 5mm, feedrate: 200mm/min)
N105 G00 Z5. (Rapid retract above part)
N110 M05 (Stop spindle)
N115 M30 (End of program)
%

Conclusion

As you can see there is a lot of way to generate G-Codes from popular tools like ChatGPT and Google Bard. Clearly, there is a lot of room to improve results.

In my opinion, this artificial intelligence technology is not ready to generate trustable programs for CNC machining firsthand, but it may be with a lot of complex prompts and third-party verification.

It is clear that these tolls will be ready soon to generate perfect programs. They are just still in the training phase.

What is CNC programming with AI?

  A: CNC programming with AI refers to using artificial intelligence technologies, such as language models, to generate CNC programs for machining tasks.

What are Google Bard and ChatGPT?

  A: Google Bard and ChatGPT are AI language models developed by Google and OpenAI, respectively. You can ask and get result immediatelly.

Can AI language models generate CNC programs accurately?

  A: While AI language models show promise in generating CNC programs, their accuracy and reliability still require improvements. It is essential to provide clear and detailed prompts, and the generated programs should be verified by a professional before use.

How do I provide a well-designed prompt for CNC programming with AI?

  A: To obtain accurate results, provide as much information as possible about the task, such as material, operation type, tool specifications even feeds and speeds and required parameters. This helps the AI model generate more accurate G-code, M-code based on your specific requirements.

By Isaac Aloyan

Isaac Aloyan is a talented mechanical engineer with a background in machinery design and manufacturing. He completed his diploma from the Department of Machinery Design and Manufacturing at Kocaeli University and also graduated from Level 7 NZDE Mechanical Engineering at Manukau Institute of Technology (M.I.T). Isaac has developed strong expertise in various areas of mechanical engineering, including CNC programming and machining, vacuum mold design and production, manual machining, CAD and CAM, and thermoforming machine design and production. Also, he has educator experience in the area of CNC machinery and programming and mechanical design. With two decades of experience under his belt, Isaac has established a website called mechutopia.com to share his knowledge and help others who are interested in the field of mechanical engineering. The site is likely to feature a wealth of information, resources, and tips for those looking to learn about CNC machines, machining, mold production, and more. It is a testament to Isaac's dedication to the field and his commitment to helping others excel in sub-domains of mechanical engineering like design and manufacturing.