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

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

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

  1. #1
    Registered
    Join Date
    Nov 2015
    Posts
    5
    Downloads
    0
    Uploads
    0

    Default 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:


    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.

    Similar Threads:


  2. #2
    Member
    Join Date
    Dec 2015
    Posts
    15
    Downloads
    0
    Uploads
    0

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

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



  3. #3
    Member
    Join Date
    Feb 2012
    Location
    United States
    Posts
    52
    Downloads
    0
    Uploads
    0

    Default 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
    Downloads
    0
    Uploads
    0

    Default 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:*

    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
    Location
    Australia
    Posts
    9
    Downloads
    0
    Uploads
    0

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

    Thats amazing. Very impressed



  6. #6
    Member Tkamsker's Avatar
    Join Date
    Oct 2010
    Location
    Austria
    Posts
    1189
    Downloads
    0
    Uploads
    0

    Default 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
    Member
    Join Date
    Jun 2012
    Location
    SA
    Posts
    153
    Downloads
    0
    Uploads
    0

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

    Last edited by reg.miller; 06-14-2017 at 03:01 AM.


  8. #8
    Member
    Join Date
    Jun 2012
    Location
    SA
    Posts
    153
    Downloads
    0
    Uploads
    0

    Default 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
    Member
    Join Date
    Mar 2013
    Location
    Slovenija
    Posts
    26
    Downloads
    0
    Uploads
    0

    Default 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
    Downloads
    0
    Uploads
    0

    Default 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

    Default 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
    Member
    Join Date
    Dec 2005
    Location
    CANADA
    Posts
    231
    Downloads
    4
    Uploads
    0

    Default 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!



  13. #13
    Registered
    Join Date
    Dec 2016
    Posts
    5
    Downloads
    0
    Uploads
    0

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

    Quote Originally Posted by reg.miller View Post
    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.
    It's not my intention to start new vs. old flame war. I'm interesting in a fair critique of Nikolay approach using DMA controller. Given large enough circular buffer and dedicated high priority channel for DMA operations you could minimize negative effects of whatever controls CPU, RT kernel or not. I presume most promising results could be achieved using closed-loop drivers. Just to be clear: I'm talking here about general approach of using DMA controllers, not this very particular found in BCM2835/BCM2836, which could be inappropriate for some other reasons.



  14. #14
    Registered
    Join Date
    Nov 2015
    Posts
    5
    Downloads
    0
    Uploads
    0

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

    Thank you for your feedbacks and critiques.

    Quote Originally Posted by jcdammeyer View Post
    hardware PRUs
    btw, I'm think about adding BBB with PRU to one of the HAL implementation of my project. But definitely not in the close future.

    Quote Originally Posted by reg.miller View Post
    You NEED real time control for controlling machines.
    I can precisely generate pulses for steppers using SoC's hardware modules, why do I need to control something else in realtime during machine run? I've used only 3d printers, cutters and engraving machines, all of them don't require realtime handling, only pulses at the right time moments. So, what for I need realtime? I haven't use lathe machine, may be there is something I don't know(some sensors which I need to take into consideration during machine run or something else), please tell me.

    Quote Originally Posted by saxa View Post
    Great work man, do you plan to develop a kind of GUI for it ?
    Thanks. Yes, I'm thinking about some graphical interface, but definitely not about any native window systems. I think web interface would be the best choice for that.



  15. #15
    Member
    Join Date
    Feb 2008
    Location
    USA
    Posts
    644
    Downloads
    0
    Uploads
    0

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

    A DMA based stepgenerator is basically a buffered system and if the host has no real time capabilities there's
    no way to use real time feedback from machine inputs to control motion. If a RTOS was used, the DMA buffer
    could be smaller and close to real time control might be possible.

    Here are a few places where real time feedback is required (or realtime is a superior and more flexible solution than a non-realtime solution ):

    Threading (threading is possible without realtime feedback with servo spindles but not the more common induction motors/VFDs that need encoder feedback )
    Rigid tapping
    Probing (if reaction time is not important, probing might be possible by polling a DMA GPIO
    read data stream with known synchronization with the step generator stream)
    Closed loop position control (reading position and running feedback loop in real time)
    Adaptive feed
    Velocity / Gcode aware Plasma THCs

    The advantage of systems like LinuxCNC is that they can do all of these (and almost any additional real time function you might require)
    using almost any hardware.



  16. #16
    Registered
    Join Date
    Dec 2016
    Posts
    5
    Downloads
    0
    Uploads
    0

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

    Quote Originally Posted by PCW_MESA View Post
    A DMA based stepgenerator is basically a buffered system and if the host has no real time capabilities there's
    no way to use real time feedback from machine inputs to control motion. If a RTOS was used, the DMA buffer
    could be smaller and close to real time control might be possible.
    MCU/FPGA between host and driver could make that job.

    Quote Originally Posted by PCW_MESA View Post
    The advantage of systems like LinuxCNC is that they can do all of these (and almost any additional real time function you might require)
    using almost any hardware.
    At the cost of profound code complexity. The main benefits of using LinuxCNC are a permissive license and user head count. Hardly technical arguments.



  17. #17
    Member
    Join Date
    Feb 2008
    Location
    USA
    Posts
    644
    Downloads
    0
    Uploads
    0

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

    Quote Originally Posted by for View Post
    MCU/FPGA between host and driver could make that job.

    Sure

    At the cost of profound code complexity. The main benefits of using LinuxCNC are a permissive license and user head count. Hardly technical arguments.
    Nonsense, there are lots of technical advantages for a simple single locus of control realtime motion system like LinuxCNC
    Buffered systems that have the same capabilities are more complex



  18. #18
    Member
    Join Date
    Jan 2005
    Location
    USA
    Posts
    1943
    Downloads
    2
    Uploads
    0

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

    Quote Originally Posted by for View Post
    MCU/FPGA between host and driver could make that job.



    At the cost of profound code complexity. The main benefits of using LinuxCNC are a permissive license and user head count. Hardly technical arguments.
    So when your system can match even 10% of the capabilities as a simple parallel port LinuxCNC system then you might have an argument.



  19. #19
    Registered
    Join Date
    Dec 2016
    Posts
    5
    Downloads
    0
    Uploads
    0

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

    Quote Originally Posted by PCW_MESA View Post
    Nonsense, there are lots of technical advantages for a simple single locus of control realtime motion system like LinuxCNC
    Buffered systems that have the same capabilities are more complex
    I beg your pardon. There are three different linux rt patch sets, yet none of these is fully incorporated in the mainline, even though one of them has been selected to be there over 10 years ago. There are reasons why enforcing realtime regime on general purpose OS designed to run on general purpose CPU is so challenging. I'm not questioning what you wrote about advantages and so on. But I guess I can achieve the very same set of functionalities (that I'm interested in) enforcing clear hardware distinction between rt domain and the rest with less effort required.



  20. #20
    Registered
    Join Date
    Dec 2016
    Posts
    5
    Downloads
    0
    Uploads
    0

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

    Quote Originally Posted by 109jb View Post
    So when your system can match even 10% of the capabilities as a simple parallel port LinuxCNC system then you might have an argument.
    I'm not sure which decile you are referring to, but I can imagine that e.g. a combination of PyCNC and Tarocco would make happy pretty large part of LinuxCNC user base at some point; set aside more gentle learning curve.



Page 1 of 2 12 LastLast

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
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

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

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