# A Safe Admittance Boundary Algorithm for Rehabilitation Robot Based on Space Classification Model
## 2 Safe Admittance Boundary Algorithm
### Point Cloud Isodensification  
To build the space classification model based on the distribution of point cloud densities, we perform point cloud isodensification in the human and robot workspaces. This results in two isodense point clouds with uniform distribution. Then, the method for determining the workspace in the FK model is improved by combining the Monte Carlo method and voxel center filtering. This method is illustrated in Figure 3.  
First, the joint angle for each degree of freedom (DOF) is traversed under the two FK models using the Monte Carlo method. Specifically, random numbers are generated offline for the increment of the joint angle for each DOF using the Rand function under each of the two FK models. These random numbers are generated as many times as possible as depicted below:  
\[\mathrm{g_{n,FK}}=\mathrm{g_{n,min}}+\mathrm{RAND}\times\big{(}\mathrm{g_{n, max}}-\mathrm{g_{n,min}}\big{)},\mathrm{n}=1,2,3,\dots,\mathrm{m} \tag{1}\]  
where \(\mathrm{g_{n,FK}}\), \(\mathrm{g_{n,max}}\), and \(\mathrm{g_{n,min}}\) are the joint angle traversed in real-time for the n-th DOF and the upper and lower bounds of the joint angle for this DOF, respectively. m is the number of DOFs in the FK model. During the traversal of the joint angles for each DOF, 3D coordinates of the end-effector in the FK model are recorded. In this way, two point clouds representing the spaces accessible by the human arm and the robot are obtained.  
Next, the side lengths of the minimum bounding box are calculated for each point cloud. The differences between the maxima \(\mathrm{X_{max}}\), \(\mathrm{Y_{max}}\), and \(\mathrm{Z_{max}}\) and minima \(\mathrm{X_{min}}\), \(\mathrm{Y_{min}}\), and \(\mathrm{Z_{min}}\) of the X-, Y-, and Z-axis values in the set of coordinates of the point cloud are calculated. On these bases, the side lengths \(\mathrm{l_{x}}\), \(\mathrm{l_{y}}\), and \(\mathrm{l_{z}}\) of the minimum bounding box are estimated:  
\[\begin{cases}\mathrm{l_{x}}=\mathrm{X_{max}}-\mathrm{X_{min}}\\ \mathrm{l_{y}}=\mathrm{Y_{max}}-\mathrm{Y_{min}}\\ \mathrm{l_{z}}=\mathrm{Z_{max}}-\mathrm{Z_{min}}\end{cases} \tag{2}\]  
For the voxel octree representation, we build voxel grids for the first and second point clouds. Let the side length r of the voxel grids be equal between the first and second point clouds. That is, \(\mathrm{r_{1}}=\mathrm{r_{2}}\), ensuring that the two point clouds that are outputted subsequently have the same density. For any point in the non-empty voxel, the voxel center \(\mathrm{C_{center}}\big{(}\mathrm{x_{center}},\mathrm{y_{center}},\mathrm{z_ {center}}\big{)}\) is located based on the row, column, and lay of the voxel (row, col, lay) and the calculated minimal coordinates \(\mathrm{x_{min}}\), \(\mathrm{y_{min}}\), and \(\mathrm{z_{min}}\) for the voxel:  
\[\begin{cases}\mathrm{x_{center}}=\mathrm{x_{min}}+(\mathrm{col-0.5})\times \mathrm{r}\\ \mathrm{y_{center}}=\mathrm{y_{min}}+(\mathrm{row-0.5})\times\mathrm{r}\\ \mathrm{z_{center}}=\mathrm{z_{min}}+(\mathrm{lay-0.5})\times\mathrm{r}\end{cases} \tag{3}\]  
All non-empty voxels in the first and the second point clouds are traversed. Each voxel center approximately represents all other points in the same voxel. Finally, we obtain the first point cloud \(\mathrm{P_{i,FK1}},\mathrm{i}=1,\ 2,\ 3,\ \dots,\mathrm{k_{FK1}}\) and the second point cloud \(\mathrm{P_{i,FK2}},\mathrm{i}=1,\ 2,\ 3,\dots,\mathrm{k_{FK2}}\) with uniform point distribution. Here, \(\mathrm{k_{FK1}}=\mathrm{k_{FK2}}\), where \(\mathrm{k_{FK1}}\) and \(\mathrm{k_{FK2}}\) are the sizes of data of \(\mathrm{P_{i,FK1}}\) and \(\mathrm{P_{i,FK2}}\), respectively.  
Figure 3: Method for point cloud