Panoramaker
As promised before, here is the Python script that runs my panoramic camera hardware. It is a very quick prototype and is by no means intended for widespread use since it requires manual calibration. Nevertheless, it might be very useful to those seeking to learn how to position the servos or control a digital camera through Python.
This script requires my Pololu library and includes some codes from here in order to control the camera. Besides the basic requirements of lib_pololu, the script also requires gPhoto. If you are running Linux, you most likely already have it but in case you do not, you can install it through your favourite package manager or by using the console (e.g. for Ubuntu/Debian):
sudo apt-get install gphoto
If you are using some other OS, you can download gPhoto from here.
The Code
# Assuming that the file is at /your/path/to/the/library/lib_pololu.py
import sys
sys.path.append(‘/your/path/to/the/library’)
# Import the lib_pololu module
import lib_pololu
# Import the serial communication and time modules
import serial
import time
# Open serial port
port = serial.Serial(‘/dev/ttyUSB1′)
port.baudrate=2400 #set an appropriate baudrate
# Camera Code (from vmlaker.org)
import os, re
from subprocess import call, Popen, PIPE
def run(command):
print ‘Running:’, command
p = Popen(command, shell=True, stdout=PIPE)
lines = p.stdout.readlines()
for line in lines:
print ‘Stdout :’, line,
return lines
def capture():
c = ‘gphoto2 -capture-image’
sout = run(c)
firstLine = sout[0]
expr = ‘New file is in location (.*?) on the camera’
comp = re.compile(expr, re.DOTALL)
path = re.findall(comp, firstLine)[0]
dir, fname = os.path.split(path)
c = ‘gphoto2 -get-file %s -folder %s’%(fname, dir)
run(c)
c = ‘gphoto2 -delete-file %s -folder %s’%(fname, dir)
run(c)
c = ‘gphoto2 -storage-info’
run(c)
# Calibration Parameters
# These parameters set the limits and reference positions of the rig.
# They have been obtained trough trial and error.
horizontal = 93.5
front = 95.5
back_l = 84.5
back_r = 107
top = 70
bottom = 110
# Create two motors
# There are associated to the panning and tilting motion of the rig.
tilt = lib_pololu.Servo(port, 0, 1150, 4650)
pan = lib_pololu.Servo(port, 1, 1200, 4987)
# Define a capture routine
# This is a simple loop that takes pictures in order to produce a
# 360 deg panorama.
def capture_pano():
# Capture parameters
steps_h = 16
steps_v = 4
step_h = (back_r - back_l)/steps_h
step_v = (bottom - top)/steps_v
pos_v = bottom
while (pos_v >=top):
tilt.set_pos(pos_v)
pos_v = pos_v - step_v
pos_h = back_l
while(pos_h <= back_r):
pan.set_pos(pos_h)
pos_h = pos_h + step_h
time.sleep(2)
capture()
# Initialize the motors
tilt.set_pos(horizontal)
pan.set_pos(front)
time.sleep(2)
# Capture the panorama
capture_pano()
Again, many thanks to RobotShop who provided the hardware that made this project possible.


















