Coder Social home page Coder Social logo

facebot's Introduction

Facebot

A little raspberry pi based robot that lurches menacingly toward human faces. The OpenCV code is cobbled together from various openCV demos on http://www.pyimagesearch.com/

Facebot

Bits and pieces

  • Rasperry pi 2 or 3
    • Running rasbian Jessie
      • Wheezy won't work unless you feel like compiling openCV - which takes hours.
  • raspirobotboard
    • These are actually not very good - but it is what this code works with. A much better idea would be the version 3 of this board - it adds a switch mode power supply so it won't get so hot, and allows you to speed control the motors!
      • The code would be similar.
  • A robot chassis and motors
    • I used a Magician Chassis - I used this one from mindkits. You could self source the bits for less from ebay - or 3D print something. On the other hand, the mindkits people are very nice.
      • Also note that the motors that come with this kit are designed for about 5V - we will run them at a bit more than that, reducing their life.
      • The also don't have power leads attached so you'll need to solder or crimp some wire on.
  • A rasperry pi camera.
    • In hindsight the rasperry pi camera doesn't really add anything - it is nice as it has more bandwidth than a usb 2 interface and has low latency - however the facial detection code is so slow that these advantages are lost. If you have webcam lying around, try that first I think it could be made to work just as well.
    • I 3D printed this mount, case and hinge for it
  • some kind of usb wireless dongle, unless you are using the pi3 in which case that is built in.

The code

Install dependancies

Note that best practise is to install the python dependancies with pip and use python virtualenvs. However for the sake of simplicity, this just installs all the dependancies system wide.

System dependancies

sudo apt-get install libopencv-dev python-opencv
sudo apt-get install python-numpy
sudo pip install rpio
sudo pip install picamera  # not if using a webcam
sudo pip install 'picamera[array]' #not if using a webcam

Raspirobot library

wget https://github.com/simonmonk/raspirobotboard/archive/master.zip # different if using a version2 or 3
unzip master.zip
cd raspirobotboard-master
sudo python setup.py install

Facebot project

Either get the project zip

cd ~
wget https://github.com/andre-geldenhuis/facebot/archive/master.zip
unzip master.zip  # project is in facebot-master

Or clone the github repository

git clone https://github.com/andre-geldenhuis/facebot.git

Test the robot mechanics

SSH into the robot. Alternativly you could use a keyboard, mouse and a monitor - though this won't work once you have it driving around!

Start an interactive python interpreter:

python

In the interpreter:

from raspirobotboard import *
rr = RaspiRobot()

# Test the motors both turn in the correct direction to drive the robot forward
# 0.3 drives for 0.3 seconds -  this helps stop the robot driving off your desk!
# If the motors turn in the wrong direction, swap the wire around for the offending motor
rr.forward(0.3)

# Test the motors are wired correctly left and right.
# This test is easier with the bot facing away from you.
# The left motor should driving that wheel backward
# the right motor should drive that wheek forward
# if not, swap the motor connectors over.
rr.left(0.3)

Running the robot.

SSH into the robot and change to the Facebot project directory. Run the project

python facebot

It should now lurch toward human faces - if it doesn't work well (and it won't) it'll need tuning.

Tuning

This robot doesn't work very well - the simple proportional controller settings need to be tuned. If you have version 3 of the raspirobotboard you could try use PWM speed control on the motors rather than controlling the motor run times.

The proportional controller settings are in the facenav.py file

There are two possible face detection cascades you can use, the haar cascade is much better, but much slower - you'll be lucky to get 1 frame per second processed. The lbp cascade is about 3-4x faster but is much less good at detecting faces. You can select which one to use by commenting out the corresponding lines in facebot.py

Note that you proportioanl controller gain K will probably need to be a bit different depending on which cascade you are using as the process time will effect the controller responsivess and stability.

facebot's People

Contributors

andre-geldenhuis avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.