How to draw a rectangle in Gcode

So you’ve played with the Makelangelo‘s generated Gcode and now you want to experiment on your own. Cool! Here’s a simple rectangle to get you started.

Now let’s give some values to these parameters:


My method is to lift the pen, drive to a corner, put the pen down, and then trace the rectangle. That means going to five points because we have to come back to the start.

G0 Z90; # pen up
G0 X-10 Y20;  # p1 
G0 Z40; # pen down 
G0 X30 Y20;  # p2
G0 X30 Y-40;  # p3 
G0 X-10 Y-40;  # p4 
G0 X-10 Y20;  # p1 again
G0 Z90; # pen up

And voila! I’ve deliberately done this with the origin away from the center so the numbers are more obvious. I hope you see that in a cartesian system the origin could be anywhere. For example, if it were below and to the left of P4 all the X and Y values would be positive.


Creating my own Processing arc method

The Processing arc() command isn’t robust enough for my tastes so I wrote a new one that gives me more control over the things I care about. Along the way it lets me validate my arc code for the Makelangelo’s support of gcode commands G02 and G03. If people are learning Gcode then their arc() command would be helpful if it looked the same as a gcode command. Don’t you agree?