This section shows a virtual motor that controls the angle of a mirror. Two motors are involved, mirr_y_1 and mirr_y_2. A second virtual motor, see the preceeding section, uses these motors to change the height of 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 angle of a mirror. [mrad] # use POSIX; my ($method, $value_new) = @ARGV; my ( $min, $max) = ( -5, 5); # # here are 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; } my $len = $Spectra::SYM{ mirr_length}; if( !$len) { Spectra::error( "vm2: missing MIRR_LENGTH"); goto finish; } # # read the positions # my $p1 = Spectra::gmup( $m1); my $p2 = Spectra::gmup( $m2); my $p = ($p1 + $p2)*0.5; goto finish if( !defined( $p1) || !defined( $p2)); if( $method eq "set_position") { if( $value_new < $min || $value_new > $max) { $status = Spectra::error( "vm2: end position $value_new outside limits [$min, $max]"); goto finish; } # # 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 = POSIX::tan( $value_new/1000.)*$len; $status = Spectra::move( $m1 => ($p - $delta*0.5), $m2 => ($p + $delta*0.5)); goto finish if( !Spectra::protect( $m1 => 1, $m2 => 1)); } elsif( $method eq "get_position") { $SYM{RETURN_VALUE} = POSIX::atan( ($p2 - $p1)/$len) * 1000; } elsif( $method eq "get_limit_min") { $SYM{RETURN_VALUE} = $min; } elsif( $method eq "get_limit_max") { $SYM{RETURN_VALUE} = $max; } elsif( $method eq "exec_stop") { Util::log( "method exec-stop"); } else { Spectra::error( "vm2: failed to identify $method"); $status = 0; goto finish; } $status = 1; finish: $status;