m45_Self_Balance_Bot-1
Photo by Hep Svadja
Build this project and more in Make: Vol. 45. Don’t have the issue? Get yours today!
Build this project and more in Make: Vol. 45. Don’t have the issue? Get yours today!

Ready to level-up your robot skills? ArduRoller is a self-balancing, inverted pendulum robot that’s also capable of autonomous navigation indoors or out. I created it as an entry for the annual SparkFun Autonomous Vehicle Competition: The goal was to create a nontraditional vehicle capable of quickly navigating an obstacle course including multiple turns, bumpy terrain, 50-gallon drums, and ramps.

I chose a surplus APM 2.5 autopilot from 3D Robotics because it contains all the sensors needed to create the bot on a single board. The build is straightforward and the software is free and open source, based on the ArduPilot system developed by the DIY Drones community. It’s a great way to get started with autonomous robots.

The heart of a self-balancing bot is the IMU or inertial measurement unit, consisting of 3-axis rate gyros, accelerometers, and magnetometers. These 9 sensors are sampled up to 1,000 times per second and integrated with a piece of code called the DCM (direction-cosine-matrix algorithm), a mathematical filter that combines the best attributes of each sensor. The robot’s higher-level code can simply ask the DCM the angle and the rate of rotation of the bot as needed for balancing.

How to Make a Robot Balance

An inverted pendulum balance-bot is inherently unstable. Conveniently, the high center of gravity creates a large moment of inertia that slows the rate at which it will fall. We can leverage this slow fall by continually moving the wheels under the vehicle as it falls. If it leans forward, the wheels roll forward to counteract the fall.

A simple PID loop in the robot’s software is the basis of the balance control:

  • The proportional term takes the angle error of the bot and sends that scaled value to the motors, to keep the wheels rolling into the fall.
  • The integral term is used the same way, but is the sum of all angle errors over time and helps to cancel out center-of-gravity issues.
  • The derivative term is critical. Without it, we couldn’t control acceleration.

adruorollerMake It Travel

A simplistic bot just leans into the direction of travel. This works for a while, but the bot constantly accelerates and soon falls over (A). If the bot tries to right itself, forward motion stops.

Instead we need to move forward while rolling vertically (B). The first step is to make the wheels rotate at the desired speed while leaving enough power to keep the bot balanced and perfectly upright. Next we take the velocity of the wheels and feed that forward into the desired speed. This gives the bot the ability to resist rapid changes in angle, such as a person trying to push the bot over. This algorithm was developed through observation of how people balance when being pushed. For example, a lineman in a football game throws his leg back and leans in when hit.

These two additional inputs are summed with the balancing algorithm and sent to the wheels, enabling the bot to gracefully accelerate and travel long distances.

Make it Navigate

In order to make the robot navigate, we need to know precisely where it is and where it’s going. GPS is great, but only accurate to a few meters. We need far higher accuracy — down to centimeter scale.

m45_Self_Balance_Bot-16
Photo by Hep Svadja

Wheel encoders allow accuracy down to millimeters and are a good complement to GPS. Motors sold by Pololu have optional Hall effect (magnetic) sensors that work like a bicycle computer: Small magnets rotate past the sensor, giving us the speed of the wheels as they rotate. An Arduino Pro Mini reads the thousands of pulses per second sent by the encoders, and relays that data to the autopilot via an I2C interface. Once you measure the diameter of the wheels, the bot will know exactly how fast and how far it has traveled. Because the bot also knows its compass heading, it can plot its precise position in 2D space. When available, GPS is used to gently nudge this solution over time to ensure that wheel slippage or other errors don’t build up and send it off course.

If the vehicle becomes stuck while roving in autopilot, it will sense the wheels have stopped. The bot will reverse course and try again, slightly to the right.

The rest of the robot’s control software, including waypoint navigation, is simply a modified version of ArduCopter, the open-source drone project that I founded 4 years ago. This allows us to leverage a large volume of work built by a community of drone enthusiasts.

Time to make! The following project takes about 3–5 hours to complete and can cost around $400–$500.

YouTube player

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Project Steps

Gather up the gear

The first image shows the brushed DC motors from Pololu with their encoder units attached. A 34:1 gear reduction was chosen to increase torque.

The off-road wheels from Pololu come with adapters that perfectly attach to the 4mm motor shafts. The soft tires help the bot go over any terrain and absorb bumps that would normally knock it over.

3D-print the body sections

Grab the 3D files for printing at thingiverse.com/MAKE. I printed these on a MakerBot Replicator 2X (item #MKMB04, makershed.com).

Mount the motors

Fit the motors into the 3D-printed base. They’re held tightly by internal ribs, but I added hot glue between 2 ribs to help keep them from slipping.

Connect the electronics

Connect the APM autopilot, motor shield, logic level converter, and Arduino Mini as shown in the wiring diagram (click here for a larger version).

Connect the GPS module and telemetry radio for autonomous operation.

To control the bot manually, connect your R/C receiver. For PPM receivers, use the jumpers that came with the APM (as shown in the second image here).

Connect the electronics, cont'd

Hot-glue the electronics to a foamcore board that easily slides into place inside the robot. Make sure the autopilot stands with its “Front” arrow pointing straight up.

Finally, connect the electronics to the motors and slip the electronics board into the base.

Final assembly

Slip the middle body section (with the window) over the electronics and press-fit it into the base. Then press the top section into place. The battery is stored in the top section, under the dome. A power switch is a useful addition and can be mounted on the side of the bot.

Mount the wheels if you haven’t already.

The glass dome is actually a plastic tree ornament sold by Amazon. LEDs in the electronics light up the insides of the bot through the (optional) plexiglass window.

Mount the telemetry radio on the side of the bot; you can use it to program missions or to control the bot directly.

Program your balance bot

Download the ArduRoller source code (APM 2.5 or 2.6) from github.com/jason4short/ardupilot/tree/ArduRoller and upload it to the APM 2.5, using a modified version of the Arduino IDE called ArduPilot-Arduino (Windows or Mac) from ardupilot.com/downloads.

Download the wheel encoder source code (Arduino Pro Mini) from github.com/jason4short/WheelEncoder, then use the ordinary Arduino IDE to upload it to the Pro Mini.

For autonomous missions, get Mission Planner for PCs (Windows only) at ardupilot.com/downloads, or Mission Planner for PC’s: ardupilot.com/downloads/?did=82.

Use It

Once the bot is built, you can drive it around with an R/C controller or send it on long, autonomous missions using GPS. The Mission Planner software lets you enter point-and-click waypoints using Google Maps; track your robot’s location, speed, and heading; run your own Python scripts; download and analyze mission logs, and more.

Lately I’m using Droid Planner on an Android tablet, and it works great.

Add a video transmitter to see your robot’s view in first person, and a GoPro to record HD video. You could even add sonar to allow your ArduRoller to avoid obstacles entirely!