# A Safe Admittance Boundary Algorithm for Rehabilitation Robot Based on Space Classification Model
## 2 Safe Admittance Boundary Algorithm
### Space Classification Model
To reduce the computational cost of the subsequent real-time operation, we calculate the relative densities of \(P_{i,FK1}\), \(P_{i,FK2}\), and \(P_{i,combine}\) offline. All points in \(P_{i,FK1}\), \(P_{i,FK2}\), and \(P_{i,FK2}\) are represented by the four-dimensional coordinates \(S^{\prime}(x,y,z,\rho)\) to obtain the four-dimensional point clouds \(P^{\prime}_{i,FK1}\), \(P_{i,FK2}\), and \(P^{\prime}_{i,combine}\) (as shown in Figure 4b). It can be observed that \(P^{\prime}_{i,FK1}\) and \(P^{\prime}_{i,FK1}\) have the same density at any point, which is a fixed value \(\rho_{\text{low}}\), i.e., \(\rho_{\text{low}}=\rho_{\text{s,FK1}}=\rho_{\text{s,FK2}}\). The maximal density is defined as \(\rho_{\text{high}}\) in \(P^{\prime}_{i,combine}\). The density between \(\rho_{\text{low}}\) and \(\rho_{\text{high}}\) is represented by \(\rho_{\text{mid}}\), i.e., \(\rho_{\text{mid}}\in\left(\;\rho_{\text{low}},\;\rho_{\text{high}}\right)\). Finally, the real-time moving point \(S\;(x,y\;,z\;)\) of the robot is introduced online into \(P^{\prime}_{i,combine}\) as the target point. K-NN is used again to find the nearest neighbor for \(S\;\) in \(P^{\prime}_{i,combine}\). The relative density \(\rho_{\text{s,combine}}\) is calculated for this point. A comparison is made between \(\rho_{\text{s,combine}}\) vs. \(\rho_{\text{low}}\) and \(\rho_{\text{high}}\) to build the space classification model. The algorithm is shown in Algorithm 1. ```
1:functionBoundary judgment \((x_{d},y_{d},z_{d})\)
2:\(\omega_{\text{dan}}\)\(\leftarrow\)Dangerous Space, the dangerous workspace for HRI
3:\(\omega_{\text{hri}}\)\(\leftarrow\)HRI Space, the safe workspace for HRI
4:\(\omega_{\text{bou}}\)\(\leftarrow\)Boundary Space, the extreme workspace scope for HRI
5: (a) Load the moving point \(S\);
6: (b) Load \(P^{\prime}_{i,combine}\) as the training data set;
7: (c) Search for the nearest point for \(S\) in \(P^{\prime}_{i,combine}\), according to the k-d tree structure and Equation (5);
8: (d) Obtain the density information \(\rho_{\text{s,combine}}\) of the nearest neighbor point;
9: (e) Judge the space:
10: if\(\rho_{\text{s,combine}}=\rho_{\text{high}}\)then
11: return\(S_{d}\in\omega_{\text{hri}}\)
12:elseif\(\rho_{\text{s,combine}}=\rho_{\text{low}}\)then
13: return\(S_{d}\in\omega_{\text{dan}}\)
14:elseif\(\rho_{\text{s,combine}}=\rho_{\text{mid}}\)then
15: return\(S_{d}\in\omega_{\text{bou}}\)
16:else
17: return False
```  
**Algorithm 1** Space classification algorithm  
Three woThree workspaces are defined for HRI in the algorithm. The density-defined spatial relationship between the three spaces is shown in Figure 5a. The space classification model is built based on the pattern of density variation of the point clouds (Figure 5b). Utilizing the influence of nearest neighbor search on the space boundaries (Figure 5c), we achieve the small-scale moving of the density-defined boundaries and the expansion of the workspaces. In this way, we delineate virtual boundaries with small-scale redundancy and build the space classification model.