File Coverage

blib/lib/Lab/XPRESS/Sweep/Magnet.pm
Criterion Covered Total %
statement 11 59 18.6
branch 0 22 0.0
condition 0 3 0.0
subroutine 4 11 36.3
pod 1 7 14.2
total 16 102 15.6


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