CNC Controller in Python

Technical Challenge

Typically, Computer numerical control (CNC) machine controllers are implemented in C or C++ and run on OSless or real-time operating systems. For example, Linux by default is not a real-time operating system. And running projects like LinuxCNC requires adding special real-time features to the kernel.

Some of these approaches seem to be quite old-fashioned. Modern ARM processors allow using high-level programming languages like Python to provide easy development, flexibility, and migration between hardware.

About the Project

This is the first ever CNC machine controller implementation in pure Python (without dependencies or any C modules) for ARM-based Linux boards.

The hardware access layer (HAL) allows creating an implementation for almost any ARM SoC (System on Chip) / CPU with a suitable DMA module, but this is currently only implemented for Raspberry Pi. It works on Raspberry Pi 2 and 3.

Solution

The video below demonstrates the developed with Python solution running on Raspberry Pi 2 with Linux:

The solution uses DMA (Direct Memory Access) on the chip hardware module that just copies the buffer of GPIO states allocated in the RAM to the actual GPIO registers. And this copying process is clocked by the system clock and works completely independently from the CPU cores. So, the sequence of pulses for axis stepper motors are generated in the memory, and then DMA sends them precisely.

As for access to the processor registers, it's implemented with the /dev/mem system device. It can be developed with different languages, but Python is a very simple language that provides a great development experience. Of course, Python’s performance is not that good, but on the other hand, modern ARMv7 processor performance is more than enough to run it.

Open Source

The project is open source software. The source code is available here: https://github.com/Nikolay-Kha/PyCNC

There is a wiring diagram and instructions for running the code in the git repo.

The PyCNC implementation supports 4 axises, 2 heaters, a PWM (Pulse Width Modulation) controlled spindle, cooling, end stop sensors, linear and circular (in 3 planes) interpolations. So currently it is a fully functional controller for engraving and 3d printer machines. This functionality can be easily expanded for more complicated machines, for example laser, waterjet, and plasma cutters.

Business Impact

Supporting legacy technologies and hardware is always expensive and time consuming. Using modern architectures and popular languages like Python disrupts the whole industry allowing it to drastically shorten the time to market and decrease proof-of-concept efforts. As the result, it reduces the learning curve of CNC in general.

Moreover, using modern tools opens a wide range of integration options with other cutting edge technologies, solutions, and infrastructures making the whole market more customer centric.

For more information please submit an RFP form or send an email to sales@dataart.com.