Editor’s note: This build diary is condensed into project steps below. Read on to build your own!
After seeing the first trailer for Star Wars Episode VII, I knew what my next robotics project had to be. I wanted to build a working, full-size BB-8.
I started by figuring out how I thought BB-8 would work and I decided that I would make two robots. One robot would rest on the top of the ball and its job is just to stay on the top and not fall off. A second robot would be inside the ball moving around and rolling the ball.
I worked on this project from early June to late August of 2015. Everything in this project was new to me. I needed to learn about a new development platform, learn how to program with different motors, figure out how to wire up sensors, learn a new language, and many more things. I felt well prepared for this challenge because of my previous experience with Lego NXT robotics and electronics. I had so much fun! Each step provided a new challenge.
This project also taught me so many new things about robotics, such as building and designing the frame, using sensors and the Kalman filter to determine position, pros and cons of different programming languages, how to choose batteries, PID controllers, stepper motors, and much more. I have learned a great deal and I plan to continue improving my droid and learning more about robotics.
Choosing the Parts
The two robots that make up my BB-8 needed three omniwheels to allow them to move in any direction. The wheels would need to be mounted at an angle to allow them to make good contact with the ball.
I needed to choose a development platform. My dad’s coworker lent me a BeagleBone Black to check out and to see if it was something I wanted to use. The BeagleBone Black is a low-cost single board computer with many connectivity options making it great for robotics.
After choosing the BeagleBone Black as a platform, I needed to choose motors. I decided on stepper motors, which allow for precise movement, called steps, and hold their position when stationary. From there, things fell into place. I needed motor drivers and a set of sensors to determine the robot’s position. For the set of sensors, I choose a 10-axis inertial measurement unit.
Wiring the Electronics
My parts arrived and the first step was to solder the headers onto the motor driver breakout board. Then I was ready to wire up the board to my new BeagleBone Black and the stepper motor.
The next step was to get all three motors to spin. I soldered the headers to the rest of the boards and realized that I needed a bigger breadboard. I wired up the motors to the BeagleBone Black and started programming.
My program was able to run the stepper motors at full step and half step. I was happy to get the motors to half step because that meant that I would have better precision movements of my robot. The bigger breadboard was too big to fit in the robot so I chose to use four smaller breadboards that I attached together in a square. This allowed the wires from the bottom of the breadboard to be fed up through the hole in the middle of the breadboards and the wiring was very compact.
Designing the Frame
I first designed the frame using SketchUp and Omnigraffle. Then I tested it by cutting the pieces out of cardboard and using hot glue and screws to attach the pieces together.
Since one robot was going to be inside the ball and one on top, the wheel and motor assembly had to be positioned perpendicular to the surfaces of the ball. I didn’t know the correct angle ahead of time and could not measure it until I had made a frame and installed the wheels. I decided to allow the wheels to tilt into whatever position they needed to make good contact with the ball. Allowing the motors to tilt also allows the robot to drive on level surfaces for testing.
After I had settled on a design that I liked, I chose the material I would use to make the final robot. I wanted to see all of the wire and motors so I used .093″ sheets of acrylic to build the frame. I stuck the template onto the acrylic with a glue stick. Then I cut the pieces out on the bandsaw and drilled the holes.
Assembling the Frame
When all of the parts were cut out, it was time to glue them together. I used Loctite 2 part plastic glue. This glue melts the plastic and fuses the two pieces together. Once the pieces were glued, I attached the separate pieces of the frame together with the screws.
Once the frame was assembled I attached the motors, then the wheels. Next it was time to measure the angle of the wheels so that they could make good contact with the inside and outside of the ball. I marked the positions of the screws and drilled the holes.
The next step in assembly was to attach the electronics. I put colored hubcaps on the wheels and used those colors throughout my robot. The blue motor had wires wrapped with blue shrink tubing, and it attached to a blue breadboard, with wires going up to the BeagleBone Black that were kept together with more blue tubing. I did the same process for all of the motors and carefully wired up the robot. The colors allowed me to quickly find and fix any electrical problems and they helped with programming. I attached the BeagleBone Black onto the top of the robot with foam tape.
I was almost done with the frame of the robot. I still needed batteries to power the motors and the BeagleBone Black separately.
The BeagleBone Black only needs 5V and 1A, so I chose to use a cellphone charger with the same dimensions of the BeagleBone Black. The batteries for the motors were harder to find.
I first went to Batteries Plus to see if they had any 6–12 volt batteries that could supply 1A, had around 2 amp-hours of capacity, and that could fit in the tiny space in the bottom of my robot. It was then that I realized that I should have designed the robot with the batteries in mind.
I ended up trying CR123 batteries, which are used in cameras. They are 3V, so with three batteries in series, and two groups of series wired in parallel, I figured that they would give me the right amount of power and run time. But after testing different configurations, I ended up putting a battery pack containing two batteries in parallel in each of the three sides of the robot. I then wired the three battery packs in series to give 9.7V and 1A.
The batteries did not have the run time I wanted, so I needed a new plan. I bought two USB battery packs used for charging cell phones. They delivered 5V at 1A and claimed to have 2,600 milliamp-hours. I thought that these batteries would be great. They should power the robot for around 2 hours and they were pretty inexpensive.
I found out that they do not have 2,600 milliamp-hours as they only lasted about half an hour in the robot. I bought four of them — two for each robot — but two could not hold a charge and were totally dead. It turns out they were not very high quality batteries. I bought two more expensive batteries and am hoping they last longer. I also decided to power the robot from a wall adapter during testing. The wall adapter delivered 9V and could supply 2.5A, plenty for the motors.
Building BB-8’s Body
Now that I had the robot part done, I needed the ball for the robots to go into and to balance on. My first idea was to cover a playground ball with papier mâché 1 inch thick on all sides. I planned to cut the ball in half and think of some way to make the two halves lock together, and then come apart when twisted in order to remove the robot. After the first layer of papier mâché, I realized that this plan would take far too long.
In a video I had seen of another BB-8 build, the Maker mentioned that he used a hollow styrofoam ball that came in two parts that locked together. This was a very good idea and much faster than the papier mâché plan so, I decided to order some styrofoam balls online.
It turns out that very few of these balls are made in the U.S., so I had to order a 50cm diameter ball from the U.K. The head is also a sphere, so I ordered a smaller 30cm diameter ball as well. I wanted to paint the designs on the ball to make my robot look as true to the trailer as possible. I decided that gesso, a paste that is typically brushed onto canvases to prepare them for paint, would help the paint stick to the styrofoam and provide a little protection to the ball.
I applied two coats of gesso and let them properly dry. I made the designs on the ball and the head using templates I found online and the video of BB-8 on stage at the Anaheim Star Wars Celebration. I traced the outlines of the shapes onto the ball and then painted the surface. I used acrylic paint and mixed the colors to match BB-8 as closely as possible. I dipped a Lego piece in paint and used it for the bolt marks around the ball. I made the eyepiece from a plastic Christmas ornament painted black.
For a robot to balance well it needs at least two sensors to help it know when it is falling: an accelerometer and a gyroscope. The accelerometer measures the forces acting on the robot including the movement of the robot.
The accelerometer is very noisy, meaning it does not give very precise data, and is affected by the movement of the robot; however, the accelerometer always knows which way is up. The gyroscope measures the angular velocity of the robot. It is very precise, but it only measures the angular velocity and not pitch and roll.
At first I thought that I would only need one of these sensors to have the robot balance, however neither one is very good alone. The gyroscope cannot be used to make a reliable balancing robot because it does not know when it is level. The angular velocity could be measured over a short period of time and be converted into a distance traveled and all of the distances be added up over time, but the gyroscope would start to drift and the longer the program would run the more the tiny errors in the calculation would add up and eventually the robot would fall off. The accelerometer would work for a longer period of time but it would be very imprecise and the robot would quickly fall off the ball. To make a good balancing robot the values from the accelerometer and gyroscope have to be combined.
The best way to combine the data is by using a Kalman filter. I have tried other kinds of filters and have seen that this one gives the most accurate results. The Kalman filter takes the gyroscope and accelerometer values and calculates the amount of trust each one deserves. It can change the amount of trust while running and gives a much more accurate reading that the complementary filter. Once the pitch and roll are calculated by the Kalman filter the robot takes the arctangent of the two values to find the driving angle.
The robot also needs to know how fast to go. If it’s near the center of the ball it should move slower than when it’s about to fall off. The best way to calculate the speed is to use a PID (Proportional Integral Derivative) controller, which lets the robot act in proportion to the distance from the center while keeping it from going too far and allowing the robot to react quickly to any sudden changes.
The driving angle and the driving speed are given to the robot which can calculate how fast each of the omniwheels should turn to achieve the desired direction and speed. The motor controller program turns the speed of the wheels into electrical signals that are given to the motor controller breakout boards to turn the motor.
To move the wheels, I started with a full-step implementation. I then did half-steps to gain finer control. But even half- steps resulted in poor motion, so I used pulse-width modulation (PWM) to control the amount of power going to each coil. Using sine and cosine to determine the correct values, I was able to implement smooth motion with microsteps.
You can find a repository of all my Python code for BB-8 on GitHub.
The Kalman filter did a great job of correcting the limitations of the gyroscope and accelerometer by combining the values. This, together with the PID controller, does an amazing job of balancing the robot on top of the ball. The robot inside the ball provides stability, preventing sudden motions. The design seems good and I plan on refining the PID controller to improve the responsiveness. I want it to be able to respond quickly enough to stay on top as the ball rolls. I also want to have the head able to turn and nod while balancing. This will allow BB-8 to communicate with simple actions.
I entered and demonstrated this project through 4-H, winning the top awards at the Dakota County Fair and Minnesota State Fair. Below, you’ll find a condensed, step-by-step breakdown of how to replicate my BB-8 design.