Ball Balancing Robot

Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

instructables

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

Other supplies ($83)


25T servo disc (x 6)
m3 x 120mm pushrod connector (x6)
22mm long m3 tie rod (x12)

Ball Balancing Robot: Page 1


m3 x 6mm threaded inserts (x36)
m3 x 10mm stando s (x3)
m3 x 5mm stando s (x14)
m3 locknuts (x24)
3/4 x 48-inch wooden dowel
#6 x 1-1/4 inch wood screws (x4)
M3 Screws
m3 x 5mm (x24)
m3 x 10mm (x2)
m3 x 12mm (x18)
m3 x 14mm (x6)
m3 x 15mm (x4)
m3 x 20mm button head (x3)
m3 x 22mm (x6)
m3 x 30mm (x3)

Ball Balancing Robot: Page 2


Ball Balancing Robot: Page 3
https://youtu.be/kAaYaZcpbLo

Step 1: Make the Platform

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.

Ball Balancing Robot: Page 4


Download

https://www.instructables.com/FPJ/MJA7/LCDDVDXY/FPJMJA7LCDDVDXY.dxf

Download

https://www.instructables.com/FC9/WYI4/LCDDVCNC/FC9WYI4LCDDVCNC.pdf

Step 2: 3D Print the Parts

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.

Ball Balancing Robot: Page 5


https://www.instructables.comhttps://a360.co/3vtVD5k

Ball Balancing Robot: Page 6


View in 3D Download

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

Step 3: Assemble the Ball

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.

Ball Balancing Robot: Page 7


Ball Balancing Robot: Page 8
Step 4: Add Inserts to the Printed Parts

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.

Ball Balancing Robot: Page 9


Ball Balancing Robot: Page 10
Ball Balancing Robot: Page 11
Step 5: Teensy 4.1

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.

Ball Balancing Robot: Page 12


More information on the teensy 4.1 microcontroller can be found here.
Note: The teensy will not receive 7.4V from the battery because this is too high. The teensy will receive 5V. It will
get this 5V from the polulu maestro (more on this in the next step).

Ball Balancing Robot: Page 13


Ball Balancing Robot: Page 14
Ball Balancing Robot: Page 15
Step 6: Polulu Maestro

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

Ball Balancing Robot: Page 16


These settings are shown in Image #4
Next, we will modify the maestro by soldering a wire connecting VIN to servo power (+). These pins are labeled in Image
#3 and the soldered wire is shown in Image #2. This connection allows the servos and the maestro board to be powered
by the 7.4V battery.
For more information on the 6-channel polulu maestro go here.

Ball Balancing Robot: Page 17


Ball Balancing Robot: Page 18
Ball Balancing Robot: Page 19
Step 7: Pixy 2 Camera

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.

Ball Balancing Robot: Page 20


Ball Balancing Robot: Page 21
Ball Balancing Robot: Page 22
Step 8: Create the Circuit

Now let's create the full circuit.


Electronic components needed:
Modi ed Teensy 4.1 microcontroller
Modi ed 6-pin Polulu Maestro servo controller
Pixy2 camera
3.3 to 5v logic level converter
half proto board
Switch

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.

Creating the Circuit

Ball Balancing Robot: Page 23


Creating the Circuit is as simple as following the schematic shown in Image#3 (also available in PDF form below). You will
want to solder the teensy 4.1 and the LLC onto the protoboard. The maestro and the pixy will be external components
that connect to the teensy through wires.
Tips for making the circuit
Use header pins to allow the electronics to be removable.
Use heat shrink tubing to insulate the wires.
Have a multimeter handy to test connectivity to ensure that correct connections are made.
I found it best to use servo extension cables to connect a bunch of the electronics. Allowing for plug-and-
play action makes things easily removable. This is helpful when things don't work as expected.
Image #2 shows the switch wiring used. The switch turns the robot on and o by completing the circuit
on one lead of the battery. Use the XT60H female connector to connect to the switch. This way, the 7.4V
lipo battery can be plugged and unplugged.
The ground pins on all of the components should be connected together. This is known as common
ground. You can con rm this with a multimeter by checking connectivity.

