apostal
Posts: 6
Joined: Tue Apr 07, 2015 4:21 pm
Location: Minsk
Contact: Website

Raspberry Pi Tank

Fri Jul 10, 2015 7:05 pm

Hi,

I am big fan of Raspberry Pi project and have 4 Pi's at home for now.
In free time I am working on home project: Raspberry Pi Tank.
I would like to share it with you, collect some feedback and probably find some enthusiasts to collaborate.

Raspberry PI Tank (PiTank) is an open source project for controlling toy tank remotely using Raspberry Pi.
Pi is connected to tank hardware using GPIO. It controlls tank movements and tower rotation.
PiCamera is mounted on top of the tower and can be moved in vertical axis using servo.
Wi-Fi dongle is used to allow remote control.

To allow controlling GPIO remotely some server-side code was developed on Perl.
- Daemon that listens TCP/IP port and depending on received command changes some GPIO pin
- There are several backend that can send commands to this daemon:
Simplest one is telnet:). Control protocol is human readable and easy to explore(text based).
When using telnet I tried to make it CLI style.
The second backend is a perl script that continusly read keyboard presses and convert them into commands for daemon.
So tank can be controlled using well-known for gamers 'WASD' keys.

Addionally to that WebUI interface is developed on ruby (thanks to Artem Sheremet).
In WebUI you can see video streamed from camera and also control tanks using well-known 'WASD' keys or by pressing buttons on page.

And yeah, everything runs under Arch Linux.

This is how it looks right now:
Image

All code is on github:
1. Server-side code, listens to tcp/ip socket and generate GPIO pulses based on commands.
Writen by Pavel Bondar(me) on Perl:
https://github.com/bondar-pavel/rpi-tank

2. WebUI for PiTank, shows steamed video in browser, read user keypessed and transmit command via tcp/ip socket into Perl daemon.
Written by Artem Sheremet on Ruby(usingrack):
https://github.com/dotdoom/rpi-tank-rack

More info can be found here:
http://pitank.com/raspberry-pi-tank-info/

The first version looked:
Image

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Raspberry Pi Tank

Fri Jul 10, 2015 9:33 pm

Looks good!

Consider switching the Pi for a Model A+. It will be smaller and use less power and you only need 1 USB port for the dongle. It might mean you can go for a smaller battery.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

apostal
Posts: 6
Joined: Tue Apr 07, 2015 4:21 pm
Location: Minsk
Contact: Website

Re: Raspberry Pi Tank

Sat Jul 11, 2015 4:04 pm

Thanks! Switching to Model A+ sounds like a good idea.
How significantly it is better in terms of power consumption over Model B+?
I guess about twice(something like 200 mA vs 400mA), but not sure if these numbers are correct.

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: Raspberry Pi Tank

Sat Jul 11, 2015 8:47 pm

Alex Eames from raspi.tv did some measurements on this topic.
Image

By the way, I like the tank and the multiple control options. ;)

Laurens

User avatar
ssirois
Posts: 2
Joined: Sun Jul 12, 2015 9:56 pm
Location: Quebec City, Canada

Re: Raspberry Pi Tank

Sun Jul 12, 2015 10:09 pm

Hi,

I made some test lately for one of my project and I think you maybe interested by the result. I also use the model A+ and the average current draw with a WiFi dongle is around 350mA. The graph show from start (nice 686mA peak) to the idle state, waiting for a login. The jump in the middle is when the WiFi is activated.
wifi-dongle.png
wifi-dongle.png (42.06 KiB) Viewed 2709 times
You can see my others test here (Google Sheets) : https://docs.google.com/spreadsheets/d/ ... sp=sharing

Enjoy! Steve

apostal
Posts: 6
Joined: Tue Apr 07, 2015 4:21 pm
Location: Minsk
Contact: Website

Re: Raspberry Pi Tank

Mon Jul 13, 2015 12:49 pm

Wow! That is cool! Model A+ consumes almost 4x less power than model B.
Currenly I was using model B in PiTank, but already received model B+ and Pi 2 model B (using them for another purpose now).
And A+ is twice better over them in idle.
However according ssirois tests wif-fi dongle consumes ~200 ma (since total power consumption is ~350ma),
so it is twice more that Pi A+ itself.
Anyway, I am ordering Pi A+ already:)

