Raspberry Pi Cam Tank V1.0

93,421

544

45

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!

Intro: Raspberry Pi Cam Tank V1.0

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!

Share

Recommendations

  • Metalworking Contest

    Metalworking Contest
  • Audio Contest 2018

    Audio Contest 2018
  • Fix It! Contest

    Fix It! Contest

45 Discussions

0
None
ValeriyM

1 year ago

where can i find 3d models files for this tank?

0
None
AlexanderK139

1 year ago

Hello, I've been attempting to create a similar vehicle with arduino
but I've run into an issue with the canon portion of the build,
particularly the enclosure for all the moving parts. Do you happen to
have any tips for modeling the gun enclosure on the tank? Thank you in
advance

0
None
datenkrieger

1 year ago

Hi, I started with the installation on the Pi but it seems that RPIO doesn't support the Pi 2. Not sure if I can control servos with RPi.GPIO, any ideas?

2 replies
0
None
Friedlcdatenkrieger

Reply 1 year ago

Hi datenkrieger, I realized this issue lately, too.

I have to look around for alternatives and I found this helpful: http://rpi.science.uoit.ca/lab/servo/

Good luck!

0
None
datenkriegerFriedlc

Reply 1 year ago

I found the pigpio library, it should work better with less servo jitter because it uses hardware timing for the pwm

http://abyz.co.uk/rpi/pigpio/python.html#stop

0
None
Gaffkjn

2 years ago

Hi Friedlc, awesome project. I enjoyed it immensely. Can you provide more detail for the shooting hardware. Specifically, I,m interested in HW you created around the two stage plunger system.

Thanks,

JG

Thanks

3 replies
0
None
FriedlcGaffkjn

Reply 2 years ago

Hi Gaffkjn, you can find it here:

https://www.amazon.com/Soft-Air-Stryke-Electric-Airsoft/dp/B006SRZWO8/ref=sr_1_1?ie=UTF8&qid=1391477491&sr=8-1&keywords=automatic+airsoft+cyber+s

0
None
FriedlcGaffkjn

Reply 2 years ago

Hi Gaffkjn, you can find it here:

https://www.amazon.com/Soft-Air-Stryke-Electric-Airsoft/dp/B006SRZWO8/ref=sr_1_1?ie=UTF8&qid=1391477491&sr=8-1&keywords=automatic+airsoft+cyber+s

0
None
FriedlcGaffkjn

Reply 2 years ago

Hi Gaffkjn, you can find it here:

https://www.amazon.com/Soft-Air-Stryke-Electric-Airsoft/dp/B006SRZWO8/ref=sr_1_1?ie=UTF8&qid=1391477491&sr=8-1&keywords=automatic+airsoft+cyber+s

0
None
22181

2 years ago

Dude, that's so cool

0
None
Joey18brindle

2 years ago

And you can control it via wife from you phone!?! Wow wish my wife coukd do things like that!

0
None
carter54

3 years ago on Introduction

I really wanted to make this work as I have all the materials. But it is the wiring that stumped me. How to wire up the raspi to the controller to the motors on the breadboard. Tried to see if I could work it from the photo but no luck - can anyone point me to a diagram?

0
None
ghostlightcf

3 years ago on Step 3

Amazing build! Can you put up the 3D models for the whole turret assembly on thingiverse please? I have the exact same gun for a very similar project and I am having issues modelling it myself.

0
None

Good work! This is a great project, I stumbled upon it in my search for how to control an airsoft gun with Raspberry Pi since I'm doing a somewhat similar project. I don't quite understand HOW the Raspberry Pi controls the firing of the gun though, could you give me a little more detail please?

2 replies
0
None
Friedlcthegoatdoctor

Reply 4 years ago on Introduction

Hi thanks! I was unable to control the gun electrically. I tried to connect the gun motor to the h-bridge or a mosfet. Both way didn't work. I think the gun motor just draws to much current for the h-bridge to handle, but it could be some error I made. In the videos I just plugged the gun directly to a 6v power source. A walk around is put another servo just pulling the trigger. You can take this instructable as reference. https://www.instructables.com/id/CS-Robot/

0
None
MattTuckFriedlc

Reply 3 years ago on Introduction

Why not use a relay switch then? have the switch open/close wired to the bridge, and the power source to the gun.... then you could open and close the switch via your bridge, and thus fire the gun on command

0
None
marios8543

4 years ago on Introduction

