Terrain classification and adaptive locomotion for a hexapod robot Qingzhui

Legged robots have potential advantages in mobility compared with wheeled robots in outdoor environments. The knowledge of various ground properties and adaptive locomotion based on different surface materials plays an important role in improving the stability of legged robots. A terrain classification and adaptive locomotion method for a hexapod robot named Qingzhui is proposed in this paper. First, a force-based terrain classification method is suggested. Ground contact force is calculated by collecting joint torques and inertial measurement unit information. Ground substrates are classified with the feature vector extracted from the collected data using the support vector machine algorithm. Then, an adaptive locomotion on different ground properties is proposed. The dynamic alternating tripod trotting gait is developed to control the robot, and the parameters of active compliance control change with the terrain. Finally, the method is integrated on a hexapod robot and tested by real experiments. Our method is shown effective for the hexapod robot to walk on concrete, wood, grass, and foam. The strategies and experimental results can be a valuable reference for other legged robots applied in outdoor environments.


Introduction
The current decade has seen robots stepping into people's lives. Many mobile robots have been used to accomplish patrol and disaster relief operations instead of human beings. The DARPA Robotics Challenge program conducted a series of competition events to develop and demonstrate technology for disaster response [1]. The Argos Challenge is a robotic challenge in the oil and gas industry sponsored by TOTAL [2]. Although many robots perform well in these kinds of competitions, most of them are wheeled or tracked robots.
In contrast to traditional wheeled or tracked robots, legged robots have potential advantages in mobility. Legged robots can walk on rough, highly unstructured terrains by selecting appropriate foothold positions. With respect to the control strategies of legged robots, many methods have been proposed in the past decades. Raibert et al. [3] developed BigDog that can travel on many outdoor terrains including rocks, gravel, and ice. SpotMini is an electric agile robot developed by Boston Dynamics and has a capable face-arm to accomplish operations such as opening doors [4]. Hutter et al. [5,6] developed StarlETH that utilizes a series elastic actuator to accomplish the precise control of leg forces. Hutter et al. [7][8][9] split the locomotion control of ANYmal into five key components, namely, state estimation, localization and mapping, navigation, foothold, and motion planning as well as whole body control. Bledt et al. [10][11][12][13] used an event-based finite state machine to define the Cheetah's gait. Semini et al. [14] used active compliance via torque control in HyQ to achieve dynamic locomotion. In contrast to quadruped robots, six-legged robots have a larger supporting polygon, which adds stability. Belter and Skrzypczyński [15,16] presented a real-time motion planning method for a hexapod robot walking on rugged terrain. Wang et al. [17,18] analyzed in detail the mobility of three statically stable ways of walking (insect-wave gait, mammal-kick gait, and mixed gait). Peng et al. [19] proposed a method of motion planning and implementation for the self-recovery of an overturned six-legged robot. Chen et al. [20,21] proposed a time-optimal trajectory planning method for a hexapod robot under actuator constraints. Tian et al. [22][23][24] decomposed motion planning on irregular terrain into foothold selection and whole body configuration planner.
Although many legged robots have walked from the laboratory to natural environments, the study of environmental adaptability is still necessary, especially detailed knowledge about terrain. For example, low friction may lead to slipping, and small compliance may result in vibration. With respect to terrain recognition and classification, much research was proposed in the past decades. In earlier research, visual features were often used to classify terrain. Filitchkin and Byl [25] used a bag of visual words created from speeded up robust features with a support vector machine (SVM) classifier to classify terrain. Milella et al. [26] proposed a self-learning framework for ground classification using radar and monocular vision. Christie and Kottege [27] provided a unique method to perceive terrain-robot interactions by listening to sounds generated during locomotion. However, vision can be sensitive to lighting variations and other effects. Brooks and Iagnemma [28] proposed a method to classify terrain based on vibrations measured by an accelerometer. Hoepflinger et al. [29] presented a haptic terrain classification for legged robots by measuring ground contact force. Giguere et al. [30] used inertial and actuator information to identify the environment of an amphibious robot RHex accurately. Shill et al. [31] and Wu et al. [32] used dynamic ground pressure data to classify terrain. Many researchers used the SVM algorithm as the machine learning method [25,27,[33][34][35][36]. Shao et al. [37] used a multilevel weighted knearest neighbor algorithm. Dutta and Dasgupta [38] used multiple weak classifiers together to improve the performance of terrain classification. Ordonez et al. [39] trained data by using a probabilistic neural network. Valada and Burgard [40] proposed deep spatiotemporal models for robust terrain classification. The model consists of a new convolution neural network architecture that learns deep spatial features, complemented with long short term memory units that learn complex temporal dynamics. More research about adaptive locomotion based on the terrain type is needed. Kottege et al. [41] improved energy utilization by switching gait. Walas [35] achieved a good balance between speed of movement and vibration.
A terrain classification method and adaptive locomotion for the hexapod robot Qingzhui is proposed in this paper. Ground substrates are classified with the feature vector extracted from the collected data using the SVM algorithm, and an adaptive locomotion based on ground properties is proposed. Compared with other methods, each foothold terrain type is identified by our method, and topographic relief is considered. Moreover, ground type information is used to change the parameters of the dynamic alternating tripod trotting gait. The experimental results show that the method is effective. This paper makes the following contributions: 1) An online terrain classification method is proposed for a hexapod robot called Qingzhui considering the potential probability of different terrain types of each foot; 2) A dynamic alternating tripod trotting gait is developed to control the robot, and the parameters can be updated online based on terrain type to reduce the vibration of the robot; 3) The proposed method is applied to a hexapod robot called Qingzhui, and several experiments are carried out to validate the methodology.
The remainder of this paper is organized as follows. The hexapod robot Qingzhui is briefly introduced in Section 2. The terrain classification method is presented in Section 3. Adaptive locomotion control by using the dynamic alternating tripod trotting gait is discussed in Section 4. The proposed method is validated by experiments in Section 5. The conclusions are presented in Section 6.

