## 3 State Machine Strategy Based on FASM Stabilization Criterion
### Finite State Machine Design  
When moving in a complex dynamic environment, the phase of each leg of the hexapod robot is programmed by its planner and controller based on a predefined gait sequence. However, generating phases solely based on time is an idealized assumption that struggles to accommodate the unstructured variations of real terrain. During locomotion, the legs may prematurely touch the ground due to obstacles or experience delayed contact due to foot misplacement, affecting gait stability. To address this issue, this paper proposes a finite state machine control strategy triggered by foot-end touchdown events, enabling rapid response and dynamic adjustment to unexpected situations such as foot misplacement and slipping. To achieve smooth switching between different states of the hexapod robot, it is necessary to comprehensively consider the leg force feedback, the flag bit of the finite state machine, and the time parameters of the swing phase and the support phase to determine whether to switch the state. The flowchart of the finite state machine is shown in Figure 4.  
Figure 3: Schematic diagram of stabilization cone. This process mainly includes the following stages:  
1. Swing state: When the foot end enters the swing phase, execute the desired trajectory tracking. 2. Support state: When the foot end enters the support phase, if the value measured by the force sensor is greater than the set value and Flag = 0, it is determined to be in a stable support state. 3. Empty-stepping state: When the foot end enters the support phase, if the force feedback suddenly changes and is lower than the set value, it is determined as empty-stepping, and corresponding decisions are triggered according to the flag bit. 4. Pit-probing state: In the empty-stepping state, if the finite state machine flag bit Flag = 2, the leg adopts admittance control to make the foot end probe the bottom of the pit along the preset trajectory and land on the ground. 5. Foot-force adjustment state: In the empty-stepping state, if the flag bit Flag = 1, the leg adopts force-based impedance control to adjust the force exerted by the foot end to reduce the impact. The flow chart of the finite state machine is shown in Figure 4.  
Figure 5 shows the support-phase polygon, which ensures that the center of gravity of the hexapod robot remains stable even when a touchdown leg steps into an empty space [21]. Figure 6 illustrates the schematic diagram of the robot's quadrupedal gait. Number 1 represents the initial state of the gait; in number 2, two legs marked with black dots enter the swing phase. After completing the swing, number 3 shows the new support state. Figure 4: The flowchart diagram of the finite state machine. Number 4 indicates that the robot has returned to six-leg support. Subsequently, the robot continues alternating between support and swing phases according to the predetermined gait pattern. According to the minimum tipping angle and the judgment of the finite state machine, the leg that steps into the empty space can adjust the foot-end displacement through admittance control. While achieving local contact and detection, it can also adjust the normal force at the contact point, thereby improving the walking stability of the robot on collapsible terrains. Figure 7 illustrates the instability that occurs during the tripod gait when a touchdown leg steps into an empty space. In this case, the footholds of the support legs cannot form a support-phase polygon, causing the hexapod robot to tip over and enter a free-fall state. To address this issue, the force-based impedance control method is adopted to reduce foot-end impact, and relevant vertical dynamics indicators [22] are used to evaluate the effectiveness of this method. Figure 8 illustrates the schematic diagram of the robot's triangular gait. Number 1 represents the initial state of the gait; in number 2, three legs marked with black dots enter the swing phase. After completing the swing, number 3 shows the new support state.