Moose/Instrument/Cryomagnetics_4G.pm

filter: Statementstmt 17.3% 36 / 207 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 16.3% 9 / 55 Podpod 80.9% 34 / 42 totaltotal 23.9% 79 / 330 CC 15 SCAR 17.0
CC
15
Cov
15%
wait
30.0
in_persistent_mode
12.0
unset_persistent_mode
12.0
CRAP 5.5
« Moose/Instrument/Cache.pm ↑ Summary Moose/Instrument/Lakeshore340.pm »
1 package Lab::Moose::Instrument::Cryomagnetics_4G;
2 1 $Lab::Moose::Instrument::Cryomagnetics_4G::VERSION = '3.931';
3 #ABSTRACT: Cryomagnetics 4G superconducting magnet power supply
4  
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moose::Util::TypeConstraints qw/enum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Lab::Moose::Instrument qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 validated_getter validated_setter setter_params /;
12 1 ▶use Lab::Moose::Instrument::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Lab::Moose::Countdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 extends 'Lab::Moose::Instrument';
18  
19 1 with qw(
20 Lab::Moose::Instrument::Common
21 );
22  
23 1 has verbose => (
24 is => 'ro',
25 isa => 'Bool',
26 default => 1
27 );
28  
29 1 has heater_delay => (
30 is => 'ro',
31 isa => 'Lab::Moose::PosInt',
32 default => 60
33 );
34  
35 1 has max_field_deviation => (
36 is => 'ro',
37 isa => 'Num',
38 default => 0.0001
39 );
40  
41 1 has field_constant => (
42 is => 'ro',
43 isa => 'Num',
44 required => 1,
45 );
46  
47 0 ▶sub BUILD {
Subroutine BUILD: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my $self = shift;
49 0 my $units = $self->get_units();
50 0 ▶ if ( $units eq 'A' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($units eq "A") 0 0 0
51 0 carp
52 'Warning: Cryomagnetics 4G Power supply uses current units (A) not field units';
53 0 carp 'Switch to Gauss (but everything will be given in Tesla) units!';
54 0 $self->set_units(value => 'G');
55 }
56 }
57  
58  
59 0 ▶sub _remove_unit {
Subroutine _remove_unit: not called CC=1 SCAR=6.9
60 0 my $rv = shift;
61 0 $rv =~ s/[a-zA-Z]*$//;
62 0 return $rv;
63 }
64  
65 0 ▶sub _kG_to_tesla {
Subroutine _kG_to_tesla: not called CC=1 SCAR=6.9
66 0 my $kG = shift;
67 0 return 0.1 * $kG;
68 }
69  
70 0 ▶sub _tesla_to_kG {
Subroutine _tesla_to_kG: not called CC=1 SCAR=6.9
71 0 my $tesla = shift;
72 0 return 10 * $tesla;
73 }
74  
75 0 ▶sub _tesla_to_amp {
Subroutine _tesla_to_amp: not called CC=1 SCAR=6.9
76 0 my ($self, $value, %args) = validated_setter(
77 \@_,
78 value => { isa => 'num' },
79 );
80  
81 0 return $value * $self->field_constant();
82 }
83
84  
85  
86  
87 0 ▶sub get_field {
Subroutine get_field: not called CC=1 SCAR=6.9
Pod documented
88 0 my $self = shift;
89 0 return _kG_to_tesla( $self->get_iout(@_) );
90 }
91  
92  
93 0 ▶sub get_persistent_field {
Subroutine get_persistent_field: not called CC=1 SCAR=6.9
Pod documented
94 0 my $self = shift;
95 0 return _kG_to_tesla( $self->get_imag(@_) );
96 }
97  
98  
99 0 ▶sub sweep_to_field {
Subroutine sweep_to_field: not called CC=1 SCAR=6.9
Pod documented
100 0 my ( $self, %args ) = validated_getter(
101 \@_,
102 target => { isa => 'Num' },
103 rate => { isa => 'Num' },
104 );
105  
106 0 my $point = delete $args{target};
107 0 my $rate = delete $args{rate};
108  
109 0 $self->config_sweep( point => $point, rate => $rate, %args );
110  
111 0 $self->trg(%args);
112  
113 0 $self->wait(%args);
114 0 return $self->get_field(%args);
115 }
116  
117  
118 0 ▶sub config_sweep {
Subroutine config_sweep: not called CC=2 SCAR=17.9
Pod undocumented
119 0 my ( $self, %args ) = validated_hash(
120 \@_,
121 point => { isa => 'Num' },
122 rate => { isa => 'Num' },
123 );
124 0 my $target = delete $args{point};
125 0 my $rate = delete $args{rate};
126  
127 0 say "config sweep with target $target and rate $rate";
128  
129 0 $self->set_field_sweep_rate( value => $rate);
130 0 $self->set_target_field( value => $target);
131  
132 0 my $current_field = $self->get_field();
133 #$self->_check_sweep_parameters(
134 # current => $current_field, target => $target,
135 # rate => $rate
136 #);
137 0 ▶ if ( $self->verbose() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
138 0 say "config_sweep: target: $target (T), rate: $rate (T/min)";
139 }
140 }
141  
142  
143 0 ▶sub set_target_field {
Subroutine set_target_field: not called CC=1 SCAR=6.9
Pod documented
144 0 my ( $self, $value, %args) = validated_setter(
145 \@_,
146 value => { isa => 'Num' },
147 );
148 0 $value = _tesla_to_kG($value);
149 0 $self->set_setpoint(value => $value);
150 }
151  
152 0 ▶sub get_target_field {
Subroutine get_target_field: not called CC=1 SCAR=6.9
Pod undocumented
153 0 my ( $self, %args) = validated_getter( \@_ );
154 0 return _kG_to_tesla($self->get_setpoint());
155 }
156  
157  
158 0 ▶sub set_field_sweep_rate {
Subroutine set_field_sweep_rate: not called CC=2 SCAR=17.9
Pod documented
159 0 my ( $self, $value, %args) = validated_setter(
160 \@_,
161 value => { isa => 'Num' },
162 );
163 0 my $amprate = $self->_tesla_to_amp($value) / 60;
164 #my $gausrate = _tesla_to_kG($value) / 60;
165 0 for my $range (0 .. 4) {
166 0 $self->set_rate(range => $range, rate => $amprate);
167 };
168 };
169  
170  
171 0 ▶sub to_setpoint {
Subroutine to_setpoint: not called CC=2 SCAR=17.9
Pod undocumented
172 0 my ( $self, %args) = validated_getter( \@_ );
173 0 ▶ if ($self->get_pshtr() == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_pshtr == 0) { } 0 0 0
174 0 $self->set_sweep( value => 'UP FAST' );
175 } else {
176 0 $self->set_sweep( value => 'UP SLOW' );
177 }
178 }
179  
180 0 ▶sub set_setpoint {
Subroutine set_setpoint: not called CC=2 SCAR=17.9
Pod undocumented
181 0 my ( $self, $value, %args) = validated_setter(
182 \@_,
183 value => { isa => 'Num' },
184 );
185 0 my $lowerlimit = $self->get_llim();
186 # my upperlimit = $self->get_ulim();
187 0 ▶ if ($value < $lowerlimit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $lowerlimit) { } 0 0 0
188 0 $self->set_llim(value => $value);
189 0 $self->set_ulim(value => $value);
190 } else {
191 0 $self->set_ulim(value => $value);
192 0 $self->set_llim(value => $value);
193 }
194 }
195  
196 0 ▶sub get_setpoint {
Subroutine get_setpoint: not called CC=1 SCAR=6.9
Pod undocumented
197 0 my ( $self, %args) = validated_getter( \@_ );
198 0 return $self->get_ulim( @_ );
199 }
200  
201 0 ▶sub trg {
Subroutine trg: not called CC=1 SCAR=6.9
Pod undocumented
202 0 my ( $self, %args) = validated_getter( \@_ );
203 0 $self->to_setpoint();
204 }
205  
206 0 ▶sub wait {
Subroutine wait: not called CC=5 SCAR=34.0
Pod undocumented
207 0 my ( $self, %args) = validated_getter( \@_ );
208 0 my $target = $self->get_target_field();
209 0 my $verbose = $self->verbose();
210 # enable autoflush
211 0 my $autoflush = STDOUT->autoflush();
212 0 my $last_field;
213 0 my $time_step = 1;
214 0 while (1) {
215 0 sleep $time_step;
216 0 my $field = $self->get_field(%args);
217 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
218 0 my $rate;
219 0 ▶ if ( defined $last_field ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_field) { } 0 0 0
220 0 $rate = ( $field - $last_field ) * 60 / $time_step;
221 0 $rate = sprintf( "%.5g", $rate );
222 }
223 else {
224 0 $rate = "unknown";
225 }
226 0 printf(
227 "Field: %.6e T, Estimated rate: $rate T/min \r",
228 $field
229 );
230 0 $last_field = $field;
231 }
232 0 ▶ if ( abs( $field - $target ) < $self->max_field_deviation() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $field - $target < $self->max_field_deviation) 0 0 0
233 0 $self->hold();
234 0 last;
235 }
236 }
237 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
238 0 print " " x 70 . "\r";
239 }
240 # reset autoflush to previous value
241 0 STDOUT->autoflush($autoflush);
242 }
243  
244 # sub active {
245  
246 # }
247  
248  
249 0 ▶sub to_zero {
Subroutine to_zero: not called CC=1 SCAR=6.9
Pod documented
250 0 my ( $self, %args) = validated_getter( \@_ );
251 0 $self->set_sweep(value => 'ZERO', @_);
252 }
253  
254  
255 0 ▶sub hold {
Subroutine hold: not called CC=1 SCAR=6.9
Pod documented
256 0 my ( $self, %args) = validated_getter( \@_ );
257 0 $self->set_sweep(value => 'PAUSE', @_);
258 }
259  
260  
261 0 ▶sub in_persistent_mode {
Subroutine in_persistent_mode: not called CC=3 SCAR=24.8
Pod documented
262 0 my ( $self, %args ) = validated_getter( \@_ );
263 0 my $rv = $self->get_pshtr(@_);
264 0 ▶ if ( $rv eq 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rv eq 1) { } 0 0 0
elsif ($rv eq 0) { } 0 0 0
265 0 return 0;
266 }
267 elsif ( $rv eq 0 ) {
268 0 return 1;
269 }
270 else {
271 0 croak("unknown heater setting $rv");
272 }
273 }
274  
275  
276 0 ▶sub unset_persistent_mode {
Subroutine unset_persistent_mode: not called CC=3 SCAR=24.8
Pod documented
277 0 my ( $self, %args ) = validated_getter( \@_ );
278 0 ▶ if ($self->in_persistent_mode()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_persistent_mode) { } 0 0 0
279 0 my $pers_field = $self->get_persistent_field();
280 0 my $powerline_field = $self->get_field();
281  
282 0 ▶ if (abs($powerline_field - $pers_field) < $self->max_field_deviation()) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $powerline_field - $pers_field < $self->max_field_deviation) { } 0 0 0
283 0 $self->heater_on();
284 0 return;
285 } else {
286 0 $self->set_target_field( value => $pers_field );
287 0 $self->set_sweep(value => 'UP FAST');
288 0 countdown(120/5);
289 0 $self->set_sweep(value => 'UP');
290 #$self->wait();
291 0 $self->heater_on();
292 0 return;
293 };
294 } else {
295 0 return;
296 };
297 }
298  
299  
300 0 ▶sub set_persistent_mode {
Subroutine set_persistent_mode: not called CC=2 SCAR=17.9
Pod documented
301 0 my ( $self, %args) = validated_getter( \@_ );
302 0 ▶ if ($self->in_persistent_mode()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->in_persistent_mode) { } 0 0 0
303 0 return;
304 } else {
305 0 $self->heater_off();
306 0 $self->to_zero();
307 # $self->wait();
308 0 return;
309 };
310 }
311  
312  
313 0 ▶sub heater_on {
Subroutine heater_on: not called CC=1 SCAR=6.9
Pod documented
314 0 my ( $self, %args) = validated_getter( \@_ );
315 0 $self->set_pshtr(value => 'On', @_);
316 0 countdown( $self->heater_delay(), "Activated switch heater. Waiting for: ");
317 }
318  
319 0 ▶sub heater_off {
Subroutine heater_off: not called CC=1 SCAR=6.9
Pod documented
320 0 my ( $self, %args) = validated_getter( \@_ );
321 0 $self->set_pshtr(value => 'Off', @_);
322 0 countdown( $self->heater_delay(), "Deactivated switch heater. Waiting for: ");
323 }
324  
325  
326 0 ▶sub get_imag {
Subroutine get_imag: not called CC=1 SCAR=6.9
Pod documented
327 0 my ( $self, %args ) = validated_getter( \@_ );
328 0 my $rv = $self->query( command => "IMAG?", %args );
329 0 return _remove_unit($rv);
330 }
331  
332  
333 0 ▶sub get_iout {
Subroutine get_iout: not called CC=1 SCAR=6.9
Pod documented
334 0 my ( $self, %args ) = validated_getter( \@_ );
335 0 my $rv = $self->query( command => 'IOUT?', %args );
336 0 return _remove_unit($rv);
337 }
338  
339  
340 0 ▶sub set_llim {
Subroutine set_llim: not called CC=1 SCAR=6.9
Pod documented
341 0 my ( $self, $value, %args ) = validated_setter( \@_ );
342 0 $self->write( command => "LLIM $value", %args );
343 }
344  
345 0 ▶sub get_llim {
Subroutine get_llim: not called CC=1 SCAR=6.9
Pod documented
346 0 my ( $self, %args ) = validated_getter( \@_ );
347 0 my $rv = $self->query( command => 'LLIM?', %args );
348 0 return _remove_unit($rv);
349 }
350  
351  
352 0 ▶sub local {
Subroutine local: not called CC=1 SCAR=6.9
Pod documented
353 0 my ( $self, %args ) = validated_getter( \@_ );
354 0 $self->write( command => "LOCAL", %args );
355 }
356  
357  
358 0 ▶sub get_mode {
Subroutine get_mode: not called CC=1 SCAR=6.9
Pod documented
359 0 my ( $self, %args ) = validated_getter( \@_ );
360 0 return $self->query( command => 'MODE?', %args );
361 }
362  
363  
364 0 ▶sub set_pshtr {
Subroutine set_pshtr: not called CC=1 SCAR=6.9
Pod documented
365 0 my ( $self, $value, %args ) = validated_setter(
366 \@_,
367 value => { isa => enum( [qw/On Off/] ) },
368 );
369 0 $self->write( command => "PSHTR $value", %args );
370 }
371  
372 0 ▶sub get_pshtr {
Subroutine get_pshtr: not called CC=1 SCAR=6.9
Pod documented
373 0 my ( $self, %args ) = validated_getter( \@_ );
374 0 return $self->query( command => "PSHTR?", %args );
375 }
376  
377  
378 0 ▶sub set_range {
Subroutine set_range: not called CC=1 SCAR=6.9
Pod documented
379 0 my ( $self, %args ) = validated_getter(
380 \@_,
381 select => { isa => enum( [ ( 0 .. 4 ) ] ) },
382 limit => { isa => 'Num' },
383 );
384 0 my $select = delete $args{select};
385 0 my $limit = delete $args{limit};
386 0 $self->write( command => "RANGE $select $limit", %args );
387 }
388  
389 0 ▶sub get_range {
Subroutine get_range: not called CC=1 SCAR=6.9
Pod documented
390 0 my ( $self, %args ) = validated_getter(
391 \@_,
392 select => { isa => enum( [ ( 0 .. 4 ) ] ) },
393 );
394 0 my $select = delete $args{select};
395 0 return $self->query( command => "RANGE? $select", %args );
396 }
397  
398  
399 0 ▶sub set_rate {
Subroutine set_rate: not called CC=1 SCAR=6.9
Pod documented
400 0 my ( $self, %args ) = validated_getter(
401 \@_,
402 range => { isa => enum( [ ( 0 .. 5 ) ] ) },
403 rate => { isa => 'Num' },
404 );
405 0 my $range = delete $args{range};
406 0 my $rate = delete $args{rate};
407 0 $self->write( command => "RATE $range $rate", %args );
408 }
409  
410 0 ▶sub get_rate {
Subroutine get_rate: not called CC=1 SCAR=6.9
Pod documented
411 0 my ( $self, %args ) = validated_getter(
412 \@_,
413 range => { isa => enum( [ ( 0 .. 5 ) ] ) },
414 );
415 0 my $range = delete $args{range};
416 0 return $self->query( command => "RATE? $range", %args );
417 }
418  
419  
420 0 ▶sub set_sweep {
Subroutine set_sweep: not called CC=1 SCAR=6.9
Pod documented
421 0 my ( $self, $value, %args ) = validated_setter(
422 \@_,
423 value => {
424 isa => enum(
425 [ qw/UP DOWN PAUSE ZERO LIMIT/, 'UP SLOW', 'DOWN SLOW', 'UP FAST', 'DOWN FAST' ]
426 )
427 },
428 );
429  
430 0 $self->write( command => "SWEEP $value", %args );
431 }
432  
433 0 ▶sub get_sweep {
Subroutine get_sweep: not called CC=1 SCAR=6.9
Pod documented
434 0 my ( $self, %args ) = validated_getter( \@_ );
435 0 return $self->query( command => "SWEEP?", %args );
436 }
437  
438  
439 0 ▶sub set_ulim {
Subroutine set_ulim: not called CC=1 SCAR=6.9
Pod documented
440 0 my ( $self, $value, %args ) = validated_setter(
441 \@_,
442 value => { isa => 'Num' },
443 );
444  
445 0 $self->write( command => "ULIM $value", %args );
446 }
447  
448 0 ▶sub get_ulim {
Subroutine get_ulim: not called CC=1 SCAR=6.9
Pod documented
449 0 my ( $self, %args ) = validated_getter( \@_ );
450 0 return _remove_unit( $self->query( command => "ULIM?", %args ) );
451 }
452  
453  
454 1 cache units => ( getter => 'get_units' );
455  
456 0 ▶sub set_units {
Subroutine set_units: not called CC=1 SCAR=6.9
Pod documented
457 0 my ( $self, $value, %args ) = validated_setter(
458 \@_,
459 value => { isa => enum( [qw/A G/] ) },
460 );
461 0 $self->write( command => "UNITS $value", %args );
462 }
463  
464 0 ▶sub get_units {
Subroutine get_units: not called CC=1 SCAR=6.9
Pod documented
465 0 my ( $self, %args ) = validated_getter( \@_ );
466 0 return $self->query( command => "UNITS?", %args );
467 }
468  
469  
470 0 ▶sub set_vlim {
Subroutine set_vlim: not called CC=1 SCAR=6.9
Pod documented
471 0 my ( $self, $value, %args ) = validated_setter(
472 \@_,
473 value => { isa => 'Num' },
474 );
475  
476 0 $self->write( command => "VLIM $value", %args );
477 }
478  
479 0 ▶sub get_vlim {
Subroutine get_vlim: not called CC=1 SCAR=6.9
Pod documented
480 0 my ( $self, %args ) = validated_getter( \@_ );
481 0 return _remove_unit( $self->query( command => "VLIM?", %args ) );
482 }
483  
484  
485 0 ▶sub get_vmag {
Subroutine get_vmag: not called CC=1 SCAR=6.9
Pod documented
486 0 my ( $self, %args ) = validated_getter( \@_ );
487 0 return _remove_unit( $self->query( command => "VMAG?", %args ) );
488 }
489  
490  
491 0 ▶sub get_vout {
Subroutine get_vout: not called CC=1 SCAR=6.9
Pod documented
492 0 my ( $self, %args ) = validated_getter( \@_ );
493 0 return _remove_unit( $self->query( command => "VOUT?", %args ) );
494 }
495  
496  
497 1 __PACKAGE__->meta()->make_immutable();
498  
499 1 1;
500  
501 __END__
« Moose/Instrument/Cache.pm ↑ Summary Moose/Instrument/Lakeshore340.pm »