This paper describes the structure, working principle, hardware circuit, and control algorithm of a self-balancing robot. The system mainly consists of three parts: a mechanical walking device, a control system, and sensors. The mechanical walking device comprises a vehicle platform, a small DC motor, and left and right wheels. The control system uses a C80511310 microcontroller as its core and consists of a battery module, a motor driver chip, and peripheral circuits. An tilt sensor is used to monitor the posture of the vehicle platform. Control experiments on a physical prototype verified the rationality and effectiveness of the system.
1. Introduction
Robots are typical mechatronics products. Their creation involves knowledge from numerous disciplines such as computer science, cybernetics, mechanics, sensor technology, artificial intelligence, and bionics, making them an ideal platform for mechatronics students to conduct comprehensive knowledge training. Through robot-making activities, students can comprehensively cultivate their hands-on skills, creativity, teamwork, and enterprising spirit. Robot-making competitions, as a strategic means of innovative education, are gradually being recognized by educators.
Figure 1. Appearance of the fabricated self-balancing robot. Figure 2. System structure schematic diagram.Self-balancing robots differ from typical wheeled robots in that their two wheels are arranged in parallel left-right configurations, making them inherently unstable. This means that a self-balancing robot cannot maintain a vertically balanced position when stationary; it will always tilt forward or backward. However, in motion, it can achieve dynamic balance through certain control strategies. In recent years, the inherent instability and structural flexibility of self-balancing robots have attracted the interest of many robotics enthusiasts worldwide, leading to the creation of various self-balancing robots with different structures and appearances, and the experimentation with different control strategies to achieve self-balancing control. Typically, these robots use tilt sensors and angular velocity (or acceleration) sensors to form an attitude sensor to detect the tilt angle and tipping rate of the platform. Based on the current attitude of the platform, the magnitude and direction of the drive voltage of the DC servo motor are controlled to maintain balance. While this method produces self-balancing robots with good control performance, it is expensive and unsuitable for university students to build as extracurricular projects. This paper attempts to use inexpensive, common small DC motors as the drive mechanism, employing only tilt sensors to detect the platform's state, and supplemented by some low-cost electronic components to construct a small self-balancing robot. The article describes the robot's system structure, hardware circuitry, and control algorithm.
2 System Composition
The self-balancing robot system consists of three main parts: a mechanical walking device, a control system, and sensors. Its appearance and system schematic are shown in Figures 1 and 2, respectively. The mechanical walking device mainly comprises a vehicle platform, small DC motors, and left and right wheels. The control system uses a C8051P310 microcontroller as its core and consists of a battery module, motor driver chips, and peripheral circuits. The battery module is divided into two modules: Module 1 provides 8V and 5V voltages, powering the sensors and the microcontroller respectively. Module 2 uses a rechargeable battery to provide a separate 6V DC voltage to the two DC motors, isolating the hardware circuit power supply from the motor power supply. This not only meets the high current requirements of the motors but also eliminates the impact of motor voltage fluctuations on the stability of the hardware circuit power supply. The sensors are solid-state tilt sensors used to detect the angle of inclination of the vehicle platform relative to the ground.
The overall balance control principle is as follows: when the vehicle body deviates from the balance position (vertical position) and tilts forward, the sensors collect signals and transmit them to the microcontroller for judgment. The wheels then respond by moving forward, adjusting the vehicle body back to the balance position. Similarly, when the vehicle body tilts backward, the wheels will move backward. In this way, the robot is constantly in a dynamic process of tilt judgment and movement adjustment, keeping the vehicle body near the balance position and achieving a dynamic balance.
3. Control system and tilt sensor
The control system uses the C80511310 microcontroller as its core. Based on the magnitude and direction of the vehicle's tilt angle detected by the tilt sensor, it makes judgments according to a certain control strategy, outputs motor control signals, drives the DC motor to move, and adjusts the robot's operating state in a timely manner to maintain dynamic balance.
3.1 C8051F310 Microcontroller
The C8051F310 microcontroller features a CIP-51 core fully compatible with the 8051 instruction set and is a fully integrated mixed-signal system-on-a-chip (SoC). Its core employs a pipelined instruction architecture, with 70% of instructions executing in one or two clock cycles. At a clock frequency of 25MHz, it achieves a speed of 25 MIPS, significantly higher than other microcontrollers of the same type. Internally, it integrates almost all the analog and digital peripherals required to construct a microcontroller-based data acquisition or control system, including: a multi-channel ADC subsystem, four general-purpose 16-bit timers, four 8-bit general-purpose I/O ports, a programmable crossbar switch, and 16KB of Flash program memory. Furthermore, the C8051F310 microcontroller's compilation environment allows for convenient status monitoring and online debugging, providing easy conditions for determining the initial balance position of a balancing robot. The I/O port resource allocation based on the C8051F310 controller is shown in Figure 3.
3.2 Tilt Sensor
The selected tilt sensor is model UCB-1, available in both PWM and analog voltage output forms, with a measurement range of ±40℃. Due to its contactless structure, it is small in size, long-lasting, and highly reliable, making it particularly suitable for applications with frequent movement. Furthermore, at the same temperature, the sensor's output exhibits a good linear relationship with its input. The tilt sensor is vertically mounted on the self-balancing robot's support plate to accurately measure the angle of deviation from the robot's balanced position. The sensor's output voltage range is 2.5–4.5V, which is stabilized at 1.5–2.7V after signal conditioning circuitry before being transmitted to the microcontroller. Practical experience has proven that it can provide accurate angle values, meeting the requirements of the self-balancing robot.
Figure 3 Resource allocation of C8051F310 microcontroller I/O ports Figure 4 Control system program flowchart4 System Software Design
The entire system software can be divided into five parts: peripheral initialization module, system parameter setting module, signal acquisition module, digital filtering and scaling transformation module, and control module. The software flowchart is shown in Figure 4. The parameter setting module mainly completes the setting of control parameters. The digital filtering and scaling transformation module completes the weighted average filtering and scaling transformation of the input signal.
After the microcontroller initializes, it sends a command to acquire the tilt sensor signal. After filtering and scaling, the converted voltage value is sent to the control module for comparison and judgment. The comparison references a pre-set voltage range for the equilibrium position. If the voltage value is within the equilibrium range, the microcontroller sends a command to maintain the original equilibrium state; if it exceeds this range, it determines the tilt direction and sends a command to drive the motor to rotate forward or backward, adjusting it towards the equilibrium range. The entire system continuously acquires, compares, judges, and adjusts, ultimately ensuring the system remains within the equilibrium range. All programs are written in Keil C51, and each module has excellent independence and readability.
5. Conclusion
This paper utilizes inexpensive components and a C8051F310 microcontroller as the controller core to create a low-cost self-balancing robot. Control experiments on the actual device show that the system can effectively maintain balance at the zero point and within a certain angle range, thus verifying the effectiveness and rationality of the system design. However, the experiments also revealed that the robot's stability and anti-interference capabilities are not ideal. Because a general-performance, non-speed-adjustable DC motor is used, its response speed is slow. When the tipping range is too large, the robot cannot respond quickly to adjust to the balanced position; moreover, if the robot suddenly encounters external disturbances that disrupt its balance, it is difficult to readjust to a balanced state. Furthermore, the robot's center of gravity position also significantly affects stability. If the center of gravity is too low, the tipping speed is too fast, making effective control difficult; if the center of gravity is too high, the motor torque needs to be increased, and anti-interference capabilities are poor. In future production and testing, a speed-adjustable, faster-responding, and higher-performance DC motor will be used to overcome these shortcomings and further improve the control performance of the self-balancing robot.