# Seamless Human-Robot Collaborative Assembly Using Artificial Intelligence and Wearable Devices
## 3 Implementation
### Learning and Programming Module (LPM)  
To advance the collaboration scheme, predefined program execution needs to be replaced by automated continuous learning and adaptation of the robot motion, based on the operator's perceived needs and preferences. For this purpose, the sequence of tasks to be executed are inserted in the SDR simulation environment and MoveIt is used to generate collision-free motion plans for each task.  
When the operator is executing a collaborative task, he/she may choose to work with the robot pose proposed by the system or move the robot to a more convenient pose for him/her. The LPM module is divided into two sub-modules: (i) programming sub-module and (ii) learning sub-module  
1. Programming sub-module: The programming sub-module of LPM supports two ways of achieving such functionality: (a) direct movement of the end effector using manual guidance (Figure 5b)--the operator can grab the dedicated handles installed at the gripper of the robot and move the end effector to his preferred position, (b) indirect-AR based control of the position of the end-effector, moving a virtual end-effector at the desired position using gestures (Figure 5c)--the operator can manipulate with gestures a virtual end effector, whose position represents the target position of the physical end effector. In both cases, the target position of the end-effector is communicated with SDR and the relevant robot path to achieve such pose is generated, ensuring the avoidance of collisions with the surroundings.
2. Learning sub-module: Each execution of a specific assembly step provides a new input to the learning sub-module of LPM, associated with a score (Tij_score) computed from two KPIs; operator satisfaction (oper_sat), and ergonomic score (erg_sc). This funnel is specific to each operator's habits and ways to drive the robot; thus, it is necessary to learn such a funnel for each operator. The relevant data (operator id, task id, robot pose, Tij_score, oper_sat, erg_sc) for each execution of a specific assembly step, are stored in a MongoDB. Prior to the execution of each assembly step, the Learning sub-module determines the mode Tij_score value from the dataset and instructs the robot to adapt the pose corresponding to the mode Tij_score (Figure 5d).  
To calculate the score for the execution of a specific task (Tij_score), the following formula is used (1):  
\[Tijscore=w1\times oper\_sat+w2\times erg\_sc \tag{1}\]  
where:  
1. Tij_score: is the score for task i, and j is a counter increasing each time a new input for task i is inserted into the learning funnel.
2. oper_sat: declares the operator's satisfaction. It can have binary values; 1 if the operator does utilize the proposed robot configuration or 0 if the operator manually adjusts the position of the end effector.
3. erg_sc: refers to the ergonomic score calculated by the EIM using the RULA assessment. The value is inverse normalized, meaning that erg_sc equal to 1 declares a good ergonomic score.
4. w1 and w2: denote weighting factors for the oper_sat and erg_sc values, respectively. If the erg_sc is above a predefined threshold, the Tij_score is set to 0. The various Tij_score values are stored at a database, along with the corresponding robot pose and erg_sc and grouped based on their value with 0.1 increments.