Robotic Tank Software install

Change history:

5/20/16:  code modified

1.   to support ffplay instead of motion – less video latency from the tank’s eye, floating window (does not launch in browser),  less configuration

2.  added software limits to pan left and pan right.  This was required to prevent cable strain/stress on motor and servo wires running to their respective hats in the 3D tank build


This section will discuss the installation/build process of various software components to support the building of a robotic tank and will be dictated by the hardware employed. Currently I am using a Raspberry Pi2, and either Adafruit MotorHATS or Pyborg MotorHATS, and PS3 Game Controller (don’t know if a PS4 GameController will work). I will try to streamline the procedure by reducing it to a series of cut and paste commands where possible.  This installation sequence is important.

1.  Operating System

Linux.  Your choice of distribution.  I am currently using Ubuntu Mate and this procedure will be based upon that distribution.

After the initial install bring your OS up to latest revision by doing:

sudo apt-get update

sudo apt-get upgrade

Be sure that python is installed by:

python -V – will provide the version number

if it is not installed then:

sudo apt-get install python


2. Additional Linux software – install from distribution’s repository

You should check to see if these additional packages are installed.  Many are installed by the generic OS install.  The easiest way to do this is to launch the graphical Ubuntu Software Center.  If you search for it and there is a “check” by the code then it is installed.  Go on to the next package.  Many of these packages were installed during the initial build in my case.

GIT –        sudo apt-get install git

compiler – sudo apt-get install gcc

motion –    sudo apt-get install motion – onboard video support – optional

I2C –         sudo apt-get install python-smbus

sudo apt-get install i2c-tools

sudo apt-get install libi2c-dev

3. Software to support specific Hardware

A.  Adafruit

