You are on page 1of 2

Two Wheel Self Balancing Robot

Benjamin Giacoppo
Segways are two wheeled self balancing electric vehicles controlled primarily by the user shifting their
body weight, leaning in the direction they wish to travel. To reduce cost and ensure safety, this
projects aim was to build a small, remote-controlled Segway-like robot. The operator can move the set
point of the controller mirroring a user shifting their weight.
A complementary filter and PID controller were developed to facilitate self balancing behaviour. The
Two Wheel Self-Balancing Robot uses an accelerometer and a gyroscope, interfaced with a
microcontroller, which communicates wirelessly to a local computer. This in turn provides control, live
tuning and information of the robots state for debugging purposes.
The robot can perform several manoeuvres including moving forwards, backwards and also has the
capability of turning left/right. It has the ability of self-balancing on common indoor surfaces and
handle significant disturbances.
It was designed in SoildWorks, to be as simple as possible while much effort was made to keep the
overall cost to a minimum. High torque motors were selected as torque in this case is far more
relevant than speed. The XBee wireless module was chosen as it is an all in one wireless solution
which allowed for simple interfacing with the microcontroller. A Zilog Z8 microcontroller is at the heart
of the mini-segway as it met the requirements of the project, which were, 1 UART, 2 PWM pins, 6 ADC
pins, with room to expand and a 20MHz clock to handle the computational demands of the control
loop. The motors are controlled by PWM through dual H-bridges.

The entire microcontroller code was developed in embedded C. The control loop runs at 100Hz which
is the same rate as the Segway. Their measurements are combined using an approximation of a
complimentary filter to reduce computation, to produce a more robust measurement of the robots
current angle. By filtering out the high frequency noise of the accelerometer and low frequency drift
from the gyroscope. This angle is then fed through a PID controller discredited using the backward
difference rule. This is performed exclusively to control the motors and to maintain the robots balance.
The set point is then used to control forward and backward movement while turning is accomplished
by offsetting the values delivered to the motors. Feedback from the numeric integral was used to
influence the robots set point as when using a set point of an angle to get the robot to move, the only
available way to maintain that angle the robot will have to keep increasing speed until it falls, this
feedback effectively makes the robot lean back as its speed increases.

An application which provides live values for sensors filter output and current motor values was
written in C# because it is easily adaptable standard from C. It also allowes live tunning of the robots
PID controller, as well as logging the received values for latter analysis. The robot is controlled by a
gamepad joystick which sends new set points and motor offset values. Due to this the received set
point by the robot is low pass filtered to make the robots movement more realistic rather than having
the robot snapping to a position as it can be commanded by the controller.

You might also like