Robot system overview
A terrain classification and adaptive locomotion method for the hexapod robot Qingzhui is proposed in this paper. The robot system is introduced in this section. This robot is designed to accomplish exploration and transportation missions in the field environment. First, the structure and sensors used by the robot are introduced. Second, the hierarchical control framework of the robot is discussed.

Structure and sensors
The six-legged walking machine called Qingzhui is used in our experiments. The trunk of the robot is about 1.2 m long and 0.8 m wide. Figure 1 shows that each leg has three degrees of freedom (DOFs): Abduction-adduction degree, rotation degree of the thigh, and rotation degree of the shank. Six legs can be divided into two groups while walking. One is the middle front (MF) leg, the right back (RB) leg, and the left back (LB) leg. The other is the middle back (MB) leg, the right front (RF) leg, and the left front (LF) leg. Three foot positions in one group form a supporting triangle to prevent the robot from falling. Figure 2 shows that each driver unit in the leg joints is composed of a servo motor, a reducer, an encoder, and a torque sensor. The encoder can record the position and velocity of the rotating joint, and the torque sensor can capture the torque of the driver unit. Figure 3 shows that the robot Qingzhui hosts an inertial measurement unit (IMU), 18 encoders, and 18 torque sensors as proprioceptive sensors, and two RGBD cameras and a LiDAR as perceptive sensors. The motion control frequency is about 1000 Hz, and the frequency of communication between two controllers is 200 Hz. This robot weighs about 60 kg, and the payload is about 20 kg. It can walk on a slope with 20°and on flat terrain at 1.5 m/s. The robot has walked successfully on many terrains including concrete, foam, wood, grassland, and sand.

