Moose/Sweep/Continuous/Magnet.pm

filter: Statementstmt 61.5% 16 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 55.5% 20 / 36 SCAR 13.6
CC
3
Cov
53%
get_value
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.9
« Moose/Instrument/RS_FSV.pm ↑ Summary Connection/RS232.pm »
1 package Lab::Moose::Sweep::Continuous::Magnet;
2 1 $Lab::Moose::Sweep::Continuous::Magnet::VERSION = '3.881';
3 #ABSTRACT: Continuous sweep of magnetic field
4  
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Time::HiRes 'time';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 extends 'Lab::Moose::Sweep::Continuous';
13  
14 1 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 ▶ my $self = shift;
Subroutine get_value: not called CC=3 SCAR=24.8
Pod undocumented
21 0 my $from = $self->from;
22 0 my $to = $self->to;
23 0 my $rate = abs( $self->rate );
24 0 ▶ my $sign = $to > $from ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$to > $from ? : 0 0 0
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 ▶ if ( not defined $t0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t0) 0 0 0
32 0 croak "sweep not started";
33 }
34 0 my $t = time();
35 0 return $from + ( $t - $to ) * $sign * $rate / 60;
36 }
37  
38 1 __PACKAGE__->meta->make_immutable();
39 1 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.881
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
« Moose/Instrument/RS_FSV.pm ↑ Summary Connection/RS232.pm »