INDI サーバーにはスクリプトを受け付ける
ツールが用意されており、このツールを使ってデバイスのモニタをしたり、パラメータを設定したりできます。
CCDの温度をいきなり目標値に設定するのは避けたいので、QSI583のCCD温度を徐々に冷却または外気温に戻すようなスクリプトを書きました。
まず、以下に示したshellスクリプトをcooler.shというファイル名でQSI583を制御するINDIサーバーが動作しているRaspberryPiに保存し、以下のように実行権を与えます。
$ chmod 744 cooler.sh
これでshellスクリプトとして実行できるようになりました。
使い方は ./cooler.sh step goal で変化ステップ温度をstepに、目標温度をgoalで与えます。
負(-)のstep値は冷却を、正(+)のstep値は加温を表しますので、例えば、
$ .cooler.sh -1.0 -20.0
とすると、-20.0になるまで、だいたい1分間ごとに(-1.0度づつ)冷却していきます。また、
$ .cooler.sh 1.0 25.0
とすると、25.0になるまで、だいたい1分間ごとに(+1.0度づつ)温めていきます。
目標温度に到達するか、設定温度に5分間経過しても到達しなかった時は処理を終了します。
#!/bin/sh
#
# Usage: ./cooler.sh step goal
#
# Example: ./cooler.sh -1.0 -20.0 (cooldown for - step value)
# Example: ./cooler.sh 1.0 33.0 (warmup for + step value)
step=$1
goal=$2
echo "Cooler step degree: `perl -se 'printf ("%.1f\n", $stp)' -- -stp=$step` deg"
echo "CCD goal temp: `perl -se 'printf ("%.1f\n", $gl)' -- -gl=$goal` C"
# indi server alive?
ids=`indi_getprop -1 "QSI CCD.CONNECTION.CONNECT"`
if [ "$ids" = "Off" ]
then
echo "CONNECTION IS NOT ESTABLISHED. Try to establish connection."
`indi_setprop "QSI CCD.CONNECTION.CONNECT=On"`
sleep 3s
echo "Retry ./cooler.sh, Bye."
exit
elif [ "$ids" = "On" ]
then
echo "CONNECTION IS ESTABLISHED."
ct=`indi_getprop -1 "QSI CCD.CCD_TEMPERATURE.CCD_TEMPERATURE_VALUE"`
pw=`indi_getprop -1 "QSI CCD.CCD_COOLER_POWER.CCD_COOLER_VALUE"`
echo "Current temp: `perl -se 'printf("%.1f", $tp)' -- -tp=$ct` C, Cooler power: $pw %"
echo "Please input initial setting temp"
read initemp
echo "Set initial temp: `perl -se 'printf("%.1f", $itp)' -- -itp=$initemp` C"
else
echo "Indi server might not be started."
exit
fi
# initial setting
tgt=`perl -se 'printf("%.1f", $pt + $stp)' -- -pt=$initemp -stp=$step`
tpt=`indi_getprop -1 "QSI CCD.CCD_TEMPERATURE.CCD_TEMPERATURE_VALUE"`
fin=0
while [ $fin -eq 0 ]
do
#tgt=`perl -se 'printf("%.1f", $pt + $stp)' -- -pt=$ctp -stp=$step`
#indi_setprop "QSI CCD.CCD_TEMPERATURE.CCD_TEMPERATURE_VALUE=`perl -se 'printf("%.1f", $pt + $stp)' -- -pt=$ctp -stp=$step`"
indi_setprop "QSI CCD.CCD_TEMPERATURE.CCD_TEMPERATURE_VALUE=$tgt"
echo "Set target temp: $tgt C"
sleep 5s
if [ `echo "$step < 0" | bc` -eq 1 ]
then
#Cool down
if [ `echo "$tpt <= $goal" | bc` -eq 1 ]
then
fin=1
else
cnt=0
loopc=0
while [ $cnt -lt 10 ]
do
tpt=`indi_getprop -1 "QSI CCD.CCD_TEMPERATURE.CCD_TEMPERATURE_VALUE"`
tpw=`indi_getprop -1 "QSI CCD.CCD_COOLER_POWER.CCD_COOLER_VALUE"`
echo "Current temp: `perl -se 'printf("%.1f", $tp)' -- -tp=$tpt` C, Cooler power: $tpw %, Cnt:$cnt, Loopc:$loopc"
if [ `echo "$tpt <= $tgt" | bc` -eq 1 ]
then
cnt=`expr $cnt + 1`
elif [ $loopc -gt 60 ]
then
echo "CCD temp cannot reach goal. Abort to cooler.sh."
exit
else
loopc=`expr $loopc + 1`
fi
sleep 5s
done
# next targt
tgt=`perl -se 'printf("%.1f", $pt + $stp)' -- -pt=$tgt -stp=$step`
if [ `echo "$tgt < $goal" | bc` -eq 1 ]
then
tgt=$goal
fi
fin=0
fi
else
#Warm up
if [ `echo "$tpt >= $goal" | bc` -eq 1 ]
then
fin=1
else
cnt=0
loopc=0
while [ $cnt -lt 10 ]
do
tpt=`indi_getprop -1 "QSI CCD.CCD_TEMPERATURE.CCD_TEMPERATURE_VALUE"`
tpw=`indi_getprop -1 "QSI CCD.CCD_COOLER_POWER.CCD_COOLER_VALUE"`
echo "Current temp: `perl -se 'printf("%.1f", $tp)' -- -tp=$tpt` C, Cooler power: $tpw %, Cnt:$cnt, Loopc:$loopc"
if [ `echo "$tpt >= $tgt" | bc` -eq 1 ]
then
cnt=`expr $cnt + 1`
elif [ $loopc -gt 60 ]
then
echo "CCD temp cannot reach goal. Abort to cooler.sh."
exit
else
loopc=`expr $loopc + 1`
fi
sleep 5s
done
# next targt
tgt=`perl -se 'printf("%.1f", $pt + $stp)' -- -pt=$tgt -stp=$step`
if [ `echo "$tgt > $goal" | bc` -eq 1 ]
then
tgt=$goal
fi
fin=0
fi
fi
done
echo "Done."
(注)上記のスクリプト領域をダブルクリックすると全選択できます。
時々、サーバーからの返答が遅くなると表示がおかしくなりますが、表示が元に戻って動作していればそのまま何もしなくて問題ないと思います。
shellスクリプトでは小数点演算ができないので内部でperlを使ってますが、特段難しいことはしていません。
また、プログラムの無駄が多いように思いますので、改造等は自由にしていただいて結構です。
ただし、このスクリプトで万が一問題が発生しても当方は免責とさせていただきます。