Ball Balancing Robot: Page 24


Ball Balancing Robot: Page 25
Download

https://www.instructables.com/F0T/5DY7/LCDDWV49/F0T5DY7LCDDWV49.pdf

Step 9: Assemble the Base

To assemble the base of the robot you will need:


The 6 servos
The base plate
The pixy2 bottom mount
m3 x 5mm screws (x8)

Ball Balancing Robot: Page 26


m3 x 15mm screws (x4)
Start by using the m3 x 15mm screws to mount the pixy2 bottom onto two of the servos and then to the
front of the base plate (the front of the robot is labeled in Image #1, Image #2, and Image #3).
You will then want to screw the remaining 4 servos onto the other sides of the base plate using the m3 x
5mm screws.
Next, screw the half protoboard onto the top of the base plate. You will need to remove the teensy 4.1
and LLC to get access to the holes on the protoboard to screw the board on (this is why I recommend
using header pins).
Hot glue the polulu maestro onto the base plate.
Finally, you will want to connect the 6 servos to the 6 channels on the maestro. The order is important
and is labeled on Image #1, Image #2, and Image #3. The servos must be connected to the speci ed
channel on the maestro.

Ball Balancing Robot: Page 27


Ball Balancing Robot: Page 28
Ball Balancing Robot: Page 29
Ball Balancing Robot: Page 30
Ball Balancing Robot: Page 31
Step 10: Cover the Base

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.

Ball Balancing Robot: Page 32


Ball Balancing Robot: Page 33
Ball Balancing Robot: Page 34
Ball Balancing Robot: Page 35
Step 11: Assemble the Servo Arms

Now we will assemble the servo arms. You will need:


link 1 (x6)
25T servo disc (x6)
m3 locknuts (x18)
m3 x 120mm pushrod connector (x6)
22mm long m3 tie rod (x12)
m3 x 12mm screws (x12)
m3 x 22mm screws (x6)
Start by screwing each 25T servo disc onto each 3D printed link using two locknuts and two m3 x 12mm
screws per disc as seen in Image #1 and Image #2.
Assemble the six tie rods by attaching two tie rod ends to each of the pushrod connectors as seen in
Image #3.
Screw on the other end of each of the six 3D printed links onto one of the ends of the tie rods using an
m3 x 22mm screw and a locknut for each link to form six servo arms. This is shown in Image #4 and
Image #5.

Ball Balancing Robot: Page 36


Ball Balancing Robot: Page 37
Ball Balancing Robot: Page 38
Ball Balancing Robot: Page 39
Step 12: Install Two Arduino Libraries

Before we continue with this build, we must install two Arduino Libraries:
A library for the pololu maestro
A library for the pixy2 camera

To learn how to install an Arduino library go here

Ball Balancing Robot: Page 40


Step 13: Mount the Servo Arms

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.

Fine-tuning servo positions


As you will notice when the servo arms are attached, they will not be perfectly perpendicular like in Image #4. They will
most likely look more like Image #3. To get these servo arms to be perfectly perpendicular, you will need to change the
o set value for each servo in the code.
In this section of the code, all of the o set values will originally be set to 0 as shown in Image #5. Go through each servo
and change the o set value from 0 to 5. See if the servo arm moves closer to being perpendicular.
If it does move closer to being perpendicular, ne-tune the position of the servo arm by going higher or
lower than 5 but still keeping the value positive. For example, if the servo arm needs to move closer to
being perpendicular you may change the value to 7.
If the servo moves farther away from being perpendicular, then make the o set value -5 and ne-tune
the value (while still keeping it negative) until the arm is completely perpendicular. Do this for all servos.
In the end, you will have an o set value for each servo as shown in Image #6.
None of the servos should exceed the range of o set values between -14 and 14.

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.

Ball Balancing Robot: Page 42


Ball Balancing Robot: Page 43
Ball Balancing Robot: Page 44
Ball Balancing Robot: Page 45
Download

https://www.instructables.com/FCS/MGTP/LCETD3PY/FCSMGTPLCETD3PY.ino

Step 14: Build the Platform

Let's build the platform using:


The polycarbonate platform
The platform frame
m3 x 20mm button head screws (x3)
m3 locknuts (x3)
m3 x 5mm stando s (x3)

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.

Ball Balancing Robot: Page 46


Ball Balancing Robot: Page 47
Step 15: Attach the Platform

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.

Ball Balancing Robot: Page 48


Ball Balancing Robot: Page 49
Ball Balancing Robot: Page 50
Ball Balancing Robot: Page 51
Step 16: Attach the Camera Mounts

Cut the 3/4" wooden dowel to 19" long.


Use #6 screws (x2) to screw the wooden dowel onto the pixy2 bottom mount.
Use #6 screws (x2) to screw the pixy2 top mount onto the other end of the wooden dowel.

Ball Balancing Robot: Page 52


Ball Balancing Robot: Page 53
Ball Balancing Robot: Page 54
Step 17: Attach the Pixy2 Camera

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.

Ball Balancing Robot: Page 55


Ball Balancing Robot: Page 56
Step 18: Teach the Pixy2 to Detect the Ball

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.

Ball Balancing Robot: Page 57


Step 19: Calibrate the Platform

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.

Ball Balancing Robot: Page 58


Ball Balancing Robot: Page 59
Ball Balancing Robot: Page 60
Download

https://www.instructables.com/FUO/4FMH/LCETD3SB/FUO4FMHLCETD3SB.ino

Step 20: Upload the Ball Balancing Sketch

This is the nal step in getting the ball-balancing robot to work.


First, download the ball-balancing Arduino code below.
Just like before, you will need to change the o set values of the servos. This section should look similar to
the last two programs as shown in Image #2.
Next change the origin and r_platform values that are set to 0 to the values that you found in the last
step. This section is shown in Image #3.
Now upload the code and you should see that robot balances the ball when the ball is placed on the
platform.
If the pixy cam sees more than one signature in the frame, the robot will go to its home position and not
move.
If the ball is in the frame, but not on the platform, the robot will go to its home position and not move.

Ball Balancing Robot: Page 61


Ball Balancing Robot: Page 62
Download

https://www.instructables.com/FU3/V2LT/LCETD3UI/FU3V2LTLCETD3UI.ino

Step 21: How This Works

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.

This is drawn in Image #4


So in order to balance, the ball the robot must take into account the location of the ball and the velocity of the ball at any
given moment. It then uses those values to simultaneously move the ball closer to the center of the platform and slow
the ball down.
If only the position of the ball is considered, then the robot will not be able to slow the ball down and the
ball would fall.
If only the velocity of the ball is considered, then the robot would not be able to move the ball closer to
the center of the platform and the ball would eventually fall.

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.

Ball Balancing Robot: Page 63


Optional: As shown in Image #5 you can change the kp and kd constants in the Ball Balance program to get di erent
levels of reactiveness from the robot. I discuss the e ects of increasing or lowering these values in my video.

Ball Balancing Robot: Page 64


Ball Balancing Robot: Page 65
https://youtu.be/NwRuQ7r6xLQ

Very interesting. A very good job, congratulations!!!!

thanks!

Wouaahhh amazing, wonderfull, crazy, exceptionnal :-0

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.

Very well explained and thanks for sharing!

no problem thanks!

Wow
Just fantastically brilliant
appreciate it!

This is awesome. Really well explained and documented. Thanks for your work.

sure thing, thanks!

Ball Balancing Robot: Page 66


Wow...Great work

thanks!

Brilliant instructable. Very nice work along with a great explanation.

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.

Great job on explaining it all.


Thanks

Excellent, well written and lucidly explained! Thanks for sharing.

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

Ball Balancing Robot: Page 67

You might also like