Hierarchical control framework
A hierarchical control framework is proposed to accomplish the terrain traversing task for the robot in our experiments. Figure 4 shows that by decomposing the walking mission, the control system can be divided into three stages: Low-, middle-, and high-level control. In high-level control, the six-legged robot receives the control instruction from the human-machine interface. The robot senses the surroundings and avoids obstacles by fusing data from LiDAR and RGBD cameras. One RGBD camera is used to detect obstacles, and another is used to establish the robot-terrain model to avoid collisions. In addition, terrain classification is accomplished based on the foot force calculated with the data from torque sensors. The   final output of the advanced-level control is the robot trajectory. In middle-level control, a leg trajectory generator is used to generate the leg position reference, and a body pose stabilizer is responsible for generating the force reference for correcting the body pose. The stability of the robot is monitored by a stability reviewer. Leg impedance is adjusted by a compliance modulator based on terrain type. A gait state machine is used to coordinate these components and connected with the robot trajectory. The low-level control is the leg-level impedance, which requires a position reference and a force reference as input. Each leg has its own impedance controller, and adaptive locomotion is based on this. Details of the leg-level impedance are introduced in Section 4.

Terrain classification system
Details of the terrain classification system are introduced in this section. The results of the ground stiffness estimated by Bosworth et al. [42] showed that the stiffness of concrete is harder than 300 kN/m, the stiffness of foam is about 20 kN/m, and the stiffness of wood is approximately an average of them. Thus, they can be good representatives for hard, soft, and medium grounds in our paper. Figure 5 shows a block diagram of this method. The collected data include the foot contact force, the pitch and roll angles, and the forward velocity of the robot. Contact foot force is separated into three sub windows, and each sub window provides five features. With the attitude angles and the forward velocity, 18 features from time domains are extracted to compile a data set. These features are fed into a multiclass SVM offline in MATLAB to generate the terrain classification model. This model is then utilized by the robot to classify terrain online. The average run time on a real robot is approximately 10 ms, which is much less than the gait cycle (about 300 ms).

Data overview
The data come from encoders and torque sensors installed in the joint to capture the foot contact force. Each leg has three revolution degrees: Abduction-adduction degree, rotation degree of the thigh, and rotation degree of the shank. Positions can be captured by encoders, and joint torques can be collected by torque sensors. Foot contact force can be calculated by utilizing a 3D Jacobian matrix. Figure 6 shows the schematic diagram of the leg mechanism for kinematics, and joint j 2 is out of parallel connection through a parallelogram mechanical structure. Tip position vector p ¼ x y z ½ T can be calculated from joint position vector j ¼ j 0 j 1 j 2 ½ T as follows: where c i and s i ði ¼ 0, 1, 2Þ stands for sine and cosine of joint position values, respectively. The velocity of the foot tip (v) can then be obtained as follows: where _ p is the derivative of the tip position (p) with respect to time, j # is derivative of the joint position (j) with respect to time, and J cb is the Jacobian matrix shown as below: According to the data of the torque sensors assembled at the joints and IMU information, tip force can be calculated as follows: where F b is the set of tip forces of the three coordinate directions in the body frame, R b L denotes the orientation of the leg frame rotations with respect to the body frame, J T cb is the transposed matrix of J cb , and τ is the torque set of three revolution joints. Six legs are divided into two groups: MF, RB, and LB legs move as Group A; MB, RF, and LF legs move as Group B. Figure 7 shows the force of the y-axis and position of the tips in Group A when the hexapod robot walks on flat concrete with a dynamic alternating tripod trotting gait. Velocity is 0.3 m/s, and acceleration is 0. The position of the y-axis is set to 0 when the leg is in the flying phase to focus on the data when the leg is in the support phase. An evident variance between different legs' force curves is observed because the distribution of the six legs is not a regular hexagonal, which is the main reason why each leg has its own classifier and impedance controller.
The data from the accelerometer and the gyro in IMU are fused to capture the pitch and roll angles of the robot. The average speed of the tip in the stance phase is calculated to capture the forward velocity of the robot.

