# Optimizing Assembly in Wiring Boxes Using API Technology for Digital Twin
## 4 Proof of Concept for Optimizing Assembly in Wiring Boxes
### Configuring and Integrating the Olfactory Lite 6 Robot  
The first step was to configure the custom gripper arm. The payload weighed 0.27 kg, and the coordinates were Cx = 0 mm, Cy = 0 mm, and Cz = 30 mm. The second step was to set up the origin, the initial position. It is very important for the robot to always start from the same position. This leads to higher precision in the assembly of fuses. This sets up the initial conditions and calibrates the robotic arm to ensure it starts from the correct position every time. The initial position parameters were x = 93.2 mm, y = 2 mm, and z = 71.6 mm. After the collaborative robotic arm was configured, it was programmed using the Python programming language. The programming involved developing four programs:  
1. Fuse assembly program: This program handles the precise assembly of fuses, ensuring that each step is executed with accuracy. The program is sent to the robot using the Olfactory Studio 1.0.1. interface, Figure 10.
2. Computer vision program: Using an Oak-D Lite camera (Luxonis Holding Corporation, Littleton, CO 80127, USA) can identify the fuses in the storage location. This program is sent to the robot using the Pycharm platform, Figure 11.
3. Digital twin monitoring program: This program monitors the robot's activity during assembly. It is sent to the robot using the Pycharm platform, Figure 12.
4. Digital twin control program: This program allows us to control the robot's activity from CAD environment on a computer. It is sent to the robot using the Pycharm platform, Figure 13.  
Figure 10: Fuse assembly program—Ufactory studio interface. The computer vision program uses the OpenCV library for image processing and DepthAI for interfacing with the camera. Figure 11: Computer vision program: (**a**) Pycharm program, (**b**) setup camera. Figure 12: Digital twin monitor and control program. Figure 13: Example of digital twin assembling fuses by robot: (**a**) initial position, (**b**) work position. The program is structured into several main sections:  
* DepthAI pipeline configuration: configuring the video source and output for video capture. * Video capture: initializing video capture from the default camera. * Image processing: applying filters to detect colors and identify fuses in boxes. * Object identification and marking: identifying and marking the positions of fuses in the video frame. The next section configures the pipeline for DepthAI, setting up the camera, and the video output for image capture. import cv2  
import numpy as np  
import depthai as dai  
pipeline = dai.Pipeline()  
source = pipeline.create(dai.node.ColorCamera)  
output = pipeline.create(dai.node.XLinkOut)  
output.setStreamName('video')  
source.setBoardSocket(dai.CameraBoardSocket.CAM_A)  
source.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)  
source.setVideoSize(1920, 1080)  
output.input.setBlocking(False)  
source.video.link(output.input)  
device = dai.Device(pipeline, maxUsbSpeed=dai.UsbSpeed.HIGH)  
queue = device.getOutputQueue('video', 1, False)  
Video capture from the default camera is initialized using OpenCV 4.10.0.84.  
cap = cv2.VideoCapture(0)  
For image processing, color ranges in the HSV space are defined for different colors of interest (green, brown, and blue). The frame processing function applies the color mask to each video frame and identifies and counts the fuses within predefined rectangles, marking them based on the presence of colors. The program uses computer vision techniques to detect and count fuses in cable boxes. This approach automates the assembly process, reducing human errors and increasing production efficiency. APIs (Application Programming Interfaces) are essential for the interaction between software and hardware, allowing the exchange of data and commands between different components of the system. In our project, we use two main APIs:  
* xArm API--for controlling the robotic arm. * Onshape API--for monitoring and updating the digital model.