# Straight Gait Research of a Small Electric Hexapod Robot
## 3 Basic Control Method of the Robot  
### Control System  
The picture of HexWalker II is shown in Figure 1. The dimensions of the robot are 268 mm \(\times\) 166 mm \(\times\) 275 mm, and the weight of the robot is around 3 kg. The axis of the root joint is parallel to the body of the robot. The legs are entirely under the body, not the side. The design imitates mammalian structure, which is more conducive to the realization of the small ground occupation and strong load-bearing capacity [27]. The robot has a 2 DOF platform with a USB camera, which can monitor a wide range of video images. Each joint of the robot is actuated by a servo. The servo is a Digital Robot Servo with a 6 V power supply and 15 kg\(\cdot\)cm torque output. The rotation angle of each servo can be controlled by sending commands through the serial port based on the set communication protocol. Meanwhile, the servo also supports the function of angle back reading, which means it can provide feedback on its current angle.  
The system of the robot includes two parts: the robot part and the remote control part. The remote control part is a mobile device implemented with human-machine interface software, which can help the user send commands to control the robot's motion and watch the video collected by the USB camera on the robot. The controller on the robot contains two layers to improve the real-time performance of the system. The upper layer is Raspberry Pi 3B+, which runs the core control algorithm of the robot and communicates with the remote control part through the network. The lower layer is a self-designed embedded system, which mainly realizes the functions of joint actuating and signal acquisition. It communicates with the IMU module through the serial port to obtain the actual attitude information of the robot.  
Figure 2 shows the main research contents of the robot's core control algorithm. According to the requirements, the foot trajectory planning and gait planning scheme is designed to determine the desired position of each foot at each time. Foot trajectory planning and gait planning are based on body modeling and can be adjusted with sensor feedback. Combined with the results of kinematics analysis, the angle commands of each  
Figure 1: Picture of HexWalker II.  
Based on the D-H parameters, the homogeneous transformation between coordinate systems of adjacent links can be calculated, and the following results can be finally obtained.  
\[\left[\begin{array}{c}P_{1x}\\ P_{1y}\\ P_{1z}\end{array}\right]=\left[\begin{array}{c}-a_{3}\sin(\theta_{12}+\theta_{ 13})-a_{2}\sin\theta_{12}\\ a_{3}\sin\theta_{11}\cos(\theta_{12}+\theta_{13})+a_{2}\sin\theta_{11}\cos \theta_{12}+a_{1}\sin\theta_{11}\\ -a_{3}\cos\theta_{11}\cos(\theta_{11}+\theta_{13})-a_{2}\cos\theta_{11}\cos \theta_{12}-a_{1}\cos\theta_{11}\end{array}\right] \tag{1}\]  
where \(P_{1x}\), \(P_{1y}\), and \(P_{1z}\) represent the foot position of leg 1 relative to the coordinate system \(\{O_{1B}\}\). Of course, the foot position in the body coordinate frame \([B]\) can be obtained easily. This is the process of forward kinematic analysis.  
According to the position of the foot, inverse kinematic analysis can calculate the angle of each joint of the leg, which is the basis of controlling the robot's motion. Based on the forward kinematic analysis and mathematical derivation, the inverse kinematic equations can be given as follows:  
\[\theta_{i1}=\arctan\frac{-P_{iy}}{P_{iz}} \tag{2}\]  
\[\theta_{i2}=\arctan\frac{-P_{ix}}{\sqrt{P_{iy}^{2}+P_{iz}^{2}}-a_{1}}-\arctan \frac{a_{3}\sin\theta_{i3}}{a_{3}\cos\theta_{i3}+a_{2}} \tag{3}\]  
\[\theta_{i3}=\pm\arccos\frac{\left(\sqrt{P_{iy}^{2}+P_{iz}^{2}}-a_{1}\right)^{ 2}+P_{ix}^{2}-a_{2}^{2}-a_{3}^{2}}{2a_{3}a_{2}} \tag{4}\]  
Due to the different leg bending directions, \(\theta_{i3}\) is positive for the front legs (\(i=1,2\)), but negative for the middle and rear legs (\(i=3,4,5,6\)).