Python Success Stories
This story is about applying Python in the automated CD/DVD disc packaging industry. In the wholesale market, CD/DVD discs are sold in units of 10, 20 or 50 in one shrink-wrapped bulk package. Counting out stacks of discs for these packages is labor-intensive and requires several steps to accomplish:
- picking up an estimated number of discs from a large stack,
- verifying the correctness of the number of discs using a disc counter,
- adding or removing discs to meet the required number, and
- sending the disks to a packaging machine
To make the packaging process cost effective, an automatic CD/DVD disc partitioner is used to carry out the above steps.
Acqutek Corporation was contracted by Micro Image Precision Co. Ltd to develop the control software for this partitioner machine. The project was time critical, with less than 4 months available to complete the work. Furthermore, no hard specification was available at first, and the requirements changed from time to time with the concurrently evolving mechanical design of the partitioner.
To satisfy the customer's needs and manage the dynamic requirements of the project, we needed a quick and flexible way to develop the software for the system. After surveying the available technologies, we settled on Python. The interactive nature of this object oriented language, its suitability for rapid prototyping, and its extensive standard libraries made it ideal for a project with rapidly changing requirements.
Hardware of the CD/DVD Disc Partitioner
The CD/DVD disc partitioner, designed by Micro Image Precision Co, is composed of six disc counting and picking machines. Each of these can pick up a fixed number of disks from an input spindle, move the disks forward, and release them on an empty spindle. The six spindles are moved among the disc counters on a conveyor that brings them to the point where they are fed to the packaging machine.
The main computer communicates with the six CD/DVD disc partitioners through RS-485 connections and controls the air cylinders on the conveyor through digital I/O buses.
Control Software Architecture
The controller software is divided into five major components: The central control logic, the error handler, the digital I/O interface, the RS-485 serial communicator, and the graphical user interface (GUI).
The control logic component is in charge of controlling, coordinating, and monitoring the production processes. Depending on events from the GUI and signals from other parts of machine, it sends a sequence of commands to the counting and picking machines and the air cylinders on the conveyor.
The digital I/O interface provides various methods for the control logic to access the status of sensors, and control the up and down movement of the air cylinders on the conveyor.
The RS-485 serial communicator provides methods for sending commands to and receiving responses from the disc partitioner.
The GUI component provides user interfaces for operators to set, test, debug, start, pause, and stop the machine.
Python's threading module proved to be a very important tool in handling concurrent processes in the control logic. Threads are used to simultaneously monitor the production process, watch events from the GUI, and detect error messages coming in from other parts of the machine.
The digital I/O interface and RS-485 serial communicator were libraries written in C. SWIG was used to quickly make these callable from Python code.
The GUI components of the CD/DVD partitioner were built using Tkinter, which provides a simple but very reliable GUI development toolkit.
cx_Freeze was used to package up the Python control software into an executable.
At the hardware level, a JUKI-740E (K6 400MHz CPU and 64M RAM) CPU card is used for the main computer. The OS is Linux kernel 2.4.18 and the system software includes BusyBox, minimized X11 window server, touch panel daemon, and network driver.
All of these fit onto a 64MB flash memory stick. While it is possible to reduce the root file system size further, it was not necessary for this project.
A simulator was developed in the early stages of the project, before the actual machine was available. This provided the developer with a graphical animation of the movement of the spindles, air cylinders, and the status of the sensors.
The simulator allowed the software developer to start building the control software before the hardware design and assembly were complete. It also acts as a convenient way to debug and stress test the control software.
The graphical animation displayed by the simulator was built with the pygame module. The simulator proved to be very realistic; code running on on it can be uploaded to the main computer with very little modification. Only the simulated I/O module is replaced by the real I/O module.
The control software of the CD/DVD disc partitioner took one developer about 4 months to complete. The software development process was almost parallel with the hardware development process. At the end of the project, the control software passed all field tests and is running smoothly in production.
The project was developed almost 100% in Python. This shows that Python is not just a toy. It is a powerful weapon for solving real problems.
There was one concern raised in the beginning of the project: Would Python be fast enough to deal with the real-time demand of the production process? In the CD/DVD partitioner, Python and Linux work perfectly as long as the fastest required response time is greater than 1 millisecond. For faster applications, a real time OS may be required to provide sufficiently fast and precise response times.