# Design and Implementation of a Two-Wheeled Self-Balancing Car Using a Fuzzy Kalman Filter
## 4 Experimental Verification  
This experiment compares the time for a dual-wheel self-balancing car to return to balance from an unbalanced state and the angular fluctuations in the balanced state under the fuzzy Kalman filtering algorithm, Kalman filtering algorithm [21], and complementary filtering algorithm [20]. The self-balancing car is placed on the ground, and it is rotated around the motor axis to find the angle at which the car approaches balance, which is considered the mechanical center of the robot. In this experiment, the mechanical center of the robot is defined as 0\({}^{\circ}\).  
The CH340G driver for the USB to TTL module was installed, MCUISP v0.995 software was used to flash the pre-written program into the STM32 microcontroller (STMicroelectronics corporation from Geneva, Switzerland), the robot was connected to the PC using a MicroUSB cable, the MiniBalance 3.5 software was opened, the appropriate port was selected, and the baud rate was set to 115,200. This configuration allows the operator to view the data waveform of the robot's inclination angle through the software. To ensure the stable operation of the dual-wheel self-balancing car depicted in Figure 1, it is imperative to fine-tune the controller parameters governing the car's upright, speed, and steering loops. The PD controller parameters for the upright loop are set as: \(K_{p}=225\) and \(K_{d}=1.08\); the PI controller parameters for the speed loop are set as: \(K_{p}=160\) and \(K_{i}=0.80\); the PD controller parameters for the steering loop are set as: \(K_{p}=42\) and \(K_{d}=0.40\). The covariance of process noise and measurement noise are set as \(q=0.25\) and \(r=0.16\); the filtering period is set as \(T=0.005\), i.e., filtering is performed every 5 milliseconds.  
Measurements were conducted to observe the car's behavior under three different filtering algorithms as it transitioned from tilting backward at angles of 10\({}^{\circ}\), 20\({}^{\circ}\), and 30\({}^{\circ}\) (denoted as \(-10^{\circ}\), \(-20^{\circ}\), and \(-30^{\circ}\)), as well as tilting forward at angles of 10\({}^{\circ}\), 20\({}^{\circ}\), and 30\({}^{\circ}\) (denoted as \(10^{\circ}\), \(20^{\circ}\), and \(30^{\circ}\)), until it reached a balanced state. Subsequently, angle fluctuation graphs were generated, as depicted in Figures 8-13. To assess the variations in the car's stability across the three filtering algorithms, the integral absolute error (IAE) was employed as the error metric, where \(IAE=\sum\limits_{k=200}^{600}|e(k)|\).  
Figure 7: The principle of complementary filter.  
Figure 8: Angular fluctuations of \(-10^{\circ}\) back to equilibrium [20,21].  
Figure 10: Angular fluctuations of \(-30^{\circ}\) back to equilibrium [20,21].  
Figure 9: Angular fluctuations of \(-20^{\circ}\) back to equilibrium [20,21].  
Figure 11: Angular fluctuations of 10\({}^{\circ}\) back to equilibrium [(20,21)].  
Figure 12: Angular fluctuations of 20\({}^{\circ}\) back to equilibrium [(20,21)].  
Figure 13: Angular fluctuations of 30\({}^{\circ}\) back to equilibrium [(20,21)].  
From the simulation results, it is evident that the jitter of the two-wheeled self-balancing car is minimized when employing the designed Kalman filtering algorithm proposed in this study compared to the other two algorithms. Additionally, the time required for the system to recover to a balanced state from the same angle is shorter, and the absolute error is smaller than with the other two algorithms. Note that there is a visible difference between positive and negative tilting, which may be caused by the measurement error in the experimental process.