File Coverage

blib/lib/Lab/Moose/Sweep/Continuous/Magnet.pm
Criterion Covered Total %
statement 11 21 52.3
branch 0 4 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 15 31 48.3


line stmt bran cond sub pod time code
1             package Lab::Moose::Sweep::Continuous::Magnet;
2             $Lab::Moose::Sweep::Continuous::Magnet::VERSION = '3.900';
3             #ABSTRACT: Continuous sweep of magnetic field
4              
5 1     1   2704 use v5.20;
  1         5  
6              
7              
8 1     1   10 use Moose;
  1         3  
  1         19  
9 1     1   7717 use Carp;
  1         2  
  1         80  
10 1     1   6 use Time::HiRes 'time';
  1         3  
  1         12  
11              
12             extends 'Lab::Moose::Sweep::Continuous';
13              
14             has filename_extension => ( is => 'ro', isa => 'Str', default => 'Field=' );
15              
16             # field value for filename extensions.
17             # Only used if separate datafiles are produces for different fields.
18             # Should use 'step' sweep for this in most cases.
19             sub get_value {
20 0     0 0   my $self = shift;
21 0           my $from = $self->from;
22 0           my $to = $self->to;
23 0           my $rate = abs( $self->rate );
24 0 0         my $sign = $to > $from ? 1 : -1;
25              
26             # Only estimate field.
27             # Do not query field for performance reasons.
28             # Will give wrong results, if the sweep slowly saturates to the setpoint.
29              
30 0           my $t0 = $self->start_time();
31 0 0         if ( not defined $t0 ) {
32 0           croak "sweep not started";
33             }
34 0           my $t = time();
35 0           return $from + ( $t - $to ) * $sign * $rate / 60;
36             }
37              
38             __PACKAGE__->meta->make_immutable();
39             1;
40              
41             __END__
42              
43             =pod
44              
45             =encoding UTF-8
46              
47             =head1 NAME
48              
49             Lab::Moose::Sweep::Continuous::Magnet - Continuous sweep of magnetic field
50              
51             =head1 VERSION
52              
53             version 3.900
54              
55             =head1 SYNOPSIS
56              
57             use Lab::Moose;
58              
59             #
60             # 1D sweep of magnetic field
61             #
62            
63             my $ips = instrument(
64             type => 'OI_Mercury::Magnet'
65             connection_type => ...,
66             connection_options => {...}
67             );
68              
69             my $multimeter = instrument(...);
70            
71             my $sweep = sweep(
72             type => 'Continuous::Magnet',
73             instrument => $ips,
74             from => -1, # Tesla
75             to => 1,
76             rate => 1, (Tesla/min, always positive)
77             interval => 0.5, # one measurement every 0.5 seconds
78             );
79              
80             my $datafile = sweep_datafile(columns => ['B-field', 'current']);
81             $datafile->add_plot(x => 'B-field', y => 'current');
82            
83             my $meas = sub {
84             my $sweep = shift;
85             my $field = $ips->get_field();
86             my $current = $multimeter->get_value();
87             $sweep->log('B-field' => $field, current => $current);
88             };
89              
90             $sweep->start(
91             datafiles => [$datafile],
92             measurement => $meas,
93             );
94              
95             =head1 COPYRIGHT AND LICENSE
96              
97             This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
98              
99             Copyright 2018 Simon Reinhardt
100             2020 Andreas K. Huettel
101              
102              
103             This is free software; you can redistribute it and/or modify it under
104             the same terms as the Perl 5 programming language system itself.
105              
106             =cut