User avatar
ssirois
Posts: 2
Joined: Sun Jul 12, 2015 9:56 pm
Location: Quebec City, Canada

Re: Raspberry Pi Tank

Mon Jul 13, 2015 1:42 pm

Hi again!

BTW, if you want to conduct your own test, here's the schematic of the circuit that I build and the code for the Arduino (sorry, I killed my backup Pi so I had to go back in my treasure chest! :-).
sampler.png
sampler.png (60.55 KiB) Viewed 2594 times
I also use a small Processing program to sniff the output of the serial line to collect the data and push into a Google sheet. So nothing fancy here, a differential op-amp to read the voltage drop on a shunt resistor and feed it to an ADC (this TLC548 was seating on my bench for the last 30 year!! He finally found is purpose in life). I choose an external ADC for one reason; I can change the reference voltage for TLC and not the Arduino. So instead of having a 10 bits resolution on a 5V range, I got a 8 bits resolution on a 2.5V range. The trim pot and the TLC271 is to zero the voltage diff on inputs.

That's it! Have fun.

P.S.: :-) Forget about not been able to change reference voltage on the Arduino. There's a pin label AREF and using the function analogReference(EXTERNAL) you can achieve the same thing without my TLC548 (and with better resolution)! I miss this one... but my TLC548 his happy so! ;-) My resolution was still 1.7mA so, good enough!
Attachments
read_serial_arduino.zip
Processing code
(16.19 KiB) Downloaded 41 times
read_current_draw_mA.zip
Arduino code
(1 KiB) Downloaded 39 times
-----------------------
Steve

apostal
Posts: 6
Joined: Tue Apr 07, 2015 4:21 pm
Location: Minsk
Contact: Website

Re: Raspberry Pi Tank

Thu Jul 16, 2015 9:50 pm

ssirois, that looks cool!

apostal
Posts: 6
Joined: Tue Apr 07, 2015 4:21 pm
Location: Minsk
Contact: Website

Re: Raspberry Pi Tank

Thu Jul 16, 2015 10:20 pm

Right now I am switching video streaming from usual usb web-camera(logitech one) to Pi Camera.

I used mjpg_streamer to stream video into any browser (iPad and Androids worked fine as well).
With USB camera this worked good:

mjpg_streamer -i "/usr/lib/input_uvc.so -f $FRAMERATE -r $RESOLUTION" -o "/usr/lib/output_http.so -w /srv/http -p 8280"

30 fps on 1024x768 provided very low delay(I guess 0.1-0.3 sec over wi-fi), and low CPU usage, so it was comfortable to use for remote control. Streaming could consume 3-10Mbits, but for wi-fi it is usually not an issue.

Now I am switching to Pi Camera and as I see input_uvc.so can not be used for it.
Found popular workaround for it:
http://blog.miguelgrinberg.com/post/how ... spberry-pi
http://blog.miguelgrinberg.com/post/str ... nd-android

It recommends to use raspistill to periodically capture image to file:
raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 &
and then stream video using mjpg from this file using input_file.so :
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www"

This way works, but delay is more than 1 second, so it is not very suitable for remote control.
I played with options, chainging -tl down to zero, but it seems that best results I could reach is just several fps.

From https://www.raspberrypi.org/documentati ... /camera.md:
--timelapse, -tl Timelapse mode.
The specific value is the time between shots in milliseconds. Note you should specify %04d at the point in the filename where you want a frame count number to appear. e.g.
Is there any way to reach low delay with Pi Camera and mjpg?

apostal
Posts: 6
Joined: Tue Apr 07, 2015 4:21 pm
Location: Minsk
Contact: Website

Re: Raspberry Pi Tank

Fri Oct 09, 2015 11:42 am

Some update on Raspberry Pi Tank topic.
Made a video of outdoor PiTank driving, check it out on youtube:
https://www.youtube.com/watch?v=RKjUhOgZHmU

And if you interested in this topic just subscribe Raspberry Pi Tank channel on youtube

Return to “Automation, sensing and robotics”