This section shows a virtual motor that controls the height of a mirror. Two motors are involved, mirr_y_1 and mirr_y_2. A second virtual motor, see the next section, uses these motors to rotate the mirror.
Before the virtual motor can be used, the following
command has to be entered: ONLINE> def vm1.
#!/usr/bin/perl -w
#
# this script moves the height of a mirror
#
my ($method, $value_new) = @ARGV;
#
# the motor names
#
my ( $m1, $m2) = ( "mirr_y_1", "mirr_y_2");
my $status = 0;
if( !Spectra::search_motor( $m1))
{
Spectra::error( "vm1: missing $m1");
goto finish;
}
if( !Spectra::search_motor( $m2))
{
Spectra::error( "vm1: missing $m2");
goto finish;
}
#
# read the positions
#
my $p1 = Spectra::gmup( $m1);
my $p2 = Spectra::gmup( $m2);
goto finish if( !defined( $p1) || !defined( $p2));
if( $method eq "set_position")
{
#
# the mirror motors should be moved from the VM scripts only,
# that's why they are protected
#
goto finish if( !Spectra::privilege( flag => 1));
goto finish if( !Spectra::protect( $m1 => 0, $m2 => 0));
my $delta = $value_new - ($p1 + $p2)*0.5;
$status = Spectra::move( $m1 => ($p1 + $delta),
$m2 => ($p2 + $delta));
goto finish if( !Spectra::protect( $m1 => 1, $m2 => 1));
}
elsif( $method eq "get_position")
{
$SYM{RETURN_VALUE} = ($p1 + $p2)*0.5;
}
elsif( $method eq "get_limit_min")
{
$SYM{RETURN_VALUE} = (Spectra::gmuli( $m1) + Spectra::gmuli( $m2))*0.5;
}
elsif( $method eq "get_limit_max")
{
$SYM{RETURN_VALUE} = (Spectra::gmula( $m1) + Spectra::gmula( $m2))*0.5;
}
elsif( $method eq "exec_stop")
{
Util::log( "method exec-stop");
}
else
{
Spectra::error( "vm1: failed to identify $method");
$status = 0;
goto finish;
}
$status = 1;
finish:
$status;