A Cigarette Surface Defect Detection System Based on Data Acquisition Card

The author introduces a self-learning control system used in cigarette surface defect detection system. The database, data acquisition card and industrial computer are used to realize high speed detection of cigarette surface defects. The results show that the advantages compared with the traditional measurements are as follows: Firstly, realize the detection of entire cigarette surface; Secondly, achieve the unmanned operation with no manual operation needed from the beginning to the end; Thirdly, save the qualified and unqualified testing data, convenient to historical retrospection and data statistics.


Introduction
The traditional method of surface defects detection mainly relies on the artificial observation which is inefficient and not comprehensive.Even if there are some manufacturers using automatic detection system, most of them aim at the detecting the shape of the seal, rather than the position of the seal and other defects on the cigarette [1] .Therefore, this paper introduces a work piece surface defect detection system based on the data acquisition card and database in improving the work piece machining process with high measurement accuracy and efficiency.

Overview
System works as shown in Figure 1,the programming language of the system is C# based on Visual Studio software.And the program includes the information of measuring point on work piece surface and the database of measurement information.Firstly, the system controls the motion of work piece and the detection of defect by servo motor and optical encoder.Then, the DAQ-2010 data acquisition card collects signal and realizes analogue-to-digital conversion [3] .Thirdly, IPC processes and stores the data, and sends the results to PLC.Finally, PLC issues an instruction to remove the non-qualified cigarettes according to the test results.For Human-Computer Interaction, the operators can set the parameters and adjust the historical data manually through the user interface.+, c # and so on [4,10] .The control process of PC software based on C# programming language and data acquisition card is as follows: 1) Install driver, then automatically generate dynamic link library files D2K-Dask.dllon disk c; 2) Call the library function of the data acquisition card; 3) Initialize the data acquisition card; Firstly, there will be a card number after registering the card using the function D2K_Register_Card; Then, set the acquisition voltage range and acquisition mode of each card using the function D2K_AI_CH_Config and D2K_AI_Config.For this project ,the voltage range is -10V~10V,the acquisition mode is external trigger, and the external trigger signal is A pulse in Optical encoder.The data acquisition card collects data once the A pulse detected.The optical encoder is installed on the motor which is used for production.There are 256 pulses in one revolution of the optical encoder.And the length of each 64 pulses is as long as one detected cigarette.Thirdly, set the acquisition channel using the function D2K_GCTR_Reset.Set the acquisition mode using the function D2K_GCTR_Setup and D2K_GCTR _Control.The acquisition of A pulse is on the service of the detecting production rate [6] .Finally, set the cache.Create the double cache using the function D2K_GCTR_Reset to insure the speed of operation and the data security.For the double cache, one is used to handle the cached data, the other is used for data acquisition.And set the cache to 256 bytes, the same size as 4 cigarettes.That is all the work for the initialization of the data acquisition card.4)Enable and close the data acquisition card; Enable the data acquisition card using the function D2K_AI_ContReadChannel.It begins to acquit data once receiving the external trigger signal.After using the acquisition card, release the cache using the function D2K_AI_AsyncClear, and close the data acquisition card using function D2K_Release_Card.

Optical Detection
Optical detection device is composed of photoelectric diode, lens, LED lamp and amplifying circuit.Optical detection has the advantages of fast measurement, high sensitivity, simple operation, low price and so on [2,9] .The optical detection operating diagram is shown in Figure 2 as follows.This optical detection system is divided into eight channels, each channel with two LED lights.LED lights on the surface of the cigarette, and the light is focused on the photodiode by spectacle lenses after the reflection .The voltage signal generated on the photodiode is amplified by the amplifying circuit and then outputted .Then the data acquisition card acquits the voltage signal to distinguish the surface colour on the cigarette.

self-learning system
The program starts to run automatically after the computer powered-on.The multithreading technology is used in the program because of the need for high-speed acquisition and processing.Among these threads, the acquisition card monitoring thread ,velocity measurement thread, A pulse counting thread and learning thread are related to the self-learning system.The velocity measurement thread starts running after the program begins working .The principle of velocity measurement is to collect the number of A pulse in Optical encoder.When the number of A pulse reaches the requirement, the system starts to execute the self-learning mode.The operating diagram of velocity measurement thread is shown in Figure 3 as follows: The number of A pulse is counted by the A pulse counter.The data acquisition monitoring thread card starts detecting the state of the card.When half full (one buffer of the double is full), extract data and transform the data into standard voltage value using the function D2K_AI_ContVScale.Then, the learning thread will collect 20 sets of data, and compute a standard template using these data.The learning thread functional diagram is shown as figure 4. In this system, the learning thread starting signal is provided by velocity thread; the half full signal that a set of data detected is provided by monitoring thread.For the leaning process, the first step is saving the acquitted data; then find the Z pulse generated by the motor when it turns a turn.The third step is alignment data.The number of pulses may be more than 256 in one revolution of the optical encode because of mechanical vibration.So it is absolutely important to align data based on the Z pulse when detecting the position of seal on the cigarette.Acquisition times are set up in the program.The initial value is 20 which can be also changed manually.When the acquitted times comes to the initial value, the system stops collecting data and begins processing data.And the processing mainly includes calculating the average curve and envelope.The average curve is calculated by the average value of the test points in 20 sets of data.Then calculate the upper and lower envelope according to the average curve.The average curve and envelope are as shown in figure 5, where the X-axis is the length of detected cigarette and the Y-axis is the voltage value acquitted.

Figure.5. The learning thread figure
In figure 5,the standard curve is the average curve .And the length of a standard cigarette is 64mm.As long as the value of detected point is within the envelope, the result is qualified.After learning ,the learning thread is closed and detected thread starts.The self-learning system reduces the intensity of work caused by different varieties of cigarette .

Data storage
C# provides a variety of interface technology such as ODBC,DAO,OLE/DB and ADO to support database programming.Through these interfaces, the database such as Microsoft Access, SQL Server can be operated directly.But we find that these databases can not store such the fast update data, so we use txt to store these data using Stream Writer.Because the storage speed will be lower and lower with the increase of file memory, the program creates 600 txt files one day such as 1.txt, 2.txt, 3.txt……600.txtto reduce the size of every single file.Once comes the half full, the data is put into one txt in the program.In this way, the error in program and data missing can be avoided .

Conclusion
This is a self-learning control system used in a cigarette surface defect detection system.When the machine is powered, the computer and program start automatically.The self-learning and detection can be finished automatically without any manual operation.The cigarette is full rang detected by optical measurement .The program includes all kinds of defect statistics.And the unqualified cigarette will be eliminated by the eliminating valve.

Figure 1 .
Figure 1.Schematic diagram of cigarette defect detection system

Figure 2 .
Figure 2. The optical detection principle

Figure 3 .
Figure 3.The optical detection principle

Figure 4 .
Figure 4.The learning thread principle new Stream Writer method .The program specifies the file path, and opens the file using the function File.Appendtext();The function wlog.Write() is used to write data ; The function wolg.Flush() is used to save the file.Then wlog.Close() is used to close the connection.The problem of data high speed memory is solved by txt which is convenient to historical data tracing and statistics.