R2D2 Tutorial

From GcatWiki
Revision as of 16:33, 9 May 2012 by Letaylor (talk | contribs) (Set up iRobot)
Jump to: navigation, search

Introduction

Our project was motivated by people leaving windows open inside chambers.

Requirements

  • MacOS X computer
    • Needs bluetooth
    • Needs MatLab and Python 2.7.3
  • iRobot Create
  • BAM iRobot bluetooth adaptor
  • Wifi webcam that you can power
    • We used Foscam FI8918W because it ran off 5 volt power, allowing us to wire it to the iRobot for power.

Guide

Install software/packages/scripts on Mac

  • MatLab Setup
  1. Install Matlab Toolbox for the iRobot Create
  • Python Setup
  1. Download and Install MacPorts
  2. Open terminal and type the following commands.
  3. Install open cv for python 2.7
    sudo port -v install opencv +python27
  4. Install pil for python 2.7
    sudo port install py27-pil
  5. Optional: Install selenium for python 2.7 (use this option if you want to control the webcam via a browser)
    sudo port install py27-selenium
  6. Set this MacPorts installed python as the default python interpreter:
    sudo port select --set python python27
  7. Download webcam.py to control the wifi webcam
  • Other Terminal Setup
  1. Install pkill command to terminal via MacPorts
    sudo port install proctools

Set up iRobot

  1. Determine how you want to power the webcam while it is attached to the robot (Is it going to feed off the robot power or have its own dedicated power supply?)
  2. Determine how you want to mount the camera to the iRobot
  3. Connect the the BAM bluetooth adaptor to the iRobot by following the File:BAM iRobot Manual.pdf to connect it to the computer.
  4. Now connected to the iRobot, ensure the camera is turned on

Control the iRobot

  1. Configure webcam.py
    1. webcam.py has a method (write_img_stream) that will constantly write and update the same image jpeg file. Set the webcam object to write that file to a directory accessible by matlab.
    2. The webcam.py script should only set up the webcam object and call write_img_stream() for the way we set it up
  2. Configure matlab script
    1. Set the read image path for matlab to read in the file that python constantly writes to. This way, whenever the brain in matlab needs an image to process, it can simply read the file written by the python webcam controller.
  3. Run the robot
    1. Begin webcam.py script in terminal
      python /path/to/webcam.py
    2. Run the matlab code
    3. When you are done, the python script needs to be killed (its in an infinite loop) so in another terminal window
      pkill -9 -f webcam.py