## 3 Implementation and Discussion  
The smart factory application is a drilling process that showcases the integration of a KUKA robot (KR 6 sixx r900) with Siemens S7 PLC. A TCP network is built between them to facilitate communication. The process starts by placing a workpiece on a defined slot opposite to an ultrasonic sensor. The position of the workpiece is transmitted from the sensor and camera via the controller to the robot. The robot then moves to pick up the workpiece and places it on the drilling table. After placing the workpiece, the controller actuates a pneumatic cylinder that holds the workpiece in place and starts a lead screw mechanism which has a drill. The drill moves down vertically and drills the workpiece after the drilling is complete. Figure 8: Producer–consumer loops. Figure 9: Producer loop state diagram. The robot picks up the workpiece and places it in the designated stack and waits for another workpiece. Figure 10 shows the interfaces between the main components of the system, and Figure 11 shows the detailed program data flow. The LabVIEW API creates two client sockets for both the PLC and the JOpenShowVar server program. In the API's producer loop, the incoming data from the two devices are parsed, encapsulated, and enqueued. In the API's consumer loop, the data are dequeued, decapsulated, and published to the IoT platform. Variables of interest from the KUKA robot:  
1. \(AXIS\_ACT\_MEAS\): returns the axis angles of the current robot position. 2. \(VEL\_AXIS\_ACT[axisnumber]\): returns the current speed as a percentage of the maximum speed of the axis number. 3. \(MOT\_TEMP[axisnumber]\): returns the current speed of the motor of the axis number as a percentage of maximum speed. Variables of interest from S7 1200:  
1. \(Dint\_12\): counts the number of workpieces passed by the conveyor belt. 2. Boolean array of 8 bits that is used to indicate the position of the workpiece based on the sensor readings. Two java projects are created: The first is JOpenShowVar-core-client1, which is responsible for exchanging the actual process parameters with myRIO. Its main function is in Newproject.java, and four global variables are defined to be exchanged with myRIO. These variables are defined and configured in KRC. The KRL program is structured in a way that allows these exchangeable global variables to control its flow. Figure 10: Interfacing network. The four variables are also defined in NewProject.java. The program enters a while loop and reads the TCP socket input stream. It reads one line at a time. The read string is then split by whitespaces. If the length of the string array after the split is zero, then that means that a read operation is required. The split elements are then compared with \(get_{s}status\), which gets the current status of the robot. In the application, four states are distinguished:  
* Status 0 indicates the robot is busy with a motion block. * Status 1 indicates that the robot is waiting for a valid distance to the workpiece to pick it up and moves it to the drill table. * Status 2 indicates that the robot is waiting for the drilling process to be finished. * Status 3 indicates that the robot has clamped the workpiece and is waiting for the pneumatic release of the cylinder  
If the length of the string array is 2, then that means that a write operation to one of the variables has to occur. The first string indicates what variable to write to and the second is the value to be written. The second is \(JOpenShowVar-core-client2\), which is responsible for sending the robot's sensor readings such as velocity, torque, axis motors' currents, and axis motors' temperature to the IBM Watson IoT platform through \(JOSV_{client_{1}0T}\). This data can be accessed from the system variables[see KUKA manual system variables], which are read-only global variables. Note that in the KRL program, there is WAIT SEC 0. These lines serve the purpose of stopping the advance run pointer.