508,453 active members
3,870 visitors online
Register for free
Login
IndustryArena Forum > OpenSource CNC Design Center > Raspberry Pi CNC > PyCNC - first CNC machine controller on pure Python for Raspberry Pi.
Page 1 of 2 12
Results 1 to 12 of 23
  1. #1
    Registered
    Join Date
    Nov 2015
    Posts
    5

    PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    Hello!
    I'd like to present first ever CNC machine controller implementation on pure Python(even without dependencies or any C modules) for ARM based Linux boards. Hardware access layer(HAL) allows to implement support for almost any ARM SoC/CPU with suitable DMA module, but currently it is implemented for Raspberry Pi only. It already works on Raspberry Pi 2 and 3.

    Typically, CNC machine controllers are implemented with C or C++ programming language and running on OSless or very real time operation systems. For example, Linux by default is not real time operation system and running LinuxCNC on it require to add special real time features to kernel. I believe that is very old approaches for building such controllers and it's high time to use modern ARM processors for CNC and use very high level programming languages like Python to provide easy development, flexibility and migration between hardware.

    I managed to do this! First ever CNC controller implemented on pure Python on Raspberry Pi 2 running Linux, it's better to see, than read:
    https://youtu.be/vcedo59raS4

    How it works? It uses DMA(Direct Memory Access) on chip hardware module, which just copy allocated in RAM buffer of GPIO states to actual GPIO registers. And this copying process is clocked by system clock and works completely independently from CPU cores. So, I was needed just to generated pulses sequence for axis stepper motors in memory and DMA precisely sends it. As for access to processor registers, it's implemented with /dev/mem system device. That can be implemented with different languages, but Python is very simple language which provides better development experiences. Of course, Python performance is not good, but on the other hand, modern ARMv7 processor performance is more than enough to run it.

    And the most pleasant part, I open sourced this project!
    Project is here - https://github.com/Nikolay-Kha/PyCNC
    There is a wiring diagram and running instructions in git repo.
    It's just a begging of this project, currently, it supports just simple things - spindle control, linear interpolation and some basic gcode commands. I have plans in near feature to add round interpolation, 4th axis, temperature sensors, heaters support and implement fully functional 3D printer CNC controller.

    Thank you for reading, hope it was interesting for you.

  2. #2
    Registered
    Join Date
    Dec 2015
    Posts
    12

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    very cool. Just starting to wade through it right now.

  3. #3
    Registered
    Join Date
    Feb 2012
    Posts
    52

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    Great job. I am very interested in this and will be studying this.

  4. #4
    Registered
    Join Date
    Nov 2015
    Posts
    5

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    Now PyCNC is compatible with HDMI monitors. So, PyCNC can be run directly from Raspberry Pi3 with mouse, keyboard and monitor:*
    https://youtu.be/fFp9MaTRyE4
    Also, I purchased a new frame — Chinese implementation of RepRap Prusa i3 in aluminum. Now I’m awaiting for delivery.*
    As you may see, I’m going to implement full functional 3d printer with PyCNC, and RepRap Prusa i3 and Raspberry Pi3 will be reference devices for that.

  5. #5
    Registered
    Join Date
    Apr 2013
    Posts
    9

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    Thats amazing. Very impressed

  6. #6
    Registered
    Join Date
    Oct 2010
    Posts
    1189

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    Verry nice it May be Perfect for a lathe and cutting gears...


    Gesendet von iPad mit Tapatalk

  7. #7
    Registered
    Join Date
    Jun 2012
    Posts
    113

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    So you have chosen to code this in an inefficient interpreted language on top of a non real time linux kernel and describe using a fast, efficient compiled language in direct machine contorl on an RT kernel as "old" solutions.

    I agree that modern ARM CPUs are the way to go but your other choices seem like a backwards step from the "old" method. You do not want the sloppy latency of having an OS in the way when controlling machine hardware. This is fundamentally the wrong way to go about it.

    Whether the OS is on a desktop PC controlling some hardware via a peripheral port, or directly on a SoC does not change the problem. You NEED real time control for controlling machines. That is why everyone does it that way using "old" methods.

    It is the hardware abstraction layer ( not access layer ) which will give portability not python. That is where the hard work lies in porting to another hardware platform.

  8. #8
    Registered
    Join Date
    Jun 2012
    Posts
    113

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    NO, it would not be "ideal" or even suitable for controlling heavy machinery like a lathe.

    It may be OK for 3D printers where it does not really matter if something goes wrong. Although printers usually move quite fast and this is likely to mean lack of RT will lead to errors. Since home 3D printers produce pretty crude results anyway you may not notice some of them.

    Please don't use it for anything bigger.

  9. #9
    Registered
    Join Date
    Mar 2013
    Posts
    21

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    Great work man, do you plan to develop a kind of GUI for it ?

  10. #10
    Registered
    Join Date
    Oct 2015
    Posts
    1

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    With a couple decades of electronic motion control and modest machining experience, I agree with you reg.miller. CNC means a lot of things to many people, and this controller might be fine for those little Chinese routers, but is possibly unsuitable (or worse) on a larger machine with higher speeds and greater inertia.

    The project looks like fun, and I can see people employing it for hobby desktop machining. But, I advise caution for anyone who might want to retrofit this controller onto full-sized machinery for all the reasons reg.miller outlines.

  11. #11
    Registered
    Join Date
    Jul 2016
    Posts
    15

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    This is a really cool project. There are a couple of things you can do to mitigate the concerns expressed in this thread.

    First, you can install real-time kernel extensions or just start with an image that already has them installed:
    Raspberry Pi Going Realtime with RT Preempt | {ε}
    https://emlid.com/raspberry-pi-real-time-kernel/

    Up next would be getting away from interpreted code and start running your code closer to the metal. You can compile to machine code by taking an intermediary step. There are a couple of popular software solutions that do this for you. Cython and Numba:
    Cython: C-Extensions for Python
    Numba — Numba

    Now that you've got better latency on your kernel and you're running real, optimized, executable code this project becomes much more attractive for multiple applications. I am interested in seeing performance differences. If you had 2 SD cards you could run them back to back and see the differences. Call one DEV and the other PROD. The production system is the one with the real time kernel and compiled code. Every time you want to publish a build you just compile it and move it over to the PROD image. Then you always have those 2 versions to do comparisons.

  12. #12
    Registered
    Join Date
    Dec 2005
    Posts
    207

    Re: PyCNC - first CNC machine controller on pure Python for Raspberry Pi.

    Impressive project that you are able to get simple step/dir motion control working. As the author of the ELS developed with user feedback on the yahoo E-Leadscrew group I can certainly understand the difficulty and how good you probably feel having accomplished as much as you have. I also open sourced my ELS code so congratulations on doing the same with your project.
    Therefore, having been there with spindle tracking and threading, perhaps I could give you a suggestion:

    Replace the Raspeberry Pi with a Beagle Bone Black. Install the MachineKit LinuxCNC and compare how it works with yours. The two Programmable Real Time Units deal with the hardware apart from the linux and the graphical user interface. And even it cannot yet do threading on a lathe.

    I believe when you try to read a G-Code file, do the circular interpolation along with smooth transitions between short segments and also display the path graphically, which is already there on the Beagle MachineKit, that you will find your approach with Python and the Pi will fail. Python is just so slow compared to other languages and when it decides to do garbage collection on the dynamically allocated memory your application will stutter and slow.

    And truthfully, the Beagle even with the same clock rate as a Pi3 seems to run at less than half the speed. Longer to boot, longer to load Lazarus. Runs identical Lazarus programs at 1/2 the speed of the same program on Pi3. But it has the hardware PRUs to deal with the slowness while the Pi does not.

    The Pi will be good for the user interface. Perhaps consider attaching it to one of the Ethernet or USB stepping engines. I'm using a PMDX-125BoB with USB SmoothStepper controlled by WIN-XP/MACH3 with a PC much slower than a Pi or Beaglebone. This gives you the best of both worlds. A nice small compact controller with graphical user interface and a box underneath that sits with the power supply, stepper drivers and BoB. All your work is then portable to other Linux Based systems. But their website doesn't show that it works with Linux. https://warp9td.com/ So here's a perfect place to use your Linux/Pi3 expertise and work with warp9td and create an Ethernet driver for your CNC front end.

    Or not. What you learn from developing your project is priceless. And that's what most education is really all about. Learning how to re-invent the wheel. Nicely done!

Page 1 of 2 12

Similar Threads

  1. *NEED HELP* machining pure molybdenum
    By vladp in forum General MetalWorking
    Replies: 3
    Last Post: 09-27-2016, 09:08 PM
  2. For nerds only: Raspberry Pi for EMC2 controller?
    By crane550 in forum Raspberry Pi CNC
    Replies: 159
    Last Post: 12-03-2015, 10:17 PM
  3. Pure Magic
    By CNCadmin in forum EnRoute
    Replies: 0
    Last Post: 03-03-2012, 09:00 PM
  4. just another python gcode thing
    By cyclestart in forum LinuxCNC (formerly EMC2)
    Replies: 8
    Last Post: 02-18-2008, 03:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •