Dependencies

To setup the software you'll need to install the following dependencies on the Raspberry Pi:
  • Python
  • Flask, a python web application framework.
  • NumPy, a python library for numeric computing.
  • Git, revision control system to download the code used by this project.
Fortunately the installation of these dependencies is easy by installing pre-built packages. To install these packages connect to your Raspberry Pi in a command line session and execute the following command:
sudo apt-get install python python-flask python-numpy python-smbus git
You might already have some of these dependencies installed on your Raspberry Pi. If a command exits with an "already the newest version" message you can ignore it and move on.

Code

Now you can download the software for the project from GitHub by executing the following command. This will create a 'pi-catlaser' folder in your current directory which will contain the code for the project.
git clone https://github.com/tdicola/pi-catlaser.git
Navigate inside the newly created pi-catlaser folder to continue the software setup.

For reference some of the important files in the pi-catlaser directory are:
  • server.py: The main web application python code. At the top of this file is a small set of configuration values for the I2C address of the servo controller, channels for each servo, and min/max/center servo values.
  • model.py: The code for moving, targeting, and calibrating the laser.
  • modeltests.py: Python unit tests for validating the model's functionality.
  • servos.py: Code to interface with the servo controller and move the servos.
  • Adafruit_I2C.py & Adafruit_PWM_Servo_Driver.py: Code from the Adafruit Raspberry Pi python code library to interface with the PCA9685 servo controller board.
  • templates/main.html: The HTML code for the web application. The image tag which contains the MJPEG video stream for the network camera is in this file beneath a comment near line 19.
  • static/js/calibration.js: The javascript code to calibrate and overlay graphics on the video.
  • calibration.json: This file will initially not exist, but after calibration this file will save the calibration values.
At a minimum you will need to edit templates/main.html to set the URL for your network camera's MJPEG video stream. Edit this file (using a text editor on the Raspberry Pi such as 'nano') and change the src attribute of the img tag on line ~19 to your camera's MJPEG stream URL. You can usually find the MJPEG stream URL for your camera on the web.

If your servo controller is not on the default 0x40 I2C address or your servos are not hooked up to channels 0 and 1 of the servo controller, edit server.py (using a text editor on the Raspberry Pi such as 'nano') and adjust these values at the top of the file.

With any changes to the code made, you're ready to start the server, test the servo movement, and calibrate the laser.

This guide was first published on Sep 13, 2013. It was last updated on Sep 13, 2013.

This page (Software Setup) was last updated on Oct 15, 2021.

Text editor powered by tinymce.