Feature extraction
The foot force in the stance phase is separated into three sub windows, and five features are extracted in each sub window. The algorithm calculates the maximum, minimum, mean, median, and standard deviation of the force signal in each sub window, resulting in 15 features. Attitude angle features are extracted by calculating the average pitch and roll angle during the touchdown phase. The average velocity of the foot tip in the leg coordinate  system is also extracted as a feature. From the above, 18 features are extracted for each leg during the stance phase.
where s fi is the feature set extracted from the ith sub window, s p is the feature extracted from pitch angle, s r is the feature extracted from roll angle, and s v is the feature extracted from velocity. max fi is the maximum force in the ith sub window, min fi is the minimum force in the ith sub window, fi is the average force in the ith sub window, m fi is the median force in the ith sub window, and fi is the standard deviation of force in the ith sub window. Data are collected when the robot walks on concrete, foam, and wood. Figure 8 shows the tip force along the y-axis. In each diagram, terrain types from left to right are concrete, foam, and wood. Figures 8(a) and 8(d) show the tip force of the front legs. Figures 8(b) and 8(e) show the tip force of the back legs. Figure 8(c) shows the tip force of the MB leg. Figure 8(f) shows the tip force of the MF leg.

Classification
SVM provides a nonlinear high-dimensional model that is less prone to overfitting [43]. Open-source LIBSVM library is implemented to accomplish online terrain classification [44]. A practical guide to support vector classification is followed to achieve acceptable results [45]. First, each feature attribute is linearly scaled to the range [0, 1]. The same scaling factors are used in training and testing data. Second, radial basis function kernels are selected because they nonlinearly map samples into a higher-dimensional space. Third, v-fold cross-validation and grid search are applied to determine the optimal parameters c and g for the radial basis function kernels. Figure 9 shows that using the grid search and three-fold cross-validation, the optimal value of the penalty parameter c is 0.25, and kernel parameter gamma g in kernel function is 0.0625. The classification model is established offline in MATLAB and will be used in the online control of the robot.

Adaptive locomotion
Adaptive locomotion control is introduced in this section. The robot uses a dynamic alternating tripod trotting gait. First, the gait state machine is revealed to illustrate the coordinated movement of the six legs. Then, the impedance control for each leg is described in detail. Finally, the stiffness adjustment strategy is introduced. Other parts of gait control are not covered in this paper and can be referred with our early work [24]. 4.1 Gait state machine Figure 10(a) shows the gait sequence that ensures at least three alternating legs form a supporting triangle to keep the robot from falling. Figure 10(b) shows four phases in the state machine for a leg: Landing state (LDS), weight acceptance state (WAS), thrust state (THS), and lifting state (LTS). Once LDS is over, the state machine turns into WAS. The leg provides support force and extends to push the robot body upward in THS. When the supporting period is over, the state machine turns into LTS, and the leg shortens and lifts up. After that, the leg swings to the desired position on LDS until the next landing is detected.

