A self-balancing two-wheel robot is an inverted pendulum on wheels, which means its center of mass is above its wheel axle and it naturally wants to tip over. It stays upright by constantly measuring its tilt and moving its wheels underneath its body. This idea matters because the same control principles appear in scooters, humanoid robots, camera stabilizers, and autonomous machines.
The robot is a clear example of how sensors, programming, and physics work together in real time.
An inertial measurement unit senses angular velocity and acceleration, then software estimates the robot's tilt angle. A controller compares the measured tilt with the desired upright position and calculates how much motor torque is needed. Wheel encoders can add feedback about wheel speed and position, helping the robot control both balance and motion.
To accelerate forward without falling, the robot first leans slightly forward so the wheels can push under its center of mass while maintaining balance.
Understanding Robotics: Self-Balancing Two-Wheel Robot
The hardest part of balancing is that a small lean does not stay small. Gravity creates a turning effect that makes the body rotate farther from upright. As the angle grows, the correction needed becomes larger and faster.
The wheels must have enough grip to create the needed horizontal force. A smooth floor, a loose carpet, or dust on the tyres can change the result.
A heavy battery placed high on the frame makes the robot slower to react and harder to recover. A lower, well-centred mass usually gives the controller more time to respond.
Tilt sensing is less simple than reading one sensor value. A gyroscope detects how quickly the robot rotates, so it reacts quickly to motion. However, its tiny measurement errors build up over time and cause drift.
An accelerometer can indicate the direction of gravity when the robot is still or moving gently. During a sharp wheel movement, it feels the robot's acceleration as well as gravity, so its angle estimate becomes misleading for a moment.
Software combines these strengths with a filter. Good calibration matters because a sensor mounted slightly crooked or given a wrong zero value can make the robot believe that a tilted position is upright.
The control program runs repeatedly, often hundreds of times each second. Each cycle must finish quickly enough to matter before the robot has fallen farther. Delay comes from sensor reading, calculation, motor response, and communication in the electronics.
Too much delay produces wobbling because the wheels correct an old position rather than the current one. The proportional part of a controller responds to the present lean. The derivative part responds to how rapidly the lean is changing and can reduce overshoot.
The integral part corrects a small steady bias, such as one caused by uneven motors. If its stored correction grows too large while a motor is at its limit, recovery can be poor. This problem is called integral windup.
Motors do not instantly deliver the requested motion. Motor torque depends strongly on current, while the available current depends on the battery, motor driver, wiring, and motor speed. A weak battery can turn a stable design into an unstable one.
Gear reduction can increase wheel torque, though it can reduce the maximum wheel speed. Wheel encoders help reveal whether both wheels actually moved as expected.
They are especially useful when one wheel slips or when the robot is commanded to travel straight. Turning is a separate challenge because the wheels need different speeds, yet the body must still stay balanced.
A sensible way to learn this system is to test one problem at a time. First confirm that the reported tilt changes in the correct direction. Then check that a small forward lean commands wheel motion in the direction that brings the wheels back beneath the body.
Use low power and support the robot during early tests. Record angle, wheel speed, and motor command while it runs. These graphs show whether the robot is oscillating, reacting too slowly, or reaching motor limits.
Students should pay close attention to sign conventions, timing, sensor noise, battery voltage, and mechanical looseness. Small faults in any of these areas can look like a programming mistake.
Key Facts
- A two-wheel balancing robot is an inverted pendulum because its center of mass is above the wheel axle.
- Tilt error is found by error = desired angle - measured angle.
- A PID controller can use u = Kp e + Ki integral(e) dt + Kd de/dt to compute motor command.
- Motor torque changes wheel acceleration, which moves the contact point under the robot's center of mass.
- IMU data often combines accelerometer and gyroscope measurements to estimate tilt more reliably.
- To accelerate forward, the robot must lean forward slightly so gravity and wheel motion produce a controlled change in speed.
Vocabulary
- Inverted pendulum
- A system with its mass balanced above a pivot point, making it unstable unless actively controlled.
- IMU
- An inertial measurement unit is a sensor module that measures acceleration and rotation rate.
- PID controller
- A PID controller calculates a correction using proportional, integral, and derivative parts of the error.
- Wheel encoder
- A wheel encoder measures how far and how fast a wheel has turned.
- Torque
- Torque is a twisting force that causes rotation, such as a motor turning a wheel.
Common Mistakes to Avoid
- Assuming the robot balances by keeping the wheels still is wrong because balance requires constant small wheel motions to keep the contact point under the center of mass.
- Using only accelerometer data for tilt is wrong because acceleration from wheel motion can confuse gravity-based angle estimates.
- Setting the proportional gain extremely high is wrong because too much correction can cause overshoot, vibration, or rapid falling in the opposite direction.
- Forgetting motor limits is wrong because a controller may calculate a correction that the motors cannot physically deliver.
Practice Questions
- 1 A robot's desired tilt angle is 0 degrees and its measured tilt angle is 6 degrees forward. What is the tilt error using error = desired angle - measured angle?
- 2 A proportional controller uses u = Kp e with Kp = 12. If the tilt error is -4 degrees, what motor command u does the controller calculate?
- 3 Explain why a self-balancing robot must lean forward briefly in order to accelerate forward without falling backward.