# A Wheeled Inverted Pendulum Learning Stable and Accurate Control from Demonstrations
## 5 Experiment  
In this section, we validate the proposed method on a real wheeled inverted pendulum with a motion capturer to observe the position and pose information (as shown in Figure 6). The wheeled inverted pendulum uses STM32 single chip computer as the processor to control the velocities of its two wheels. The Bluetooth interface was provided for communications between the STM32 single chip computer and the upper computer. We used the Vicon Tracker 3.4 motion capturer to observe the state of the wheeled inverted pendulum in real-time. The motion capturer can send the observed state to the local network that it is connected to. We, therefore, built software to receive the state observed from the motion capturer. After handling the date received through the algorithm in the upper computer, we subsequently send orders to the STM32 computer to actuate the wheeled inverted pendulum at an interval of 0.005 s.  
The effectiveness of the proposed algorithm was verified by applying it to the path following task. We collected three kinds of trajectories with three groups of demonstrations for each kind (Figure 7). The recorded demonstrated trajectories were used to train the dynamic system in Equation (6). The sampling interval was also set as 0.005 s.  
Figure 6: The configuration of the experiment. (**a**) A wheeled inverted pendulum with markers attached on it; (**b**) a laptop as the upper computer sends orders to the wheeled inverted pendulum through Bluetooth; (**c**) the hardware of the motion capturer. There are four cameras to observe the position and pose information of the wheeled robot in total; (**d**) shows the software interface of the motion capturer. It can send the position and pose information through UDP protocol such that the upper computer can receive the information in real-time.  
Figure 7: The demonstrations given by humans to teach a model that can regulate a wheeled inverted pendulum to undertake path following task.  
Subsequently, we picked a demonstration from each kind of trajectory as the reference trajectory. We let the robot start from a different position to follow the reference trajectory.  
The results by the proposed method and two traditional control methods [34; 35] are shown in Figure 8. It can be seen that the proposed learning method can smoothly follow the reference trajectory and finally converge to the target position.  
We also used the swept error area standard (SEA) [29] to evaluate the proposed method and the traditional methods [34; 35] quantitatively. The SEA standard measures the difference between the generated and the reference trajectories by their included area (Figure 9). The meaning of the SEA standard can be simply thought as a fact that the generated trajectory should be enough close to the reference counterpart, if the evaluated controller is effective in path following. The computing formula is given by  
\[E =\sum_{k=1}^{T-1}A\left\langle\left(\hat{x}^{k},\hat{y}^{k}\right) ^{\mathrm{T}},\left(\hat{x}^{k+1},\hat{y}^{k+1}\right)^{\mathrm{T}},\left(x^{k },y^{k}\right)^{\mathrm{T}},\left(x^{k+1},y^{k+1}\right)^{\mathrm{T}}\right\rangle, \tag{21}\]  
where \(\left(\hat{x}^{k,n},\hat{y}^{k,n}\right)^{\mathrm{T}}\) and \(\left(x^{k,n},y^{k,n}\right)^{\mathrm{T}}\) are sampling points, respectively, from the \(n\)th generated and reference trajectories. \(A\left\langle\cdot\right\rangle\) is the area of the tetragon enclosed by the four adjacent points along the trajectories.  
The SEA results by the proposed method and the approaches in [34; 35] can be seen in Table 1. From the results, we can see that the proposed method can better achieve the capacity of path following; i.e., the error between the generated trajectory by the learned controller and the reference trajectory is smaller.  
Figure 8: The results by the proposed method and the methods in [34; 35]. The upper row shows the general trajectory shape of the path following. The lower row records the path following results through MATLAB.