Since I have the MidTBot ESP32 plotter running properly, I thought I should look at better ways of generating G-Code than using BASIC and lots of print statements. Ed Nisley — from whom I’ve learned a lot — always seems to be doing interesting things using the gcmc – G-Code Meta Compiler, and it looks like a useful little language to learn.
Here’s the code to make at least half of the above:
/*
osculating circles - scruss, 2021-01
gcmc version
Usage with midTbot / grbl_esp32:
gcmc osccirc.gcmc | grep -v '^G64' > osccirc.gcode
Or for SVG:
gcmc --svg --svg-no-movelayer --svg-toolwidth=0.25 osccirc.gcmc | sed 's/stroke:#000000/stroke:#C80022/g;' > osccirc.svg
*/
comment("osculating circles - scruss, 2021-01");
/* machine constants */
up = [-, -, 5.0mm];
down = [-, -, 0.0mm];
park = [5.0mm, 145.0mm, 5.0mm];
feedrate(6000mm);
/* model parameters */
centre = [100.0mm, 75.0mm];
r = 65.0mm;
lim_r = 3.0mm;
pr = r;
a = 0.0deg;
da = 6.0deg;
sc = 0.95;
comment("centre: ", centre, "; r: ", r, "; lim_r: ", lim_r, "; pr: ", pr, "; a: ", a, "; da: ", da, "; sc: ", sc);
/* counter / sense marker */
n = 0;
goto(up);
do {
centre += [(pr-r)*cos(a), (pr-r)*sin(a)];
goto([centre.x - r, centre.y]);
goto(down);
n++;
if (n%2) {
circle_cw(centre);
}
else {
circle_ccw(centre);
}
goto(up);
a += 360.0deg + da;
a %= 360.0deg;
pr = r;
r *= sc;
} while (r >= lim_r);
/* end */
comment(n, " circles");
goto(park);