Abstract
This paper introduces the design of an infrared remote-controlled self-balancing car utilizing the STM32 as the master control chip. The system employs an MPU6050 sensor to acquire real-time attitude data, which is then processed using a Kalman filter algorithm and data fusion techniques. A PID control algorithm calculates the PWM duty cycle to drive the motors, enabling the car to maintain balance while performing maneuvers such as moving forward, backward, and turning via infrared commands.
Introduction
The two-wheeled self-balancing car is a classic "inverted pendulum" problem in control theory. Characterized by inherent instability, multivariable inputs, and high non-linearity, it serves as a rigorous benchmark for real-time control systems. Unlike traditional four-wheeled vehicles, this platform must continuously modulate motor output to maintain an upright posture. This research details the development of a functional prototype that achieves autonomous balance and precise maneuverability.
System Architecture and Hardware Integration
The system's core is the STM32F103C8T6 microcontroller (ARM Cortex-M3), chosen for its 72MHz clock speed, which is essential for high-frequency control loops.
As illustrated in the hardware architecture, the STM32 interfaces with several critical modules:
- MPU6050 Motion Sensor: A 6-axis device providing raw accelerometer and gyroscope data.
- L298N Motor Drive: Translates PWM signals into high-current power for the DC motors.
- Infrared Module: Decodes NEC protocol signals for user-driven directional control.
- Voltage Regulator: Converts the 12V power source into stable levels for the logic circuits.
Control Strategy
Stability is achieved through a combination of sophisticated state estimation and a multi-layered PID control loop.
State Estimation via Kalman Filtering
Raw sensor data presents a trade-off: accelerometers are stable in the long term but noisy due to vibrations, while gyroscopes are smooth but suffer from long-term drift. The system implements a Kalman filter to fuse these sources, providing an optimal estimate of the car's actual tilt angle and angular velocity.
Triple-Layer PID Control
To ensure both balance and positional stability, the controller employs a three-part PID strategy:
- Angle Control ($Kp$): The primary loop for maintaining vertical balance.
- Speed Control ($Kd$): Dampens oscillations and manages the velocity of the motors.
- Displacement Control ($Ki$): Prevents the robot from drifting away from its starting position when no commands are received.
Experimental Results and Parameter Tuning
Physical testing confirmed the system's efficacy, with the robot maintaining its position with a displacement error of less than 3cm. A significant portion of the development involved tuning the PID parameters to find the "sweet spot" between responsiveness and stability.
As shown in the debugging table, improper tuning leads to failure: a $Kp$ of 80 caused violent shaking ("overstrike"), while a $Kp$ of 40 resulted in a sluggish response. The optimal configuration was identified as $Kp=60, Ki=0.02, Kd=1$.
Conclusion
This project successfully demonstrates a stable self-balancing vehicle using an STM32-based architecture. While the current model relies on human input via infrared, future iterations could integrate ultrasonic or LIDAR sensors for autonomous obstacle avoidance, transforming the platform into a fully autonomous mobile robot.
Summary updated