XPRESS/Sweep/Motor.pm untested

filter: Statementstmt 0.0% 0 / 70 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 103 CC 6 SCAR 28.3
CC
6
Cov
0%
exit_loop
42.0
new
2.0
go_to_sweep_start
2.0
CRAP 17.0
1 package Lab::XPRESS::Sweep::Motor;
2 #ABSTRACT: Stepper motor sweep
3 $Lab::XPRESS::Sweep::Motor::VERSION = '3.899';
4 use v5.20;
5  
6 use Lab::XPRESS::Sweep;
7 use Time::HiRes qw/usleep/, qw/time/;
8 use strict;
9  
10 our @ISA = ('Lab::XPRESS::Sweep');
11  
12 sub new {
13 my $proto = shift;
14 my @args = @_;
15 my $class = ref($proto) || $proto;
16 my $self->{default_config} = {
17 id => 'Motor_sweep',
18 +filename_extension => 'PHI=',
19 interval => 1,
20 points => [],
21 duration => [],
22 mode => 'continuous',
23 allowed_instruments =>
24 [ 'Lab::Instrument::PD11042', 'Lab::Instrument::ProStep4' ],
25 allowed_sweep_modes => [ 'continuous', 'list', 'step' ],
26 number_of_points => [undef]
27 };
28  
29 $self = $class->SUPER::new( $self->{default_config}, @args );
30 bless( $self, $class );
31  
32 return $self;
33 }
34  
35 sub go_to_sweep_start {
36 my $self = shift;
37  
38 # go to start:
39 print "going to start ... ";
40 $self->{config}->{instrument}->move(
41 @{ $self->{config}->{points} }[0],
42 @{ $self->{config}->{rate} }[0],
43 { mode => 'ABS' }
44 );
45 $self->{config}->{instrument}->wait();
46 print "done\n";
47  
48 }
49  
50 sub start_continuous_sweep {
51 my $self = shift;
52  
53 # continuous sweep:
54 $self->{config}->{instrument}->move(
55 @{ $self->{config}->{points} }[ $self->{iterator} + 1 ],
56 @{ $self->{config}->{rate} }[ $self->{iterator} + 1 ],
57 { mode => 'ABS' }
58 );
59  
60 }
61  
62 sub go_to_next_step {
63 my $self = shift;
64  
65 # step mode:
66 $self->{config}->{instrument}->move(
67 {
68 position => @{ $self->{config}->{points} }[ $self->{iterator} ],
69 speed => @{ $self->{config}->{rate} }[ $self->{iterator} ],
70 mode => 'ABS'
71 }
72 );
73 $self->{config}->{instrument}->wait();
74  
75 }
76  
77 sub exit_loop {
78 my $self = shift;
79 if ( not $self->{config}->{instrument}->active() ) {
80 if ( $self->{config}->{mode} =~ /step|list/ ) {
81 if (
82 not defined @{ $self->{config}->{points} }
83 [ $self->{iterator} + 1 ] ) {
84 return 1;
85 }
86 }
87 if ( $self->{config}->{mode} eq 'continuous' ) {
88 if (
89 not defined @{ $self->{config}->{points} }
90 [ $self->{sequence} + 2 ] ) {
91 return 1;
92 }
93 $self->{sequence}++;
94 $self->{config}->{instrument}->move(
95 @{ $self->{config}->{points} }[ $self->{sequence} + 1 ],
96 @{ $self->{config}->{rate} }[ $self->{sequence} + 1 ],
97 { mode => 'ABS' }
98 );
99 }
100 return 0;
101 }
102 else {
103 return 0;
104 }
105 }
106  
107 sub get_value {
108 my $self = shift;
109 return $self->{config}->{instrument}->get_position();
110 }
111  
112 sub exit {
113 my $self = shift;
114 $self->{config}->{instrument}->abort();
115 }
116  
117 1;
118  
119 __END__