Skip to content

A robot to visually track and target an object. (RaspberryPi2 + RaspiCam + OpenCV + Dlib + servos/driver)

Notifications You must be signed in to change notification settings

decentropy/SentryTurret

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SentryTurret

The purpose of this project is to create a cheap autonomous turret, capable of detecting motion and targetting objects.

Pew Pew

Overview

These instructions were written for constructing the robot with RPi2+RaspiCam+servos, but you may try it out on a desktop with a webcam (after installing required python packages).

The basic structure of the program follows:

  • Main()
    • Spawn Camera() thread to fetch camera frames
    • Spawn Turret() thread to listen and move servos. If centered and armed, will fire.
    • Spawn Controller() thread to listen for input (keyboard or bluetooth)
    • Loop:
      • Get last frame from Camera()
      • If tracking target:
        • Find center of target in frame
        • Give Turret() new target coords
      • Else if searching for target, do one of:
        • Detect face mode
        • Detect motion by color
        • Detect motion by object
      • If input, do command. E.g:
        • Quit
        • Targetting mode
        • Adjust setting
        • etc.

Install

See CONFIG.INI for settings

Python Package Requirements

python-dev
libopencv-dev
python-opencv
open-cv
dlib (see note below)
configobj
python-smbus
webcolors
bluez python-bluetooth python-gobject  (for bluetooth)
pyttsx (for speech)

Installing dlib While "sudo apt-get install" works for opencv, dlib (used for object tracking) requires compilation. Here are basic steps to do that:

sudo apt-get install cmake
Install boost from: http://sourceforge.net/projects/boost
sudo apt-get install libboost-python-dev
wget http://dlib.net/files/dlib-18.18.tar.bz2
tar jxf dlib-18.18.tar.bz2
cd dlib*
sudo python setup.py install
pip install dlib

Hardware To Construct Robot

  • Raspberry Pi 2 + power supply
  • RaspiCam
  • PWM Servo Driver + power supply
  • 3 standard servos
  • Optional: Speaker (for speech feedback)
  • Optional: Bluetooth USB adapter (for bluetooth control)
  • Robot frame: camera mounted direction of gun, with servos for trigger and pan/tilt rotation

Usage

$ python main.py

See HELP.TXT for commands

Setup Tips

Camera: For using raspicam with opencv, add bcm2835-v4l2 with sudo modprobe bcm2835-v4l2 (read here and here).

  • CONFIG.INI settings:
    • upsidedown: how you mount the camera.
    • width,height: camera capture dimensions
    • scaledown: for faster processing/framerate
    • display: on or off to display robot view. (Slower)

Turret/Servos: Here is a good tutorial on connecting servos with your RPi. (Also read about setting I2C permissions).

  • CONFIG.INI settings:
    • panchannel/tiltchannel/triggerchannel: channels on servo driver for each servo
    • fireposition: how far back to pull trigger
    • firesensitivity: how centered before firing? (higher is more "trigger happy")
    • TODO: These other settings need some clean up or auto-calibration. Tweak if needed.
      • stepsleep: seconds per microstep
      • pixelsperpulse: you have to manually measure & set this per rotation/camera, (pixels between same point after turret rotates 1.0 pulse.)
      • fps: how fast turret expects coordinates

Speech: (Optional) If you connect a speaker, robot will speak modes and actions. Make sure volume is up the first time: $ amixer sset PCM,0 100%.

  • CONFIG.INI settings:
    • quiet: on or off (turn off if you don't have speaker)

Controller : Send commands by either: keyboard (direct USB) or bluetooth (USB dongle + android app, such as BlueMCU). Read about bluetooth setup and helpful commands.

  • CONFIG.INI settings:
    • usebluetooth: on or off (turn off if you don't use)

E.g. To enable serial port, and connect bluetooth to your phone

$ sdptool add SP
$ sudo rfcomm bind rfcomm0 XX:XX:XX:XX:XX:XX 1 (<-your address here)

Issues and Workarounds

You see a lot of output on start which may be ignored.

Bluetooth may need reset before restarting bot.

$ sudo hciconfig hci0 reset

Stdin may stop showing what you type after running. Reset with:

$ stty sane

Contribute

Contributions are welcome to improve accuracy and movement of the robot!

License

This project licensed under GNU GENERAL PUBLIC LICENSE https://www.gnu.org/licenses/gpl.txt

About

A robot to visually track and target an object. (RaspberryPi2 + RaspiCam + OpenCV + Dlib + servos/driver)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published