Test Scripts for the DSLR Cameras


#1

While testing POCS with the cameras attached, we found that there weren’t really any tests for the DSLR cameras. @james.synge provided us with some bash scripts used for testing PAN006 (found below). If anyone has comments on these scripts or tips while we work on creating DSLR test script, those would be appreciated.

Thanks!

take_picture.sh

#!/bin/bash -x
set -e

DIR="$( cd “$( dirname “${BASH_SOURCE[0]}” )” && pwd )"
source “$DIR/gphoto2_funcs.sh”

GPHOTO_PORT=
DURATION_SECS=0.5
IMAGE_FILE=/tmp/some-image.$(date +%T.%N).cr2

function usage()
{
echo “Usage: $0 [–port usb:bus,port] [–duration ] [–file <output_file>]”
exit 1
}

while test $# -gt 0
do
case “${1}” in
–port)
shift
# Make sure there is another arg.
if test $# -eq 0 ; then
usage
fi
GPHOTO_PORT="${1}"
if is_camera_port “${GPHOTO_PORT}”
then
shift
else
echo “Missing parameter for --port”
usage
fi
;;
–duration)
shift
# Make sure there is another arg.
if test $# -eq 0 ; then
usage
fi
DURATION_SECS="${1}"
shift
;;
–file)
shift
# Make sure there is another arg.
if test $# -eq 0 ; then
usage
fi
IMAGE_FILE="${1}"
shift
;;
*)
echo “Unexpected parameter: ‘${1}’”
usage
esac
done

GPHOTO_PORT=$(arg_or_first_detected_camera ${GPHOTO_PORT})
echo “GPHOTO_PORT=${GPHOTO_PORT}”

gphoto2 --set-config eosremoterelease=Immediate
–wait-event=${DURATION_SECS}s
–set-config eosremoterelease=4
–wait-event-and-download=2s
–filename “${IMAGE_FILE}”

ls -l ${IMAGE_FILE}

configure_camera.sh

#!/bin/bash -x

set -e

DIR="$( cd “$( dirname “${BASH_SOURCE[0]}” )” && pwd )"
source “$DIR/gphoto2_funcs.sh”
GPHOTO_PORT=$(arg_or_first_detected_camera $1)
echo “GPHOTO_PORT=${GPHOTO_PORT}”

gphoto2 --auto-detect

gphoto2_get_config serialnumber

gphoto2_set_config /main/settings/autopoweroff 0
gphoto2_set_config /main/settings/reviewtime 0
gphoto2_set_config /main/settings/capturetarget 0
gphoto2_set_config /main/settings/artist ‘Project PANOPTES’
gphoto2_set_config /main/settings/ownername ‘Project PANOPTES’
gphoto2_set_config /main/settings/copyright “Project PANOPTES $(date +%Y)”
gphoto2_set_config /main/imgsettings/imageformat 9
gphoto2_set_config /main/imgsettings/imageformatsd 9
gphoto2_set_config /main/imgsettings/imageformatcf 9
gphoto2_set_config /main/imgsettings/iso 1
gphoto2_set_config /main/capturesettings/focusmode 0
gphoto2_set_config /main/capturesettings/continuousaf 0
gphoto2_set_config /main/capturesettings/autoexposuremode 3
gphoto2_set_config /main/capturesettings/drivemode 0
gphoto2_set_config /main/capturesettings/shutterspeed 0

gphoto2 --auto-detect

exit 0

gphoto2 --auto-detect

gphoto2 --port “${PORT}” --set-config /main/actions/viewfinder=1

gphoto2 --auto-detect

gphoto2 --port “${PORT}” --set-config /main/settings/autopoweroff=0
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/settings/reviewtime=0
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/settings/capturetarget=0
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config ‘/main/settings/artist=Project PANOPTES’
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config ‘/main/settings/ownername=Project PANOPTES’
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config ‘/main/settings/copyright=Project PANOPTES 2016’
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/imgsettings/imageformat=9
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/imgsettings/imageformatsd=9
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/imgsettings/imageformatcf=9
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/imgsettings/iso=1
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/capturesettings/focusmode=0
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/capturesettings/continuousaf=0
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/capturesettings/autoexposuremode=3
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/capturesettings/drivemode=0
gphoto2 --auto-detect
gphoto2 --port “${PORT}” --set-config /main/capturesettings/shutterspeed=0
gphoto2 --auto-detect

configure_cameras.sh

#!/bin/bash

Run configure-camera.sh on both cameras in parallel, as a way of

checking whether gphoto2 has problems when run in parallel with two cameras.