Leg impedance control
Impedance controllers are widely adopted in dynamic locomotion on legged robots, which can give the robot legs more compliance without additional physical compliant components, such as springs or dampers. Considering the mechanical configuration of the leg, which has a planar parallel structure with the first two joints intersected at one point, our impedance controller is deployed in a spherical coordinate system instead of a Cartesian coordinate system. Figure 11(a) shows the definitions of the leg coordinates between Cartesian system and spherical system, and Fig. 11(b) shows the abstract schematic diagram of the virtual mass-spring-damping system. Tip position pðx, y, zÞ is described in leg Cartesian coordinate, which can be translated into p s ðl, , fÞ described in leg  spherical coordinate, where ðl, , fÞ stand for the length of the leg, forward/backward angle, and the abduction/ adduction angle of the leg, respectively. Figure 12 shows the flow chart of leg impedance control. The trajectory generalizer furnishes the designed position and velocity, and the stabilizer provides the reference force of the tip. Coordinate translators convert these designed quantities into a spherical description. The spherical impedance controller calculates the designed force and then converts it into torque needed of each joint of the leg. Close-loop torque PID controls are accomplished with the help of torque sensors distributed on each joint. Joint encoders collect joint angles and angle velocities, and dispense them to coordinate translators, kinematics, and impedance controller.
First, the related quantities should be converted between different coordinates.
where a right superscript s is employed to represent the quantities described in the spherical coordinate of the leg. Typically, j, which is the vector that stands for three jointvalues when calculating velocity and force, should be referenced. T c2s_x , T c2s_v , and T c2s_f are the translators that convert the designed position (p c d ), designed velocity (v c d ), and reference force (f c ref ) of the foot tip described in the leg Cartesian coordinate into corresponding quantities (p s d , v s d , f s ref ) described in the leg spherical coordinate. The designed position, designed velocity, and reference force of the foot tip described in the leg Cartesian coordinate are shown as follows: where x d_x is the designed position in x-axis, x d_y is the designed position in y-axis, x d_z is the designed position in z-axis, f ref _x is the designed force in x-axis, f ref _y is the designed force in y-axis, and f ref _z is the designed force in z-axis. The designed position, designed velocity, and reference force of the foot tip described in the leg spherical coordinate are shown as follows: where f l is the designed force of the foot tip along the direction l, t is the designed torque about the axis of and t f is the designed torque about the axis of f. Second, impedance control is accomplished in the spherical coordinate. Parallelogram mechanical linkage is applied in the leg structure to reduce leg inertia. The whole mass of one leg is about 5.8 kg, and approximately 80% of the weight is concentrated in the driver units (each driver unit is about 1.5 kg). The leg impedance controller is designed to realize a desired compliant behavior indicated by the mass-damper-spring leg model in the leg spherical coordinate, which can be described as follows: where M s d , B s d , and K s d are diagonal positive definite mass, damping, and stiffness parameter matrices of the desired impedance model, respectively, f s d is the vector of the designed forces the leg needs in the spherical coordinate.
Designed joint torque vector t d can be calculated by hiring translator T s2j_t .
Finally, t d is sent to the torque-PID controller. Each joint has been deployed with a torque sensor, which is used to accomplish more accurate torque executions. The final step of the leg impedance controller is regulating t d with torque t sr measured by their corresponding torque sensor (of course filtered) with the normal PID controller as follows: where R PID stands for the normal PID regulation, t d,i and t sr,i are the ith items of vector t d and vector t sr , respectively, and t i is the final torque needed that is sent to the corresponding joint actuator.

Stiffness adjustment
Two impedance modes are applied in our gait controller: The "swing" mode and the "stance" mode. The "swing" mode is adopted in LDS, and the swing leg is set compliant to follow the ground and reduce the disturbance of nonsimultaneous landing. M s d , B s d , and K s d are selected by our landing experiments. The "stance" model is adopted in the supporting and semi supporting states including WAS, THS, and LTS. The "stance" mode aims to assign proper impedance parameters to the legs to support the body. M s d , B s d , and K s d are selected by referring to the biological study on animals [46] and our experiments. In this paper, the stiffness adjustment is accomplished in the "stance" model by setting proper impedance parameters, while the parameters in the "swing" mode do not change. The robot can walk on many surfaces with an acceptable performance by using the same parameters in leg impedance control. However, an appropriate parameter can reduce robot jitter. A leg impedance control simulation experiment is conducted, and the results are shown in Fig. 13. Based on the stiffness measurements of different ground types [42], the ground is modeled as a springdamping system whose stiffness and damping are set to 70 kN/m and 200 N/(m$s -1 ), respectively. Hip target position is set to a sine curve. In the leg impedance control model, damping is set to 200 N/(m$s -1 ), while stiffness is set to three different parameters, namely, 5, 15, and 25 kN/m. When stiffness is set to 5 kN/m, maximum position error is approximately 0.04 m. When stiffness is set to 15 kN/m, maximum position error is approximately 0.01 m. When stiffness is set to 25 kN/m, maximum position error is approximately 0.04 m, and apparent oscillation occurs. Based on the simulation results, leg impedance control needs an appropriate stiffness. Soft or hard stiffness may result in large position errors and even unstable characteristics. During the real robot control, two kinds of parameters are preset for the robot. One is used on hard ground, and the other is used on relatively soft ground. After terrain classification, each leg needs to decide which kind of stiffness to use. Leg stiffness only switches after confirming the terrain change three times to reduce detection error.

