# Design and Implementation of a Two-Wheeled Self-Balancing Car Using a Fuzzy Kalman Filter
## 1 Introduction
While the Kalman filter's theoretical foundation lies in linear Gaussian systems, its efficacy may diminish for nonlinear, non-Gaussian systems. In contrast, fuzzy control can address nonlinear and fuzzy problems, rendering it suitable for complex systems. Fuzzy control represents an intelligent control methodology grounded in fuzzy set theory, fuzzy linguistic variables, and fuzzy logic reasoning, which emulates human fuzzy reasoning and decision-making processes [12]. This approach encompasses three primary components: fuzzification, fuzzy control rule generation, and defuzzification. Fuzzification converts precise inputs into fuzzy inputs, while fuzzy control rule generation infers output fuzzy quantities from input fuzzy quantities. Finally, the defuzzification process transforms fuzzy outputs into precise outputs. In addressing the challenge of inaccurate attitude angle estimation during carrier motion, reference [13] proposes the adoption of a fuzzy Kalman filtering algorithm for attitude estimation. Leveraging accelerometer data as an input to the fuzzy controller, this approach notably enhances accuracy during motion and augments real-time performance under static, rotational, and motion conditions. Similarly, reference [14] introduces a parking kinematic model employing fuzzy Kalman filtering for vehicle speed estimation. This model effectively mitigates calculation errors in displacement and heading angle during parking maneuvers. Reference [15] combines fuzzy theory with a Kalman filter for processing unobservable spectral components of uncertain experimental data. In reference [16], a fuzzy PI model regulator and an adaptive Kalman filter are applied to accurately estimate the state of charge. Moreover, reference [17] constructs a mobile robot kinematic model within Simulink and designs a fuzzy controller based on real-time robot angles to facilitate precise obstacle avoidance. This study addresses the issue of low stability in sensor data acquisition for the two-wheeled self-balancing car by integrating a fuzzy controller into the Kalman filter, proposing the fuzzy Kalman filtering algorithm to enhance the speed and stability of the upright loop of the two-wheeled self-balancing car. Accelerometer data are utilized as an input for the fuzzy controller, and fuzzy logic is employed to adjust the parameters of the Kalman filtering algorithm. The Kalman filtering measurement noise variance is continuously adjusted to obtain the optimal estimate of the car's balance posture. Additionally, a dual closed-loop PID control algorithm is formulated, incorporating attitude information and velocity as feedback control variables. This algorithm is combined with the use of the high-performance STM32F103C8T6 (STMicroelectronics corporation from Geneva, Switzerland) chip as the main controller to enhance the stability and anti-interference capability of the two-wheeled self-balancing car system. To compare the proposed fuzzy Kalman filtering algorithm with other methods, namely complementary filtering and Kalman filtering algorithms, in terms of speed and stability on the two-wheeled self-balancing car, this study conducted comparative verifications. Through simulation comparisons, the fuzzy Kalman filtering algorithm proposed in this paper demonstrates stronger system stability and anti-interference capability. This paper is structured as follows: Section 2 describes the two-wheeled self-balancing car system and includes the dynamic model of the considered two-wheeled self-balancing car and the PD control algorithm of the upright loop of the two-wheeled self-balancing car. Section 3 proposes the fuzzy Kalman filtering algorithm to leverage information derived from observation data to continuously estimate and rectify the model and noise statistical characteristics in real time. To compare with other filtering algorithms, this section also briefly introduces the classical Kalman filtering theory without fuzzy theory and the widely used complementary filtering theory.