CAM1=usb:002,017
CAM2=usb:002,018

LOGS_ROOT=$HOME/tmp

mkdir -p $LOGS_ROOT/cam1_logs
mkdir -p $LOGS_ROOT/cam2_logs

for COUNT in $(seq 1000)
do
echo “COUNT=$COUNT”
set -x

./configure-camera.sh $CAM1 &>$LOGS_ROOT/cam1_logs/cam1.$COUNT.log &
CAM1_JOB=$!
./configure-camera.sh $CAM2 &>$LOGS_ROOT/cam2_logs/cam2.$COUNT.log &
CAM2_JOB=$!

wait $CAM1_JOB
STATUS=$?
if [[ $STATUS -ne 0 ]] ; then
echo “Camera 1 job failed with status=$STATUS”
exit $STATUS
fi

wait $CAM2_JOB
STATUS=$?
if [[ $STATUS -ne 0 ]] ; then
echo “Camera 2 job failed with status=$STATUS”
exit $STATUS
fi

set +x
done

exercise_camera.sh

#!/bin/bash -x

set -e

DIR="$( cd “$( dirname “${BASH_SOURCE[0]}” )” && pwd )"
source “$DIR/gphoto2_funcs.sh”
GPHOTO_PORT=$(arg_or_first_detected_camera $1)
echo “GPHOTO_PORT=${GPHOTO_PORT}”

configure-camera.sh ${GPHOTO_PORT}

DURATION_SECS=0.5
IMAGE_FILE=/tmp/some-image.$(date +%T.%N).cr2

gphoto2 --set-config eosremoterelease=Immediate
–wait-event=${DURATION_SECS}s
–set-config eosremoterelease=4
–wait-event-and-download=2s
–filename “${IMAGE_FILE}”

ls -l ${IMAGE_FILE}

sleep 10s

gphoto2_funcs.sh

gphoto2 Bash Helper Functions

GPHOTO_BIN=$(which gphoto2)
DO_DEBUG_GPHOTO2=1
DEBUG_FILE_DIR=$HOME/tmp/gphoto2-debug-logs
mkdir -p $DEBUG_FILE_DIR

function gphoto2()
{
local port_flag=""
if [[ -n “${GPHOTO_PORT}” ]] ; then
port_flag="–port=${GPHOTO_PORT}"
fi
if [[ $DO_DEBUG_GPHOTO2 -eq 1 ]] ; then
local -r debug_file=$DEBUG_FILE_DIR/gphoto2.$$.$(date +"%Y%m%d-%H%M%S.%N").log
local -r debug_flag="–debug --debug-logfile=$debug_file"
$GPHOTO_BIN “${port_flag}” $debug_flag “$@”
else
$GPHOTO_BIN “${port_flag}” $@
fi
}

function gphoto2_get_config()
{
local -r config="${1}"
shift
gphoto2 --get-config “${config}” “$@”
}

function gphoto2_set_config()
{
local -r config="${1}"
local -r new_value="${2}"
shift 2
local -r old_output="$(gphoto2_get_config “${config}” “$@”)"
gphoto2 --set-config “${config}=${new_value}” “$@”
local -r new_output="$(gphoto2_get_config “${config}” “$@”)"
if [[ “${old_output}” == “${new_output}” ]] ; then
echo “Value of config ${config} is unchanged: ${new_value}”
return
fi
echo “Changed value of config ${config} from:”
echo
echo “${old_output}”
echo
echo “To:”
echo
echo “${new_output}”
echo
}

function all_detected_cameras()
{
(GPHOTO_PORT= gphoto2 --auto-detect 2>/dev/null | grep ‘usb:’ | sort) | while read LINE
do
# Remove everything before “usb:”.
local port="${LINE/*usb:/usb:}"
# Remove whitespace and print the result.
echo “${port//[[:space:]]/}”
done
}

function is_camera_port()
{
local -r arg=$1
for camera_port in $(all_detected_cameras)
do
if [ “${arg}” == “${camera_port}” ]
then
return 0
fi
done
return 1
}

function first_detected_camera()
{
local -r camera="$(GPHOTO_PORT= gphoto2 --auto-detect 2>/dev/null | grep ‘usb:’ | sort | head -1)"
if [[ -z “${camera}” ]] ; then
>&2 echo “Unable to find a camera!”
exit 1
fi
local port="${camera/*usb:/usb:}"
port="${port//[[:space:]]/}"
echo $port
}

function arg_or_first_detected_camera()
{
if [[ “$1” == usb:* ]] ; then
echo $1
else
first_detected_camera
fi
}