## 4 State Machine for the Robot
### State Machine Design  
The overall state machine is given in Figure 6. To allow the states in the state machine to be transferred as desired, the switch conditions (SCs) should be designed based on the feedback of the sensors, and the details of such SCs are given in Table 4.  
In Table 4, \(\Delta d_{ad}\) and \(\Delta d_{up}\) are the distance constraints that are set up according to the experiments. Based on the SCs, the robot can be switched between different modes defined in Section 3 by using the state machine shown in Figure 6, and the operations of such a state machine are briefly described as follows:  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**SCs** & **Conditions** & **Related Basic Actions** \\ \hline SC1 & No stairs detected & Mode on the ground \\ SC2 & Stairs and \(|d_{1L}-d_{1R}|\geq\Delta d_{ad}\) & Posture adjustment: case 1 \\ SC3 & \(|d_{1L}-d_{1R}|\geq\Delta d_{ad}\parallel d_{2L}-d_{2R}|\geq\Delta d_{ad}\) & Posture adjustment: case 2 \\ SC4 & \(d_{1L}<\Delta d_{up}\) and \(d_{1R}<\Delta d_{up}\) & Stair-climbing: case I \\ SC5 & (\(d_{1L}<\Delta d_{up}\) \& \(d_{1R}<\Delta d_{up}\)) \(\parallel\) (\(d_{2L}<\Delta d_{up}\) & Stair-climbing: case II \\  & \& \(d_{2R}<\Delta d_{up}\)) \\ SC6 & \(d_{2L}<\Delta d_{up}\) and \(d_{2R}<\Delta d_{up}\) & Stair-climbing: case IV \\ SC7 & SC4 \(\parallel\) SCS \(\parallel\) SC6 & Stair-climbing: case III \\ \hline \hline \end{tabular}
\end{table}
Table 4: The conditions of the transition of the states.  
Figure 6: The state machine of moving upstairs.  
When the robot gets the start signal, it firstly operates in the ground mode, unless SC2 is met. In ground mode, the function of path planning and obstacle avoidance is enabled, and, since these issues are not the topic of this paper, they are not discussed;
* When the SC2 is met, the state machine goes to Case 1; thus, the robot adjusts its pose. After finishing the posture adjustment, the robot's front wheels are close to the stairs, allowing the tetrapod to land on the ground to prepare for the chassis frame stepping up on the upper stair; then, SC7 is triggered;
* Once SC7 is triggered, the state machine goes to Case III and begins to climb the stair. Then, the robot switches to one case of Case 1, Case 2, or Case 4 according to the SCs;
* Specifically, after Case I is finished, SC3 is used to check the posture of the robot. Once SC3 is trigged, the state machine goes to Case 2; thus, the robot undergoes posture adjustment on the stair. It is worth mentioning that the posture adjustment is executed only when the error of the motion is accumulated to a certain value;
* If the state marching is in Case IV, this implies that the robot is almost on the ground again. Once SC1 is triggered, the state machine turns to ground mode. In our design, the robot is allowed to be turned off only when the robot is in ground mode to avoid the risk of staying on the stair. Based on the state machine, the robot can finish climbing any number of steps. The state machine of moving downstairs can also be established using Case 1', Case 2', Case I', Case II', Case III', and Case IV', as shown in Figure 7. The state flow can be analyzed in a similar manner; thus, the details are not repeated here.