Using chatGPT to write gcode

Hi there!
I’m trying to make chatgpt write simple gcode for plots for me. I’m sorry for a LONG wall of nonsense, but I find this possibility quite fascinating. I’m going to try to make it draw SVGs, perhaps that works better.

T:
Can you make a gcode for a Smiley Face to use on a pen plotter? The smiley should be 15x15cm. The z depth is 5mm and clearance is 0.5mm.

ChatGPT

Certainly, here’s a G-code program for a smiley face that you can use on your pen plotter:

cssCopy code

G90 ; set absolute positioning mode
G21 ; set units to millimeters
G1 Z0.5 ; move to clearance height
G0 X75 Y75 ; move to the center of the smiley face
G1 Z-5 F200 ; lower the pen to the drawing surface
G2 X60 Y75 I-15 J0 F200 ; draw the left eye
G2 X90 Y75 I15 J0 ; draw the right eye
G2 X75 Y90 I0 J15 ; draw the mouth
G1 Z0.5 ; lift the pen to the clearance height

Here’s what each line of the program does:

  • G90: sets absolute positioning mode, so that all subsequent coordinates are interpreted as absolute positions from the origin.
  • G21: sets the units to millimeters.
  • G1 Z0.5: moves the pen to a clearance height of 0.5mm.
  • G0 X75 Y75: moves the pen to the center of the smiley face, which is located at (75,75).
  • G1 Z-5 F200: lowers the pen to a depth of 5mm at a feed rate of 200mm/min.
  • G2 X60 Y75 I-15 J0 F200: draws the left eye of the smiley face using a clockwise arc with a radius of 15mm centered at (60,75), at a feed rate of 200mm/min.
  • G2 X90 Y75 I15 J0: draws the right eye of the smiley face using a clockwise arc with a radius of 15mm centered at (90,75).
  • G2 X75 Y90 I0 J15: draws the mouth of the smiley face using a clockwise arc with a radius of 15mm centered at (75,90).
  • G1 Z0.5: lifts the pen back to the clearance height.

Note that the I and J parameters in the G2 commands specify the center point of the arc, relative to the starting position of the pen. So for example, in the G2 X60 Y75 I-15 J0 command, the center of the left eye is at (60-15,75), which is 15mm to the left of the starting position of the pen.

can you please redo the code without I and J axises? The code is not complete, how can I help you to get a useable output?

ChatGPT

Sure, here’s the updated G-code program without the I and J parameters:

cssCopy code

G90 ; set absolute positioning mode
G21 ; set units to millimeters
G1 Z0.5 ; move to clearance height
G0 X75 Y75 ; move to the center of the smiley face
G1 Z-5 F200 ; lower the pen to the drawing surface
G1 X60 Y75 ; draw the left eye
G1 X90 Y75 ; draw the right eye
G1 X75 Y90 ; draw the mouth
G1 Z0.5 ; lift the pen to the clearance height

This code uses the G1 command for linear movement to draw the smiley face. The X and Y parameters specify the absolute positions of the pen in millimeters.

You can copy and paste this code into a text editor, save it with a .gcode extension, and then load it onto your pen plotter software to run it.

If you would like to add any modifications or other details to the smiley face, please let me know and I’ll be happy to assist you.

Thank you so much for trying, but the code is very incomplete. The face needs details. The gcode is only creating a few points

ChatGPT

I apologize for the previous code not meeting your needs. Here is an updated G-code program that should create a more detailed smiley face:

cssCopy code

G90 ; set absolute positioning mode
G21 ; set units to millimeters
G1 Z0.5 ; move to clearance height
G0 X75 Y75 ; move to the center of the smiley face
G1 Z-5 F200 ; lower the pen to the drawing surface

; draw the face outline
G1 X60 Y60
G1 X90 Y60
G1 X90 Y90
G1 X60 Y90
G1 X60 Y60

; draw the left eye
G1 X65 Y70
G1 X70 Y70
G1 X70 Y75
G1 X65 Y75
G1 X65 Y70

; draw the right eye
G1 X85 Y70
G1 X90 Y70
G1 X90 Y75
G1 X85 Y75
G1 X85 Y70

; draw the mouth
G1 X67.5 Y85
G3 X75 Y92.5 I0 J7.5
G3 X82.5 Y85 I7.5 J0

G1 Z0.5 ; lift the pen to the clearance height

