A library that turns C code into gcode.
Inspired by OpenSCAD and Tool Path Language.
I want to machine stuff on my CNC mill and lathe without having to use clunky UIs or spend time learing well all the buttons are in a "free as in beer" program, just for that program to move the machining features behind a paywall (im looking at you Fision 720).
The available open source CAM packages are bloated with UI code which makes it nearly impossible for everyone but the core developers to understand.
C is one of the oldest languages still around, yet it is one of the simplest to learn from a syntax point of view. There are only 32 keywords that you have to remember, most of which are not used 99% of the time.
Most importantly, writing toolpaths in a real programming language means that you can use all the tricks you use for data with shapes, like for
loops for patterns, conditionals, functions that draw custom shapes etc.
Writing everything in C also means that it is easy to port to other platforms or use the code for plugins.
Finally, I love C!
But, Pointers???? - you ask
Here is you 5 minute explanation of pointers (don't worry you will not need pointers to use libccam):
Varibles are put somewhere in the memory of a computer when they are defined like this int a = 5;
. A pointer just holds the address of that variable so that you can use the value inside without copying it, which would be slow. It's really that simple. Where most people strugle and get frustrated with pointers is when they forget when and where to put the *
, &
, .
or ->
. Don't worry about it, just look it up online when you need it, most of the time the compiler will tell you if you used the wrong one and which one would be correct.
- Easy way to generate gcode without a bloated UI.
- Be able to do most machining opperations that you would want
- Help you learn gcode.
- Easy to understand code.
- Learn some cool C.
- Traveling at rapid feedrate (G0)
- Moving at curring feedrate (G1)
- Setting rapid/feed speed
- Relative and Absolute moves (G90/G91)
- Arcs and circles (G2/G3)
- Pause, Stop and Hold the program with
pause()
,stop()
andwait()
- Profile cuts with aray of points/arcs with
profile()
- Facing at any angle with
face()
- Boring with
bore()
- Drilling and pecking (G83) with
drill()
,peck()
andadvanced_peck()
- Pockets
- Adaptive tool paths (AKA high efficiency tool paths)
- Tool change
- grbl support
- Lathe support
Just download the repo to your project folder and use the examples/Makefile
inside of your project folder.
Check out the examples/
folder for example code and libccam.h for what the functions do, that is probably the best tutorial.
You can also find some useful tools in the tools
.
Make sure you have GCC installed.
Run make generate
in that folder to convert main.c
to gcode (output saved in out.nc
).
Install entr and run:
ls | entr -c ./generate
to have the file automatically recompiled every time main.c (or any file for that matter) is changed.
Use Ctrl+C
to quit.
Run make show
to generate the gcode and display it with cginc
.
Requires cginc
to be installed!
Or for a more advanced visualisation, install CAMotics and open out.nc
as a new project in order to simulate your gcode.
Pressing the refresh icon will reload the gcode file.