## 3 Control Design Methodology
### Design of the Mid-Level Control  
Exploiting Simulink and Stateflow enables the straightforward implementation of multiple state machines to characterize the operational modes of the exoskeleton and potential state transitions. With reference to Figure 5, the dedicated module is DATA PROCESSING, that is the core module where all the control is implemented by means of control algorithms and state machines. The processing unit describes all the possible states transitions between the different behaviours of the device. The tasks performed in the Data Processing subsystem are: (I) Estimation of the SEAs torques; (II) Setup and reaching of the homing position (resting position of the exoskeleton); (III) Managing of the different working modes (passive exercises, exercise with compliance achieved thanks to impedance control, transparency, learn and replay); (IV) Computation of the pose of the exoskeleton end-effector; (V) Computation of the scapular elevation coupling following the method suggested in [1] The scapular elevation is function of the shoulder flexion. Once the shoulder flexion overcomes 60\({}^{\circ}\), refer to Figure 3a, J2 is coupled with J5 with a ratio 1:3); (VI) Trajectory generation; (VII) Computation of the gravity torques from the robot dynamic model; (VIII) Torque control target generation (friction compensation, impedance, transparency). Figure 5: Top Layer of the Simulink control model. The model is built and then deployed on Speedgoat real time target machine. In this layer it is possible to identify four main blocks: CAN communication setup, readings of sensor data, processing of all the received data (this unit establishes the exoskeleton behaviour) and the output block that send over the CAN line the command signals. Different control strategies can be implemented to treat and support patients during rehabilitative therapy. During the initial phases of rehabilitation, it is reported that rigid guidance can help the subject understand movement paths and maintain high training intensity [21]; however, as the patient's voluntary motor control increases, rigid control becomes less suitable, and collaborative forms of control strategies are suggested [10; 22; 23]. Dealing with complex robotic systems that interact with the human body (Human-in-the-loop control) [24], where the subject is considered the controller [25], it is essential to develop control strategies capable of making the robot compliant with the user's movement intention. Complex approaches based on modelling dynamic nonlinear interaction (which emphasize the importance of neuromuscular actuation mechanisms as a source of nonlinearity in the human controller) and on identifying movement intention have being explored [25]. A more commonly used approach is the implementation of partially assistive control strategies, which enable human-machine interaction based on reading sensors placed at the user-device interface [26; 27; 28]. Assistance-as-needed (AAN) [29], control strategies allow active control of exoskeleton motion by the impaired subject, supporting patient movement based on the level of residual motor capabilities. A common solution to provide AAN to the impaired limb is to transition from rigid control to compliant control. These controls exploit impedance/admittance algorithms to make the device compliant to user movement [26; 30]. Additionally, by modeling the dynamics of the interaction, these controls allow the implementation of variable levels of support selectable according to the patient's condition, as proposed for the Harmony [6] and AyExo [5] devices. Moreover, in the work proposed by [PERSON] et al., the importance of good transparency implementation (specifically compensation for gravity and robot dynamics) is emphasized, as it directly correlates with the exoskeletons' ability to provide correct assessment of the quality of human motion [10].