Instrument/ProStep4.pm

filter: Statementstmt 8.3% 26 / 311 Branchbran 0.0% 0 / 90 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 19.0% 4 / 21 Podpod 6.6% 1 / 15 totaltotal 5.9% 31 / 522 SCAR 81.9
CC
65
Cov
6%
move
380.0
init_limits
240.0
get_position
240.0
CRAP 3606.3
« Moose/Instrument/ProStep4.pm ↑ Summary Instrument/PD11042.pm »
1 package Lab::Instrument::ProStep4;
2 #ABSTRACT: ProStep4 step motor
3 1 $Lab::Instrument::ProStep4::VERSION = '3.881';
4 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Time::HiRes qw/usleep/, qw/time/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Lab::Instrument;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $AXIS = 1;
11 1 our $RESOLUTION = 1024;
12 1 our $GETRIEBEMULTIPLIKATOR = 0.015;
13 1 our $NULL = 32768;
14 1 our $STEPS_PER_ROUND = 400;
15 1 our $BACKLASH = 200;
16 1 our $AA = 200;
17 1 our $AE = 200;
18 1 our $VA = 0;
19 1 our $VE = 30;
20 1 our $VM = 30;
21  
22 1 our %fields = (
23 supported_connections => [ 'VISA', 'VISA_RS232', 'RS232', 'DEBUG' ],
24 connection_settings => {
25 baudrate => 9600,
26 databits => 8,
27 stopbits => 1,
28 parity => 'none',
29 handshake => 'none',
30 termchar => '\r',
31 timeout => 2,
32 inipath => '',
33 logpath => '',
34 },
35  
36 device_settings => {
37 read_default => 'device',
38 pos_mode => 'ABS',
39 speed_max => 180,
40 upper_limit => 180,
41 lower_limit => -180,
42  
43 },
44  
45 device_cache => {
46 position => undef,
47 target => undef,
48 },
49  
50 device_cache_order => ['id'],
51 );
52  
53 1 our @ISA = ("Lab::Instrument");
54  
55 sub new {
56 0 ▶ my $proto = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
57 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
58 0 my $self = $class->SUPER::new(@_);
59 0 $self->${ \( __PACKAGE__ . '::_construct' ) }(__PACKAGE__);
60  
61 #$self->init();
62  
63 0 $self->{active} = 0;
64 0 return $self;
65 }
66  
67 sub _device_init {
68 0 ▶ my $self = shift;
Subroutine _device_init: not called CC=1 SCAR=6.9
69  
70 0 $self->query("C:\r\n");
71 0 $self->InitEncoder( $STEPS_PER_ROUND, $RESOLUTION, $NULL );
72 0 $self->InitRamp( $AXIS, $AA, $AE, $VA, $VE, $VM );
73 0 $self->clear();
74  
75 0 $self->init_limits();
76 }
77  
78 sub InitEncoder {
79 0 ▶ my $self = shift;
Subroutine InitEncoder: not called CC=1 SCAR=6.9
Pod undocumented
80 0 my ( $steps, $res, $null )
81 = $self->_check_args( \@_, [ 'steps', 'res', 'null' ] );
82  
83 0 $self->write("encoder: $steps $res $null\r\n");
84 0 my $result = $self->read( { read_length => 300 } );
85  
86 0 return $result;
87 }
88  
89 sub InitRamp {
90 0 ▶ my $self = shift;
Subroutine InitRamp: not called CC=1 SCAR=6.9
Pod undocumented
91  
92 0 my ( $axis, $aa, $ae, $va, $ve, $vm )
93 = $self->_check_args( \@_, [ 'axis', 'aa', 'ae', 'va', 've', 'vm' ] );
94  
95 0 $self->write("tp: $axis $aa $ae $va $ve $vm\r\n");
96 0 my $result = $self->read( { read_length => 100 } );
97  
98 0 return $result;
99 }
100  
101 sub move {
102 0 ▶ my $self = shift;
Subroutine move: not called CC=19 SCAR=59.4
Pod undocumented
103  
104 0 my ( $position, $speed, $mode )
105 = $self->_check_args( \@_, [ 'position', 'speed', 'mode' ] );
106  
107 0 ▶ if ( not defined $mode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mode) 0 0 0
108 0 $mode = $self->device_settings()->{pos_mode};
109 }
110 0 ▶ if ( not $mode =~ /ABS|abs|REL|rel/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode =~ /ABS|abs|REL|rel/u) 0 0 0
111 0 Lab::Exception::CorruptParameter->throw( error =>
112 "unexpected value for <MODE> in sub move. expected values are ABS and REL."
113 );
114 }
115 0 ▶ if ( not defined $speed ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $speed) 0 0 0
116 0 $speed = $self->device_settings()->{speed_max};
117 }
118 0 ▶ if ( not defined $position ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $position) { } 0 0 0
elsif (not $position =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/u) { } 0 0 0
119 0 Lab::Exception::CorruptParameter->throw(
120 error => $self->get_id() . ": No target given in sub move! " );
121 }
122 elsif (
123 not $position =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ )
124 {
125 0 Lab::Exception::CorruptParameter->throw( error => $self->get_id()
126 . ": Illegal Value given for POSITION in sub move!" );
127 }
128  
129 # this sets the upper limit for the positioning speed:
130 0 $speed = abs($speed);
131 0 ▶ if ( $speed > $self->device_settings()->{speed_max} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($speed > $self->device_settings->{"speed_max"}) 0 0 0
132 0 print new Lab::Exception::CorruptParameter( error =>
133 "Warning in sub move: <SPEED> = $speed is too high. Reduce <SPEED> to its maximum value defined by internal limit settings of $self->device_settings()->{speed_max}"
134 );
135 0 $speed = $self->device_settings()->{speed_max};
136 }
137  
138 0 $speed = $self->angle2steps($speed) / 60;
139  
140 # Moving in ABS or REL mode:
141 0 my $CP = $self->get_position(); # get current position
142 0 ▶ if ( $mode eq "ABS"
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'ABS' or $mode eq 'abs' or $mode eq 'ABSOLUTE' or $mode eq 'absolute') { } 0 0 0
elsif ($mode eq 'REL' or $mode eq 'rel' or $mode eq 'RELATIVE' or $mode eq 'relative') { } 0 0 0
Condition0%0/9
$mode eq "ABS" or $mode eq "abs" or $mode eq "ABSOLUTE" or $mode eq "absolute"
l!l&&r!l&&!r
000
$mode eq "ABS" or $mode eq "abs" or $mode eq "ABSOLUTE"
l!l&&r!l&&!r
000
$mode eq "ABS" or $mode eq "abs"
l!l&&r!l&&!r
000
MC/DC0%0/4
$mode eq "ABS" or $mode eq "abs" or $mode eq "ABSOLUTE" or $mode eq "absolute"
$mode eq "ABS" $mode eq "abs" $mode eq "ABSOLUTE" $mode eq "absolute"
Truth table0%0/5
A or B or C or D
A= $mode eq "ABS"B= $mode eq "abs"C= $mode eq "ABSOLUTE"D= $mode eq "absolute"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
143 or $mode eq "abs"
144 or $mode eq "ABSOLUTE"
145 or $mode eq "absolute" ) {
146 0 ▶ if ( $position < $self->device_settings()->{lower_limit}
Branch: 1 branch
BranchTrueFalseTotal
if ($position < $self->device_settings->{"lower_limit"} or $position > $self->device_settings->{"upper_limit"}) 0 0 0
Condition0%0/3
$position < $self->device_settings->{"lower_limit"} or $position > $self->device_settings->{"upper_limit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$position < $self->device_settings->{"lower_limit"} or $position > $self->device_settings->{"upper_limit"}
$position < $self->device_settings->{"lower_limit"} $position > $self->device_settings->{"upper_limit"}
Truth table0%0/3
A or B
A= $position < $self->device_settings->{"lower_limit"}B= $position > $self->device_settings->{"upper_limit"}
ABresult
1X1
011
000
147 or $position > $self->device_settings()->{upper_limit} ) {
148 Lab::Exception::CorruptParameter->throw( error =>
149 "unexpected value for NEW POSITION in sub move. Expected values are between "
150 . $self->device_settings()->{lower_limit} . " ... "
151 0 . $self->device_settings()->{upper_limit} );
152 }
153 0 $self->device_cache()->{target} = $position;
154 0 $self->_save_motorlog( $CP, $position );
155 0 $self->save_motorinitdata();
156 0 $self->query(
157 "ma$AXIS " . $self->angle2steps($position) . " $speed\r\n" );
158 }
159 ▶ elsif ($mode eq "REL"
Condition0%0/9
$mode eq "REL" or $mode eq "rel" or $mode eq "RELATIVE" or $mode eq "relative"
l!l&&r!l&&!r
000
$mode eq "REL" or $mode eq "rel" or $mode eq "RELATIVE"
l!l&&r!l&&!r
000
$mode eq "REL" or $mode eq "rel"
l!l&&r!l&&!r
000
MC/DC0%0/4
$mode eq "REL" or $mode eq "rel" or $mode eq "RELATIVE" or $mode eq "relative"
$mode eq "REL" $mode eq "rel" $mode eq "RELATIVE" $mode eq "relative"
Truth table0%0/5
A or B or C or D
A= $mode eq "REL"B= $mode eq "rel"C= $mode eq "RELATIVE"D= $mode eq "relative"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
160 or $mode eq "rel"
161 or $mode eq "RELATIVE"
162 or $mode eq "relative" ) {
163 0 ▶ if ( $CP + $position < $self->device_settings()->{lower_limit}
Branch: 1 branch
BranchTrueFalseTotal
if ($CP + $position < $self->device_settings->{"lower_limit"} or $CP + $position > $self->device_settings->{"upper_limit"}) 0 0 0
Condition0%0/3
$CP + $position < $self->device_settings->{"lower_limit"} or $CP + $position > $self->device_settings->{"upper_limit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$CP + $position < $self->device_settings->{"lower_limit"} or $CP + $position > $self->device_settings->{"upper_limit"}
$CP + $position < $self->device_settings->{"lower_limit"} $CP + $position > $self->device_settings->{"upper_limit"}
Truth table0%0/3
A or B
A= $CP + $position < $self->device_settings->{"lower_limit"}B= $CP + $position > $self->device_settings->{"upper_limit"}
ABresult
1X1
011
000
164 or $CP + $position > $self->device_settings()->{upper_limit} ) {
165 Lab::Exception::CorruptParameter->throw( error =>
166 "ERROR in sub move.Can't execute move; TARGET POSITION ("
167 . ( $CP + $position )
168 . ") is out of valid limits ("
169 . $self->device_settings()->{lower_limit} . " ... "
170 . $self->device_settings()->{upper_limit}
171 0 . ")" );
172 }
173 0 $self->device_cache()->{target} = $CP + $position;
174 0 $self->_save_motorlog( $CP, $CP + $position );
175 0 $self->save_motorinitdata();
176 0 $self->query(
177 "mr$AXIS " . $self->angle2steps($position) . " $speed\r\n" );
178  
179 }
180  
181 0 return 1;
182  
183 }
184  
185 sub active {
186 0 ▶ my $self = shift;
Subroutine active: not called CC=1 SCAR=6.9
Pod undocumented
187  
188 0 my $result = $self->get_position();
189  
190 0 return $self->{active};
191  
192 }
193  
194 sub wait {
195 0 ▶ my $self = shift;
Subroutine wait: not called CC=5 SCAR=34.0
Pod undocumented
196  
197 0 my $flag = 1;
198 0 local $| = 1;
199  
200 0 ▶ while ( $self->active() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->active) 0 0 0
201 0 my $current = $self->device_cache()->{position};
202 0 ▶ if ( $flag <= 1.1 and $flag >= 0.9 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($flag <= 1.1 and $flag >= 0.9) { } 0 0 0
elsif ($flag <= 0) { } 0 0 0
Condition0%0/3
$flag <= "1.1" and $flag >= "0.9"
!ll&&!rl&&r
000
MC/DC0%0/2
$flag <= "1.1" and $flag >= "0.9"
$flag <= "1.1" $flag >= "0.9"
Truth table0%0/3
A and B
A= $flag <= "1.1"B= $flag >= "0.9"
ABresult
0X0
100
111
203 0 print $self->get_id()
204 . sprintf( " is sweeping (%.2f\370)\r", $current );
205 }
206 elsif ( $flag <= 0 ) {
207 0 print $self->get_id()
208 . sprintf( " is (%.2f\370)\r", $current );
209 0 $flag = 2;
210 }
211 0 $flag -= 0.1;
212 0 usleep(2e3);
213 }
214  
215 0 print "\t\t\t\t\t\t\t\t\t\r";
216 0 $| = 0;
217  
218 0 return 1;
219  
220 }
221  
222 sub abort {
223 0 ▶ my ($self) = @_;
Subroutine abort: not called CC=2 SCAR=17.9
Pod undocumented
224 0 while (1) {
225 0 $self->query("sa$AXIS\r\n");
226 0 ▶ if ( not $self->active() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->active) 0 0 0
227 0 last;
228 }
229 }
230 0 print "Motor stoped at " . $self->get_position() . "\n";
231 0 return;
232 }
233  
234 sub init_limits {
235 0 ▶ my $self = shift;
Subroutine init_limits: not called CC=15 SCAR=54.8
Pod undocumented
236 0 my $lowerlimit;
237 my $upperlimit;
238  
239 0 ▶ if ( $self->read_motorinitdata() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->read_motorinitdata) 0 0 0
240 0 while (1) {
241 0 print
242 "Motor-Init data found. Do you want to keep the reference point and the limits? (y/n) ";
243 0 my $input = <>;
244 0 chomp $input;
245 0 ▶ if ( $input =~ /YES|yes|Y|y/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($input =~ /YES|yes|Y|y/u) { } 0 0 0
elsif ($input =~ /NO|no|N|n/u) { } 0 0 0
246 0 return 1;
247 }
248 elsif ( $input =~ /NO|no|N|n/ ) {
249 0 my $result = $self->query("sa$AXIS\r\n");
250 0 my $result = $self->query("nullen\r\n");
251 0 $self->device_settings->{lower_limit} = -360;
252 0 $self->device_settings->{upper_limit} = 360;
253 0 last;
254 }
255 }
256 }
257  
258 0 print "\n\n";
259 0 print "----------------------------------------------\n";
260 0 print "----------- Init Motor ProStep4 -------------\n";
261 0 print "----------------------------------------------\n";
262 0 print "\n";
263 0 print
264 "This procedure will help you to initialize the Motor ProStep4 correctly.\n\n";
265 0 print "Steps to go:\n";
266 0 print " 1.) Define the REFERENCE POINT.\n";
267 0 print " 2.) Define the LOWER and UPPER LIMITS for rotation.\n";
268 0 print " 3.) Confirm the LOWER and UPPER LIMITS.\n";
269 0 print "\n\n";
270  
271 0 print "----------------------------\n";
272 0 print "1.) Define the REFERENCE POINT:\n\n";
273 0 print "--> Move the motor position to the REFERENCE POINT.\n";
274 0 print "--> Enter a (relative) angle between -180 ... +180 deg.\n";
275 0 print
276 "--> Repeat until you have reached the position you want to define as the REFERENCE POINT.\n";
277 0 print
278 "--> Enter 'REF' to confirm the actual position as the REFERENCE POINT.\n\n";
279  
280 0 while (1) {
281 0 print "MOVE: ";
282 0 my $value = <>;
283 0 chomp $value;
284 0 ▶ if ( $value eq "REF" or $value eq "ref" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value eq 'REF' or $value eq 'ref') { } 0 0 0
elsif ($value =~ /^[+-]?\d+$/u and $value >= -180 and $value <= 180) { } 0 0 0
Condition0%0/3
$value eq "REF" or $value eq "ref"
l!l&&r!l&&!r
000
MC/DC0%0/2
$value eq "REF" or $value eq "ref"
$value eq "REF" $value eq "ref"
Truth table0%0/3
A or B
A= $value eq "REF"B= $value eq "ref"
ABresult
1X1
011
000
285  
286 # set actual position as reference point Zero
287 0 $self->device_cache()->{position} = 0; # for testing only
288 0 my $result = $self->query("sa$AXIS\r\n");
289 0 my $result = $self->query("nullen\r\n");
290 0 last;
291 }
292 ▶ elsif ( $value =~ /^[+-]?\d+$/ and $value >= -180 and $value <= 180 )
Condition0%0/6
$value =~ /^[+-]?\d+$/u and $value >= -180 and $value <= 180
!ll&&!rl&&r
000
$value =~ /^[+-]?\d+$/u and $value >= -180
!ll&&!rl&&r
000
MC/DC0%0/3
$value =~ /^[+-]?\d+$/u and $value >= -180 and $value <= 180
$value =~ /^[+-]?\d+$/u $value >= -180 $value <= 180
Truth table0%0/4
A and B and C
A= $value =~ /^[+-]?\d+$/uB= $value >= -180C= $value <= 180
ABCresult
0XX0
10X0
1100
1111
293 {
294 0 $self->move( $value, { mode => 'REL' } );
295 0 $self->wait();
296 }
297 else {
298 0 print
299 "Please move the motor position to the REFERENCE POINT. Enter an angle between -188\370 ... +180\370.\n";
300 }
301 }
302  
303 0 print "----------------------------\n";
304 0 print "2.) Define the LOWER and UPPER LIMITS for rotation:\n\n";
305 0 print "--> Enter LOWER LIMIT\n";
306 0 print "--> Enter UPPER LIMIT\n\n";
307  
308 0 while (1) {
309 0 print "LOWER LIMIT: ";
310 0 my $value = <>;
311 0 chomp $value;
312 0 $lowerlimit = $value;
313 0 $self->device_settings()->{lower_limit} = $lowerlimit;
314 0 print "UPPER LIMIT: ";
315 0 my $value = <>;
316 0 chomp $value;
317 0 $upperlimit = $value;
318 0 $self->device_settings()->{upper_limit} = $upperlimit;
319  
320 0 ▶ if ( $lowerlimit < $upperlimit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerlimit < $upperlimit) { } 0 0 0
321 0 last;
322 }
323 else {
324 0 print "LOWER LIMIT >= UPPER LIMIT. Try again!\n";
325 }
326 }
327  
328 0 print "----------------------------\n";
329 0 print "3.) Confirm the LOWER and UPPER LIMITS:\n\n";
330 0 print "--> Motor will move to LOWER LIMIT in steps of 10 deg\n";
331 0 print "--> Motor will move to UPPER LIMIT in steps of 10 deg\n";
332 0 print
333 "--> Confirm each step with ENTER or type <STOP> to take the actual position as the limit value. \n\n";
334  
335 0 print "Moving to LOWER LIMIT ...\n";
336 0 while (1) {
337 0 print "MOVE +/-10: Please press <ENTER> to confirm.";
338 0 my $input = <>;
339 0 chomp $input;
340 0 ▶ if ( $input =~ /stop|STOP/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /stop|STOP/u) 0 0 0
341 0 $lowerlimit = $self->get_position();
342 0 last;
343 }
344 0 ▶ if ( abs( $self->get_position() - $lowerlimit ) >= 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $self->get_position - $lowerlimit >= 10) { } 0 0 0
345 0 ▶ if ( $lowerlimit <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerlimit <= 0) { } 0 0 0
346 0 $self->move( -10, { mode => 'REL' } );
347 0 $self->wait();
348 }
349 else {
350 0 $self->move( 10, { mode => 'REL' } );
351 0 $self->wait();
352 }
353 }
354 else {
355 0 $self->move( $lowerlimit, { mode => 'ABS' } );
356 0 $self->wait();
357 0 last;
358 }
359  
360 }
361 0 print "Reached LOWER LIMIT\n";
362 0 print "Please confirm the position of the LOWER LIMIT: ";
363 0 <>;
364 0 $self->device_settings()->{'lower_limit'} = $lowerlimit;
365 0 print "\n\n";
366 0 print "Moving to REFERENCE POINT ... \n";
367 0 $self->move( 0, { mode => 'ABS' } ) . "\n";
368 0 $self->wait();
369 0 print "Moving to UPPER LIMIT ...\n";
370  
371 0 while (1) {
372 0 print "MOVE +/-10: Please press <ENTER> to confirm.";
373 0 my $input = <>;
374 0 chomp $input;
375 0 ▶ if ( $input =~ /stop|STOP/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /stop|STOP/u) 0 0 0
376 0 $upperlimit = $self->get_position();
377 0 last;
378 }
379 0 ▶ if ( abs( $upperlimit - $self->get_position() ) >= 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $upperlimit - $self->get_position >= 10) { } 0 0 0
380 0 $self->move( 10, { mode => 'REL' } );
381 0 $self->wait();
382 }
383 else {
384 0 $self->move( $upperlimit, { mode => 'ABS' } );
385 0 $self->wait();
386 0 last;
387 }
388  
389 }
390 0 print "Reached UPPER LIMIT\n";
391 0 print "Please confirm the position of the UPPER LIMIT: ";
392 0 <>;
393 0 $self->device_settings()->{'upper_limit'} = $upperlimit;
394 0 print "\n\n";
395 0 $self->save_motorinitdata();
396  
397 0 print "moving to the reference point.\n";
398 0 $self->move( 0, { mode => 'ABS' } );
399 0 $self->wait();
400 0 print "------------------------------------------------------\n";
401 0 print "------------ Motor ProStep4 initialized --------------\n";
402 0 print "------------------------------------------------------\n";
403 0 print "\n\n";
404  
405 }
406  
407 sub steps2angle {
408 0 ▶ my $self = shift;
Subroutine steps2angle: not called CC=1 SCAR=6.9
Pod undocumented
409 0 my ($steps) = $self->_check_args( \@_, ['value'] );
410  
411 0 my $angle = $steps * $GETRIEBEMULTIPLIKATOR;
412 0 return $angle;
413 }
414  
415 sub angle2steps {
416 0 ▶ my $self = shift;
Subroutine angle2steps: not called CC=1 SCAR=6.9
Pod undocumented
417 0 my ($angle) = $self->_check_args( \@_, ['value'] );
418  
419 0 my $steps = $angle / $GETRIEBEMULTIPLIKATOR;
420 0 return sprintf( "%0.f", $steps );
421  
422 }
423  
424 sub get_value {
425 0 ▶ my $self = shift;
Subroutine get_value: not called CC=1 SCAR=6.9
Pod undocumented
426 0 my ($read_mode) = $self->_check_args( \@_, ['read_mode'] );
427 0 return $self->get_position( { read_mode => $read_mode } );
428 }
429  
430 sub get_position {
431 0 ▶ my $self = shift;
Subroutine get_position: not called CC=15 SCAR=54.8
Pod undocumented
432 0 my ($read_mode) = $self->_check_args( \@_, ['read_mode'] );
433  
434 0 my $cmd = "a" . $AXIS . "?\r\n";
435 0 my $result;
436  
437 0 ▶ if ( not defined $read_mode
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $read_mode and $read_mode =~ /device|cache|request|fetch/u) 0 0 0
Condition0%0/3
defined $read_mode and $read_mode =~ /device|cache|request|fetch/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $read_mode and $read_mode =~ /device|cache|request|fetch/u
defined $read_mode $read_mode =~ /device|cache|request|fetch/u
Truth table0%0/3
A and B
A= defined $read_modeB= $read_mode =~ /device|cache|request|fetch/u
ABresult
0X0
100
111
438 or not $read_mode =~ /device|cache|request|fetch/ ) {
439 0 $read_mode = $self->device_settings()->{read_default};
440 }
441  
442 0 ▶ if ( $read_mode eq 'cache'
Branch: 4 branches
BranchTrueFalseTotal
if ($read_mode eq 'cache' and defined $self->{'device_cache'}{'position'}) { } 0 0 0
elsif ($read_mode eq 'request' and $self->{'request'} == 0) { } 0 0 0
elsif ($read_mode eq 'request' and $self->{'request'} == 1) { } 0 0 0
elsif ($read_mode eq 'fetch' and $self->{'request'} == 1) { } 0 0 0
Condition0%0/3
$read_mode eq "cache" and defined $self->{"device_cache"}{"position"}
!ll&&!rl&&r
000
MC/DC0%0/2
$read_mode eq "cache" and defined $self->{"device_cache"}{"position"}
$read_mode eq "cache" defined $self->{"device_cache"}{"position"}
Truth table0%0/3
A and B
A= $read_mode eq "cache"B= defined $self->{"device_cache"}{"position"}
ABresult
0X0
100
111
443 and defined $self->{'device_cache'}->{'position'} ) {
444 0 return $self->{'device_cache'}->{'position'};
445 }
446 ▶ elsif ( $read_mode eq 'request' and $self->{request} == 0 ) {
Condition0%0/3
$read_mode eq "request" and $self->{"request"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$read_mode eq "request" and $self->{"request"} == 0
$read_mode eq "request" $self->{"request"} == 0
Truth table0%0/3
A and B
A= $read_mode eq "request"B= $self->{"request"} == 0
ABresult
0X0
100
111
447 0 $self->{request} = 1;
448 0 $self->write($cmd);
449 0 return;
450 }
451 ▶ elsif ( $read_mode eq 'request' and $self->{request} == 1 ) {
Condition0%0/3
$read_mode eq "request" and $self->{"request"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$read_mode eq "request" and $self->{"request"} == 1
$read_mode eq "request" $self->{"request"} == 1
Truth table0%0/3
A and B
A= $read_mode eq "request"B= $self->{"request"} == 1
ABresult
0X0
100
111
452 0 $result = $self->read();
453 0 $self->write($cmd);
454 0 return;
455 }
456 ▶ elsif ( $read_mode eq 'fetch' and $self->{request} == 1 ) {
Condition0%0/3
$read_mode eq "fetch" and $self->{"request"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$read_mode eq "fetch" and $self->{"request"} == 1
$read_mode eq "fetch" $self->{"request"} == 1
Truth table0%0/3
A and B
A= $read_mode eq "fetch"B= $self->{"request"} == 1
ABresult
0X0
100
111
457 0 $self->{request} = 0;
458 0 $result = $self->read();
459 }
460 else {
461 0 ▶ if ( $self->{request} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'request'} == 1) { } 0 0 0
462 0 $result = $self->read();
463 0 $self->{request} = 0;
464 0 $result = $self->query($cmd);
465 }
466 else {
467 0 $result = $self->query($cmd);
468 }
469 }
470  
471 0 for ( 0 .. 2 ) {
472 0 ▶ if ( $result =~ m/Posi_$AXIS:\s+([+-]?\d+)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result =~ /Posi_$Lab::Instrument::ProStep4::AXIS:\s+([+-]?\d+)/u) { } 0 0 0
elsif ($result =~ m[Soll/Ist/Speed_$Lab::Instrument::ProStep4::AXIS:\s+([+-]?\d+)\s+([+-]?\d+)\s+([+-]?\d+)]u) { } 0 0 0
473 0 $self->device_cache()->{position} = $self->steps2angle($1);
474 0 $self->{active} = 0;
475 0 last;
476 }
477 elsif ( $result
478 =~ m/Soll\/Ist\/Speed_$AXIS:\s+([+-]?\d+)\s+([+-]?\d+)\s+([+-]?\d+)/
479 ) {
480 0 $self->device_cache()->{position} = $self->steps2angle($2);
481 0 $self->{active} = 1;
482 0 last;
483 }
484 else {
485 0 $result
486 = $self->connection()->BrutalRead( { read_length => 100 } );
487 }
488 }
489  
490 0 $self->save_motorinitdata();
491 0 $self->{value} = $self->device_cache()->{position};
492 0 return $self->device_cache()->{position};
493  
494 }
495  
496 sub save_motorinitdata {
497 0 ▶ my $self = shift;
Subroutine save_motorinitdata: not called CC=1 SCAR=6.9
Pod undocumented
498  
499 0 open( DUMP, ">C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.ini" )
500 ; #open for write, overwrite
501  
502 0 print DUMP "POSITION: " . $self->device_cache()->{position} . "\n";
503 0 print DUMP "TARGET: " . $self->device_cache()->{target} . "\n";
504 0 print DUMP "SPEED_MAX: " . $self->device_settings()->{speed_max} . "\n";
505 print DUMP "UPPER_LIMIT: "
506 0 . $self->device_settings()->{upper_limit} . "\n";
507 print DUMP "LOWER_LIMIT: "
508 0 . $self->device_settings()->{lower_limit} . "\n";
509 0 print DUMP "TIMESTAMP: " . time() . "\n";
510  
511 0 close(DUMP);
512 }
513  
514 sub _save_motorlog {
515 0 ▶ my $self = shift;
Subroutine _save_motorlog: not called CC=1 SCAR=6.9
516 0 my ( $init_pos, $end_pos )
517 = $self->_check_args( \@_, [ 'init_pos', 'end_pos' ] );
518 0 open( DUMP, ">>C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.log" )
519 ; #open for write, overwrite
520  
521 0 print DUMP ( my_timestamp() ) . "\t move: $init_pos -> $end_pos \n";
522  
523 0 close(DUMP);
524 }
525  
526 sub read_motorinitdata {
527 0 ▶ my $self = shift;
Subroutine read_motorinitdata: not called CC=8 SCAR=42.8
Pod undocumented
528  
529 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (open DUMP, "<C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.ini") 0 0 0
530 not
531 open( DUMP, "<C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.ini" ) )
532 {
533 0 return 0;
534 }
535 0 ▶ while (<DUMP>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DUMP)) 0 0 0
536 0 chomp($_);
537 0 my @line = split( /: /, $_ );
538 0 ▶ if ( $line[0] eq 'POSITION' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($line[0] eq 'POSITION') { } 0 0 0
elsif ($line[0] eq 'TARGET') { } 0 0 0
elsif ($line[0] eq 'SPEED_MAX') { } 0 0 0
elsif ($line[0] eq 'UPPER_LIMIT') { } 0 0 0
elsif ($line[0] eq 'LOWER_LIMIT') { } 0 0 0
539 0 $self->device_cache()->{position} = $line[1];
540 }
541 elsif ( $line[0] eq 'TARGET' ) {
542 0 $self->device_cache()->{target} = $line[1];
543 }
544 elsif ( $line[0] eq 'SPEED_MAX' ) {
545 0 $self->device_settings()->{speed_max} = $line[1];
546 }
547 elsif ( $line[0] eq 'UPPER_LIMIT' ) {
548 0 $self->device_settings()->{upper_limit} = $line[1];
549 }
550 elsif ( $line[0] eq 'LOWER_LIMIT' ) {
551 0 $self->device_settings()->{lower_limit} = $line[1];
552 }
553  
554 }
555  
556 0 print "\nread MOTOR-INIT-DATA\n";
557 0 print "--------------------\n";
558 0 print "POSITION: " . $self->device_cache()->{position} . "\n";
559 0 print "TARGET: " . $self->device_cache()->{target} . "\n";
560 0 print "SPEED_MAX: " . $self->device_settings()->{speed_max} . "\n";
561 0 print "UPPER_LIMIT: " . $self->device_settings()->{upper_limit} . "\n";
562 0 print "LOWER_LIMIT: " . $self->device_settings()->{lower_limit} . "\n";
563 0 print "--------------------\n";
564 0 return 1;
565 }
566  
567 sub my_timestamp {
568  
569 my (
570 0 ▶ $Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
Subroutine my_timestamp: not called CC=6 SCAR=37.4
Pod undocumented
571 $Jahr, $Wochentag, $Jahrestag, $Sommerzeit
572 ) = localtime(time);
573  
574 0 $Monat += 1;
575 0 $Jahrestag += 1;
576 0 ▶ $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
Branch: 1 branch
BranchTrueFalseTotal
$Monat < 10 ? : 0 0 0
577 0 ▶ $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
Branch: 1 branch
BranchTrueFalseTotal
$Monatstag < 10 ? : 0 0 0
578 0 ▶ $Stunden = $Stunden < 10 ? $Stunden = "0" . $Stunden : $Stunden;
Branch: 1 branch
BranchTrueFalseTotal
$Stunden < 10 ? : 0 0 0
579 0 ▶ $Minuten = $Minuten < 10 ? $Minuten = "0" . $Minuten : $Minuten;
Branch: 1 branch
BranchTrueFalseTotal
$Minuten < 10 ? : 0 0 0
580 0 ▶ $Sekunden = $Sekunden < 10 ? $Sekunden = "0" . $Sekunden : $Sekunden;
Branch: 1 branch
BranchTrueFalseTotal
$Sekunden < 10 ? : 0 0 0
581 0 $Jahr += 1900;
582  
583 0 return "$Stunden:$Minuten:$Sekunden $Monatstag.$Monat.$Jahr\n";
584  
585 }
586  
587 1 1;
588  
589 __END__
590  
591 =pod
592  
593 =encoding UTF-8
594  
595 =head1 NAME
596  
597 Lab::Instrument::ProStep4 - ProStep4 step motor
598  
599 =head1 VERSION
600  
601 version 3.881
602  
603 =head1 COPYRIGHT AND LICENSE
604  
605 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
606  
607 Copyright 2013 Christian Butschkow, Stefan Geissler
608 2014-2015 Christian Butschkow
609 2016 Simon Reinhardt
610 2017 Andreas K. Huettel
611 2020 Andreas K. Huettel
612  
613  
614 This is free software; you can redistribute it and/or modify it under
615 the same terms as the Perl 5 programming language system itself.
616  
617 =cut
« Moose/Instrument/ProStep4.pm ↑ Summary Instrument/PD11042.pm »