Introduction: Raspberry Pi Cam Tank V1.0

About: A Interaction Designer with Industrial Design and EE background. Maker since a kid. Super grateful to new technology and online communities made everything possible!

I love tanks since as a little kid. Building my own tank toy is always one of my dreams. But due to the lack of knowledge and skills. Dream is just a dream.

After years of study in engineering and industrial design. I acquired skills and knowledge. And thanks to the cheaper hobby 3D printers. I can finally take my step.

What features I want this tank to have?

  • Remote controlled
  • Suspensioned idle wheels(like the real tank!)
  • Has a rotatable turret and a tilting BB gun can shoot 6mm bullets
  • Can stream video to the controller so you can control it far away

In the beginning I planed to use arduino as controller, but after some research I found there's no practical way to stream video by itself. However, Raspberry Pi seems to be a good candidate for streaming video. And you can control it via wife from you phone!

Let's get started.

Step 1: Parts Needed

For controlling

Raspberry Pi version B

Powered Usb hub(Belkin F4u040)

USB webcam(Logitech C270)

Wifi dongle(Edimax)

Female to male jumper cable

For driving

Two high torque continues servo or motor(for two drive wheels)

One 1/8" steel rode for wheel shafts(bought at home depot and inexpensive )

Ten sleeve bearings (ordered on Mcmaster)

Some springs for suspension(bought a spring assortment at Harbor Freight, inexpensive)

For turret

A automatic BB gun toy

One high torque mini DC motor

A micro servo for tilting up and down

Some 1/4" steel rode as gun axle

Other stuff

I 3D printed most of parts of this tank, if you have easy access to a laser cutter, that would work too.

I used PLA filament for printing because it is easier to deal with(no wrap issues on ABS). But, really hard to sand, cut, drill later.

You might think 3D printing is good for customized parts and you can print very complicated part as one piece. That is true. However, I think that way is not practical and economical for a hobbyist. Reasons are:

Your hobby printer won't be that precise.

You will make mistakes in measurement and calculations(tolerance, alignment etc).

Anyway, there's a pretty high chance your prints do not work or fit on your first shot. It's fine for a small part, you can just change the model then reprint. But for a bigger and more complicated part, it is frustrating to know something's wrong after hours of printing. It's a waste of time and material. So here's my approach:

For anything is symmetrical, print only half of it, try it out, if everything works fine, print the whole thing.

Modeling the part while thinking about 3D printing. Could there be a flat surface to attach the printer bed?Could it be split into smaller pieces to avoid a lot supporting structure?

For parts have many features(interacting with many other parts), split the model into modules. So if one feature failed, you don't have reprint the whole part. Just tweak the module and reprint that. I use screws and nuts to connect them.

Be a good friend with hand tools, hand saw, X-acto, power drill, hot glue gun. If you can fix a mistake print, fix it.

This explains why my tank has so many parts. I am still tweaking those parts and once I found a good combination, I can print them together as one piece. Then that would be my Cam Tank v2.0.

Step 2: The Driving System

Suspension

At first I made a prototype without any suspension, just axles across the lower hull with bearings and wheels. But thinking of the operator's comfort(I gonna drive it watching the streaming video!), I decided to add suspension to make it cooler.

All I have are some coil springs, no hydraulic, no leaf spring. I experimented some torsion bar mechanism with PLA at first. (Torsion bar suspension is common on some tanks). Turns out after a couple twist, the printed PLA bar would get soft and eventually break. ABS might be better for this purpose but I never tried. So, after further research, I found Christie suspension design , here's a short video shows how it works.

However, the christie suspension has so many small parts, and I have no confidence in my printer then. So I made some suspension like this.

(image)

This configuration occupies too much inner space. So I rotate the inner arm 90 degrees. Notice that the first and last wheel got a shorter

Rear tensioner

I thought when the tank running over some obstacles, idle wheels might move up and the track will lose tension. So I added some tensioner mechanism on the rear wheel. Basically it's two springs pushing the real axle all the time, exerting some force on it to tight the tracks.

Driving wheels and Tracks

I designed this caterpillar tracks and driving wheels in solidworks. I don't know much about mechanical engineering thus can not do the gear calculation. So I simulated parts in solidworks to see if it works before I hit the Print button. Each track is connected with some spare 3mm filament. It works pretty well with some sanding. But the track design has a flaw, the surface touching ground is too smooth that it is hard to grip. If I print it upside down, I could add some tread, but it will cost a lot supporting material because of the tooth. Future solutions: 1: print the tooth separately then glue them together. 2. Apply some rubber coating spray paint.

Then I printed the housing for servos and make sure the driving wheel can be attached to the servo arm with screws.

Step 3: Weapon System

This part is the most exciting for me. You can buy a camera tank toy. But I didn't find one toy combine camera and some weapon.

