## 2 Control Design  
The idea is to offer a remote assistance service for home rehabilitation. Since the physiotherapist and the patient are at different sites, the system must ensure that the physiotherapist controls and supervises the rehabilitation process and that the patient repeats the same actions performed by the physiotherapist. To this end, a human-machine interface (HMI) has been developed to allow the physiotherapist to remotely control the robot and supervise the rehabilitation process. As shown in Figure 1, based on the Microsoft Kinect Sensor V2 for Windows, the physiotherapist's skeleton is detected and the elbow joint is calculated. The desired position is acquired by the HMI software in order to calculate the corresponding torque on the basis of an adaptive controller. Then, the torque generated is sent via an MQTT protocol to the robot's on-board card. The range of motion (RoM) measured by a rotary encoder, the output of the current sensor and the raw EMG signal are sent to the HMI software. TD features are taken directly from the pre-processed EMG and classification is performed by a first fuzzy logic system (FLS) to estimate muscle contraction. A second FLS is implemented to estimate pain based on muscle contraction, current sensor feedback and RoM. In the proposed control architecture, we used the Microsoft Kinect Sensor V2 for Windows as the generator of the desired range of motion. Kinect v2 is a 3D video camera that provides the distance between the camera and the objects in the scene. The camera has the ability to track, at the same time, up to six skeletons with 25 points for each. Kinect is an active stereoscopic 3D camera with an infrared light source and an infrared camera with a resolution of 512 \(\times\) 424 pixels. In addition to the stereoscopic 3D vision component, the Kinect device also has a color camera with a resolution of 1920 \(\times\) 1080 pixels. For each pixel of the image, it finally provides four pieces of information: the three color components and the depth. The sensor sends a stream composed of the distance between the camera plane and the nearest object found. Each pixel of the resulting image contains the given distance expressed in millimeters. Unlike the Kinect v1, the new Kinect employs a time-of-flight, or ToF, camera. ToF cameras function by measuring the time it takes for light emitted by a Kinect to reach an object and come back. Knowing the speed of light in a typical living room atmosphere, the Kinect can calculate the distance between itself and the object. The measurement of depth as a triangulation process is described by the inventors in [48]. To connect the Kinect sensor to LabVIEW, we used the Haro3D library that contains API VIs to access the following features of the Kinect v2:  
* Bodies (people and joints tracking);
* Colored 3D cloud of points;
* Depth sensing;
* Color high-definition camera;
* Active infrared imaging;
* 3D volume reconstruction. Feature extraction is the process of selecting useful information and deleting unwanted EMG parts. In order to correctly extract the information conveyed by the EMG signal, algorithms for signal processing and pattern matching were developed, which perform the extraction of characteristics and the classification of patterns. These algorithms depend directly on the characteristics used to represent the acquired signals. The main features in analysis of the EMG signal are: the time domain (TD), the frequency domain (FD) and the time-frequency or time-scale (TS) representation [49]. The TD features, and unlike the FD and TS features, are the easiest to calculate and implement since they do not require any other additional transformation and they are extracted directly from the raw EMG signal. Indeed, the TS and FD features require additional transformations which impose very complex calculations and consequently dedicated processors. In this paper, the TD features are used as inputs of the first block of the fuzzy logic controller to estimate the muscle contraction.