2
$\begingroup$

How can I write G-code for a triangle without sharp tips?

Example of required triangle

I want to generate the corners manually, rather than using a slicer to generate them, just to know how it is done.

$\endgroup$
3
  • 1
    $\begingroup$ your question is extremely terse. Do you want to generate the corners manually or do you want to understand how a slicer maces them? How a CAD does them?! $\endgroup$ – Trish Jul 4 '19 at 17:18
  • 1
    $\begingroup$ With lots and lots of tiny segments. $\endgroup$ – towe Jul 5 '19 at 6:23
  • $\begingroup$ @towe True, even if you use G2/G3 $\endgroup$ – 0scar Jul 5 '19 at 11:40
4
$\begingroup$

Marlin has G2 (clockwise arc) and G3 (counterclockwise arc) commands that could be used to do this. You can find detailed documentation for the command here.

Basically, you can use

G2 R1 X5 Y5

to draw a (clockwise) arc from the current position to $(X,Y)=(5,5)$ with a radius of $1$.

So, your rounded triangle could be drawn with 3 straight line moves and 3 arc moves. Figuring out the exact coordinates for each move would be a quite challenging geometry exercise, as you'd need to know where the straight line portion of each side ends and the rounded portion starts.

$\endgroup$
4
  • $\begingroup$ it's an easy exercise with a CAD though $\endgroup$ – Trish Jul 5 '19 at 8:29
  • $\begingroup$ Do note that in the firmware support for G2/G3 must be enabled in the firmware, e.g. in Marlin by definition of #define ARC_SUPPORT in the Configuration_adv.h file. Also, shouldn't your printer board must have a sufficient capable processor to process the calculations for this option? $\endgroup$ – 0scar Jul 5 '19 at 9:05
  • $\begingroup$ @0scar circles are rather usual in CNC commands and most printer boards can double for those. I assume you might want to use the IJ argument instead of the R Argument though. $\endgroup$ – Trish Jul 5 '19 at 9:07
  • $\begingroup$ @Trish The question specifies the G-code must be created "manually". I'm not sure if using CAD still counts as manual. $\endgroup$ – Tom van der Zanden Jul 6 '19 at 6:54
3
$\begingroup$

First, convert the given measurements into a sketch...

Sketched out dimensions

G-code shenanigans

we actually have the printer do circles.. let's plot that out...

Plotted all start-ends and centers

Using that, it's easy to write the G-code using the Documentation for G1 and G2. You'll have to add the E values to extrude something along the paths, but your sketch would turn into this path:

G92 X0 Y0 ; the current position is now (0,0) on the XY
G90 ;Abolute mode for everything...
M83 ;...but for the E-argument, so you can just put the length into the extrusions that are to be done
G0 X10.66 Y2 
G2 R5 X6.33 Y9.5 ; Alternate: G3 I0 J5 X6.33 Y9.5
G1 X45.66 Y77.638 
G2 R5 X54.33 Y77.638 ; Alternate: G3 I4.33 Y-2.5 X54.33 Y77.638
G1 93.67 Y9.5
G2 R5 X89.33 Y2 ; Alternate: G3 I-4.33 Y-2.5 X89.33 Y2
G1 X10.66 Y2
G0 X0 Y0
G91 ; return to relative coordinates

This code has to be prefixed by a move to where you want to start the pattern and will not know if you move it off the build plate, so keep 100 mm X and 87 mm in Y of the allowable build plate. It will end exactly where you started it.

Iterative approach

In many uses of g-code, rounded corners are actually n-gons with a very high number n. then we only need G1 and can easily calculate the length of the stretches and fill in the G1. We need to iterate down to somewhat circular...

Let's start iterating with n=3 aka a triangle, which gives a direct line over the corner gives this:

Iteration 1

going to n=6 (hexagon) follows the curve a lot better...

Iteration 2

going to n=12 looks almost round on a larger scale...

Iteration 3

and when we reach n=24, we are pretty close to the circle..

iteration 4

And as we go above n=6, we also get easier math for the corners, as we always get the same lengths of movement along X and Y just swapped around due to symmetry.

With all these stretches defined, we could start to work in relative coordinates easily, again without E, and only for the bottom left corner:

G0 X10.66 Y2 
G1 X-1.294 Y0.17
G1 X-1.206 Y0.5
G1 X-1.036 Y0.795
G1 X-0.795 X1.036
G1 X-0.5 Y1.206
G1 X-0.17 Y1.294
G1 X0.17 Y1.294
G1 X0.5 Y1.036
...
$\endgroup$
2
  • 1
    $\begingroup$ Killer explanation ... love the graphics, which completely help the understanding. +1 $\endgroup$ – Pᴀᴜʟsᴛᴇʀ2 Jul 5 '19 at 16:50
  • $\begingroup$ Beautifully illustrated, but it is responsive to the question The question seemed to be about writing arcs in g-code, rather than how one could simulate arcs with line segments. $\endgroup$ – cmm Jul 11 '19 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.