Dude like youre in my mind. I was thinking of making exactly the same thing but with rf and geared dc motors. Anyway that's great. In fact I'm making this right now.

0
None
webzter30

4 years ago on Introduction

I still can't get the html file to open so I can copy and paste it, even in the RAR file. Is their a trick to it?

thanks.

webzter

2 replies
0
None
Friedlcwebzter30

Reply 4 years ago on Introduction

Here's all the code

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="viewport" content = "height = 300, width = 580, user-scalable = no" />

<title>CamBot</title>

<script type="text/javascript" src="/webiopi.js"></script>

<script type="text/javascript">

function init() {

var button;

button = webiopi().createButton("bt_up", "/\\", go_forward, stop);

$("#up").append(button);

button = webiopi().createButton("gun_up", "/\\", servo_z_dim);

$("#gunup").append(button);

button = webiopi().createButton("bt_left", "<", turn_left);

$("#middle").append(button);

button = webiopi().createButton("bt_stop", "X", stop);

$("#middle").append(button);

button = webiopi().createButton("bt_right", ">", turn_right);

$("#middle").append(button);

button = webiopi().createButton("bt_down", "\\/", go_backward, stop);

$("#down").append(button);

button = webiopi().createButton("gun_down", "\\/", servo_z_aum);

$("#gundown").append(button);

button = webiopi().createButton("servo_y_dim", "LU", servo_y_dim);

$("#su").append(button);

button = webiopi().createButton("servo_x_dim", "RD", servo_x_dim);

$("#RD").append(button);

button = webiopi().createButton("servo_center", "0", servo_center);

$("#medio").append(button);

button = webiopi().createButton("servo_centerX", "R0", servo_centerX);

$("#R0").append(button);

button = webiopi().createButton("servo_centerY", "L0", servo_centerY);

$("#medioY").append(button);

button = webiopi().createButton("servo_x_aum", "RU", servo_x_aum);

$("#RU").append(button);

button = webiopi().createButton("servo_y_aum", "LD", servo_y_aum);

$("#giu").append(button);

button = webiopi().createButton("fire", "F", fire);

$("#fire").append(button);

button = webiopi().createButton("stop_fire", "S", stop_fire);

$("#stopfire").append(button);

}

function go_forward() {

webiopi().callMacro("go_forward");

}

function go_backward() {

webiopi().callMacro("go_backward");

}

function turn_right() {

webiopi().callMacro("turn_right");

}

function turn_left() {

webiopi().callMacro("turn_left");

}

function stop() {

webiopi().callMacro("stop");

}

function servo_y_aum() {

webiopi().callMacro("servo_y_aum");

}

function servo_y_dim() {

webiopi().callMacro("servo_y_dim");

}

function servo_x_aum() {

webiopi().callMacro("servo_x_aum");

}

function servo_x_dim() {

webiopi().callMacro("servo_x_dim");

}

function servo_z_aum() {

webiopi().callMacro("servo_z_aum");

}

function servo_z_dim() {

webiopi().callMacro("servo_z_dim");

}

function servo_center() {

webiopi().callMacro("servo_center");

}

function servo_centerX() {

webiopi().callMacro("servo_centerX");

}

function servo_centerY() {

webiopi().callMacro("servo_centerY");

}

function fire() {

webiopi().callMacro("fire");

}

function stop_fire() {

webiopi().callMacro("stop_fire");

}

webiopi().ready(init);

</script>

<style type="text/css">

button {

margin: 5px 5px 5px 5px;

width: 50px;

height: 30px;

font-size: 18pt;

font-weight: bold;

color: black;

background-color:yellow;

}

input[type="range"] {

display: block;

width: 160px;

height: 45px;

}

img{

width:320px;

height:240px;

margin-left:10px;

left:115px;

top:0px;

}

</style>

</head>

<body>

<table width=550px>

<td>

<div id="su"></div>

<div id="medioY"></div>

<div id="giu"></div>

</td>

<td>

<div id="RU"></div>

<div id="R0"></div>

<div id="RD"></div>

</td>

<td id="spacing">

<img src="http://raspberrypi:8001/?action=stream" width="320" align="center">

<div id="middle" align="center"></div>

</td>

<td>

<div id="content" align="center">

<div id="gunup"></div>

<div id="gundown"></div>

<div id="fire"></div>

<div id="stopfire"></div>

</div>

</td>

</body>

</html>