# Mechanical Design and Gait Optimization of Hydraulic Hexapod Robot Based on Energy Conservation
## 3 Robot Modeling
### Kinematic Modeling  
The initial posture and the general posture are shown in Figure 4 and the D-H parameters are shown in Table 1.  
Figure 4: Leg posture and coordinate frames: (**a**) initial posture; (**b**) general posture.  
Figure 3: Geometric parameters of the leg structure: (**a**) hip and knee joint; (**b**) root joint.  
The transformation matrix from the foot coordinate system to the body one at a general configuration can be written as  
\[g_{ST}(\theta)=\prescript{S}{A}{T}{\theta}_{B}^{T}{T}_{C}^{B}{T}_{T}^{C}{T}=\left[ \begin{array}{cc}\mathbf{R}(\theta)&\mathbf{P}(\theta)\\ 0&1\end{array}\right] \tag{4}\]  
\[\mathbf{R}(\theta)=\] \[\left[\begin{array}{ccc}-\sin(\theta_{1}+\theta_{2}+\varphi)&-\cos( \theta_{1}+\theta_{2}+\varphi)&0\\ \cos(\theta_{1}+\theta_{2}+\varphi)\sin\theta_{0}&-\sin(\theta_{1}+\theta_{2}+ \varphi)\sin\theta_{0}&\cos\theta_{0}\\ -\cos(\theta_{1}+\theta_{2}+\varphi)\cos\theta_{0}&\sin(\theta_{1}+\theta_{2}+ \varphi)\cos\theta_{0}&\sin\theta_{0}\end{array}\right] \tag{5}\]  
\[\mathbf{P}(\theta)=\left[\begin{array}{cc}-L_{1}\sin\theta_{1}-L_{2}\sin( \theta_{1}+\theta_{2}+\varphi)\\ (\mathrm{d}+L_{1}\cos\theta_{1}+L_{2}\cos(\theta_{1}+\theta_{2}+\varphi)) \sin\theta_{0}\\ -(\mathrm{d}+L_{1}\sin\theta_{1}+L_{2}\sin(\theta_{1}+\theta_{2}+\varphi)) \cos\theta_{0}\end{array}\right]=\left[\begin{array}{c}P_{x}\\ P_{y}\\ P_{z}\end{array}\right] \tag{6}\]  
According to Equation (6), the joint angles can be obtained through inverse displacement analysis, and two solutions are obtained. Given the range of joint angles, the following solution is chosen.  
\[\theta_{0}=-\mathrm{arctan}\Big{(}\frac{P_{y}}{P_{z}}\Big{)}\] \[\theta_{1}=-\mathrm{arctan}\Big{(}\frac{P_{x}}{L}\Big{)}+ \mathrm{arccos}\Big{(}\frac{L_{1}{}^{2}-L_{2}{}^{2}+L^{2}+P_{x}{}^{2}}{2L_{1} \sqrt{L^{2}+P_{x}{}^{2}}}\Big{)} \tag{7}\] \[\theta_{2}=-\mathrm{arccos}\Big{(}\frac{L_{1}{}^{2}+L_{2}{}^{2}- L^{2}+P_{x}{}^{2}}{2L_{1}L_{2}}\Big{)}-\varphi\]  
where  
\[L=\sqrt{P_{y}{}^{2}+P_{z}{}^{2}}-d \tag{8}\]  
The Jacobian matrix of the single leg model can also be calculated by Equation (6).  
\[\mathbf{J}(\theta)=\frac{\partial\mathbf{P}(\theta)}{\partial\mathbf{\Theta} }=\left[\begin{array}{ccc}\frac{\partial P_{x}}{\partial\theta_{0}}&\frac{ \partial P_{x}}{\partial\theta_{1}}&\frac{\partial P_{x}}{\partial\theta_{2}} \\ \frac{\partial P_{y}}{\partial\theta_{0}}&\frac{\partial P_{y}}{\partial\theta_{ 1}}&\frac{\partial P_{y}}{\partial\theta_{2}}\\ \frac{\partial P_{z}}{\partial\theta_{0}}&\frac{\partial P_{z}}{\partial\theta_ {1}}&\frac{\partial P_{z}}{\partial\theta_{2}}\end{array}\right]=\left[ \begin{array}{c}\mathbf{J}_{1}\\ \mathbf{J}_{2}\\ \mathbf{J}_{3}\end{array}\right] \tag{9}\]  
where  
\[\mathbf{J}_{1}=\left[\begin{array}{c}0\\ -L_{1}\cos\theta_{1}-L_{2}\cos(\theta_{1}+\theta_{2}+\varphi)\\ -L_{2}\cos(\theta_{1}+\theta_{2}+\varphi)\end{array}\right]^{T}\] \[\mathbf{J}_{2}=\left[\begin{array}{c}(\mathrm{d}+L_{1}\cos \theta_{1}+L_{2}\cos(\theta_{1}+\theta_{2}+\varphi))\cos\theta_{0}\\ -(\mathrm{d}+L_{1}\sin\theta_{1}+L_{2}\sin(\theta_{1}+\theta_{2}+\varphi)) \sin\theta_{0}\\ -L_{2}\sin(\theta_{1}+\theta_{2}+\varphi)\sin\theta_{0}\end{array}\right]^{T} \tag{10}\]  
\begin{table}
\begin{tabular}{c c c c c} \hline
**Link** & \(\theta_{1}\) & \(\theta_{1}\) & \(\theta_{1}\) & \(\theta_{1}\) & \(\theta_{1}\) & \(\theta_{1}\) \\ \hline
0 & \(90^{\circ}\) & 0 & 0 & \(90^{\circ}\) \\
1 & \(\theta_{0}-90^{\circ}\) & 0 & \(\mathrm{d}\) & \(-90^{\circ}\) \\
2 & \(\theta_{1}\) & 0 & \(\mathrm{L}_{1}\) & 0 \\
3 & \(\theta_{2}+\varphi\) & 0 & \(\mathrm{L}_{2}\) & 0 \\ \hline \end{tabular}
\end{table}
Table 1: Denavit–Hartenberg (D-H) parameters for the 3 DOF (3 degrees of freedom) leg.