# Straight Gait Research of a Small Electric Hexapod Robot
## 5 Correction Algorithm of Yaw Angle  
Based on the previous work, the basic motion control of the hexapod robot can be realized. The user can send instructions through the mobile device to make the robot realize the expected gait. Of course, this is just an open-loop control. Next, the actual feedback attitude information is used to design an algorithm to reduce the yaw of the robot's attitude in motion. Figure 8: Flow chart of gait transformation. The idea of the algorithm is to adjust the direction of the robot by adjusting foot positions of the support leg relative to the body coordinate system \(\{B\}\), so that the robot can move close to the desired direction at the next moment to achieve the purpose of correcting the yaw angle in time. This way, when the robot determines the foot positions at the next moment, it needs to consider the adjustment of the walking direction, which is necessary to establish a kinematic model to describe it better. Figure 9 shows the kinematic model of yaw angle correction, here taking the tripod gait as an example. Suppose that the robot is not in the ideal direction at the current time, and the support leg needs the body to advance a distance of \(s^{\prime}\) in the next moment (\(s^{\prime}\) can be determined based on the results of the original gait planning and foot trajectory planning). Now, to reduce the yaw angle error, make the robot rotate at an angle \(\Delta\gamma\) around the origin of the body coordinate system \(\{B\}\) to adjust to the ideal direction first. After that, the support legs can support the body forward. Now it is necessary to recalculate and determine the foot position of each support leg relative to the coordinate frame \(\{B\}\) in the next moment. For the support leg \(i\), suppose the foot position of it relative to \(\{B\}\) is \(\left[ \begin{array}{cccc}^{B}P_{ix}&^{B}P_{iy}&^{B}P_{iz}&1\end{array}  \right]^{\text{T}}\) at the current moment and \(\left[ \begin{array}{cccc}^{B}P_{ix}^{\prime}&^{B}P_{iy}^{\prime}&^{B}P_{iz }^{\prime}&1\end{array} \right]^{\text{T}}\) at the next moment. Based on the kinematic analysis, the relationship between the two can be obtained:  
\[\left[ \begin{array}{cccc}^{B}P_{ix}\\ ^{B}P_{iy}\\ ^{B}P_{iz}\\ 1\end{array} \right]=\left[ \begin{array}{cccc}\cos\Delta\gamma&-\sin\Delta \gamma&0&0\\ \sin\Delta\gamma&\cos\Delta\gamma&0&0\\ 0&0&1&0\\ 0&0&0&1\end{array} \right]\left[ \begin{array}{cccc}1&0&0&s^{\prime}\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1\end{array} \right]\left[ \begin{array}{cccc}^{B}P_{ix}^{\prime}\\ ^{B}P_{iy}^{\prime}\\ ^{B}P_{iz}^{\prime}\\ 1\end{array} \right] \tag{9}\]  
Furthermore, we have  
\[\left[ \begin{array}{cccc}^{B}P_{ix}^{\prime}\\ ^{B}P_{iy}^{\prime}\\ ^{B}P_{iz}^{\prime}\\ ^{B}P_{iz}^{\prime}\\ 1\end{array} \right]=\left[ \begin{array}{cccc}^{B}P_{ix}\cos\Delta\gamma+^ {B}P_{iy}\sin\Delta\gamma-\ s^{\prime}\\ ^{-B}P_{ix}\sin\Delta\gamma+^{B}P_{iy}\cos\Delta\gamma\\ ^{B}P_{iz}\\ 1\end{array} \right] \tag{10}\]  
The foot position of the support leg \(i\) relative to \(\{O_{1B}\}\) in the next moment can be further obtained. In this way, when the robot continues to move, the adjustment of the walking direction is added. The flow chart of the yaw angle correction algorithm designed in this paper is shown in Figure 10.  
In the straight gait, the desired yaw angle of the robot is always \(0^{\circ}\). In the process of robot walking, the feedback information of yaw angle can be obtained based on the  
Figure 9: Kinematic model of yaw angle correction in straight gait. IMU module. Compared with the expected yaw angle, the difference \(\Delta\gamma_{0}\) is obtained as the input of the controller, and the output of the controller is \(\Delta\gamma\), which is the variable in the previously proposed kinematics model of yaw angle correction for the robot. In the program, sampling is done every 10 ms. According to the model, the foot positions of the robot's support legs at each moment can then be recalculated to adjust the walking direction (See Equation (10)).