Experiments
The proposed terrain classification and adaptive locomotion scheme is integrated on the hexapod robot Qingzhui. Three experimental results are introduced in this section: The first one shows the performance of terrain classification, the second one shows the performance of adaptive locomotion when the robot walks on a foam at a speed of 0, and the third one shows the performance of the robot walking on concrete and foam at a speed of 0.6 m/s.
Three types of terrain are tested in the first experiment. Data are collected when the robot walks on concrete, wood, and foam with different velocities. The payload is 5 kg, and the step height is set to 5 cm to adapt to the unevenness of the ground. The range of walking velocity is from 0 to 0.6 m/s, and 200 features are extracted in each experiment. These data are randomly separated into training data and testing data. Testing data account for 20% of all data. Table 1 shows the confusion matrix, precision, and recall metrics of the first leg. Precision is the positive predictive value, whereas recall is the true positive rate or sensitivity. They can be calculated as follows: where "true positives" means the prediction is positive, and the result is positive, "false positives" means the prediction is positive, and the result is negative, and "false negatives" means the prediction is negative, and the result is positive. Four prediction errors are observed. Table 1 shows that three concrete samples are identified as wood, and one wood sample is identified as foam. Table 2 shows that precision and recall are above 90% for the three classes, which shows that the utilized feature vector is suitable for terrain classification. The accuracy metric is approximately 96.67%, which shows that the terrain classification method is effective. Moreover, the average run time on the real robot is approximately 10 ms, which is much less than the gait control. Above all, the terrain types can be effectively identified online.   A laser tracker is used to record the position of the robot and evaluate the performance of adaptive locomotion in the second experiment. Figure 14 shows the scenario. The robot steps on a foam that is approximately 3 cm thick, and forward velocity is set to 0. A target ball is assembled on the center of the robot platform, and a laser tracker is utilized to track the target ball. At first, the robot steps with the default parameters used on the hard surface. Then, terrain classification and adaptive locomotion are active. The stiffness of each leg is decided by the terrain type detected by the terrain classifier. Figure 15(a) and its boxplot in Fig. 15(b) show the acceleration data along the y-axis. These two figures show that the vibration of the robot is reduced when terrain classification and adaptive locomotion method work. Figure 15(c) shows the position trajectory of the target ball, and its boxplot is drawn in Fig. 15(d). Based on these data, the robot platform jitter is smaller when terrain classification and adaptive locomotion method work. This experiment demonstrates the effectivity of the proposed method.
The performance of terrain classification and adaptive locomotion when the robot walks at a speed of 0.6 m/s on two different materials is evaluated in the third experiment. The robot stands still at first but speeds up to 0.6 m/s in three gait cycles after the command of moving forward. Default control stiffness is set as 9 kN/m. After terrain identification, the stiffness in active compliance control is changed to 7 kN/m while walking on concrete and 11 kN/m while walking on foam. Figure 16 shows the vibration of the robot's body. Figures 16(a) and 16(c) show the acceleration data along the y-axis (direction of gravity) measured by IMU in 5 s. Figures 16(b) and 16(d) show the boxplot based on the curve of acceleration over time to observe the distribution of acceleration. The maximum decreases, and the minimum increases after adaptive compliance control works. Moreover, the distribution of outliers shows that the platform jitter becomes smaller by adjusting control stiffness. The results show that whether the robot walks on concrete or soft foam, the vibration of the robot decreases by adjusting the control parameters using the above method. Although the impedance control has good ground adaptability, the knowledge of various ground properties and adaptive locomotion on different surfaces improves the robot's walking performance, especially the robot vibration.

Conclusions
In this paper, a terrain classification and adaptive locomotion method for the hexapod robot Qingzhui is proposed. A terrain classification method based on SVM is proposed, and a dynamic alternating tripod trotting gait that can adaptively adjust the leg's stiffness is utilized to achieve robot motion. Several real experiments are carried out, and the results verify the effectiveness of the method.
Compared with other terrain classification algorithms, the major advantages of the method are as follows: 1) Each foot has an independent terrain classifier to adapt to complex surface environments; 2) the leg impedance controller can change its parameters based on the terrain type during one gait cycle; 3) the proposed method is tested by a real hexapod robot and is shown effective. The drawbacks are that only three terrain types are tested. The dynamic performance of the robot will be improved, and data will be collected from other terrain types, such as rocks, grass, and carpet in the future work.