The Basics of Self-Balancing Robot Design

Robotics and Automation
4 followers
This is my self-balancing robot.
A self-balancing robot is one of the best intermediate projects that you can build.
It makes you consider the mechanical, electrical, and software components.
You'll learn how it balances and how I made it.
So firstly, how does this thing even work?
Hi, I'm Robonix's mascot Nyx, and now we're going to get into self-balancing theory.
Self-balancing robots are based on the inverted pendulum concept.
The robot acts like an inverted pendulum that is naturally unstable
and needs active control to stay standing or rolling.
Our goal is to keep the center of mass directly above the wheel.
When the robot starts to tilt,
the wheels need to turn in the direction of the tilt
to bring the center of mass back over the wheel axis.
To do this, we'll need sensors to measure the tilt,
a microcontroller to run the control algorithm,
and motors to actually move the robot.
For our motor, there's three popular options that we can choose.
Stepper motors, brush DC motors, and brushless DC motors.
Let's see what we're working with.
Firstly, stepper motors.
They're a popular pick.
They're fairly easy to control and very precise.
However, they draw a lot of current and are pretty slow.
They also weigh a lot more compared to the other motors.
Next, we've got brush DC motors.
They're also a popular pick because they're cheap and easy to use.
However, you can't control them precisely.
Now, brushless DC motors are rarely used in self-balancing robots,
even though they're pretty cheap and powerful.
This is because it's pretty complex to control them precisely,
but if you can, you can build some really epic projects.
For this project, we're going to use stepper motors
because it offers a nice balance between performance and ease of use.
I love stepper motors.
The sensor that we're going to use to measure the tilt angle is the IMU-BNO-055.
Accurate, reliable, and simple to use.
Like, honestly, you can't really go wrong with this thing.
And for the microcontroller that'll run the control algorithm,
we'll settle with the ESP32-DEVKIT-C.
Why we're choosing this over an Arduino is because it has more pins,
which lets us connect a bunch of peripherals,
and also it has an antenna so we can wirelessly communicate.
After those three main components, we're going to harvest some more mats.
So firstly, a 14.8 1100mAh LiPo battery to power this JIT,
a cool-looking on-off switch,
and two screens to give our robot Nix some personality.
Now, let's switch to the PCB editor and go sicko mode!
When designing a circuit board,
the first thing you want to do is define how big you want it to be.
Then you want to import your components and arrange them neatly,
just like playing Tetris.
Then you want to draw the lines through the components,
like bang, bang, bang, bang, bang!
After that, you want to run the design rules checker,
and it says I got a perfect PCB!
Then you export from manufacturing.
Yeah!
These PCBs are pretty nice.
And how do they make them?
JLCPCB.
Easy, fast, reliable PCB solutions.
They sponsored me to say this part, but I was going to say this anyways.
Here's a pro tip.
Don't even think about trying to make PCBs yourself.
You have to use harsh chemicals,
really intricate CNC drilling,
and lots of physical labor.
And all of that effort just to make some ugly bum PCB.
Literally, just drag your design files into the website,
hit order, and then wait one week.
It's only two bucks for five PCBs.
Click the first link in the description if you want to check out their website.
The purpose of a PCB is to make wiring components together easy.
In this circuit board, I used two kinds of components.
Surface mount components, which have metal pads,
and through-hole components, which have metal pins.
When assembling a PCB, you need to start with the surface mount components.
Apply solder paste, and carefully place each component on the PCB.
Then, use a heat gun to melt the solder to form strong electrical connections.
Hell yeah!
Then, you want to solder the through-hole components.
Easy.
Then, snip the legs.
Put in the daughterboards, like the motor drivers, IMU, and screen,
and bang!
That's a beautiful PCB.
What a great PCB.
Now, let's get into the mechanical design.
The most important thing about a 3D model is that it has to look freaking epic.
And unlike a last-minute college project,
when 3D modelling, the first thing I consider is the general layout and shape of the project.
I know that the wheels have to be on the bottom,
and the motors have to be next to the wheel,
and all the electronics have to be on top of the motor.
So, basically, what I'm getting at is a big long rectangle with wheels.
Um, that's kind of ugly, and I want this robot to look cute and futuristic.
So, whenever aesthetics play a role in my projects,
I always draw a couple mock-ups of the design first.
It can be really tempting to design the 3D model first,
and then consider all the aesthetic stuff later.
But then, like, the result every time I do that is so atrocious.
I made the design really rounded and oversized,
drawing inspiration from these really cutesy characters.
It also improves performance.
Hold on, you just said it improves performance?
Going back to the inverted pendulum concept,
a higher centre of mass actually improves the stability.
This is because it creates a larger mean of inertia,
which slows down the falling motion.
This is why it's easier to balance a long pencil in your finger
than it is to balance a short pencil in your finger.
So, having a big-ass head with the battery at the highest point we can,
and also big-ass wheels to height max,
will raise the centre of mass.
Also, if you couldn't tell,
this robot is heavily inspired by the Robonix logo.
Everything here can be 3D printed with PLA plastic,
except for these side panels and the tyres.
The tyres need traction,
so I'm printing them using flexible 85A TPU plastic.
These side plates can be 3D printed,
however, I want to manufacture them out of aluminium.
They serve as the main structural plates of the robot,
and I know that this robot will be falling down a lot in the testing phase,
so having a material that isn't as brittle as plastic is preferred.
The only issue is that I don't have any machines
that can manufacture plates like these,
plus all these online vendors are pretty expensive.
But, here's a neat trick to get aluminium plates cheap as heck.
You order them through a PCB vendor,
but don't put any PCB on them.
So, you basically make an empty PCB and submit it to JLC's website.
Then, you click on aluminium,
and it's only $8 for 5 aluminium plates.
Brother, that is nuts!
And even better, they give you $60 worth of coupons if you sign up.
So, um, first link?
Yeah, let's get building.
Yo, that was a fire build montage.
Now, let's learn about the control algorithm.
This is the Robonix self-balancing robot.
In my opinion, it's pretty cute and pretty cool.
But aesthetics aside, this self-balancing robot does self-balance.
And it's slightly more complicated than just
if tilting this way, then move this way.
But if tilting the other way, then move the other way.
It uses something called a PID algorithm, which looks like this.
What the hell is that?
Trust me, it's pretty simple.
It consists of three parts.
P plus I plus D.
P stands for proportional.
The greater the tilt, the faster the wheels will turn.
By itself, you'll get a self-balancing robot.
However, it won't stand completely still.
I stands for integral.
The longer it's been tilted, the faster the wheels will turn.
By itself, it'll work, but you won't be able to respond to fast changes in tilt.
D stands for derivative.
The faster the tilt changes, the faster the wheels will turn.
This will not work by itself, as the D just helps to smooth out the P and the I.
But combine them all together, and you'll get something pretty sick.
Yep, that's the self-balancing robot.
It self-balances.
And honestly, that's all it does.
Let's face it.
It's cool for like five seconds, and then it gets kind of dry.
Which is why I have one more thing.
This is the robot controller.
It's got two joysticks and four switches,
allowing you to control this robot and program all sorts of moves.
It uses an ESP32, which allows it to communicate wirelessly to the robot with the ESPNOW protocol.
Once we turn both devices on, they instantly pair.
And the up and down controls the forward and backward lean.
And the left and right rotates the robot clockwise or counterclockwise.
If I hit this switch, it'll change the eyes to love heart.
And you know what?
I actually haven't programmed the other switches.
But you can, because I've made the 3D model, code, PCBs,
and documentation for both the robot and the controller free in the Robotica Academy.
It's a platform for the community,
and it has everything you need to upskill as fast as possible.
Online video courses, weekly design review sessions, and a forum to chat.
So click the second link in the description to join for free.
See you there, and I appreciate you for watching.
