## 3 Leg Control Based on Human Motion Prediction Using Motion Sensor
They calculate the normalized Euclidean distance \(d^{i}\) between \(\mathbf{X}_{t}^{i}\) and \({}^{q}\mathbf{X}_{t}\), where \(i\) is the data index in database \(D\). It chooses \(k\) datasets from the database \(D\) with the smallest distances based on a normalized \(d_{i}\), and collects the set of motion category IDs \(\mathbf{c}=(c_{1},c_{2},\cdots,c_{k})\), each of which is one of the motion categories \(c_{s}\), \(c_{w}\), and \(c_{b}\). Then, the k-nearest neighbor algorithm outputs most of the motion category in \(\mathbf{c}\). The term \"majority\" indicates the motion category with the maximum number of category indices in the nearest neighbor set of the motion category indices \(c\). For example, if the number of the nearest datasets with the motion category index \(c_{s}\) is higher than that of datasets with motion category indices \(c_{w}\) and \(c_{b}\), \(c_{s}\) is said to be in the majority. The normalized distance \(d_{i}\) is calculated as below:  
\[d_{i}^{2}=(^{q}\mathbf{X}_{t}-{{}^{c}\mathbf{X}_{t}})\Sigma^{-1}(^{q}\mathbf{X}_{t}-{{}^{ c}\mathbf{X}_{t}})^{\mathrm{T}} \tag{1}\]  
Figure 4: Overview of proposed control system. where T indicates the transpose and \(\Sigma\) is a variance matrix with variance vector \(\mathbf{\sigma}\) on the diagonal. The variance vector \(\mathbf{\sigma}\) is the vector whose components are the variances of the corresponding components of \(\mathbf{X}_{t}\), which used for database \(D\). It estimates the appropriate joint angles of the powered exoskeleton at time \(t+\Delta t\), \(\phi_{t+\Delta t}^{d}\), according to the estimated motion of the wearer based on the k-nearest neighbor algorithm. For example, if the estimated motion is \"standing\", it chooses only the datasets whose motion categories \(c_{i}\) is \(c_{s}\) for the estimation of \(\phi_{t+\Delta t}^{d}\). An overview of the estimation of the appropriate joint angles \(\phi_{t+\Delta t}^{d}\) is provided in Figure 5 and the algorithm is shown in Algorithm 1. The input to the joint motor \(u_{t}\) is calculated by Equation (2):  
\[u_{t}=-k_{p}(\phi_{t+\Delta t}^{d}-\phi_{t})-k_{d}\left((\phi_{t+\Delta t}^{d}- \phi_{t})-(\phi_{t+\Delta t-1}^{d}-\phi_{t-1})\right) \tag{2}\]  
where \(\phi_{t}^{d}\) is the desired joint angle and \(\phi_{t}\) is the actual joint angle of the powered exoskeleton at time \(t\). \(k_{p}\), \(k_{i}\), and \(k_{d}\) are the proportional, integral, and differential gains, respectively. ```
load database \(D=\{(\mathbf{X}_{t}^{0},c_{i}^{0},\mathbf{\phi}_{t+\Delta t}^{0}),(\mathbf{X}_{t}^{1},c_{i }^{1},\mathbf{\phi}_{t+\Delta t}^{1}),\cdots\}\) acquire sequential motion data of the wearer \(\mathbf{X}_{t}\) \(\mathbf{c}=knn(\mathbf{X}_{t},D)\): components of \(\mathbf{c}\) is \(c_{s}\), \(c_{w}\) or \(c_{b}\) if majority of \(\mathbf{c}\) is \(c_{s}\)then  recognizes the current motion as \"standing\" motion \(\mathbf{\Phi}=knn(\mathbf{X}_{t},D|c_{i}=c_{s}):\mathbf{\Phi}=(\mathbf{\phi}_{t+\Delta t}^{1}, \mathbf{\phi}_{t+\Delta t}^{2},\cdots,\mathbf{\phi}_{t+\Delta t}^{k})\) endif if majority of \(\mathbf{c}\) is \(c_{w}\)then  recognizes the \"walking forward\" motion \(\mathbf{\Phi}=knn(\mathbf{X}_{t},D|c_{i}=c_{w}):\mathbf{\Phi}=(\mathbf{\phi}_{t+\Delta t}^{1},\mathbf{\phi}_{t+\Delta t}^{2},\cdots,\mathbf{\phi}_{t+\Delta t}^{k})\) endif if majority of \(\mathbf{c}\) is \(c_{b}\)then  recognizes the \"walking backward\" motion \(\mathbf{\Phi}=knn(\mathbf{X}_{t},D|c_{i}=c_{b}):\mathbf{\Phi}=(\mathbf{\phi}_{t+\Delta t}^{1},\mathbf{\phi}_{t+\Delta t}^{2},\cdots,\mathbf{\phi}_{t+\Delta t}^{k})\) endif \(\mathbf{\phi}_{t+\Delta t}^{d}=\frac{1}{k}\sum_{i=1}^{k}\mathbf{\phi}_{t+\Delta t}^{i}\) return \(\mathbf{\phi}_{t+\Delta t}^{d}\)
```  
**Algorithm 1** Wearer's motion estimation, and calculation of joint angle of powered exoskeleton  
Figure 5: Estimation of joint angle at time \(t+\Delta t\), \(\mathbf{\phi}_{t+\Delta t}\), based on k-NN.