ChatGPT is a chatbot developed by OpenAI that uses large language model technology, which is a deep learning algorithm that uses very large data sets to recognize, summarize, translate, predict and generate content. Among other tasks, ChatGPT can create G-code programs.
Images provided by CAMInstructor.
In early 2023, ChatGPT was everywhere, writing stories, articles, essays, recipes, poems — and code. The chatbot can create programs in a variety of languages, including G code. But are its programs any good? I spoke to a CAM expert who has tested ChatGPT’s G-code programming abilities. Here’s his take what it can do now, and how AI might affect programming in the future.
Early Assesments
Mike Wearne is an educational content creator at CAMInstructor, which specializes in creating books, videos, and online curricula covering CNC programming, Mastercam, and SolidWorks for educational programs and manufacturers. As part of this, he has produced two videos (so far) on using ChatGPT for G-code programming. The first covered GPT-3, which was the latest version available to the public at the time.
Featured Content
In the first video, he tests GPT-3’s G-code programming capabilities by giving it simple tasks such as facing parts or drilling four holes evenly spaced one inch apart. Once ChatGPT gave him a program, he plotted the program with CIMCO Edit software to visually show the results, along with any issues in the code.
At present, two versions of ChatGPT are available. GPT-3.5, which is available for free, can produce code for simple programs that Mike Wearne, an educational content creator at CAMInstructor, grades as a high C or low B. The overall structure is correct, but it’s missing elements such as tool changes and spindle speeds.
His take on the GPT-3 code? “If we use a basic program that's a drill four holes sort of thing, and compare this to someone who's just learning G code, I would say it's not bad,” he says. “I would give it a low B or a high C.” The overall structure was there — it put the right codes in the right places, such as G20 and G21 to switch between metric and imperial units, and G90 for absolute positioning at the top of the program. “If you're new to G-code programming, those are usually the tough things to remember and to get in the right spot,” he notes. However, it was missing some elements, such as tool changes and spindle speeds.
Wearne asked GPT-3 to create code to drill a bolt circle (seen above). These are the results, plotted in CIMCO Edit.
But GPT-3 has its limits. Notably, it can self-correct itself, but only to a certain point. Wearne says if you prompt ChatGPT to fix an issue in a program, it will make edits. But if you start a new chat or prompt for an entirely new program, you’re starting from scratch. However, he thinks the biggest thing holding GPT-3 back is how much information users need to provide in order to get a good program, and how difficult it is for users to input this information. “For example, if you want to drill holes, you’ve got to tell it where the holes are, which size holes you want, what tool you’re using, what material you’re cutting and what kind of machine you’re using,” he says. “All of that is still very hard to get into a chat interface like ChatGPT.” Users have to manually communicate all the information from a print into ChatGPT in a format it can understand.
The biggest limit of GPT-3.5 is that users might find it difficult to communicate the information from a print via text so ChatGPT can understand it. GPT-4, which is available via paid subscription, enables users to upload image files, solving what Wearne says was one of GPT-3.5’s biggest issues.
Raising the Grade
GPT-4 has also improved its ability to write G-code. “For the simple parts, if we’re in G-code 101, GPT-4 is getting an A,” Wearne says.
However, AI technology moves quickly, and while preparing this article, Wearne released a new video reviewing GPT-4’s programming capabilities. (At the time of writing, GPT-3.5 is the latest version available for free, and GPT-4 is the latest version available to the public via paid subscription.) GPT-4 allows users to submit images, including prints, solving one of Wearne’s biggest issues with GPT-3. “Describing your part through text was not really feasible,” he says. “Uploading an image or print brings this much closer to being useful.”
The bolt circle code seen above, generated by GPT-4 and plotted in CIMCO Edit.
GPT-4 users can upload a variety of file types (including images and PDFs) into the interface, and from there Wearne says the chatbot can tell what’s been uploaded — the user just has to tell it what to do with the image. For example, if you upload a part file with four holes, you can tell ChatGPT to write a program to drill the holes. Wearne says it currently works for simpler parts and shapes. “Anything beyond that is not doable,” he adds. “At least, not yet.”
Wearne also noticed a marked improvement in the G code ChatGPT produces. “It’s like GPT-4 can think more about its answers and GPT-3.5 just spits out whatever it comes up with as quick as it can,” he explains. With its most recent update, Wearne says it can program simple parts almost perfectly. Whereas GPT-3 was getting a high C or low B as a grade for its code, “For the simple parts, if we’re in G-code 101, GPT-4 is getting an A,” he says.
Extra Credit
According to Wearne, the next step ChatGPT needs to make in G-code programming is tool motion during a cut. He adds that, on its own, this might be too complex for ChatGPT to handle. “I’m not sure it would be able to produce something like a dynamic milling operation on a large pocket,” he notes. “The amount of code it would need to generate would likely be beyond its scope.” But integrating ChatGPT with CAM programming software such as Mastercam could provide the resources needed to generate complex toolpaths. “But then again, I don’t think attempting to cut complex parts with GPT is the best use case for it,” he says.
Wearne has found other uses for ChatGPT in manufacturing. “It can give you ideas for things to try, especially if you're stuck on something,” he says. He believes ChatGPT is particularly helpful in creating macros, which are a way to store a series of commands in a program and repeat them. “Surprisingly, GPT-4 is pretty good with error codes,” he adds. Instead of Googling the error code and searching for the answer on a website or forum, he says you can give ChatGPT the machine type and error code and it will tell you what the error code is and how to troubleshoot it.
GPT-4 also enables users to create and train their own GPTs. Wearne has used this feature to create a custom chatbot trained on a Haas CNC mill programming manual. “When I asked it to program a part that contained a simple pocket, it was able to tell me I need to program it with a G150 command and also provided the variables for that canned cycle and what they controlled,” he says. He believes that creating the roughing motion for a pocket would be difficult for GPT, but the chatbot knew it could perform the task with Haas’s built-in code. “The custom GPTs are quite useful,” he says. “The limitation is your imagination and the data you can feed it.” For example, GPT-4 users can train a custom GPT using a machine manual and ask it for information such as alarms and G-code variables.
Overall
According to Wearne, “GPT-4 is a tool shops can use now,” and not just for programming. This is just the beginning for AI in machining, he believes. “It will be extremely interesting to see where this is in a year from now,” he says. “I would guess most will be using some sort of AI within the next few years, whether that’s GPT or something built into existing CAD/CAM. And I mean real AI, not a simple algorithm labeled as AI.”
OpenAI (the maker of ChatGPT) has not announced a timeline for releasing its newest version, GPT-5, but work on it is underway. “GPT-4 was close to or mimicking what humans are capable of, but GPT-5 is supposed to be ‘super intelligent,’” Wearne notes. “Where this takes G code, who knows? Maybe we won’t even need code then!”
RELATED CONTENT
-
Sophisticated Software for Solid Gear Design
Whether your computer platform is standalone or part of a suite, desktop or on the cloud, there’s a gear design package developed specifically to meet your needs.
-
Transferring CAD/CAM Files
Importing and exporting CAD files is a fundamental function of CAM software. An understanding of this process can help you know what to expect and will aid you when making a CAM purchase.
-
AI Chip Flushing Keeps the Lights Out
Swiveling, camera-guided coolant nozzles solve a CNC machining automation problem that is ideal for artificial intelligence (AI).