This code uses a series of G1 and G3 commands to create the smiley face. The G3 command is used to create a clockwise arc with a specified center point and radius.

In this program, the face outline is drawn first, followed by the left and right eyes, and then the mouth. You can modify the X and Y coordinates of each point to adjust the size and position of the smiley face as needed.

Again, I apologize for any inconvenience caused by the previous code. Please let me know if you have any other questions or concerns.
image

Thank you, this is better - but the outline is a square, not a circle. Can you redo it as a circle?

ChatGPT

Certainly! Here is the updated code with a circular outline:

cssCopy code

G90 ; set absolute positioning mode
G21 ; set units to millimeters
G1 Z0.5 ; move to clearance height
G0 X75 Y75 ; move to the center of the smiley face
G1 Z-5 F200 ; lower the pen to the drawing surface

; draw the face outline
G1 X75 Y60
G2 X60 Y75 I0 J15
G2 X75 Y90 I15 J0
G2 X90 Y75 I0 J-15
G2 X75 Y60 I-15 J0

; draw the left eye
G1 X65 Y70
G1 X70 Y70
G1 X70 Y75
G1 X65 Y75
G1 X65 Y70

; draw the right eye
G1 X85 Y70
G1 X90 Y70
G1 X90 Y75
G1 X85 Y75
G1 X85 Y70

; draw the mouth
G1 X67.5 Y85
G3 X75 Y92.5 I0 J7.5
G3 X82.5 Y85 I7.5 J0

G1 Z0.5 ; lift the pen to the clearance height

This code uses the G2 command to create circular arcs with a specified center point and radius. The I and J parameters in the G2 commands specify the distance from the current position to the center point of the arc.

In this program, the face outline is drawn with four G2 commands to create a circular shape. The rest of the code is the same as the previous version.

I hope this updated code meets your needs. Please let me know if you have any further questions or modifications.

image

4 Likes

Now trying SVG:
Hello there. Can you make a 15x15cm smiley face in svg code?

ChatGPT

Sure, here’s an example of a 15x15cm smiley face in SVG code:

svgCopy code

<svg width="15cm" height="15cm" viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
  <circle cx="75" cy="75" r="70" fill="#FFC107"/>
  <circle cx="55" cy="60" r="10" fill="#FFFFFF"/>
  <circle cx="95" cy="60" r="10" fill="#FFFFFF"/>
  <path d="M 75 95 C 65 95, 60 100, 60 110 L 90 110 C 90 100, 85 95, 75 95 Z" fill="#FFFFFF"/>
  <path d="M 70 50 A 5 5 0 0 1 80 50 A 5 5 0 0 1 70 50 M 75 70 A 20 20 0 0 0 55 50 A 25 25 0 0 0 95 50 A 20 20 0 0 0 75 70" stroke="#FFFFFF" stroke-width="5" fill="none"/>
</svg>

This code creates a yellow circle with a radius of 70 units (or 70/150 = 0.47 of the viewport width), and adds two white circles for the eyes, as well as a curved mouth and an outline. The eyes are positioned at (55,60) and (95,60), and have a radius of 10 units (or 10/150 = 0.067 of the viewport width). The mouth is drawn using a Bezier curve, with the starting point at (60,110), the control points at (65,95) and (85,95), and the ending point at (90,110). The mouth and the outline are drawn using paths, with the outline stroke-width set to 5 units (or 5/150 = 0.033 of the viewport width).

Note that the actual size of the smiley face may vary depending on the display size and scaling settings of the SVG viewer.

Actually, that SVG looks like an angry owl. Can you improve it?

ChatGPT

I’m sorry about that! Here is an updated SVG code for a 15x15cm smiley face that should look more like a traditional smiley face:

svgCopy code

<svg width="15cm" height="15cm" viewBox="0 0 150 150" xmlns="http://www.w3.org/2000/svg">
  <circle cx="75" cy="75" r="70" fill="#FFC107"/>
  <circle cx="55" cy="60" r="10" fill="#FFFFFF"/>
  <circle cx="95" cy="60" r="10" fill="#FFFFFF"/>
  <path d="M 75 95 C 65 95, 60 100, 60 110 C 60 120, 65 125, 75 125 C 85 125, 90 120, 90 110 C 90 100, 85 95, 75 95 Z" fill="#FFFFFF"/>
  <path d="M 70 50 A 5 5 0 0 1 80 50 A 5 5 0 0 1 70 50 M 75 70 A 20 20 0 0 0 55 50 A 25 25 0 0 0 95 50 A 20 20 0 0 0 75 70" stroke="#FFFFFF" stroke-width="5" fill="none"/>