1.  setup up base path – $HOME will contain two directories for Adafruit.  One will be for the motorHAT (tanks tracks) and the other for the ServoHAT (robotic arm/(Camera Pan/Tilt)

cd $HOME


git clone


git clone

python support –      sudo apt-get install python-dev

cd $HOME/Adafruit-Motor-HAT-Python-Library

sudo python install

sudo vi /etc/modules – add the following 2 lines


if the file /etc/modprobe.d/raspi-blacklist.conf exists on your system then comment out the following lines:

blacklist spi-bcm2708
blacklist i2c-bcm2708

sudo vi /boot/config.txt and add the following 2 lines:


sudo shutdown -Fr now – reboot the Pi


cd $HOME

sudo i2cdetect -y 1 (for a Pi2)

This should produce output similar to the following.

0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — — — — — — — — —
20: — — — — — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: 40 — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: 60 — — — — — — — — — — — — — — —
70: 70 — — — — — — —

sudo i2cdetect -y 0 (for an older Pi)

B.  Pyborg – not done yet

C.  PS3 Game contoller support

joystick support

sudo apt-get install python-pygame

bluetooth support

might already be installed.  Please note that on Ubuntu Mate the following packages were installed under one package known as “bluez”.  If you see that package installed then you wont need to install the following:

sudo apt-get -y install bluez-utils bluez-compat bluez-hcidump

joystick diagnostic tool – very helpful

sudo apt-get install jstest-gtk

configuring, pairing PS3

sudo apt-get -y install checkinstall

Insert your bluetooth dongle

hciconfig – should produce output similar to the following:

hci0: Type: BR/EDR Bus: USB
BD Address: 98:58:8A:04:09:5C ACL MTU: 1021:8 SCO MTU: 64:1
RX bytes:612 acl:0 sco:0 events:37 errors:0
TX bytes:942 acl:0 sco:0 commands:37 errors:0

If you do not see output similar to the above then do not proceed until you fix this problem.


—skip this statement—

sudo apt-get install libusb-dev libbluetooth-dev joystick pyqt4-dev-tools libjack-dev qt3-designer

–end skip —


sudo apt-get install libusb-dev

sudo apt-get install libbluetooth-dev

Pairing Support

mkdir $HOME/joystick

cd $HOME/joystick


gcc -o sixpair sixpair.c -lusb – generates an executable called sixpair in current directory

now connect your PS3 controller to the Pi2 using a USB cable.

sudo ./sixpair – you should see something like the following:

Current Bluetooth master: 00:00:00:00:00:00
Setting master bd_addr to 98:58:8a:04:09:5c

Talk to the PS3 Game Controller

Please read ahead.  You will probably get an error if the “wget” command fails to get “clean” code, i.e., it has not been fixed yet.  If so I provide a work around.

cd $HOME/joystick


tar xfvz QtSixA-1.5.1-src.tar.gz

cd QtSixA-1.5.1/sixad


if you get errors like: error: ‘close’ was not declared in this scope
you need to fix them. Here is how:

1.  cd $HOME/joystick/QtSixA-1.5.1

2. vi compilation_sid.patch in the current directory – not that this patch file with patch the shared.h file in the sixad directory, i.e., you are one directory above.  This patch file can be a royal pain.  If you have problems by getting the same error messages it means it do not patch correctly.  Try to good for “qtsixa path” and try a “cut and paste” from that file.

3. in the file put the following snippet.  Pay attention to the indentation of each line or the patch will fail to install.  I have made every effort to ensure accuracy but on a cut/paste things have a way of changing. If the patch screws up remove the QtSixA-1.5.1 directory and untar again.  You can not patch a screwed up patch file.

--- QtSixA-1.5.1.orig/sixad/shared.h	2011-10-12 03:37:38.000000000 +0300
+++ QtSixA-1.5.1/sixad/shared.h	2012-08-14 19:30:12.190379004 +0300
@@ -18,6 +18,8 @@
 #ifndef SHARED_H
 #define SHARED_H
 struct dev_led {
     bool enabled;
     bool anim;

4.  save the file

5.   patch -Np1 -i compilation_sid.patch – install the patch

6.  make clean

7.  make – should run without errors.  errors are bad so you will need to fix them

8.  sudo mkdir -p /var/lib/sixad/profiles

9.  sudo checkinstall

create default set?  y

descriptor:  sixad <enter> <enter>

package will build


Done. The new package has been installed and saved to:  YOUR_$HOME/joystick/QtSixA-1.5.1/sixad/sixad_20150804-1_armhf.deb

you can remove it from your system anytime using:

dpkg -r sixad

D.  Video Support – this is optional.  you have 2 choices:  motion or ffplay.  You can install both and decide later which to use.  My preference is ffplay because there seems to be less latency than with motion, its much easier to configure (all parameters passed on command line).  

    1.  Motion – optional

sudo apt-get install motion

cd /etc/motion

vi motion.conf – make following changes

v4l2_palette 8 #  based upon your cameras attributes

framerate = 30

output_pictures = off

stream_motion = on

stream_maxrate 100

stream_localhost off

norm = 1 # if you use NTSC

Make sure “target_dir” (/var/lib/motion) is not filling up


start motion at boot – do:

vi /etc/motion/motion.conf and change “daemon off” to “daemon on”

vi /etc/default/motion and set “start_motion_daemon=no” to “start_motion_daemon=yes”

start motion manually:


2.  ffplay – optional but preferred

sudo apt-get install libav-tools

The tank control code launches/activates ffplay automatically.  Comment this line out and uncomment the line for motion if you are going to use it instead of ffplay.

Software install is now complete.

4. Lets get it working.opencv

a.  pair the device – PS3 game controller must be connected by USB to Pi2

cd $HOME/joystick

sudo ./sixpair

b.  talk to the PS3 game controller

sudo sixad –start &  (be sure it is:  dash dash start)

should get something like:

output follows: SUCCESS!!!!
[1] 27711
sixad-bin[27735]: started
sixad-bin[27735]: sixad started, press the PS button now <—–NOTE!!!!!!

disconnect the USB cable from PS3 THEN PRESS THE PS BUTTON

c.  done

to stop the sixad app:  sudo sixad –stop

d.  Lets check our PS3 Game Controller

Launch the graphical joystick app:  jstest-gtk by using the appropriate icon

it should look like the video below:

You might notice that 3 of the axis scroll continuously.  This is ok because your PS3 game controller is reacting to its own movement.  Place it on a table and all should settle down.  Now move a joystick and note the effected axis and shown in the video below.

4.  Install Software to control the tank

a.  login

b.  mkdir $HOME/tank – or some directory where you want the application

c.  cd $HOME/tank

d.  download the following code – this code has been modified to use ffplay instead of motion.

Download “PS3 Tank Controller w/ffplay” ps3_tank.py_.gz – Downloaded 147 times – 5 KB

e.  uncompress and extract the tar file:  tar -zxvf ps3_tank.gz

f.  things you should be aware of:

1.  the code assumes the following path configuration:



       If your setup for the Adafruit software is different then you will need to go into the program and changes the “append” lines to your path for these drivers.

2.  The program determines your $HOME and your Pi’s HOSTNAME

3.  I had determined that the best video performance was achieved using Linux Motion ffplayMotion needs to be running before starting the program or it will fail to start.  You can auto run motion at boot by following the instruction earlier in this procedure, or you can start it manually:  sudo motion.  ffplay is launched by the program.  The program contains entries for both motion and ffplay, but the motion statement has been commented out.

4.  The code header defines which buttons on a PS3 Game Controller provide which functionality but I will detail it here.

The buttons are broken down into 3 groups of functionality:  a.  tank control/movement, b. camera Pan/Tilt and c.  headlights on/offTank control:
Left Joystick:  control forward backward movement of tank
Right Joystick:  controls left/right turn.Camera Pan/Tilt:
This is controlled by the buttons on the front of the game controller (2nd picture).
left buttons (as in left in this picture) control tilt.  Top button tilts up.  Bottom button tilts down.
Right buttons control pan.  Top pans left.  Bottom Pans right.Headlights on/off:
Green Triangle button turns headlights on.  Blue “X” turns headlights off.
You can easily change the button/function relationship in the code, i.e. the left joystick could be used to control forward/backward motion AND left/right turn.  I did try this but did not like it because when moving the joystick forward its too easy to wonder left or right causing turn inputs to occur when you really don’t want them.

Leave A Reply

Your email address will not be published. Required fields are marked *


Bad Behavior has blocked 449 access attempts in the last 7 days.