Why realtime matters in CNC machining controllers
If you deal with the topic of CNC control systems long enough, you will inevitably stumble across terms such as real-time and real-time capability of systems. But what do these terms actually mean and why are they even important?
Time critical motion planning
Let's say you want to control an axis of your milling machine. It might be able to move with a speed of 12m/min or 200mm/s. The axis controller constantly compares the actual position with the desired position of the axis. If this process isn't fast enough, the positioning will get unprecise. For example, if the controller idles only for 10 milliseconds, the axis in our example machine will have moved 2mm. For a precise operation, this is totally unacceptable. So, axis controllers have to be fast, but with todays computers this shouldn't be an issue, right?
Processor cores
The brain of a PC or controller is a processor, also called CPU. The most important specifications of a CPU are the clock frequency and the amount of cores it has. The clock frequency indicates how many operations the CPU can do in a specific time. Usual frequencies range around 1 to 5 GHz, getting faster with each generation. While the CPU might be able to do many operations per second, it can do these operations only one after another, not at the same time. So even though you might have several applications opened on your PC that seem to run simultaneously, they are not. The CPU will for example process a task for the browser, then pause that task to to a task for the calculator and then switch again. You just don't notice because it happens so fast. Modern processors bypass this problem by having multiple cores. Each core can do a single simultaneous operation, so with 4 cores you have the possibility to run 4 tasks at the same exact time.
Realtime
So what does this all have to do with realtime? A realtime system guarantees that a certain task will be executed within a specific time. How long that timeframe is depends on the application. A controller for an emergency stop might guarantee that the time it takes from noticing the signal to switching an output will always be below 200ms. Personal and process safety play a huge part in the industry, so PLCs and other machine parts often need to be realtime compatible. For our CNC milling machine we might want a guarantee that it performs a control operation atleast every millisecond. This ensures that the movement will be predictable and accurate.
Operating systems
The problem with PC based controls is the complexity of the operation systems. While industrial PLCs often have operating systems tailored for realtime compatibility, normal user PCs running Windows or Linux aren't realtime compatible out of the box. Let's say you run your control application on a fast Windows PC. It might run flawlessly for an hour. But then you move your cursor or an antivirus check starts. Windows might decide that this is more important than your application, so it pauses the application for 100ms. These 100ms will have your workpiece ruined. Due to the complexity of the OS, it's not a trivial task to guarantee process execution within a timeframe. For Windows, there are solutions that utilize multicore processors. The normal Windows tasks run on one core, your application tasks run on another. But these solutions are often very pricey. Options for Linux are a bit more user friendly due to it's open source nature. But you still need a lot of knowledge about kernels and computer science to write a truly realtime application. An example for a realtime Linux kernel would be the "PREEMPT_RT" project. There are a lot of other realtime operating systems (RTOS) for different use cases like microcontrollers or robotics.
Motion Cards
But even with guaranteed realtime, your PC might be too slow for some motion control application, for example step generation for stepper motors. These often need to be generated within nanoseconds. Thats where an external FPGA comes into play. The FPGA is integrated into a dedicated motion card and turns motion signals coming from the PC into steps for the motor controller. You can think of a FPGA as a super fast processor. So if you need very precise or very fast positioning, you either need a very fast PC/PLC or an external motion card with an FPGA.