Giter VIP home page Giter VIP logo

libccam's Introduction

libccam

A library that turns C code into gcode.

Inspired by OpenSCAD and Tool Path Language.

Motivation

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.

Why C?

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.

Project Goals

  • 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.

Features

  • 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() and wait()
  • 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() and advanced_peck()
  • Pockets
  • Adaptive tool paths (AKA high efficiency tool paths)
  • Tool change
  • grbl support
  • Lathe support

Install

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).

Optional

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.

libccam's People

Contributors

bogdanthegeek avatar

Stargazers

 avatar

Watchers

 avatar  avatar

libccam's Issues

Improve readme

  • - Add checklist for project goals and supported features.
  • - Show examples
  • - Have instructions for running and checking gcode

Add pocket operation

  • - climb or conventional
  • - pitch
  • - start 0,0 or w/2, h/2
  • - start with plunge or bore

Add SVG support

I think i want to give the possibility of importing shapes that are a bit to verbose to code by hand.
SVG is pretty easy to parse (Inkscape's version at least), has abs and rel dimensions and apart from bezier curves, all the other components of a path object translate directly to gcode.
https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
Bezier curves are easy enough to convert to and array of segments using linear interpolation.
http://jamie-wong.com/post/bezier-curves/

Tools like Inkscape already have functions for outlines, which can help make pocket opps.
There are svg parser libraries, but I think I can extract the useful data in a simpler, easier to understand way. It will be a fun learning exercise none the less.

The only question would be:

  • Write a live parser in c that extracts the paths and converts them to point arrays every time the program is generated?
  • Or write a converter that extracts them to header file?

A clear goal of this project is to use easy to read C code. With that in mind I think the first option will look better, but for complex shapes, the execution time would be very slow without threads. We may have to go to threads eventually, but i want to avoid it as much as possible along with any extra library for that matter.
Either way, an svg parser/converter is next.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.