Moose/Instrument/ProStep4.pm

filter: Statementstmt 9.1% 29 / 316 Branchbran 0.0% 0 / 94 Conditioncond 0.0% 0 / 51 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 29.1% 7 / 24 Podpod 0.0% 0 / 15 totaltotal 6.8% 36 / 529 CC 66 SCAR 51.6
CC
66
Cov
6%
move
380.0
init_limits
240.0
get_position
240.0
CRAP 173.7
↑ Summary Moose/Instrument/SignalRecovery7265.pm »
1 package Lab::Moose::Instrument::ProStep4;
2 1 $Lab::Moose::Instrument::ProStep4::VERSION = '3.931';
3 #ABSTRACT: ProStep4 step motor
4 #TODO: Documentation!!!
5  
6 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose::Util::TypeConstraints qw/enum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Lab::Moose::Instrument qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 validated_getter validated_setter validated_no_param_setter setter_params /;
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  
16 1 extends 'Lab::Moose::Instrument';
17  
18  
19 #has AXIS => (
20 # is => 'ro',
21 # isa => 'Int',
22 # default => 1
23 #);
24 #
25 #has RESOLUTION => (
26 # is => 'ro',
27 # isa => 'Int',
28 # default => 1024
29 #);
30 #
31 #has GETRIEBEMULTIPLIKATOR => (
32 # is => 'ro',
33 # isa => 'Num',
34 # default => 0.015
35 #);
36 #
37 #has NULL => (
38 # is => 'ro',
39 # isa => 'Int',
40 # default => 32768
41 #);
42 #
43 #has STEPS_PER_ROUND => (
44 # is => 'ro',
45 # isa => 'Int',
46 # default => 400
47 #);
48 #
49 #has BACKLASH => (
50 # is => 'ro',
51 # isa => 'Int',
52 # default => 200
53 #);
54 #
55 #has AA => (
56 # is => 'ro',
57 # isa => 'Int',
58 # default => 200
59 #);
60 #
61 #has AE => (
62 # is => 'ro',
63 # isa => 'Int',
64 # default => 200
65 #);
66 #
67 #has VA => (
68 # is => 'ro',
69 # isa => 'Int',
70 # default => 0
71 #);
72 #
73 #has VE => (
74 # is => 'ro',
75 # isa => 'Int',
76 # default => 30
77 #);
78 #
79 #has VM => (
80 # is => 'ro',
81 # isa => 'Int',
82 # default => 30
83 #);
84  
85 1 has on => (
86 is => 'rw',
87 isa => 'Int',
88 default => 0
89 );
90  
91 1 has request => (
92 is => 'rw',
93 isa => 'Int',
94 default => 0
95 );
96  
97 1 has value => (
98 is => 'rw',
99 isa => 'Int',
100 );
101  
102 # Save all important data in hashes for better readability
103 1 my %device_props = (
104 AXIS => 1,
105 RESOLUTION => 1024,
106 GETRIEBEMULTIPLIKATOR => 0.015,
107 NULL => 32768,
108 STEPS_PER_ROUND => 400,
109 BACKLASH => 200,
110 AA => 200,
111 AE => 200,
112 VA => 0,
113 VE => 30,
114 VM => 30,
115 );
116  
117 1 my %device_settings = (
118 read_default => 'device',
119 pos_mode => 'ABS',
120 speed_max => 180,
121 upper_limit => 180,
122 lower_limit => -180,
123 );
124  
125 1 my %device_cache = (
126 position => undef,
127 target => undef,
128 );
129  
130 0 ▶sub BUILD {
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my $self = shift;
132  
133 # Since RS232 was dropped in Moose, only the VISA connection is left.
134 # In the original driver just the termchar was set...
135 # Is the enable_read_termchar() necessary?
136 0 $self->connection->set_termchar( termchar => "\r" );
137 0 $self->connection->enable_read_termchar();
138 }
139  
140 0 ▶sub _device_init {
Subroutine _device_init: not called CC=1 SCAR=6.9
141 0 my $self = shift;
142  
143 0 $self->query("C:\r\n");
144 $self->InitEncoder( $device_props{'STEPS_PER_ROUND'},
145 $device_props{'RESOLUTION'},
146 0 $device_props{'NULL'}
147 );
148 $self->InitRamp( $device_props{'AXIS'}, $device_props{'AA'},
149 $device_props{'AE'}, $device_props{'VA'},
150 0 $device_props{'VE'}, $device_props{'VM'}
151 );
152 0 $self->clear();
153  
154 0 $self->init_limits();
155 }
156  
157 0 ▶sub InitEncoder {
Subroutine InitEncoder: not called CC=1 SCAR=6.9
Pod undocumented
158 0 my ( $self, %args ) = validated_getter(
159 \@_,
160 steps => { isa => 'Lab::Moose::Int' },
161 res => { isa => 'Lab::Moose::Int' },
162 null => { isa => 'Lab::Moose::Int' },
163 );
164  
165 my ( $steps, $res, $null )
166 0 = delete @args{ qw/steps res null/ };
167  
168 0 $self->write( command => "encoder: $steps $res $null\r\n" );
169 0 my $result = $self->read( command => { read_length => 300 } );
170  
171 0 return $result;
172 }
173  
174 0 ▶sub InitRamp {
Subroutine InitRamp: not called CC=1 SCAR=6.9
Pod undocumented
175 0 my ( $self, %args ) = validated_getter(
176 \@_,
177 axis => { isa => 'Lab::Moose::Int' },
178 aa => { isa => 'Lab::Moose::Int' },
179 ae => { isa => 'Lab::Moose::Int' },
180 va => { isa => 'Lab::Moose::Int' },
181 ve => { isa => 'Lab::Moose::Int' },
182 vm => { isa => 'Lab::Moose::Int' },
183 );
184  
185 my ( $axis, $aa, $ae, $va, $ve, $vm, )
186 0 = delete @args{ qw/axis aa ae va ve vm/ };
187  
188 0 $self->write( command => "tp: $axis $aa $ae $va $ve $vm\r\n" );
189 0 my $result = $self->read( command => { read_length => 100 } );
190  
191 0 return $result;
192 }
193  
194 0 ▶sub move {
Subroutine move: not called CC=19 SCAR=59.4
Pod undocumented
195 0 my ( $self, %args ) = validated_getter(
196 \@_,
197 position => {isa => 'Lab::Moose::Int' },
198 speed => {isa => 'Lab::Moose::Int' },
199 mode => {isa => 'Lab::Moose::Int' },
200 );
201  
202 my ( $position, $speed, $mode )
203 0 = delete @args{ qw/position speed mode/ };
204  
205 0 ▶ if ( not defined $mode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mode) 0 0 0
206 0 $mode = $device_settings{'pos_mode'};
207 }
208 0 ▶ if ( not $mode =~ /ABS|abs|REL|rel/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode =~ /ABS|abs|REL|rel/u) 0 0 0
209 0 croak "unexpected value for <MODE> in sub move.
210 expected values are ABS and REL."
211 }
212 0 ▶ if ( not defined $speed ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $speed) 0 0 0
213 0 $speed = $device_settings{speed_max};
214 }
215 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
216 0 croak $self->get_id() . ": No target given in sub move!"
217 }
218 elsif (
219 not $position =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ )
220 {
221 0 croak $self->get_id()
222 . ": Illegal Value given for POSITION in sub move!"
223 }
224  
225 # this sets the upper limit for the positioning speed:
226 0 $speed = abs($speed);
227 0 ▶ if ( $speed > $device_settings{speed_max} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($speed > $device_settings{"speed_max"}) 0 0 0
228 0 warn "Warning in sub move: <SPEED> = $speed is too high.
229 Reduce <SPEED> to its maximum value defined by internal
230 limit settings of $device_settings{speed_max}";
231 0 $speed = $device_settings{speed_max};
232 }
233  
234 0 $speed = $self->angle2steps($speed) / 60;
235  
236 # Moving in ABS or REL mode:
237 0 my $CP = $self->get_position();
238  
239 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
240 or $mode eq "abs"
241 or $mode eq "ABSOLUTE"
242 or $mode eq "absolute" ) {
243 0 ▶ if ( $position < $device_settings{lower_limit}
Branch: 1 branch
BranchTrueFalseTotal
if ($position < $device_settings{"lower_limit"} or $position > $device_settings{"upper_limit"}) 0 0 0
Condition0%0/3
$position < $device_settings{"lower_limit"} or $position > $device_settings{"upper_limit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$position < $device_settings{"lower_limit"} or $position > $device_settings{"upper_limit"}
$position < $device_settings{"lower_limit"} $position > $device_settings{"upper_limit"}
Truth table0%0/3
A or B
A= $position < $device_settings{"lower_limit"}B= $position > $device_settings{"upper_limit"}
ABresult
1X1
011
000
244 or $position > $device_settings{upper_limit} ) {
245 croak "unexpected value for NEW POSITION in sub move.
246 Expected values are between "
247 . $device_settings{lower_limit} . " ... "
248 . $device_settings{upper_limit}
249 0 }
250 0 $device_cache{target} = $position;
251 0 $self->_save_motorlog( $CP, $position );
252 0 $self->save_motorinitdata();
253 0 $self->query(
254 command => "ma$device_props{'AXIS'} "
255 . $self->angle2steps($position) . " $speed\r\n" );
256 }
257 ▶ 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
258 or $mode eq "rel"
259 or $mode eq "RELATIVE"
260 or $mode eq "relative" ) {
261 0 ▶ if ( $CP + $position < $device_settings{lower_limit}
Branch: 1 branch
BranchTrueFalseTotal
if ($CP + $position < $device_settings{"lower_limit"} or $CP + $position > $device_settings{"upper_limit"}) 0 0 0
Condition0%0/3
$CP + $position < $device_settings{"lower_limit"} or $CP + $position > $device_settings{"upper_limit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$CP + $position < $device_settings{"lower_limit"} or $CP + $position > $device_settings{"upper_limit"}
$CP + $position < $device_settings{"lower_limit"} $CP + $position > $device_settings{"upper_limit"}
Truth table0%0/3
A or B
A= $CP + $position < $device_settings{"lower_limit"}B= $CP + $position > $device_settings{"upper_limit"}
ABresult
1X1
011
000
262 or $CP + $position > $device_settings{upper_limit} ) {
263 croak "ERROR in sub move.
264 Can't execute move; TARGET POSITION ("
265 . ( $CP + $position )
266 . ") is out of valid limits ("
267 . $device_settings{lower_limit} . " ... "
268 . $device_settings{upper_limit}
269 0 . ")"
270 }
271 0 $device_cache{target} = $CP + $position;
272 0 $self->_save_motorlog( $CP, $CP + $position );
273 0 $self->save_motorinitdata();
274 0 $self->query(
275 command => "mr$device_props{'AXIS'} "
276 . $self->angle2steps($position) . " $speed\r\n" );
277  
278 }
279  
280 0 return 1;
281  
282 }
283  
284 0 ▶sub active {
Subroutine active: not called CC=1 SCAR=6.9
Pod undocumented
285 0 my $self = shift;
286  
287 0 my $result = $self->get_position();
288  
289 0 return $self->active;
290  
291 }
292  
293 0 ▶sub wait {
Subroutine wait: not called CC=5 SCAR=34.0
Pod undocumented
294 0 my $self = shift;
295  
296 0 my $flag = 1;
297 # ???
298 0 local $| = 1;
299  
300 0 ▶ while ( $self->active() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->active) 0 0 0
301 0 my $current = $device_cache{position};
302 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
303 0 print $self->get_id()
304 . sprintf( " is sweeping (%.2f\370)\r", $current );
305 }
306 elsif ( $flag <= 0 ) {
307 0 print $self->get_id()
308 . sprintf( " is (%.2f\370)\r", $current );
309 0 $flag = 2;
310 }
311 0 $flag -= 0.1;
312 0 usleep(2e3);
313 }
314  
315 0 print "\t\t\t\t\t\t\t\t\t\r";
316 0 $| = 0;
317  
318 0 return 1;
319 }
320  
321 0 ▶sub abort {
Subroutine abort: not called CC=2 SCAR=17.9
Pod undocumented
322 0 my $self = shift;
323 0 while(1) {
324 0 $self->query( command => "sa$device_props{'AXIS'}\r\n" );
325 0 ▶ if ( not $self->active() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->active) 0 0 0
326 0 last;
327 }
328 }
329 0 print "Motor stoped at " . $self->get_position() . "\n";
330 0 return;
331 }
332  
333 0 ▶sub init_limits {
Subroutine init_limits: not called CC=15 SCAR=54.8
Pod undocumented
334 0 my $self = shift;
335 0 my $lowerlimit;
336 my $upperlimit;
337  
338 0 ▶ if ( $self->read_motorinitdata() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->read_motorinitdata) 0 0 0
339 0 while (1) {
340 0 print
341 "Motor-Init data found.
342 Do you want to keep the reference point
343 and the limits? (y/n) ";
344 0 my $input = <>;
345 0 chomp $input;
346 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
347 0 return 1;
348 }
349 elsif ( $input =~ /NO|no|N|n/ ) {
350 # ???
351 0 my $result = $self->query(command => "sa$device_props{'AXIS'}\r\n");
352 0 $result = $self->query(command => "nullen\r\n");
353 0 $device_settings{lower_limit} = -360;
354 0 $device_settings{upper_limit} = 360;
355 0 last;
356 }
357 }
358 }
359  
360 0 print "\n\n";
361 0 print "----------------------------------------------\n";
362 0 print "----------- Init Motor ProStep4 -------------\n";
363 0 print "----------------------------------------------\n";
364 0 print "\n";
365 0 print
366 "This procedure will help you to initialize the Motor ProStep4 correctly.\n\n";
367 0 print "Steps to go:\n";
368 0 print " 1.) Define the REFERENCE POINT.\n";
369 0 print " 2.) Define the LOWER and UPPER LIMITS for rotation.\n";
370 0 print " 3.) Confirm the LOWER and UPPER LIMITS.\n";
371 0 print "\n\n";
372  
373 0 print "----------------------------\n";
374 0 print "1.) Define the REFERENCE POINT:\n\n";
375 0 print "--> Move the motor position to the REFERENCE POINT.\n";
376 0 print "--> Enter a (relative) angle between -180 ... +180 deg.\n";
377 0 print
378 "--> Repeat until you have reached the position you want to define as the REFERENCE POINT.\n";
379 0 print
380 "--> Enter 'REF' to confirm the actual position as the REFERENCE POINT.\n\n";
381  
382 0 while (1) {
383 0 print "MOVE: ";
384 0 my $value = <>;
385 0 chomp $value;
386 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
387  
388 # set actual position as reference point Zero
389 0 $device_cache{position} = 0; # for testing only
390 # ???
391 0 my $result = $self->query(command => "sa$device_props{'AXIS'}\r\n");
392 0 $result = $self->query(command => "nullen\r\n");
393 0 last;
394 }
395 ▶ 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
396 {
397 0 $self->move( $value, { mode => 'REL' } );
398 0 $self->wait();
399 }
400 else {
401 0 print
402 "Please move the motor position to the REFERENCE POINT. Enter an angle between -180\370 ... +180\370.\n";
403 }
404 }
405  
406 0 print "----------------------------\n";
407 0 print "2.) Define the LOWER and UPPER LIMITS for rotation:\n\n";
408 0 print "--> Enter LOWER LIMIT\n";
409 0 print "--> Enter UPPER LIMIT\n\n";
410  
411 0 while (1) {
412 0 print "LOWER LIMIT: ";
413 0 my $value = <>;
414 0 chomp $value;
415 0 $lowerlimit = $value;
416 0 $device_settings{lower_limit} = $lowerlimit;
417 0 print "UPPER LIMIT: ";
418 0 $value = <>;
419 0 chomp $value;
420 0 $upperlimit = $value;
421 0 $device_settings{upper_limit} = $upperlimit;
422  
423 0 ▶ if ( $lowerlimit < $upperlimit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerlimit < $upperlimit) { } 0 0 0
424 0 last;
425 }
426 else {
427 0 print "LOWER LIMIT >= UPPER LIMIT. Try again!\n";
428 }
429 }
430  
431 0 print "----------------------------\n";
432 0 print "3.) Confirm the LOWER and UPPER LIMITS:\n\n";
433 0 print "--> Motor will move to LOWER LIMIT in steps of 10 deg\n";
434 0 print "--> Motor will move to UPPER LIMIT in steps of 10 deg\n";
435 0 print
436 "--> Confirm each step with ENTER or type <STOP> to take the actual position as the limit value. \n\n";
437  
438 0 print "Moving to LOWER LIMIT ...\n";
439 0 while (1) {
440 0 print "MOVE +/-10: Please press <ENTER> to confirm.";
441 0 my $input = <>;
442 0 chomp $input;
443 0 ▶ if ( $input =~ /stop|STOP/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /stop|STOP/u) 0 0 0
444 0 $lowerlimit = $self->get_position();
445 0 last;
446 }
447 0 ▶ if ( abs( $self->get_position() - $lowerlimit ) >= 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $self->get_position - $lowerlimit >= 10) { } 0 0 0
448 0 ▶ if ( $lowerlimit <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lowerlimit <= 0) { } 0 0 0
449 0 $self->move( command => "-10, { mode => 'REL' }" );
450 0 $self->wait();
451 }
452 else {
453 0 $self->move( command => "10, { mode => 'REL' }" );
454 0 $self->wait();
455 }
456 }
457 else {
458 0 $self->move( command => "$lowerlimit, { mode => 'ABS' }" );
459 0 $self->wait();
460 0 last;
461 }
462  
463 }
464 0 print "Reached LOWER LIMIT\n";
465 0 print "Please confirm the position of the LOWER LIMIT: ";
466 0 <>;
467 0 $device_settings{'lower_limit'} = $lowerlimit;
468 0 print "\n\n";
469 0 print "Moving to REFERENCE POINT ... \n";
470 0 $self->move( command => "0, { mode => 'ABS' }" );
471 0 $self->wait();
472 0 print "Moving to UPPER LIMIT ...\n";
473  
474 0 while (1) {
475 0 print "MOVE +/-10: Please press <ENTER> to confirm.";
476 0 my $input = <>;
477 0 chomp $input;
478 0 ▶ if ( $input =~ /stop|STOP/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /stop|STOP/u) 0 0 0
479 0 $upperlimit = $self->get_position();
480 0 last;
481 }
482 0 ▶ if ( abs( $upperlimit - $self->get_position() ) >= 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $upperlimit - $self->get_position >= 10) { } 0 0 0
483 0 $self->move( command => "10, { mode => 'REL' }" );
484 0 $self->wait();
485 }
486 else {
487 0 $self->move( command => "$upperlimit, { mode => 'ABS' }" );
488 0 $self->wait();
489 0 last;
490 }
491  
492 }
493 0 print "Reached UPPER LIMIT\n";
494 0 print "Please confirm the position of the UPPER LIMIT: ";
495 0 <>;
496 0 $device_settings{'upper_limit'} = $upperlimit;
497 0 print "\n\n";
498 0 $self->save_motorinitdata();
499  
500 0 print "moving to the reference point.\n";
501 0 $self->move( command => "0, { mode => 'ABS' }" );
502 0 $self->wait();
503 0 print "------------------------------------------------------\n";
504 0 print "------------ Motor ProStep4 initialized --------------\n";
505 0 print "------------------------------------------------------\n";
506 0 print "\n\n";
507  
508 }
509  
510 0 ▶sub steps2angle {
Subroutine steps2angle: not called CC=1 SCAR=6.9
Pod undocumented
511 0 my ( $self, %args ) = validated_hash(
512 \@_,
513 steps => { isa => 'Num' },
514 );
515  
516 0 my $steps = delete @args{qw/steps/};
517  
518 0 my $angle = $steps * $device_props{GETRIEBEMULTIPLIKATOR};
519 0 return $angle;
520 }
521  
522 0 ▶sub angle2steps {
Subroutine angle2steps: not called CC=1 SCAR=6.9
Pod undocumented
523 0 my ( $self, %args ) = validated_hash(
524 \@_,
525 angle => { isa => 'Num' },
526 );
527
528 0 my $angle = delete @args{qw/angle/};
529  
530 0 my $steps = $angle / $device_props{GETRIEBEMULTIPLIKATOR};
531 0 return sprintf( "%0.f", $steps );
532 }
533  
534 0 ▶sub get_value {
Subroutine get_value: not called CC=1 SCAR=6.9
Pod undocumented
535 0 my ( $self, %args ) = validated_hash(
536 \@_,
537 read_mode => { isa => enum( [qw/device|cache|request|fetch/] ) },
538 );
539
540 0 my $read_mode = delete @args{qw/read_mode/};
541  
542 0 return $self->get_position( command => "read_mode => $read_mode" );
543 }
544  
545 0 ▶sub get_position {
Subroutine get_position: not called CC=15 SCAR=54.8
Pod undocumented
546 0 my ( $self, %args ) = validated_hash(
547 \@_,
548 read_mode => { isa => enum( [qw/device|cache|request|fetch/] ) },
549 );
550  
551 0 my $read_mode = delete @args{qw/read_mode/};
552  
553 0 my $cmd = "a" . $device_props{'AXIS'} . "?\r\n";
554 0 my $result;
555  
556 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
557 or not $read_mode =~ /device|cache|request|fetch/ ) {
558 0 $read_mode = $device_settings{read_default};
559 }
560  
561 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
562 and defined $self->{'device_cache'}->{'position'} ) {
563 0 return $device_cache{'position'};
564 }
565 ▶ 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
566 0 $self->{request} = 1;
567 0 $self->write($cmd);
568 0 return;
569 }
570 ▶ 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
571 0 $result = $self->read();
572 0 $self->write( command => "$cmd" );
573 0 return;
574 }
575 ▶ 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
576 0 $self->{request} = 0;
577 0 $result = $self->read();
578 }
579 else {
580 0 ▶ if ( $self->{request} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'request'} == 1) { } 0 0 0
581 0 $result = $self->read();
582 0 $self->{request} = 0;
583 0 $result = $self->query( command => "$cmd" );
584 }
585 else {
586 0 $result = $self->query( command => "$cmd" );
587 }
588 }
589  
590 0 for ( 0 .. 2 ) {
591 0 ▶ if ( $result =~ m/Posi_$device_props{'AXIS'}:\s+([+-]?\d+)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result =~ /Posi_$device_props{'AXIS'}:\s+([+-]?\d+)/u) { } 0 0 0
elsif ($result =~ m[Soll/Ist/Speed_$device_props{'AXIS'}:\s+([+-]?\d+)\s+([+-]?\d+)\s+([+-]?\d+)]u) { } 0 0 0
592 0 $device_cache{position} = $self->steps2angle(command => "$1" );
593 0 $self->{active} = 0;
594 0 last;
595 }
596 elsif ( $result
597 =~ m/Soll\/Ist\/Speed_$device_props{'AXIS'}:\s+([+-]?\d+)\s+([+-]?\d+)\s+([+-]?\d+)/
598 ) {
599 0 $device_cache{position} = $self->steps2angle( command => "$2" );
600 0 $self->{active} = 1;
601 0 last;
602 }
603 else {
604 0 $result
605 # ???
606 = $self->connection()->BrutalRead( command => "{ read_length => 100 }" );
607 }
608 }
609  
610 0 $self->save_motorinitdata();
611 0 $self->{value} = $device_cache{position};
612 0 return $device_cache{position};
613  
614 }
615  
616 0 ▶sub save_motorinitdata {
Subroutine save_motorinitdata: not called CC=2 SCAR=17.9
Pod undocumented
617 0 my $self = shift;
618  
619 0 ▶ open my $dump, '>', "C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.ini"
Branch: 1 branch
BranchTrueFalseTotal
open my $dump, ">", "C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.ini" or croak("Can't open ini file!") 0 0 0
620 or croak "Can't open ini file!";
621  
622 0 print {$dump} "POSITION: " . $device_cache{position} . "\n";
623 0 print {$dump} "TARGET: " . $device_cache{target} . "\n";
624 0 print {$dump} "SPEED_MAX: " . $device_settings{speed_max} . "\n";
625 0 print {$dump} "UPPER_LIMIT: "
626 0 . $device_settings{upper_limit} . "\n";
627 0 print {$dump} "LOWER_LIMIT: "
628 0 . $device_settings{lower_limit} . "\n";
629 # ??? Problem mit time()
630 0 print {$dump} "TIMESTAMP: " . time() . "\n";
631  
632 0 close $dump;
633 }
634  
635 0 ▶sub _save_motorlog {
Subroutine _save_motorlog: not called CC=2 SCAR=17.9
636 0 my ( $self, %args ) = validated_getter(
637 \@_,
638 init_pos => { isa => 'Num' },
639 end_pos => { isa => 'Num' },
640 );
641
642 my ( $init_pos, $end_pos )
643 0 = delete @args{qw/init_pos end_pos/};
644
645 0 ▶ open my $log, '>>', "C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.log"
Branch: 1 branch
BranchTrueFalseTotal
open my $log, ">>", "C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.log" or croak("Can't open log file!") 0 0 0
646 or croak "Can't open log file!";
647  
648 0 print {$log} ( my_timestamp() ) . "\t move: $init_pos -> $end_pos \n";
649  
650 0 close $log;
651 }
652  
653 0 ▶sub read_motorinitdata {
Subroutine read_motorinitdata: not called CC=8 SCAR=42.8
Pod undocumented
654 0 my $self = shift;
655  
656 0 ▶ open my $init_file, '<', "C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.ini"
Branch: 1 branch
BranchTrueFalseTotal
open my $init_file, "<", "C:\\Perl\\site\\lib\\Lab\\Instrument\\ProStep4.ini" or croak("Can't open init file!") 0 0 0
657 or croak "Can't open init file!";
658  
659 0 ▶ while (<$init_file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $init_file)) 0 0 0
660 0 chomp($_);
661 0 my @line = split( /: /, $_ );
662 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
663 0 $device_cache{position} = $line[1];
664 }
665 elsif ( $line[0] eq 'TARGET' ) {
666 0 $device_cache{target} = $line[1];
667 }
668 elsif ( $line[0] eq 'SPEED_MAX' ) {
669 0 $device_settings{speed_max} = $line[1];
670 }
671 elsif ( $line[0] eq 'UPPER_LIMIT' ) {
672 0 $device_settings{upper_limit} = $line[1];
673 }
674 elsif ( $line[0] eq 'LOWER_LIMIT' ) {
675 0 $device_settings{lower_limit} = $line[1];
676 }
677  
678 }
679  
680 0 print "\nread MOTOR-INIT-DATA\n";
681 0 print "--------------------\n";
682 0 print "POSITION: " . $device_cache{position} . "\n";
683 0 print "TARGET: " . $device_cache{target} . "\n";
684 0 print "SPEED_MAX: " . $device_settings{speed_max} . "\n";
685 0 print "UPPER_LIMIT: " . $device_settings{upper_limit} . "\n";
686 0 print "LOWER_LIMIT: " . $device_settings{lower_limit} . "\n";
687 0 print "--------------------\n";
688 0 return 1;
689 }
690  
691 0 ▶sub my_timestamp {
Subroutine my_timestamp: not called CC=6 SCAR=37.4
Pod undocumented
692  
693 # ??? Ersatz für localtime
694 my (
695 0 $Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
696 $Jahr, $Wochentag, $Jahrestag, $Sommerzeit
697 ) = localtime(time);
698  
699 0 $Monat += 1;
700 0 $Jahrestag += 1;
701 0 ▶ $Monat = $Monat < 10 ? $Monat = "0" . $Monat : $Monat;
Branch: 1 branch
BranchTrueFalseTotal
$Monat < 10 ? : 0 0 0
702 0 ▶ $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
Branch: 1 branch
BranchTrueFalseTotal
$Monatstag < 10 ? : 0 0 0
703 0 ▶ $Stunden = $Stunden < 10 ? $Stunden = "0" . $Stunden : $Stunden;
Branch: 1 branch
BranchTrueFalseTotal
$Stunden < 10 ? : 0 0 0
704 0 ▶ $Minuten = $Minuten < 10 ? $Minuten = "0" . $Minuten : $Minuten;
Branch: 1 branch
BranchTrueFalseTotal
$Minuten < 10 ? : 0 0 0
705 0 ▶ $Sekunden = $Sekunden < 10 ? $Sekunden = "0" . $Sekunden : $Sekunden;
Branch: 1 branch
BranchTrueFalseTotal
$Sekunden < 10 ? : 0 0 0
706 0 $Jahr += 1900;
707  
708 0 return "$Stunden:$Minuten:$Sekunden $Monatstag.$Monat.$Jahr\n";
709  
710 }
711  
712 1 1;
713  
714 __END__
↑ Summary Moose/Instrument/SignalRecovery7265.pm »