
CNC milling with open source software - jhibbets
https://opensource.com/article/19/1/cnc-milling-open-source-software
======
jcoffland
If you're interested in Open-Source CNC you should check out two of my Open-
Source projects. [https://camotics.org/](https://camotics.org/) a CNC
simulator and [https://buildbotics.com/](https://buildbotics.com/) a CNC
controller. I'm somewhat surprised neither of these were mentioned.

~~~
juliangoldsmith
Is there any reason why CNC machines aren't directly controlled by CAM
software, beyond it always having been done that way?

I'd think it would be useful to integrate the two, instead of the CAM software
just firing-and-forgetting toolpaths.

~~~
DannyBee
(I have built and worked on a lot of CNC mills, routers, etc)

In some cases, it is.

There are integrated CAM + Machines depending on industry and price point.
(see woodwop, etc, which are the interface to the machine)

The motion planning aspects can be taken care of (despite other comments),
beckhoff, for example, does real time plc on windows machines by isolating
cpus away from windows. i have no problem using it as a plc. They also support
CNC control.

Outside of software like that, it's usually being taken care of by an FPGA
card and that's a pain in the butt. Assume you can solve this.

You still have the next problem: Actually driving the machine.

First, the low level

Most of the servos in these machines are using pulse train inputs of some
sort. That's what the FPGA cards are doing, generating the pulse outputs, etc.

It's only in the past 5 years that things like "drive my servo over ethercat
instead" became viable.

They use simple relays, etc to control safety/limit switches/you name it.

Now i could use an ethernet based field-io. So i'd say they are actually now
_there_ (in the past 5 years) for the low level. I can run all my field
io/spindles/servos off ethercat now, for example. I do, in fact, outside of
servos (my cnc software can't drive them over ethercat yet)!

5 years ago i couldn't do this.

Okay, so that's one level up. Now i can at least _drive_ it from the CAM
software in some standardized way if i knew what was what. Which is your next
problem - knowing what anything does. Which io's are the limit switches. How
do you home the machine or execute a tool change? How do i turn on the vacuum?
Which drives go with what axes?

There is no standardized way of describing _this_ , such that a piece of CAM
software could actually do anything.

We'll get there, mind you, but it'll be a while.

~~~
rmu09
Low-level control your machine from your CAM workstation in the office
building will never make much sense (where the CAM software directly talks to
servos).

I would prefer my (probably expensive) machine to kind of "know" what it's
physical limits are and guarantee that executed commands adhere to them.

~~~
DannyBee
It depends on what you are talking about here. CNC is used for a _lot_.

The assumption that there is a cam workstation, and that it's in an office
building, is certainly not one i would make. I wouldn't also say "will never
make much sense".

You seem to have some particular set of users in mind for which you believe it
wouldn't make sense. Okay - i'm not sure that changes that there are plenty of
sets of users for which it will?

I even gave you examples of high end wood machines that have CAM directly
integrated. There are many.

(They can also be programmed offline, but)

As for "knowing" the physical limits.

That's not actually possible since it there is no way to self-configure it
even if everything did talk to each other. They don't know their own physical
orientations (and it would be very expensive/hard to do that, and you'd still
be guessing in the end)

Most of the non-safety/accessory programming is essentially explaining enough
of the physical orientation and placement of things to the motion control that
it can do something.

~~~
rmu09
English is not my first language, so forgive me if I'm a bit ambiguous, it's
not the intention.

CAM workstation (running some "generic" CAM package with machine specific
configuration) in some office building was the precondition, in that case it
will never make much sense to control a machine's servos from that
workstation, in my opinion.

Integrating the CAM within the machine itself is something else, and yes,
stuff like that existed for very long time, but that is something completely
different IMHO.

The machine controller "knows" the physical limits because somebody configured
it (and "locked" it). It would be hard to guarantee the integrity of this
configuration if you put it on an arbitrary workstation to run CAM and machine
control.

~~~
toomuchtodo
There will always be some sort of interface between CAM and other design tools
and the physical apparatus to execute assembly. I think we're all just being
pedantic in this thread; is it likely you're going to hook your workstation
directly to the multi-axis mill? No. Is it more likely we're going to have
some sort of queue and bus that'll allow you to send more complex instruction
sets to assembly systems? I think so (based on my interaction with a firm who
is doing this for high precision additive manufacturing). What that looks like
is going to depend on the complexity of your shop floor, and manufacturing
demands.

------
opwieurposiu
CNC is programming "for keeps".

Any tiny little error in your gcode has a chance to crash the machine. Unlike
a computer crash, a CNC crash results in broken metal flying across the room
and anywhere from $5- to $5000 in damage. I programmed for a heavy machine
shop for a year before I gave up and went back to making websites.

Hobby CNC is fun though, it is amazing what you can make out of wood when you
can shape it with sub-millimeter precision. Also hobby machines are not strong
enough to cause serious damage when you crash.

~~~
th0ma5
Is there no way to test? Or there is, just not everything?

~~~
nickpinkston
The best shops use simulation tools, but you need the 3D models /
configurations of everything to make them work, and then the machinist still
needs to load everything correctly. It's very easy to make a mistake.

Check out a simulator here:
[https://www.ncsimul.com/](https://www.ncsimul.com/)

~~~
rmu09
There are machines that are "self-aware" in the sense that they run a
simulation parallel to the NC control, slightly advanded in time, to catch
catastrophic crashes and ESTOP the machine. Cutting into the machine bed can
be _very_ expensive.

~~~
nickpinkston
Which machines are you referring to?

How aware? Do they have any vision? Can they "see" or otherwise "know" about
the cutters / workholding?

~~~
rmu09
I know of WFL millturns with crashguard.

AFAIK the crash guard is a separate component that relies on 3d models of the
machine and the tools, it doesn't see anything.

If you workholding is weak and a piece comes loose the crash guard probably
won't make a difference.

------
Ccecil
I work with the smoothieware project (hardware QA). It is an opensource motion
control firmware and openhardware control board which works with 3d printers,
lasers, mills, etc. Initially based on GRBL and runs on ARM (LPC1769).

The openhardware scene has advanced quite nicely in the last 5 years. There
are many very nice projects out there to build from which are largely able to
be built at home with parts which can be made locally and/or purchased online.
Openbuilds is a good place to start if you are interested.

I always try to remind people...whether it is 3d printers, mills, lasers...the
knowledge gain from building/breaking/rebuilding your machine far outweighs
the small gain you get from simply operating one. I have never printed an
object as interesting to me as it was to create and design an entire working
machine from scratch.

If anyone is interested in openhardware projects I recommend checking out
reprap.org , smoothieware.org , openbuilds.com as well as several other
projects which I am sure you will stumble upon through research on those
sites.

There are many opensource CAD/CAM software packages out there which allow you
to pick and choose what you like. I personally use Fusion360 for most of my
CAD/CAM stuff (I know...not Opensource) and for 3d printing my personal
favorite is Slic3r.

~~~
vespakoen
I re-implemented (most of) TPLang (mentioned above) in pure JS , and called it
openjscam [1] And am working on open source software for CAM (as a hobby),
just 2.5D gcode generators, using maker.js and openjscam [2]. And made
opencamlib compile on Mac and Windows (and added basic Node.JS bindings) [3]

I am hoping more people will work on open source g-code generators so we have
better alternatives to Fusion 360 / Solidworks for free

[1]
[http://github.com/makercam/openjscam](http://github.com/makercam/openjscam)
[2] [http://github.com/makercam](http://github.com/makercam) [3]
[https://github.com/aewallin/opencamlib](https://github.com/aewallin/opencamlib)

------
rmu09
For controlling your machine there is LinuxCNC (formerly Enhanced Machine
Controller, created at NIST)
[http://www.linuxcnc.org](http://www.linuxcnc.org) and the fork MachineKit
[http://www.machinekit.io/](http://www.machinekit.io/)

Also, latest FreeCAD has a CAM module ("Path workbench") that has come a long
way and really is useful.

------
tlarkworthy
G-code is the most hilariously bad language. Keywords are G + a number, e.g.
G01, with wildly different effects, varying arg lists and no standard. E.g.
G01 move to position, G20 set the machine units to inches. Its often stateful.

Obviously its coz its old and works, but i chuckle everytime i have to look up
the codes at how comically awful it is compared to anything else i see

[https://en.m.wikipedia.org/wiki/G-code](https://en.m.wikipedia.org/wiki/G-code)

~~~
lvh
What would a good G-Code variant look like? For all its flaws, it's pretty
good at encoding the exact thing you want the CNC machine to do and while
there certainly are different post-processors for different machines and in
most cases they're not optional, it's also not like they're entirely
different.

I think of G-code as ASM. For high-performance work you might write code
differently for different (related) machines, but it's still a pretty OK
compilation target.

~~~
onmai-xyz
A good G-Code variant would roll up the un-rolled loops and separate the
geometry data from the tool config data. This is what the view of a CAM IDE
presents, G-Code source can be structured the same. If you change the
semantics on some of the syntax you get lexically scoped blocks, macro-b
subsystem which has existed for decades needs to be fully utilized for this to
happen.

A fully implemented system would provide the CAM GUI engineer and the CNC CLI
machinist to work on the same file, skipping post-processing entirely.

And, finally implement what was originally envisioned but not possible on even
the most powerful mainframes of the late 50's:
[https://youtu.be/ob9NV8mmm20](https://youtu.be/ob9NV8mmm20)

~~~
lvh
Eventually, something actuates a servo, and servos don’t understand iteration.
Do you agree eventually something with g-codes level of detail must exist
(even if it’s just unspecified internal commands)? If so, do you agree you’re
just advocating for that layer to be part of the machine?

~~~
onmai-xyz
Speaking from user space that has G65 macro-b option, not machine tool builder
(sudo) space.

>I think of G-code as ASM.

>Eventually, something actuates a servo, and servos don’t understand
iteration.

I think of it more as an intermediate language. Interpreted on the CNC control
and JIT compiled to whatever the RT system needs for servo control.

>Do you agree eventually something with g-codes level of detail must exist
(even if it’s just unspecified internal commands)?

It does exist and a strict subset with enough primitives to bootstrap an
application VM should continue to exist.

>If so, do you agree you’re just advocating for that layer to be part of the
machine?

I am advocating for a DSL one layer up to be part of the CNC machine with
support offline in say the JVM.

I want to answer this question, “how do we deploy MBE?”
[https://www.nist.gov/news-events/events/2019/04/model-
based-...](https://www.nist.gov/news-events/events/2019/04/model-based-
enterprise-summit-2019)

The answer needs to be a single digital file that can render real parts and
virtual parts. Why not?

------
jononor
Even though I love 3d-printing, and designing/building machines, I would not
build a small CNC like that from scratch. Since you get better machines for
<200 USD that runs open source firmware (grbl) out of the box. Recently got
one of them for PCB milling, a CNC 3018 Pro

~~~
cmsimike
I've been eyeballing the CNC 3018 Pro for a few weeks now. I would appropriate
any input you have on the device. Pros/cons/alternatives I should look at.
Anything!

~~~
justinclift
If you've the budget for it, a Shapeoko3 is way more capable.

[https://carbide3d.com/shapeoko/](https://carbide3d.com/shapeoko/)

:)

------
tsmarsh
I got into CNC milling about 9 months ago. SVG to 2.5D problems are easy, and
get you to a lot of cute solutions, its about as close to the work flow of 3D
printers as you can get.

But the really interesting stuff is when you get to CAM. Multiple tool paths,
genuine 3D cutting. Moving the work between paths etc. Its like going from
juggling 3 balls (2.5d) to 5 balls (3D).

I haven't seen any competitive opensource CAM products, and its the main
reason I continue to use Fusion 360 instead of OpenSCAD or SVG for my designs.

~~~
phkahler
> I haven't seen any competitive opensource CAM products...

Solvespace is open source and claims to export tool paths as gcode with cutter
radius compensation, though I have not used this feature. I found cutter
radius and export 2D section but it's not cooperating right now!

[http://solvespace.com/index.pl](http://solvespace.com/index.pl)

~~~
tsmarsh
> preparing CAM data — export 2d vector art for a waterjet machine or laser
> cutter; or generate STEP or STL, for import into third-party CAM software
> for machining

Thats been my experience with all of the OSS CAM: g-code for 2.5D, or STL so
that a 3rd Party can do the really heavy lifting.

------
cmsimike
I've been looking for a home PCB machine and would appreciate any
recommendations on what to look at or what to avoid.

I've been told multiple times that it's easier to just have a service print
your board which is probably true, but that would take a lot of fun out of the
entire process for me.

~~~
nadavami
I've been using a 3018 CNC with pretty good results. They're fairly
inexpensive machines (about $300 I believe) and are decently accurate.

I still order boards from China, but for a quick breakout board it's
incredibly handy!

I also decided to get a 5W laser which is also pretty fun to engrave with.

I'm planning on writing a series of blog posts about it if you're interested!

As a last note, if you like tinkering, these little machines are money and
time sinks.. So far, I've added limit switches, a pi, more bits, 3D printed a
tool holder etc etc

~~~
gangstead
I'm definitely interested. I got into 3D printers and CNC machines at about
the same time last year. I figured out the 3D printer right away and quickly
went from printing out things on thingiverse to doing my own designs and
outgrowing my printer and getting a fancier one.

While I've done about 250 print jobs in just under a year on my 3D printers
after 8 months with the CNC I've cut two things. I got an entry level CNC
(Millright M3) that runs the same GRBL on Arduino software stack and I've just
been stumped after setting it up and cutting a couple rectangles out. The
amount of time you have to put into setting up a CNC job is exponentially more
and the amount of reference material out there is way less and way more
specific to particular work flows / machines / pieces being cut.

~~~
dylan604
There's a big difference between an additive process vs subtractive process.
To me, additive is much easier as it starts at the bottom and build up.
Nothing is ever in the way of the next step. Subtractive is much more
difficult as you have to figure out how to get to places that needs tooling,
how to hold the piece to do the work on it (especially as the piece changes
shape in the process). Most projects I work on requires more work in setup
than actual milling/cutting/etc. It's one of those things that most people
just don't realize until they actually attempt it.

~~~
gangstead
I've found the work holding on the CNC to be somewhat analogous to bed
adhesion on the 3D printer. When milling you have to figure out how to hold
this block down and printing you're using glue sticks and tape to try to get
the first layer to stick. Both of these require the same trial and error shade
tree mechanic skills that I enjoy developing.

My sticking point is more in the CAM side of things.

First I'll design something in Fusion 360. If I want to 3D print it the next
steps are to export the stl (shape file) and open it in a slicer program. Then
there are about ten parameters that may need some tweaking especially for a
new printer and dozens more that you rarely change from the default before
sending gcode to the printer. The slicer program can get you pretty close out
of the box and the more I've done it the less time I spend slicing - my go-to
settings print perfect 90% of the time. There are lots of resources (blog
posts, youtube videos etc) explaining the different slicer settings and their
effects on the print.

For CNC Milling after I've designed the part in F360 you switch over to CAM
mode and it's like an entire different project that you have to design. With
the slicer you say "lay it down on this side and print in PLA" the CNC CAM
process makes 0 decisions for you. You can't just say "here's my stock, here's
my end mill, put this side up and cut" and then tweak settings from there.
Instead there are myriad permutations on feed rates, orders to cut things,
multiple passes. Someone's feeds and speeds posted on the internet aren't
going to work for your machine/material/design so there can't be something
like a slicer program that can automatically route your CAM based on a few
parameters and you can't reuse many settings between jobs.

I still like both printing and milling but milling is such a more difficult
task with less mature software available (especially open source and hobby
level software). That's why a fairly simple task warrants a pretty lengthy
tutorial that's worthy of the HN front page.

~~~
jdietrich
I might be a dreadful old fogey, but I think that everyone should learn manual
machining before getting into CAD/CAM. There's a level of mechanical sympathy
that can only be learned by turning the handwheels and making chips. CAM is
complex because machining is complex - removing the software from the equation
makes it far easier to learn the fundamental principles, IMO.

------
syntaxing
I owned a 3020 and own a Shapeoko 2. Unfortunately, I rarely use them. The
biggest problem with CNC is that the overhead is so expensive. There's very
little room for mistakes and material cost (stock and bits) can get very
expensive. Holding a part can get tricky and the wrong feedrate can ruin your
part. I end up using my 3D printers to do most of my parts nowadays. Though I
do use my CNC for "food grade" stuff around the house.

~~~
yourapostasy
> ...and material cost (stock and bits) can get very expensive.

I've been looking at CNC for a long time, and I've read that if you're
starting from scratch, to allocate about the same amount that you spend on the
mill itself to the consumables/logistical tail (end mills, cutting fluid,
ancillary metalworking tools). Due to the steady degradation of quality design
and manufacturing, and rapid support obsolescence, there is an endless supply
of improvements I could make around the house if I had enough time and
equipment.

It bothers me greatly to hear from appliance repair techs that I must throw
out an entire major appliance instead of repairing just the pieces that broke
[1], because the parts are either grossly expensive, or even simply not
available. I'd love to own "versioned, open source" appliances, where open
specifications let everyone repair only what breaks. And when something
breaks, the community can figure out the root cause and redesign for greater
robustness.

Like if a plastic part wears down causing a cam to miss a gear, then redesign
to machine the cam out of high strength steel. Or if lots of people note a
design oversight that makes a particular maintenance procedure a pain, a
different access panel is designed and distributed for machining. Or if
someone wants upgrade to a later version of an appliance, they swap out only
the guts that change, and not the entire assembly, ideally sending the old
guts in for recycling back into feedstock that others use for either
manufacturing new or upgrading old units themselves. Or building in self-
diagnosis over time, and auto-ordering new components for those that are
detected wearing out.

The Increvable washing machine comes close [2] in the repairability area, but
it isn't open source to the point where you can read off specs to create
completely compatible machines, and the company can still go after you for
copying their product.

[1] [https://circuitmaker.com/blog/about-open-source-washing-
mach...](https://circuitmaker.com/blog/about-open-source-washing-machines)

~~~
jandrese
Sometimes those plastic gears are serving a purpose though. They can protect
much more expensive parts by failing first when an error occurs.

So the operators gripe about replacing a stupid plastic gear so they replace
it with a metal one, then gripe when they have to replace the blown out
gearbox.

~~~
yourapostasy
Yep, thanks for pointing that out to the general audience, should definitely
be noted. Some KitchenAid mixers have a plastic gear for exactly that purpose.
On the other hand, on an outboard motor I use, the plastic gear that wears
through for a tilt lock mechanism is attached to a ludicrously expensive metal
assembly that has to be completely replaced.

I'm okay with the plastic gear designed as a sacrificial component. I don't
like having to toss an entire assembly into the landfill, though. I'd like to
be able to print/purchase just the sacrificial component and screw/glue it
onto the existing still-working assembly. Event better, I'd like to send the
broken sacrificial component back through to a process that breaks it back
down into feedstock for recycled resins that go to manufacture products that
can take slightly weaker plastic (each pass through recycling, plastic becomes
slightly weaker, with virgin plastic starting at the strongest).

Ideally, I'd like to see aluminum parts that are designed to crumple under the
specified sacrifice load like the equivalent plastic parts, and be able to
just endlessly recycle the aluminum. But I've never seen such a design of a
sacrificial gear/cam/bolt, so I don't know if that is simply an impossible
mechanical engineering ask by a dumb layperson.

------
mpmpmpmp
The Mostly Printed CNC is another great 3d printed CNC.
[https://www.v1engineering.com/specifications/](https://www.v1engineering.com/specifications/)
Almost done printing the parts for mine. Will run GRBL on it as well.

------
bcheung
I've been looking into building my own CNC. Sounds like there are some
experienced CNC peoople here. Does anyone know why there are not more polar
coordinate based CNC machines? I've been wondering what the pros and cons are.

~~~
HeyLaughingBoy
Probably because the compliance changes. The farther you go from the origin,
the easier it is to push the tool away from its intended cutting path.

A gantry-style machine, on the other hand, has the same rigidity anywhere in
the X-Y plane. Rigidity is a bit less as Z changes (due to a longer moment
arm), but it typically doesn't travel as far.

