Asynchronous Move, P09

 
#!/usr/env perl
use strict;
use Spectra;
use GQE;
use Motor;

my $ret;

# global variables
my $pos;
my $dstart;
my $dend;
my $status = 1;

if ( $ARGV[0] eq "help" )
{
	print "\n\n";
	print " This script is used to scan position of a motor, \n";
	print " one pilatus image will be obtained: start and end \n";
	print " positions are given relative to the starting point; \n";
	print " motor returns to the starting point of the scan after scan!\n\n";
	print " Usage:\n\n";
	print "   plup motor_name relativemove_start relativemove_stop exp_time";
	print "\n\n\n";
	$status = 0 ;
	goto finish ;
}

if( !defined( $Spectra::SYM{ generic_scan_name}))
{
    $Spectra::SYM{ generic_scan_name} = "hasylab";
}
my $sname = Spectra::create_scan_name();
print "scan name $sname \n";
#
# write some info to online.log
#
Spectra::log( "scan name $sname"); 
my $scan_number = -1; 
if( $sname =~ /(.+?)_0*(\d+)/)
{
    $scan_number = $2;
}
if( $scan_number == -1)
{
    Spectra::error( "shotrot_new:: trouble finding scan_number"); 
      exit 0;
}
my $motor_name = "exp_mot01";
Spectra::amove( $motor_name => 20);
#
# at this place you might want to start a detector
#
while( Spectra::cm( $motor_name))
{
	print "$motor_name " . Spectra::gmup( $motor_name) . "\n"; 
    #
    # here you might want to check the detector state
    #
}
Spectra::complete_move( $motor_name);
while( Spectra::cm( $motor_name))
{
	Spectra::wait( 0.1);
}
#
# the preceeding complete-move is not necessay, if you 
# go back to some position with a synchronous move anyway
#
Spectra::move( $motor_name => 0);
print "the scan number is $scan_number \n";
Spectra::gra_command( "create/scan $sname 0 1 1");
$Spectra::SYM{ scan_name} = $sname;
Spectra::Write_fio( scan => 1, 
					motors => 1, 
					file => $sname);
Spectra::deactivate();
Spectra::cleanup();
finish:
$status;