Astro-photography with Linux
Script for making series of photos using Canon Rebel 350D connected to PC using USB cable and an additional cable to trigger BULB exposures.This script is especially useful for astrophotography.Installation
Just place the script in the directory which is in the PATH, for instance: /usr/local/bin. Make it executable:
> sudo chmod a +rx /usr/local/bin/foto
Two additional programs are required: gphoto2 and geeqie. In Debian use the following command to install them:
> apt-get install gphoto2 geeqie
Two additional programs are required: gphoto2 and geeqie. In Debian use the following command to install them:
> apt-get install gphoto2 geeqie
To configure the script review and modify variables in the SETTINGS section at the beginning of the script, especially BASE and SPORT, to match your setup.
Usage
Start the script:> foto
It will ask for the parameters. Optionally you can specify the parameters directly:
> foto name=m27 frames=20 exptime=60
This will make 20 60 seconds exposures, with common name m27.
This will make 20 60 seconds exposures, with common name m27.
#!/bin/bash
# Written by Piotr Dlugosz
# License GPL
#set -x # uncomment to debug
# ***** SETTINGS *****
# Base directory for the photos
BASE=/home/share/ASTRO
# Serial port for BULB cable
SPORT=/dev/ttyUSB0
# Gphoto2 settings
OG="--quiet --port usb: --set-config shutterspeed=Bulb --set-config imageformat=RAW --set-config focusmode=3"
# Photo parameters (these params can be given on the command line)
OP="name=test frames=1 exptime=10 iso=400"
# ***** END SETTINGS *****
# ***** HOOK PART *****
if [ "$ACTION" = "download" ]; then
echo "DOWNLOAD"
geeqie -t -r "$ARGUMENT" #>/dev/null 2>&1
fi
[ "$ACTION" ] && exit 0
# ***** END HOOK *****
# ***** START *****
echo "*** FOTO AUTOMAT ***"
[ -d "$BASE" ] || { echo "$BASE does not exist!"; exit 1; }
# Ask for parameters and set the script variables
eval $OP # set the defaults first
if [ "$1" ]; then
eval $@ # if command line is not empty take params from command line
else
read -ei "$OP" -p "Enter the photo parameters: " ANSWER # otherwise ask
eval $ANSWER
fi
# Prepare environment
ABSPATH=`cd ${0%/*} && echo $PWD/${0##*/}`
DATE=`date -d "-6 hours" +"%y%m%d"`
NAME="${name}_${DATE}_$$"
FOLDER="$BASE/$name/$DATE"
[ -d "$FOLDER" ] || mkdir -p "$FOLDER"
cd "$FOLDER" || { echo "$FOLDER does not exits!"; exit 1; }
echo "** Folder: $FOLDER, session number: $$"
echo "** Params: exptime=$exptime frames=$frames iso=$iso"
((count=frames-1))
export count
# Start gphoto in tethered mode and set the parameters
gphoto2 $OG --set-config iso=$iso --filename "${NAME}-%03n.cr2" --hook-script "$ABSPATH" --wait-event-and-download >~/gphoto.log 2>&1 &
# Loop to make photos
for a in `seq 0 $count`; do
echo -n "* Frame: $a/$count "
sleep $exptime >$SPORT
echo "finished."
sleep 0.5
done
# Wait till the last photo is saved before exiting
LASTPHOTO="${NAME}-`printf '%03d' $count`.cr2"
while [ ! -s "$LASTPHOTO" ]; do
sleep 1
done
echo "Killing gphoto"
pkill gphoto2