File Coverage

blib/lib/Lab/XPRESS/Sweep/Motor.pm
Criterion Covered Total %
statement 11 54 20.3
branch 0 10 0.0
condition 0 3 0.0
subroutine 4 11 36.3
pod 1 7 14.2
total 16 85 18.8


line stmt bran cond sub pod time code
1             package Lab::XPRESS::Sweep::Motor;
2             #ABSTRACT: Stepper motor sweep
3             $Lab::XPRESS::Sweep::Motor::VERSION = '3.880';
4 1     1   1761 use v5.20;
  1         5  
5              
6 1     1   7 use Lab::XPRESS::Sweep;
  1         13  
  1         26  
7 1     1   11 use Time::HiRes qw/usleep/, qw/time/;
  1         2  
  1         5  
8 1     1   102 use strict;
  1         2  
  1         788  
9              
10             our @ISA = ('Lab::XPRESS::Sweep');
11              
12             sub new {
13 0     0 0   my $proto = shift;
14 0           my @args = @_;
15 0   0       my $class = ref($proto) || $proto;
16             my $self->{default_config} = {
17 0           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 0           $self = $class->SUPER::new( $self->{default_config}, @args );
30 0           bless( $self, $class );
31              
32 0           return $self;
33             }
34              
35             sub go_to_sweep_start {
36 0     0 0   my $self = shift;
37              
38             # go to start:
39 0           print "going to start ... ";
40             $self->{config}->{instrument}->move(
41 0           @{ $self->{config}->{points} }[0],
42 0           @{ $self->{config}->{rate} }[0],
  0            
43             { mode => 'ABS' }
44             );
45 0           $self->{config}->{instrument}->wait();
46 0           print "done\n";
47              
48             }
49              
50             sub start_continuous_sweep {
51 0     0 0   my $self = shift;
52              
53             # continuous sweep:
54             $self->{config}->{instrument}->move(
55 0           @{ $self->{config}->{points} }[ $self->{iterator} + 1 ],
56 0           @{ $self->{config}->{rate} }[ $self->{iterator} + 1 ],
  0            
57             { mode => 'ABS' }
58             );
59              
60             }
61              
62             sub go_to_next_step {
63 0     0 0   my $self = shift;
64              
65             # step mode:
66             $self->{config}->{instrument}->move(
67             {
68 0           position => @{ $self->{config}->{points} }[ $self->{iterator} ],
69 0           speed => @{ $self->{config}->{rate} }[ $self->{iterator} ],
  0            
70             mode => 'ABS'
71             }
72             );
73 0           $self->{config}->{instrument}->wait();
74              
75             }
76              
77             sub exit_loop {
78 0     0 0   my $self = shift;
79 0 0         if ( not $self->{config}->{instrument}->active() ) {
80 0 0         if ( $self->{config}->{mode} =~ /step|list/ ) {
81 0 0         if (
82 0           not defined @{ $self->{config}->{points} }
83             [ $self->{iterator} + 1 ] ) {
84 0           return 1;
85             }
86             }
87 0 0         if ( $self->{config}->{mode} eq 'continuous' ) {
88 0 0         if (
89 0           not defined @{ $self->{config}->{points} }
90             [ $self->{sequence} + 2 ] ) {
91 0           return 1;
92             }
93 0           $self->{sequence}++;
94             $self->{config}->{instrument}->move(
95 0           @{ $self->{config}->{points} }[ $self->{sequence} + 1 ],
96 0           @{ $self->{config}->{rate} }[ $self->{sequence} + 1 ],
  0            
97             { mode => 'ABS' }
98             );
99             }
100 0           return 0;
101             }
102             else {
103 0           return 0;
104             }
105             }
106              
107             sub get_value {
108 0     0 1   my $self = shift;
109 0           return $self->{config}->{instrument}->get_position();
110             }
111              
112             sub exit {
113 0     0 0   my $self = shift;
114 0           $self->{config}->{instrument}->abort();
115             }
116              
117             1;
118              
119             __END__
120              
121             =pod
122              
123             =encoding UTF-8
124              
125             =head1 NAME
126              
127             Lab::XPRESS::Sweep::Motor - Stepper motor sweep
128              
129             =head1 VERSION
130              
131             version 3.880
132              
133             =head1 SYNOPSIS
134              
135             use Lab::XPRESS::hub;
136             my $hub = new Lab::XPRESS::hub();
137            
138            
139             my $stepper = $hub->Instrument('PDPD11042',
140             {
141             connection_type => 'VISA_RS232',
142             gpib_address => 2
143             });
144            
145             my $sweep_motor = $hub->Sweep('Motor',
146             {
147             instrument => $stepper,
148             points => [-10,10],
149             rate => [1.98,1],
150             mode => 'continuous',
151             interval => 1,
152             backsweep => 1
153             });
154              
155             .
156              
157             =head1 DESCRIPTION
158              
159             Parent: Lab::XPRESS::Sweep
160              
161             The Lab::XPRESS::Sweep::Motor class implements a module for stepper motor sweeps in the Lab::XPRESS::Sweep framework.
162              
163             .
164              
165             =head1 CONSTRUCTOR
166              
167             my $sweep_motor = $hub->Sweep('Motor',
168             {
169             instrument => $stepper,
170             points => [-10,10],
171             rate => [1.98,1],
172             mode => 'continuous',
173             interval => 1,
174             backsweep => 1
175             });
176              
177             Instantiates a new stepper motor sweep
178              
179             .
180              
181             =head1 SWEEP PARAMETERS
182              
183             =head2 instrument [Lab::Instrument] (mandatory)
184              
185             Instrument, conducting the sweep. Must be of type Lab:Instrument.
186             Allowed instruments: Lab::Instrument::PD11042, Lab::Instrument::ProStep4
187              
188             .
189              
190             =head2 mode [string] (default = 'continuous' | 'step' | 'list')
191              
192             continuous: perform a continuous stepper motor sweep. Measurements will be performed constantly at the time-interval defined in interval.
193              
194             step: measurements will be performed at discrete values between start and end points defined in parameter points, seperated by a step defined in parameter stepwidth
195              
196             list: measurements will be performed at a list of values defined in parameter points
197              
198             .
199              
200             =head2 points [float array] (mandatory)
201              
202             array of values (in deg) that defines the characteristic points of the sweep.
203             First value is appraoched before measurement begins.
204              
205             Case mode => 'continuous' :
206             List of at least 2 values, that define start and end point of the sweep or a sequence of consecutive sweep-sections (e.g. if changing the sweep-rate for different sections or reversing the sweep direction).
207             points => [0, 180] # Start: 0 / Stop: 180
208              
209             points => [0, 90, 180, 360]
210              
211             points => [0, -90, 90]
212              
213             Case mode => 'step' :
214             Same as in 'continuous' but stepper motor will be swept in stop and go mode. I.e. stepper motor approaches values between start and stop at the interval defined in 'stepwidth'. A measurement is performed, when the motor is idle.
215              
216             Case mode => 'list' :
217             Array of values, with minimum length 1, that are approached in sequence to perform a measurment.
218              
219             .
220              
221             =head2 rate [float array] (mandatory if not defined duration)
222              
223             array of rates, at which the stepper motor is swept (deg / min).
224             Has to be of length 1 or greater (Maximum length: length of points-array).
225             The first value defines the rate to approach the starting point.
226             The following values define the rates to approach the values defined by the points-array.
227             If the number of values in the rates-array is less than the length of the points-array, the last defined rate will be used for the remaining sweep sections.
228              
229             points => [-90, 0, 90, 180],
230             rates => [1, 0.5, 0.2]
231            
232             rate to approach -90 deg (the starting point): 1 deg/min
233             rate to approach 0 deg : 0.5 deg/min
234             rate to approach 90 deg : 0.2 deg/min
235             rate to approach 180 deg : 0.2 deg/min (last defined rate)
236              
237             .
238              
239             =head2 duration [float array] (mandatory if not defined rate)
240              
241             can be used instead of 'rate'. Attention: Use only the 'duration' or the 'rate' parameter. Using both will cause an Error!
242              
243             The first value defines the duration to approach the starting point.
244             The second value defines the duration to approach the value defined by the second value of the points-array.
245             ...
246             If the number of values in the duration-array is less than the length of the points-array, last defined duration will be used for the remaining sweep sections.
247              
248             .
249              
250             =head2 stepwidth [float array]
251              
252             This parameter is relevant only if mode = 'step' has been selected.
253             Stepwidth has to be an array of length '1' or greater. The values define the width for each step within the corresponding sweep sequence.
254             If the length of the defined sweep sequence devided by the stepwidth is not an integer number, the last step will be smaller in order to reach the defined points-value.
255              
256             points = [0, 90, 180]
257             stepwidth = [10, 25]
258            
259             ==> steps: 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 115, 140, 165, 180
260              
261             .
262              
263             =head2 number_of_points [int array]
264              
265             can be used instead of 'stepwidth'. Attention: Use only the 'number_of_points' or the 'stepwidth' parameter. Using both will cause an Error!
266             This parameter is relevant only if mode = 'step' has been selected.
267             Number_of_points has to be an array of length '1' or greater. The values defines the number of steps within the corresponding sweep sequence.
268              
269             points = [0, 90, 180]
270             number_of_points = [5, 2]
271            
272             ==> steps: 0, 18, 36, 54, 72, 90, 135, 180
273              
274             .
275              
276             =head2 interval [float] (default = 1)
277              
278             interval in seconds for taking measurement points. Only relevant in mode 'continuous'.
279              
280             .
281              
282             =head2 backsweep [int] (default = 0 | 1 | 2)
283              
284             0 : no backsweep (default)
285             1 : a backsweep will be performed
286             2 : no backsweep performed automatically, but sweep sequence will be reverted every second time the sweep is started (relevant eg. if sweep operates as a slave. This way the sweep sequence is reverted at every second step of the master)
287              
288             =head2 id [string] (default = 'Motor_sweep')
289              
290             Just an ID.
291              
292             =head2 filename_extention [string] (default = 'PHI=')
293              
294             Defines a postfix, that will be appended to the filenames if necessary.
295              
296             =head2 delay_before_loop [int] (default = 0)
297              
298             defines the time in seconds to wait after the starting point has been reached.
299              
300             =head2 delay_in_loop [int] (default = 0)
301              
302             This parameter is relevant only if mode = 'step' or 'list' has been selected.
303             Defines the time in seconds to wait after the value for the next step has been reached.
304              
305             =head2 delay_after_loop [int] (default = 0)
306              
307             Defines the time in seconds to wait after the sweep has been finished. This delay will be executed before an optional backsweep or optional repetitions of the sweep.
308              
309             =head1 CAVEATS/BUGS
310              
311             probably none
312              
313             =head1 SEE ALSO
314              
315             =over 4
316              
317             =item L<Lab::XPRESS::Sweep>
318              
319             =back
320              
321             =head1 COPYRIGHT AND LICENSE
322              
323             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
324              
325             Copyright 2012 Stefan Geissler
326             2013 Andreas K. Huettel, Christian Butschkow, Stefan Geissler
327             2016 Simon Reinhardt
328             2017 Andreas K. Huettel
329             2020 Andreas K. Huettel
330              
331              
332             This is free software; you can redistribute it and/or modify it under
333             the same terms as the Perl 5 programming language system itself.
334              
335             =cut