## 3 Impedance-Based Assist-as-Needed Controller
### Design of the Controller
\tag{18}\]  
where \(\Phi\) is the gradient of the stiffness field; \(K_{2}\) is the stiffness inside the FTR; \(K_{0}\) and \(K_{1}\) are the upper and lower limits that could be changed according to the training tasks, respectively. Therefore, various stiffness fields can be constructed by changing \(K_{0}\) and \(K_{1}\). According to Equations (9)-(18), a spatial assistance force field could be constructed during the rehabilitation training, and different intensities and distributions of the force field can be realized by adjusting the parameters of the controller. Therefore, the assistance force filed in Equation (15) can be rewritten as follows:  
\[F_{assist}=\left\{ \begin{array}{lr}0&d\leq R_{W}\\ \left[K_{0}+|d-R_{W}|\cdot\frac{K_{1}-K_{0}}{R_{W}}\right]\cdot 2|d-R_{W}|&R_{W}<d<2R_{W}\\ K_{1}\cdot d&d\geq 2R_{W}\end{array} \right. \tag{19}\]  
As a band-based FTR is provided in the controller, the patient has complete freedom when moving within the FTR, and the robot is in a complete compliant state without providing any assistance force. The purpose of the AAN controller is to improve the patient's active participation and minimize the assistance of the robot. However, patients are prone to slacking because they only need to keep their arm within the FTR rather than try to complete the training task, which will greatly reduce the active participation of patients. Therefore, a velocity curve could be added in the FTR which will construct a virtual movement within the FTR. When the patient's arm is stagnant or moving too slowly in the FTR, the controller will generate a moving wall to assist the patient's arm to catch up with the virtual movement to avoid slacking. The assistance force is a fixed value along the direction of the training task trajectory within the FTR, which can be calculated by the following equations:  
\[t_{t}=\frac{d}{dR}P(R) \tag{20}\]  
\[F_{t}=k_{t}\cdot\frac{t_{t}}{|t_{t}|} \tag{21}\]  
where \(k_{t}\) is the assistance factor that can be adjusted by the therapist and \(t_{t}\) is the tangent direction along the predetermined trajectory. Therefore, the total assistance force output by the AAN controller proposed in this paper is the superposition of the rectifying force outside the FTR and the fixed assistance force within the FTR. Then, the torque at each joint of the manipulator can be calculated according to Equation (3):  
\[\tau_{assist\_total}=J^{T}(q)\cdot\left[F_{assist}+F_{t}\right] \tag{22}\]  
Therefore, once given the arbitrary training trajectory \(R\), a controllable assistance force field around the predetermined trajectory will be constructed. The distribution diagram of the assistance force field is shown in Figure 7a,b. The simplified control flow chart of the AAN controller proposed in this paper is shown in Figure 8. The right side of the flow chart is the joint torque \(\tau_{int}\) caused by the interaction force between the patient's hand and the robot, and \(\tau_{comp}\) is the dynamic model of the manipulator, which contains the Gravity term, the Coriolis force term, and the Friction term of the manipulator. The output item \(q_{act}\) on the right side of the flow chart can be measured by the position sensor at each joint of the manipulator, and then, the actual position \(P_{act}\) of the patient's hand can be calculated based on the kinematic equation of the robot that is presented in Section 2. The left side of the flow chart is the input parameters of the AAN controller. The actual position of the patient's hand is sent to the Set Point Generation module, and the output is the actual position of the patient's hand and the real-time reference position. The real-time reference position and the actual position during the training are sent to the visual interface and the rehabilitation training scene based on Unity technology to visualize the patient's movement.