</svg>

This code is similar to the previous one, but the mouth has been modified to create a smile shape, with four control points instead of two. The first control point (60, 110) and the last control point (90, 110) are the same as before, but there are now two additional control points: (60, 100) and (90, 100), which create the curved smile shape. The updated code should create a smiley face with a happy expression.

2 Likes

Conclusion: I wouldn’t count on chatGPT making my plotting gcode right yet! It DID set zero and start from 0,0,0 in the first tries, but the zeroing disappeared after a while. I guess it would add zeroing if you told it to.

Anyone else tried this, with better luck?

I got this when I asked for a smiley face with a diameter of 50cm and a z axis of 10mm, please lift the z axis between features

G21 ; Set units to millimeters
G90 ; Use absolute coordinates
G28 ; Home all axes

; Set up Z axis
G1 Z10 F500 ; Raise Z axis by 10mm

; Draw circle for face
G1 X0 Y0 F500 ; Move to center of circle
G1 Z0 F500 ; Lower Z axis to 0
G2 X0 Y0 I25 F1000 ; Draw circle with 50mm radius
G1 Z10 F500 ; Raise Z axis by 10mm

; Draw left eye
G1 X-10 Y10 F500 ; Move to left eye position
G1 Z0 F500 ; Lower Z axis to 0
G2 X-10 Y10 I5 F1000 ; Draw left eye with 10mm radius
G1 Z10 F500 ; Raise Z axis by 10mm

; Draw right eye
G1 X20 Y0 F500 ; Move to right eye position
G1 Z0 F500 ; Lower Z axis to 0
G2 X20 Y0 I5 F1000 ; Draw right eye with 10mm radius
G1 Z10 F500 ; Raise Z axis by 10mm

; Draw mouth
G1 X-20 Y-10 F500 ; Move to start of mouth
G1 Z0 F500 ; Lower Z axis to 0
G2 X20 Y-10 I20 J0 F1000 ; Draw mouth curve with 20mm radius and center at (0,-10)
G1 Z10 F500 ; Raise Z axis by 10mm

; Return to center of circle
G1 X0 Y0 F500

M2 ; End program

It is amazing what it does understand and what it doesn’t. Again, you have to ignore its confidence (that is my biggest complaint, it is always certain it is right. Trained on the Internet, I guess).

It does understand there should be eyes and a mouth. It does get the relative sizes (in coordinates, not just some ratio). It doesn’t understand that you have to lift the pen. And in the first example, it didn’t understand that it was drawing lines by connecting vertices.

And this is also a great example of how much the prompt affected the output. Learning to ise chatGPT and the children of it is going to be a combination of arr and engineering.

It definitely can be used as a good way to make a skeleton output, with an editor that knows enough to finish it, it can really improve productivity.

Pretty amazing, scary, and exciting.

1 Like

@turbinbjorn , are you using 3.5 or 4.0? My coworker paid for the 4.0 version and is getting some pretty good results for some python applications.

I’m using chat.openai. I guess it’s 3.5. Perhaps I can try out Bing, which is said to be updated to current events/development and using 4. Thanks for the idea!

1 Like

For some reason, I found that EXTRA funny today and almost spit my coffee.

2 Likes

image

1 Like

I tried ChatGPT a while back getting it to code in Picaxe Basic.
To be honest it didn’t have a clue. I spent a few whole days teaching ChatGPT how to do it properly, but still it was having problems developing any useable code for Picaxe basic.
In the end I gave up because it was quicker for me to do it myself.
Another thing was that although it had been shown where the errors were, when asked again at a later date the same errors were repeated, so it isn’t a very good learner yet.

That’s some very interesting experiments, could be pretty useful to quickly cut stuff on the CNC once it will be improved.
I wish I could experiment with it, but unfortunately openAI isn’t as open as their name would imply as users located in China are banned from using it. :frowning:

1 Like

I can create you a login to my in-house PiVPN for a German IP if you wanted to.

3 Likes

You might try to download and run them yourself? Lmstudio.ai is super easy to work with. I bet there are models trained on our fields even.

1 Like

Actually I just tried again registering with my google account and it didn’t ask me for the phone number this time, so I guess they changed their policy.
Noice :star_struck:

1 Like