I bought this automatic airsoft gun toy for $9.99 on sale. (It's around 20 bucks now and I might try something cheaper later) And tear it down to understand the mechanism. I can totally cut the body and glue it to my tank. But I don't like the ugly looking half body. So I took some measurement and remodeled the mechanical part. From these pieces I learnt a lesson of 3D printing: you will always make mistake. It takes 5 prints to make every part fit, and a lot cutting, sanding and hot gluing to make it works perfect.

After every part from the toy gun move correctly in my replicated body, I printed four other parts to clamp the body. And added the tilting gear,BB bullet funnel and camera support. These parts are all screwed onto the gun body. Eventually they can be combined to at least two parts. But I think I am not ready yet.

On the turret base, I added a micro servo, for tilting, and a micro DC motor for rotation.

Then I started to test the gun, connect 4 AA batteries and it shoots well. I was really happy that it works well. But the next day I found a problem.

Here's the video of my gun testing. the turret was connected to a 3v adapter.

Step 4: Setup the Pi

This is the most important part, the heart of our tank--Raspberry Pi!

If you have't played Raspberry Pi yet. I recommend to start with this book: Getting started with raspberry pi by MAKE.You can get the basics and a comprehensive understanding of Pi.

Get the latest raspbian OS.

The next tool I recommend a lot is the Remote Desktop. Here's the tutorial by Adam Riley. After you set up, you can view Pi desktop on you PC(not tested on Mac). Thus to run the Pi "naked", means no need for a display,mouse and keyboard. Some of my friends are using ssh command line. But I prefer the desktop.

Based on previous research, I knew Raspberry Pi is capable to stream video. So I started to mess around with different apps on the Pi. Many of the apps either has a long lag(seconds) or has a low frame rate. After couple weeks of wandering on online videos and tutorials, luckily I found the solution. A video on youtube about webiopi gave me a lot hope. More research made me believe this is the right way to go.

Webiopi is a framework that made connection between Pi and other internet device really easy. It controls all the Pi GPIOS and then start a server contains customized html. You can gain access to this html from other devices(computer, smart phone, etc), and click a button in the browser in a wifi distance, a GPIO is triggered.

The video made me full of hope, is based on a webiopi tutorial--cambot project. It is featured on the MagPi magzine #9[html][pdf] and #10[html][pdf]. Thanks Eric PTAK!

By following the tutorial step by step, you can make to two wheel cambot! Here's how it works: connect two motor with a H-bridge, then control the H-bridge with 6 GPIO pins to control direction and speed. Webiopi is used to control the GPIOs. And MJPG-streamer is used for streaming video.

If you are new to the Pi or Linux as I was months ago, you may have a little problem after following all the steps. You can run the python code for webiopi and the streaming video separately but don't know how to run them together? It took me a while to know you can add a & after a command(& is really hard to search on google, BTW), that means you want this command run on the background. So I will do this every time:

sudo python cambot.py&

sudo ./stream.sh

I believe you create a bash file containing above command into one file, and run once. I haven't tried yet.

So I tried this basic setup with two DC motor, it runs, but the motor I have is not powerful enough. Leads me to another option: continuous servos.

New question comes then: is webiopi supporting PWM controlled servos?

The answer is yes, but not by its self: RPIO is needed to generate software PWM

RPIO installation(I have no luck on the first apt-get install method. The github method works great for me)

Sample code and other discussions

Now your bot is upgraded with two servos! Think about what you can do with the extra arms!

I modified the above sample code to fit my tank. You don't need a computer science degree to do this. You are good as long you can understand the sample code and know what to copy and where to change.

Step 5: Electronic Connection

The power bank I bought, Anker Astro Pro, has two usb ports and one 9v port(main reason I bought this one). I tried to power the the Pi, wifi dongle and webcam with one usb port. Does not start up. So I used the other USB port for a powered USB hub.

Then I thought maybe I could power the servos with the USB hub port. It works, but the wifi connection is very very unstable.

To solve this problem, I brought in 4 AA battery to power the 6V servo needs. I striped the USB cable to expose the ground wire(black) and connect with the AA battery pack ground.

3 servos, red to 6V, black to ground, and signal pin connected to GPIO pins.

As planed, the turret rotating motor and gun motor should also powered by 6V with a H-bridge controlling. But when I connected everything, the gun won't shoot! It seems the motor is trying to rotate, but can't drive the gears. The output voltage is right, but seems there is no enough current to drive. I also tried MOSFET with no luck.

I have to give up this part for time reasons. And this is why in the gun test I have to connect the gun motor to adapter manually. Still a lot to learn in electronics. The worst case scenario, I could always control the gun with a servo pull and release trigger.

Step 6: Interface

I also altered the interfaces from the cambot and rasprover sample codes. Since I planned to use smart phone as controller, I optimized the layout for my phone(galaxy note3).

Most of the layouts and styles can be edited in the index.html. However the default button(dark grey with black border) style is defined in the webiopi.css located at /usr/share/webiopi/htdocs. I used terminal to run sudo nano in order to modified it.

The video stream is located in the center of screen, driving control on the left side, and weapon control on the right. I designed the driving control as two set of up(forward), stop, down(backward) wanting some finer control, but in the video you can tell it is awkward sometimes.

Step 7: Future Plan

As you can tell, this is project is not finished yet. Thanks to the raspberry pi contest, I cranked up a lot in last week, just trying to finish it before deadline. It turns pretty well until I found the gun's not shooting...

It has a lot more to be improved, but I hope you can learn something from my experience.

Short Term Plan:

Make the gun work!!!

Bigger container for more BB

The tank need to explore the world--go out side of home wifi!

Set up ad-hoc node on Pi, so the phone can connect to it anywhere

Run the tank command at start up

Add a shut down button to turn off Pi safely.

Long Term Plan:

Better driving system for stability and grip

Design my own circuit board instead of a breadboard now

First person video recording

Another gun? Let's make it a battle ship!

Add sensors for self patrolling?

Computer vision for auto targeting!

Control the tank far far away: I'll see everything at home!

Step 8: Thanks for Reading!

Thanks for reading my poor English(it's not my first language). I hope you had some fun or learnt something here. This will be an on-going project, so if you have expertise in any field, I appreciate your advise.

If you have any questions, please leave a comment, I'll try my best to answer it.

Let me make a update--The Cam Tank2.0-- in the near future.

At last, here's a video showing the battle scenario. It's quite amusing.

Enjoy and see you next time!

Raspberry Pi Contest

Participated in the
Raspberry Pi Contest