Self-balancing robot like a growing child

October 11, 2015 § Leave a Comment

self-balancing robot
Building a self-balancing robot, Roboty, teaching it how to balance and to avoid running into things is like having a child. To understand where I am getting at, let me share with you my story of building a self-balancing robot.

The journey of this self-balancing robot begins with a micro-controller, an embryo, still tethered to its mother (the laptop) through an usb cable (the umbilical chord). A simple hello world sketch brings this young embryo to life.

WIlfrid – “Hi Roboty!”
Roboty – *blink, blink*
Wilfrid – *blink blink*
Roboty – *blink blink*
Wilfrid – “Okay, let’s give you some wheels so you can do more than just blink”
Roboty – *blink blink*
Wilfrid – “Okay, I’ll give you Bluetooth and a big ass lipo battery so that you got plenty of juice as well”

With that, the robot gain new motor functions, and autonomy as it evolves into a small frame with wheels, motor controller, and a giant lipo battery (4S2P 4000 mAH). The umbilical chord is now severed, and the self-balancing robot can communicate and be programmed wirelessly through Bluetooth.

The initial frame was very crude. Fragile as it was made of some MDF boards that I found lying around in my closet, and held together by screws and 0.25″ stand-offs.

This was what Roboty looked like:

11713522_10153468840364111_11813626_n

Like a toddler the robot can’t quite stand up yet, but it can crawl on the floor, bump into things, and say gaga.

Wilfrid – “Okay, now try moving your wheels”
Roboty – *turns on wheels, and darts across the room*
Wilfrid – “TOO FAST!” *runs after Roboty*
Roboty – “gaga”
Wilfrid – “Ehh, I didn’t program that!”

For a toddler to stand up, they must understand what it is like to be upright. I prop this young robot on its two wheels, the robot begin to understand the physics of this world through its IMU sensor, capturing acceleration and gryo data.

Wilfrid – “This is what it feels like to stand up, Roboty”
Roboty – *splits out a bunch of yaw, pitch, and roll data*
Wilfrid – “Yea I know, this is a lot of information to take in. At least you didn’t have to go through the trouble of getting your IMU sensors working!”

Here we are making sure the sensors are outputting properly, and that the interrupts were setup properly to read encoder values:
Testing Sensors

It must now understand how to coordinate their wheels so that it can remain upright. I attempt to get the robot to balance on its wheels with a PID algorithm, to stabilize the pitch at 0 degrees.

Wilfrid – “Roboty, you must balance on your two wheels by moving them towards where you are leaning. If you feel you are leaning faster towards that direction, you must move your wheels even faster to compensate! Your goal is to try to stand straight up without any wobble.”
Roboty – *confused, wobbles, then face plants and runs off*
Wilfrid – “Dammit I need to program a kill switch for this” *chases after Roboty*

After some tuning to the PID algorithm…We finally get it right… but interestingly it runs off into one direction.

Wilfrid – “Okay Roboty, I know this is our 100th time doing this, but I got a good feeling about this one”
Roboty – *Stands upright*
Wilfrid – “Yay! You can stand!”
Roboty – *Runs off into one direction, smacks into the couch, turns around and face plants*
Wilfrid – “Okay… now I just need to teach you how to stay put…”

Now that we’ve stabilized the pitch, we need another slower PID loop to control the position so that the robot does not run off. If I were to redo this project again, I would use a state-space-controller to control the two outputs simultaneously.

Wilfrid – “Yay, Roboty, you can balance now and stay put!”
Roboty – *blink blink*
Wilfrid – “Okay, now let’s see how well you can reject external disturbances” *Smack, Smack*
Roboty – @_@ *Wobble Wobble*
Wilfrid – “Yeap, you know how to balance now!”

One day, while going home on the TTC. I couldn’t help but wonder how well it rejected disturbances on the subway. As I took the robot out of the bag, people looked at me strangely, and wondered what the heck was this big sketchy looking thing. To be fair, it did have a bunch of visible wires, and a giant lipo battery on top… to make it worst, there is a LCD displaying a number (voltage) on the top of the robot.

If security was around, I’m sure they would have a lot of questions for me.

Tagged: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s this?

You are currently reading Self-balancing robot like a growing child at Wilfrid Ngo.

meta