GitHub - nullp2ike/Tracking-Turret: A motion tracking turret.

A motion tracking turret for https://www.youtube.com/watch?v=HoRPWUl_sF8

Install Guide

Make sure pip is installed.

sudo apt-get install python pip

Setup I2C on your Raspberry Pi

https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

Install the Adafruit PCA9685 PWM servo library.

https://github.com/adafruit/Adafruit_Python_PCA9685

git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git
cd Adafruit_Python_PCA9685
sudo python setup.py install
sudo pip install adafruit-pca9685

Install OpenCV 3. Follow all steps for python 2.7 instructions. Note the differences below the following links!

Raspbian Stretch: https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/

Raspbian Jessie: http://www.pyimagesearch.com/2016/04/18/install-guide-raspberry-pi-3-raspbian-jessie-opencv-3/

Make sure to create your virtual environment with the extra flag:

mkvirtualenv --system-site-packages cv -p python2

Compile OpenCV:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \
    -D BUILD_EXAMPLES=ON \
    -D WITH_GTK=ON \
    -D WITH_GTK2=ON  ..

Source your bash profile

Activate your virtual environment

Clone this repository

git clone git@github.com:nullp2ike/Tracking-Turret.git

Navigate to the directory

Install dependencies to your virtual environment

pip install imutils RPi.GPIO

Run the project!

Command-Line Arguments

usage: turret.py [-h] [-m {1,2}] [-v {y,n}]

optional arguments:
  -h, --help            show this help message and exit
  -m {1,2}, --mode {1,2}
                        Input mode. (1) Motion Detection, (2) Interactive
  -v {y,n}, --video {y,n}
                        Live video (y, n)

Setting Parameters

turret.py has a couple parameters that you can set. Look for the User Parameters section.

### User Parameters ###

SERVO_MIN = 1000            # Servo min pulse
SERVO_MAX = 2000            # Servo max pulse

MOTOR_X_STARTPOS = 1500     # X-axis (base) servo start position
MOTOR_Y_STARTPOS = 1050     # Y-axis (gun) servo start position
MOTOR_FIRE_STARTPOS = 1150  # Start position of the bullet pushing motor
MOTOR_FIRE_ENDPOS = 1850    # End position of the bullet pushing motor

TURRET_SETUP_TIME = 3       # Load time in seconds
MAX_NR_OF_ROUNDS = 6        # Ammo storage capacity

MANUAL_MOVE_STEP = 5        # Movement modifier for Interactive mode
VIDEO_MOVE_STEP = 2         # Movement modifier for Motion Detection mode
MOVEMENT_MODIFIER = 10      # Multiply movement step by this modifier

RELAY_PIN = 22              # Relay PIN number on the board

LOG_MOVEMENT = True         # Log movement
FRIENDLY_MODE = True        # Friendly mode (allow firing for Motion Detection)

MAX_STEPS_X = 50            # Max motion tracking X-axis movement
MAX_STEPS_Y = 14            # Max motion tracking Y-axis movement

#######################

Running the turrent on startup

Guide available at: https://www.pyimagesearch.com/2016/05/16/running-a-python-opencv-script-on-reboot/

The on_reboot.sh script is included with this repository. To make it work, edit the crontab (sudo crontab -e) and add the line to the end:

@reboot /home/pi/Tracking-Turret/on_reboot.sh