#!/usr/bin/perl #050901 increased time to move data for slow computer #050830 trying to fix the 0-360 tile transition #050731 changed b loop to check for time left to takd image # changed offset tom2 and tom3 to 400 #050730 changed offset to 1000 all toms #050609 per Mike S. fixed round off problem for tile move #050607 added variable move off home to start so tom1 #can avoid the tree #050607 fixed tile width subroutine #050530 changed dec max offset to ra max offset and #from 2 to 2.5 #050528 added loop comments, track error from .05 to .02 #fixed tile block size to be 19 for 19 tiles per block #050523 added dec to limit after each set #050523 added ra to limit at end, ra off #050521 added dec_to_limit for restart problem? #050518 try resetting focus after each dec move #050414 move focus set up to inside main loop at start dec #update 050514 #tomx_tile.pl 050509 first working version that takes images #tomx_tile.pl 050508 #this is the general purpose tile taking program designed to work on all toms #alway date any revision then the latest date should work on any tom #loads the file this_tom.param which should also be in the running directory #this_tom.param points to tomn.cfg which is the configuration file for this tom #running directory must contain: tomx_tile.pl this_tom.param and the right #tomn.cfg to match the entry in this_tom.param tomn.cfg and this_tom.param #must be edited to match the tom being run. # # $Name: $ # # $Log: night.pl,v $ # Revision 1.2 2005/01/16 03:36:18 robert # *** empty log message *** # # Revision 1.1 2003/01/25 19:20:23 robert # *** empty log message *** # # Revision 0.1.1.1 2002/11/03 02:53:17 robert # # use strict; use warnings; use Time::HiRes qw(sleep gettimeofday tv_interval time); use Log::Agent; use Log::Agent::Rotate; use Log::Agent::Priorities qw( :LEVELS ); use Log::Agent::Driver::File; use Astro::Sunrise; use Class::Date qw( date localdate ); logconfig( -driver => Log::Agent::Driver::File->make( -prefix => 'TC', -showpid => 1, -rotate => Log::Agent::Rotate->make( -unzipped => 3, -backlog => 9, -max_size => 10_000_000, ), #-channels => { 'error' => 'night.err', # 'output' => 'night.out', # 'debug' => 'night.dbg' } ), -channels => { 'error' => 'night.out', 'output' => 'night.out', 'debug' => 'night.out' } ), -level => INFO ); use TASS::Control; my $block = 1; my $block_directory = 1; my $block_size = 18; my $cfg_file = 0; my $control = "go"; my $dec = 0; my $dec_start_tile_size = 0; my $dec_current = 0; my $dec_inc = 4; my $error = 0; my $exp = 100; my $foo = 0; my @foo = 0; my $image_time = 400; my $number_of_darks = 8; my $ra_base = 0; my $ra_current_position = 0; my $ra_max_offset = 2.5; my $ra_to_go_to = 0; my $ra_offset = 0; my $ra_ok = 0; my $ra_to_move_to; my $sun_rise_pad = 4000; my $take_it = 0; my $tile_count = 0; my $tile_block_size =19; my $tile_size = 0; my $time_left = 0; my $time_to_run = 0; my $time_to_rise = 0; my $time_to_set = 0; my @tom_param = 0; my $track_error = 0.05; open (TOMPARAM, "; chomp $tom_param[0]; $cfg_file = $tom_param[0]; print "we are using the cfg file $cfg_file \n"; my $tc = TASS::Control->new($cfg_file); #( './$tom[0] '); chomp $tom_param[1]; my $dec_start = $tom_param[1]; chomp $tom_param[2]; my $dec_max = $tom_param[2]; print "cfg file $tom_param[0] dec start $tom_param[1] dec max $tom_param[2] \n"; $dec = $dec_start; &find_tile_size; $dec_start_tile_size = $tile_size; system "rm -f *.fits "; print "rob sun time stuff \n"; ###################################### # rob mystery stuff ###################################### my $sun_set = sun_set( $tc->longitude, $tc->latitude, -18 ); my $sun_rise = sun_rise( $tc->longitude, $tc->latitude, -18, 1 ); print "Sunset is $sun_set Sunrise is $sun_rise \n"; my $tz = `date "+%Z"`; chomp $tz; my $tzoffset = `date "+%z"`; chomp $tzoffset; my $now = date( `date "+%Y-%m-%d %H:%M:%S"`, $tz ); print "my time zone is $tz my now is $now \n"; $Class::Date::DATE_FORMAT = '%Y-%m-%d'; my $set_time = date( "$now $sun_set", $tz ); my $rise_time = date( "$now $sun_rise", $tz ); $Class::Date::DATE_FORMAT = undef; #'%Y-%m-%d %H:%M:%S'; $rise_time = $rise_time + '1D'; logtrc INFO, 'Set: %s Rise: %s', $set_time, $rise_time; logtrc INFO, 'setting in %d seconds - rising in %d seconds total %d', $set_time - $now, $rise_time - $now, $rise_time - $set_time; $now = date( `date "+%Y-%m-%d %H:%M:%S"`, $tz ); logtrc INFO, 'Setting up telescope'; ######################################### print "doing the init things \n"; print "start \n"; $tc->start; print "dac start \n"; $tc->dac_start; print "init telescope \n"; $tc->init_telescope; print "starting run \n"; $tc->shutter_0_close; $tc->shutter_1_close; ##################################################### # wait here for sunset ##################################################### if ( 0 == 1) { #A print "at the time loop \n"; $now = date( `date "+%Y-%m-%d %H:%M:%S"`, $tz ); $time_to_set = ($set_time - $now); $time_to_rise= ($rise_time - $now); $time_to_run = ($rise_time - $set_time); printf "Time to set %6.1f Time to rise %6.1f Time to run %6.1f \n", $time_to_set, $time_to_rise, $time_to_run; print "waiting for sun to set \n"; while ($time_to_set > 5000) { #B print "in the wait to set loop \n"; $now = date( `date "+%Y-%m-%d %H:%M:%S"`, $tz ); $time_to_set = ($set_time - $now); $time_to_rise= ($rise_time - $now); $time_to_run = ($rise_time - $set_time); printf "Time to set %6.1f Time to rise %6.1f Time to run %6.1f \n", $time_to_set, $time_to_rise, $time_to_run; $tc->delay(100); } #B } #A print "ready to take darks \n"; ############################################## #keep to take darks ############################################## if (0 == 0) { #A system "rm *.fits"; print "taking darks \n"; $tc->take_dark_pictures($number_of_darks,$exp); $tc->delay(90); #time for last image to transfer print "moving darks \n"; system "rm darks/*.fits"; system "mv *.fits darks"; } #A ################################################ # the main loop ################################################ #home ra then # move ra off home slightly print "at the start of the main loop ra base is $ra_base \n"; $tile_count = 0; while ($control eq "go") { #A print "\n"; print "starting the A loop \n"; system "date \n"; $tc->ra_to_limit; if ($cfg_file eq "/home/tom/mk4/operate/tom1.cfg") { #B $tc->ra_move_second(1000); print "this is tom1 we are moving 1000 sec off limit \n"; } #B else { #B $tc->ra_move_second(400); print "this is not tom1 so we are moving 400 steps off limit \n"; } #B $tc->ra_on; $tc->dec_drive_to_limit; $dec = $dec_start; &get_ra_base; $ra_current_position = $tc->ra_current_degree; $ra_to_go_to = $ra_base; &move_to_ra; for ($dec = $dec_start; $dec <= $dec_max; $dec = $dec + $dec_inc) { #B &time_test_stuff; #update time stuff and look for instructions #print "control says $control \n"; #print "dec is $dec \n"; #here we check if there is enough ra range left to take image $time_left = $tc->ra_time_left; print "ra time left is $time_left \n"; if ($time_left < $image_time) { #C print "Not enough time back to home ra and out \n"; $tc->ra_to_limit; $tc->ra_on; &get_ra_base; $ra_current_position = $tc->ra_current_degree; $ra_to_go_to = $ra_base; &move_to_ra; } #C print "Start B loop to get tile at dec $dec ra base $ra_base \n"; system "date \n"; # here we check if we can get the tile without moving too much #if we can we take it and count tiles actually taken &check_to_take; if ($take_it == 1) { #C print "C loop taking image at ra $ra_to_go_to dec $dec tile size $tile_size XXXXXXXXXXXXX\n"; system "date \n"; $ra_current_position = $tc->ra_current_degree; &move_to_ra; $ra_current_position = $tc->ra_current_degree; print "error $error to go to $ra_to_go_to cur deg $ra_current_position \n"; $tc->dec_drive_move_to_degree($dec); ########################################## # here try resetting focus after each dec move ######################################### if (0 == 0) { #D $tc->focus_0_to_limit; $tc->focus_1_to_limit; $tc->focus_0_move_to_position( $tc->focus_0_best ); $tc->focus_1_move_to_position( $tc->focus_1_best ); } #D $tc->take_object_pictures(1,$exp); $tile_count++; print "tile count $tile_count directory $block_directory \n"; } #C if ($tile_count >= $tile_block_size) { #C $tc->delay(50); # to finish the transfer system "mv *.fits $block_directory"; $block_directory++; $tile_count = 0; } #C } #B } #A system "mv *.fits $block_directory"; $tc->ra_to_limit; $tc->dec_drive_to_limit; $tc->ra_off; ################################################ # find_tile_size checks what the tile size is for #a tile at the current declination # returns tile_size ################################################ sub find_tile_size { #A if (($dec >= -8) && ($dec <= 32)) { #B $tile_size = 4; } #B if (($dec >= 36) && ($dec <= 48)) { #B $tile_size = 5; } #B if (($dec >= 52) && ($dec <= 60)) { #B $tile_size = 6; } #B if (($dec >= 64) && ($dec <= 64)) { #B $tile_size = 8; } #B if (($dec >= 68) && ($dec <= 68)) { #B $tile_size = 10; } #B if (($dec >= 72) && ($dec <= 72)) { #B $tile_size = 12; } #B if (($dec >= 76) && ($dec <= 76)) { #B $tile_size = 15; } #B if (($dec >= 80) && ($dec <= 80)) { #B $tile_size = 20; } #B if (($dec >= 84) && ($dec <= 84)) { #B $tile_size = 30; } #B if (($dec >= 88) && ($dec <= 88)) { #B $tile_size = 60; } #B }#A ################################################ # check if a tile is close enough to take #enter with dec and ra_base return take_it 1 to take ################################################ sub check_to_take { #A $take_it = 0; &find_tile_size; if ($tile_size == $dec_start_tile_size) { #B $take_it = 1; } #B else { #AA my $temp1 = 0; my $temp2 = 0; &find_tile_size; $temp1 = $tc->ra_current_degree; #get ra position $temp2 = sprintf "%.0f", ($temp1/$tile_size);#integer tile #widths from zero $ra_to_go_to = $temp2*$tile_size; #this is ra center of proposed tile if (abs($temp1 - $ra_to_go_to) < $ra_max_offset) { #AB $take_it = 1; } #AB } #AA } #A ################################################ # gets ra base # enter with $dec # returns $ra_base ################################################ sub get_ra_base { #A &find_tile_size; my $foo = 0; my $goo = 0; $foo = $tc->ra_current_degree; print "in ra base ra is $foo tile size is $tile_size\n"; $goo = sprintf "%2d", ($foo/$tile_size); $ra_base = $goo*$tile_size; } #A ################################################ # move to ra # enter with $ra_to_go_to and $ra_current_position # moves to $ra_to_go_to ################################################ sub move_to_ra { #A &get_the_error; $tc->ra_move_second(-$error); } #A ############################################### # get_the_error # worries that we cover the 0-360 transition ############################################### sub get_the_error { #A $error = ($ra_to_go_to - $ra_current_position)*(3600/15); if (abs($error) < 40000) { #B } #B elsif ($error < -40000) { #B $error = ($ra_to_go_to + 360 - $ra_current_position)*(3600/15); } #B elsif ($error > 40000) { #B $error = ($ra_to_go_to - $ra_current_position - 360)*(3600/15); } #B } #A ################################################ # time test stuff looks for changes in instruction file or # sunrise or ... ################################################ sub time_test_stuff { #A open (INSTRUCTION, "; chomp $foo; if ($foo eq "focus") { #B print "instruction says focus \n"; print "enter V focus position \n"; $foo = <>; print "we are moving V to $foo \n"; $tc->focus_0_to_limit; $tc->focus_0_move_to_position( $foo ); print "enter I focus position\n"; $foo = <>; print "we are movingi I to $foo \n"; $tc->focus_1_to_limit; $tc->focus_1_move_to_position( $foo); } #B if ($foo eq "quit") { #B $control = "quit"; print "instruction says quit \n"; } #B close INSTRUCTION; $now = date( `date "+%Y-%m-%d %H:%M:%S"`, $tz ); $time_to_set = ($set_time - $now); $time_to_rise= ($rise_time - $now); $time_to_run = ($rise_time - $set_time); system "date \n"; printf "Time to set %6.1f Time to rise %6.1f Time to run %6.1f \n", $time_to_set, $time_to_rise, $time_to_run; if ($rise_time + $sun_rise_pad - $now < 0) { #E $control = "quit"; } #E } #A