Abstract:To enhance the real-time performance and stability of the two-wheeled self-balancing control system, a mechanism combining quaternion and PID algorithms has been proposed for the control of the two-wheeled self-balancing vehicle. This mechanism is based on quaternion calculation to determine the attitude angles and uses the PID algorithm to achieve motion control of the balancing vehicle. The system measures the angular velocity and angular acceleration of the balancing vehicle using MPU-6050 and measures the motor rotation speed using encoders. These measurement data are used as feedback for the balancing vehicle control system, which enables the control of the vehicle and human-machine interaction through a mobile app. Under the control algorithm designed in this paper, the balanced vehicle can maintain good balance in three scenarios: self-balancing, self-balancing with high load and self-balancing with heavy load.In total, 20 000 sets of data of the pitch angle of the balanced vehicle in the three scenarios were collected, with variances of 0.013, 0.084 and 0.065 respectively. When compared to the Kalman filter and complementary filter algorithms in a stationary state, the pitch angle variance of the balanced car in the 5 000 sets of self-balancing data was 0.000 239, smaller than the other two algorithms. These experimental results show that the proposed control mechanism can achieve stable control of the balanced vehicle while satisfying the real-time requirements.