Ball Balancing Robot
Ball Balancing Robot
Ball Balancing Robot
by aaedmusa
In this instructable, I'll show you step-by-step how I created a ball-balancing robot. More formally known as a Stewart
platform, this robot has 6DOF robot is omni-rotational and omni-translational. With the addition of a camera, this Stewart
platform can be transformed into a robot that prevents a ball from falling. Let's begin!
Supplies:
Here is a list of the tools and parts needed for the build. For a more detailed overview of the supplies needed, download
the bill of material excel le here.
Tools
needle nose pliers
wire cutters
wire strippers
2.5mm allen wrench
soldering iron and solder
exacto knife
hot glue gun and hot glue
Parts ($483)
Electronics ($400)
JX CLS6336HV 35kg digital servo (x6)
Teensy 4.1
6 channel Polulu Maestro servo controller
Pixy2 Camera
3.3 to 5v logic level converter
half proto board + screw terminal
SPST switch
18 AWG wire
XT60H connector pair
2S (7.4v) 6200mah lipo battery
The ball rests on a clear 0.118" thick 8" x 8" polycarbonate platform. You will need to manufacture this platform. I do not
have access to a waterjet, so I used the waterjet service on the Andymark site. I have attached the dxf le below if you
take this route. Another option is to simply cut out an 8" x 8" platform from a sheet of polycarbonate and drill out all of
the holes. I have attached a pdf drawing of the platform below as well.
https://www.instructables.com/FPJ/MJA7/LCDDVDXY/FPJMJA7LCDDVDXY.dxf
Download
https://www.instructables.com/FC9/WYI4/LCDDVCNC/FC9WYI4LCDDVCNC.pdf
I designed this robot in Autodesk Inventor. There are 18 3D-printed parts in total. I printed all of these parts in PLA
lament. I have attached all of the STL les below. Keep in mind that some of the parts must be printed multiple times.
This number is speci ed in the le name. The color of the parts does not matter except for the ball and the center
markers. Those should be printed in red to be easily detected by the camera.
I'd recommend using the following printer settings:
20% in ll (except for the ball, I printed it at 100% in ll to be really heavy)
Auto-generated supports
PLA (210° extruder and 45° bed)
The total lament usage for all parts is about 183g. It took a cumulative 15 hours to print all of the parts.
https://www.instructables.com/FJZ/LKP3/LCDDVD2X/FJZLKP3LCDDVD2X.stl
View in 3D Download
https://www.instructables.com/FLI/19MZ/LCDDVD2Y/FLI19MZLCDDVD2Y.stl
View in 3D Download
https://www.instructables.com/FW7/R7C7/LCDDVD2Z/FW7R7C7LCDDVD2Z.stl
View in 3D Download
https://www.instructables.com/FI2/MMY3/LCDDVD30/FI2MMY3LCDDVD30.stl
View in 3D Download
https://www.instructables.com/FFX/WSE8/LCDDVD31/FFXWSE8LCDDVD31.stl
View in 3D Download
https://www.instructables.com/FJG/05SZ/LCDDVD32/FJG05SZLCDDVD32.stl
View in 3D Download
https://www.instructables.com/FSX/LRJB/LCDDVD33/FSXLRJBLCDDVD33.stl
View in 3D Download
https://www.instructables.com/FKG/9PTN/LCDDVD34/FKG9PTNLCDDVD34.stl
View in 3D Download
https://www.instructables.com/F2M/IK0E/LCDDVD35/F2MIK0ELCDDVD35.stl
The ball comes in three parts, the two hemispheres, and the middle connection piece. You simply need to squish all three
parts together to create the ball. If the t is too tight then sand the middle connecting piece. If the t becomes too loose,
then apply some super glue to hold it in.
7 out of the 18 parts need threaded inserts to be pressed into them. These inserts serve as threads for the screws to
screw into. You will need 36 inserts in total. The parts requiring these inserts are:
Image #1: platform frame (6 inserts)
Image #2: base plate (14 inserts)
Image #3: cover plate (12 inserts)
Image #4: 4 x center marker (1 insert each)
To press these inserts into the parts, use a heated soldering iron.
Now onto the heart of the project, the electronics! Creating the circuit correctly is vital to this project. The rst part in
making the circuit is to prepare the teensy 4.1 microcontroller. The teensy is the brain of the robot. All of the other
electronic components are connected to the teensy. We will be programming the teensy using the Arduino IDE. If you
have never used a teensy before, you will need to do one of two things to allow the Arduino software to support the
teensy.
If you are using Arduino version 2.0.0 or above you will need to follow the instructions here to allow
Arduino to support the teensy.
If you are using a version of Arduino below 2.0.0 you will need to download Teensyduino in order to allow
Arduino to support the teensy.
Once this is done, I recommend verifying that all is well by uploading the blink example sketch to the teensy.
After this, you will need to modify the teensy by cutting the VIN to USB trace on the back of the teensy. I point to where to
cut this trace in Image #2. It is also labeled on the diagram in Image #4. Doing this ensures that the teensy needs an
external power source to work. We want this done because we will be powering the teensy with the 7.4V battery. We
don't need the teensy to be powered by the computer when it is plugged in.
The 6 pin polulu maestro is what controls the servos. The servos connect to the maestro and the maestro connects to the
Teensy via the maestro's RX and TX pins (Teensy pins 1 and 0 respectively). The maestro is the only component that
connects directly to the 7.4V battery. The maestro has a 5V regulator that will be used to power the Teensy. In Image #1
you can see that I have soldered two wires (+5V and ground) to connect to the Teensy.
The rst thing we will need to do to the polulu maestro is to get it set up. You will need to download the maestro control
center software to verify/change two settings. Once you have downloaded the software and connected the maestro,
plug in one of the servos and move it around from the software to verify that the board works. Here is a good tutorial on
how to get set up with the maestro.
Once you have veri ed that the maestro works, you will need to verify/change 2 of the settings on the board. Go to the
tab titled Serial Settings and ensure that:
Serial mode is UART xed baud rate (9600)
CRC is Disabled
The pixy2 camera is what we will use for object detection. Nothing on the pixy needs to be modi ed, but you will need to
download Pixymon v2 in order to view the camera footage and set up an object to be detected. For now, all you need to
do with the pixy is to plug it into your computer and ensure that it works by viewing the footage on Pixymon. I would
also suggest testing the object recognition by setting up a random object to be detected. There are 2 methods to set up
object detection. I found that the manual method works.
Here are some useful resources for setting up the Pixy and getting it to recognize objects:
Setting up a Pixy and recognizing objects (starting at 14:00)
Improving Detection Accuracy
Note: When the circuit is set up in the next step the Pixy2 camera will not be powered by the 7.4V battery
because it draws too much power. Instead, the camera plugs into the computer via micro usb. In other words,
whenever you use the robot, the teensy, the polulu maestro, and the servos will be powered by the 7.4V battery,
and the camera will be powered by the computer.
So far we have discussed 3 of the 5 main electronics: the teensy 4.1, the polulu maestro, and the pixy2 camera. Here is a
brief explanations of the two remaining electronic components: the Logic Level Converter (LLC) and the Servos.
Logic Level Converter (LLC): Since the teensy 4.1 microcontroller uses a 3.3V logic level and the maestro
uses a 5V logic level, the Pololu maestro's RX and TX pins cannot be connected directly to the Teensy.
Instead, they must connect to the LLC (that steps down the logic level) which then connects to the
teensy.
Servos: The 6 servos connect to the 6 channels on the pololu maestro. The speci c channel in which each
servo connects is important! I'll discuss this in the next step. I speci cally chose the JX CLS6336HV servos
because they are high-speed. A fast reaction time is vital to this project.
https://www.instructables.com/F0T/5DY7/LCDDWV49/F0T5DY7LCDDWV49.pdf
Now we will cover the base of the robot. You will need:
The base from the previous step
m3 x 5mm screws (x12)
Hot glue the switch onto the cover plate
Using the m3 x 5mm screws, screw the cover plate onto the top part of each servo.
Before we continue with this build, we must install two Arduino Libraries:
A library for the pololu maestro
A library for the pixy2 camera
We will now mount the servo arms onto the servos. In order to do so we must rst upload an Arduino sketch that will
move all of the servos to their home location.
Make sure the battery is plugged in and the switch is turned on, then upload the Arduino sketch below to
the teensy. You should hear all the servos turn to their home positions.
Now screw on the servo arms (using m3 x 12mm screws (x6)) so that they are as close to being
perpendicular to the servos as shown in Image #4. Do this for all of the servos.
Note: Every time you change an o set value, reupload the sketch to see its e ects.
Make sure you save these o set values somewhere, you will need to change the o set values of two other programs
later.
Ball Balancing Robot: Page 41
Once this is done, every time this sketch is uploaded to the robot all of the arms should move to their home positions
and be perfectly perpendicular.
https://www.instructables.com/FCS/MGTP/LCETD3PY/FCSMGTPLCETD3PY.ino
Screw the polycarbonate platform onto the printed platform frame using the m3 x 20mm screws and the locknuts. Make
sure you add a 5mm stando on each screw in the space between the platform and the platform frame.
Now let's attach the platform to the main body of the robot. We will need:
m3 x 5mm stando s (x6)
m3 x 14mm screws (x6)
Attach each m3 x 14mm screw onto the end of each servo arm. Screw on each m3 x 5mm stando onto the other side of
the screw, then screw the servo arm onto the platform frame where the threaded inserts are.
Now attach the Pixy2 Camera onto the Pixy2 top mount using:
m3 x 30mm screws (x3)
m3 x 10mm stando s (x3)
m3 locknuts (x3)
Ensure that the pixy2 cam has a good view of the platform by viewing the footage on pixymon. When looking at the
camera footage, you should be able to see the entire platform. If not, adjust the placement of the top mount.
Let's now teach the pixy how to detect the ball. Just like in step 7, Refer to this video to learn how to teach the Pixy2 an
object (starting at 14:00). As a reminder, I recommend using the manual method. I also recommend placing the ball on
the platform when training the pixy since this is where the ball will be when that robot is trying to balance it. It doesn't
matter which signature you set the ball to be. For simplicity, I set mine to be signature #1. You may also need to change
the signature range as shown in Image #2. This setting changes the pixy's detection accuracy. More on this here.
In order for the ball balancing program to work properly, we must nd the location of the center of the platform from the
camera's view and another value called r_platform that will help determine when the ball is on the platform or not. To do
this we will use the red 3D-printed center markers.
First, attach each center marker onto each corner of the platform using m3 x 5mm screws (x4).
The pixy cam should recognize the center markers as the ball that we trained it to recognize in the
previous step. This is why the ball and the center markers should both be red. Ensure that the pixy cam
can recognize each center marker by viewing the camera footage on pixymon. Make sure you only see
four signatures for the four markers. If the pixy detects more or less than four signatures, this program will
not work.
Download the Arduino program below and change the o set values from 0 to the ones that you found in
step 13. This section will look similar to the section in step 13 as shown in Image #4.
Upload the sketch
The program will move each servo to its home position and then display some values on the serial
monitor (shown in Image #5). The rst value is the location of the center in the format (X, Y). The second
value is a single number labeled r_platform. Save these three values!
Note: The values will take about 30 secs to be displayed on the Serial monitor
Note: The location of the ball should be in the ballpark of (150, 100) and the r_platform value should be in the
ballpark of 113. I would give an error range of +/- 20 for all three of these values.
https://www.instructables.com/FUO/4FMH/LCETD3SB/FUO4FMHLCETD3SB.ino
https://www.instructables.com/FU3/V2LT/LCETD3UI/FU3V2LTLCETD3UI.ino
There are two main components to programming this robot: rotating the platform and balancing the ball. Being able to
rotate the platform in any direction is what allows the robot to balance the ball. So how does the robot accomplish these
tasks?
Rotating the platform:
To be able to rotate the platform anyway, the robot must use Inverse Kinematic equations. These equations take in an
input (how we wish the robot to be oriented) and output 6 values (the position for each servo to turn to). For example,
when we want the platform to be completely at, the robot calculates that all of the servos must move to their home
position. I derived all of these equations using vector calculus. You can see these equations in Image #1.
Balancing the Ball:
To be able to balance the ball the robot uses a PD algorithm where:
The set point is the center of the platform.
The error is the location of the ball relative to the center of the platform.
The derivative term is the velocity of the ball.
Once the robot determines the most e ective direction to angle the platform to slow the ball down and move it closer to
the center, it uses the inverse kinematic equations to determine what position to move the servos to get the platform to
move to that angled position.
thanks!
thanks!
Nice job!
I was just wondering why you use 6 servos instead of 3. Is that for speed, power or range of
motion?
Or even just 2 servos and 1 fixed support. Yes, I am cheap.... ;-)
It’s for range of motion. 6 servos means 6DOF (translation and rotation). 3 servos would mean
3DOF (just rotation). Technically 3DOF should do the job, but I wanted to explore the bots
translation abilities along with its rotation abilities. Also a 3 servo configuration is not possible with
this design. If you want it cheaper I’d recommend using cheaper servos and buying in bulk. The
ones I used are worthwhile but it won’t be detrimental to the project.
This is a FUN instructable!
What happens if I put my checkbook on the platform?
Doesn't matter. Since you spent all your money making the project, your checkbook is already
balanced at Zero. :-)
Haha! The price I showed is if you buy everything completely from scratch. I personally already
had a lot of the components so I didn't spend that much.
Any objects that isn't round won't work.
no problem thanks!
Wow
Just fantastically brilliant
appreciate it!
This is awesome. Really well explained and documented. Thanks for your work.
thanks!
would love to see this with a ping pong ball and pre-programed patterns added.
Figure 8
spiral
square
things similar to the sand tables etc
That would be cool. I might try doing that in a next version. I believe stepper motors (rather than
servos) would give the bot the smoothness to make such patterns.
We made one of these at work a few years ago. Nice and big to take to shows and events.
Thanks!
Great Instructable!!! Well documented and presented. Somebody is going to hire this young man
soon and when they do they will have a gold mine with his talent demonstrated here
I truly appreciate it !
Great work, wish I could be able to also come up with the algorithms needed :-)
Thanks! If you know basic calculus it's a lot easier than you think. This is a great tutorial
https://www.youtube.com/watch?v=dTGITLnYAY0&list=WL&index=14&t=412s