File Coverage

blib/lib/Rinchi/CIGIPP/RateControl.pm
Criterion Covered Total %
statement 69 103 66.9
branch 13 36 36.1
condition 3 9 33.3
subroutine 18 20 90.0
pod 16 16 100.0
total 119 184 64.6


line stmt bran cond sub pod time code
1             #
2             # Rinchi Common Image Generator Interface for Perl
3             # Class Identifier: f78ac7ac-200e-11de-bda8-001c25551abc
4             # Author: Brian M. Ames
5             #
6              
7             package Rinchi::CIGIPP::RateControl;
8              
9 1     1   527 use 5.006;
  1         4  
  1         53  
10 1     1   8 use strict;
  1         3  
  1         151  
11 1     1   7 use warnings;
  1         2  
  1         36  
12 1     1   5 use Carp;
  1         2  
  1         4962  
13              
14             require Exporter;
15              
16             our @ISA = qw(Exporter);
17              
18             # Items to export into callers namespace by default. Note: do not export
19             # names by default without a very good reason. Use EXPORT_OK instead.
20             # Do not simply export all your public functions/methods/constants.
21              
22             # This allows declaration use Rinchi::CIGI::AtmosphereControl ':all';
23             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24             # will save memory.
25             our %EXPORT_TAGS = ( 'all' => [ qw(
26            
27             ) ] );
28              
29             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30              
31             our @EXPORT = qw(
32            
33             );
34              
35             our $VERSION = '0.01';
36              
37             # Preloaded methods go here.
38              
39             =head1 NAME
40              
41             Rinchi::CIGIPP::RateControl - Perl extension for the Common Image Generator
42             Interface - Rate Control data packet.
43             data packet.
44             =head1 SYNOPSIS
45              
46             use Rinchi::CIGIPP::RateControl;
47             my $rate_ctl = Rinchi::CIGIPP::RateControl->new();
48              
49             $packet_type = $rate_ctl->packet_type();
50             $packet_size = $rate_ctl->packet_size();
51             $entity_ident = $rate_ctl->entity_ident(5635);
52             $articulated_part_ident = $rate_ctl->articulated_part_ident(210);
53             $coordinate_system = $rate_ctl->coordinate_system(Rinchi::CIGIPP->World_Parent);
54             $apply_to_articulated_part = $rate_ctl->apply_to_articulated_part(Rinchi::CIGIPP->True);
55             $x_linear_rate = $rate_ctl->x_linear_rate(6.206);
56             $y_linear_rate = $rate_ctl->y_linear_rate(32.738);
57             $z_linear_rate = $rate_ctl->z_linear_rate(84.401);
58             $roll_angular_rate = $rate_ctl->roll_angular_rate(47.174);
59             $pitch_angular_rate = $rate_ctl->pitch_angular_rate(25.245);
60             $yaw_angular_rate = $rate_ctl->yaw_angular_rate(36.996);
61              
62             =head1 DESCRIPTION
63              
64             The Rate Control packet is used to define linear and angular rates for entities
65             and articulated parts.
66              
67             The Rate Control packet is useful for models and submodels whose behavior is
68             predictable and whose exact positions need not be known each frame by the Host.
69             A rotating radar dish on a ground target, for example, revolves in a consistent
70             manner, and the Host typically does not need to know its instantaneous yaw
71             angle.
72             Rates may also be used to enable the IG to compensate for transport delays or
73             jitter produced by asynchronous operation. A Rate Control packet may be sent
74             each frame in conjunction with an Entity Control packet. This provides the IG
75             with enough information to extrapolate the entity's probable position during
76             the next frame if necessary.
77              
78             When a rate is specified for an entity or articulated part, the IG maintains
79             that rate until a new rate is specified by the Host. If the Host changes the
80             position and/or orientation of an entity or articulated part, the IG will
81             perform the transformation and extrapolation will continue from that state
82             beginning with the next frame. If the Host sets all rate components to zero,
83             the entity or articulated part will become stationary.
84              
85             If the entity to which a rate is applied is destroyed, any rates specified for
86             that entity are annulled.
87              
88             =head2 EXPORT
89              
90             None by default.
91              
92             #==============================================================================
93              
94             =item new $rate_ctl = Rinchi::CIGIPP::RateControl->new()
95              
96             Constructor for Rinchi::RateControl.
97              
98             =cut
99              
100             sub new {
101 1     1 1 258 my $class = shift;
102 1   33     8 $class = ref($class) || $class;
103              
104 1         17 my $self = {
105             '_Buffer' => '',
106             '_ClassIdent' => 'f78ac7ac-200e-11de-bda8-001c25551abc',
107             '_Pack' => 'CCSCCSffffff',
108             '_Swap1' => 'CCvCCvVVVVVV',
109             '_Swap2' => 'CCnCCnNNNNNN',
110             'packetType' => 8,
111             'packetSize' => 32,
112             'entityIdent' => 0,
113             'articulatedPartIdent' => 0,
114             '_bitfields1' => 0, # Includes bitfields unused10, coordinateSystem, and applyToArticulatedPart.
115             'coordinateSystem' => 0,
116             'applyToArticulatedPart' => 0,
117             '_unused11' => 0,
118             'xLinearRate' => 0,
119             'yLinearRate' => 0,
120             'zLinearRate' => 0,
121             'rollAngularRate' => 0,
122             'pitchAngularRate' => 0,
123             'yawAngularRate' => 0,
124             };
125              
126 1 50       5 if (@_) {
127 0 0       0 if (ref($_[0]) eq 'ARRAY') {
    0          
128 0         0 $self->{'_Buffer'} = $_[0][0];
129             } elsif (ref($_[0]) eq 'HASH') {
130 0         0 foreach my $attr (keys %{$_[0]}) {
  0         0  
131 0 0       0 $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
132             }
133             }
134             }
135              
136 1         3 bless($self,$class);
137 1         4 return $self;
138             }
139              
140             #==============================================================================
141              
142             =item sub packet_type()
143              
144             $value = $rate_ctl->packet_type();
145              
146             Data Packet Identifier.
147              
148             This attribute identifies this data packet as the Rate Control packet. The
149             value of this attribute must be 8.
150              
151             =cut
152              
153             sub packet_type() {
154 1     1 1 6 my ($self) = @_;
155 1         8 return $self->{'packetType'};
156             }
157              
158             #==============================================================================
159              
160             =item sub packet_size()
161              
162             $value = $rate_ctl->packet_size();
163              
164             Data Packet Size.
165              
166             This attribute indicates the number of bytes in this data packet. The value of
167             this attribute must be 32.
168              
169             =cut
170              
171             sub packet_size() {
172 1     1 1 4 my ($self) = @_;
173 1         3 return $self->{'packetSize'};
174             }
175              
176             #==============================================================================
177              
178             =item sub entity_ident([$newValue])
179              
180             $value = $rate_ctl->entity_ident($newValue);
181              
182             Entity ID.
183              
184             This attribute specifies the entity to which the rate should be applied. If the
185             Apply to Articulated Part flag is set to True (1), the rate is applied to an
186             articulated part belonging to this entity. If the flag is set to False (0), the
187             rate is applied to the whole entity.
188              
189             =cut
190              
191             sub entity_ident() {
192 1     1 1 6 my ($self,$nv) = @_;
193 1 50       5 if (defined($nv)) {
194 1         9 $self->{'entityIdent'} = $nv;
195             }
196 1         2 return $self->{'entityIdent'};
197             }
198              
199             #==============================================================================
200              
201             =item sub articulated_part_ident([$newValue])
202              
203             $value = $rate_ctl->articulated_part_ident($newValue);
204              
205             Articulated Part ID.
206              
207             This attribute specifies the articulated part to which the rate should be
208             applied. If the Apply to Articulated Part flag is set to True (1), this
209             attribute refers to an articulated part belonging to the entity specified by
210             Entity ID. If the flag is set to False (0), this attribute is ignored.
211              
212             =cut
213              
214             sub articulated_part_ident() {
215 1     1 1 5 my ($self,$nv) = @_;
216 1 50       4 if (defined($nv)) {
217 1         2 $self->{'articulatedPartIdent'} = $nv;
218             }
219 1         3 return $self->{'articulatedPartIdent'};
220             }
221              
222             #==============================================================================
223              
224             =item sub coordinate_system([$newValue])
225              
226             $value = $rate_ctl->coordinate_system($newValue);
227              
228             Coordinate System.
229              
230             This attribute specifies the reference coordinate system to which the linear
231             and angular rates are applied.
232              
233             When this attribute is set to World/Parent (0) and the entity is a top-level
234             (non-child) entity, the rates are defined relative to the database. Linear
235             rates describe a path along and above the surface of the geoid. Angular rates
236             describe a rotation relative to a reference plane as described in Section
237             3.3.1.2 of the CIGI ICD.
238              
239             When this attribute is set to World/Parent (0) and the entity is a child
240             entity, the rates are defined relative to the parent's local coordinate system
241             as described in Section 3.3.2.2 of the CIGI ICD.
242              
243             When this attribute is set to Local (1), the rates are defined relative to the
244             entity's local coordinate system. Note: This attribute is ignored if Apply to
245             Articulated Part is set to True (1)
246              
247             World_Parent 0
248             Local 1
249              
250             =cut
251              
252             sub coordinate_system() {
253 1     1 1 2 my ($self,$nv) = @_;
254 1 50       3 if (defined($nv)) {
255 1 50 33     6 if (($nv==0) or ($nv==1)) {
256 1         2 $self->{'coordinateSystem'} = $nv;
257 1         3 $self->{'_bitfields1'} |= ($nv << 1) &0x02;
258             } else {
259 0         0 carp "coordinate_system must be 0 (World_Parent), or 1 (Local).";
260             }
261             }
262 1         2 return (($self->{'_bitfields1'} & 0x02) >> 1);
263             }
264              
265             #==============================================================================
266              
267             =item sub apply_to_articulated_part([$newValue])
268              
269             $value = $rate_ctl->apply_to_articulated_part($newValue);
270              
271             Apply to Articulated Part.
272              
273             This attribute determines whether the rate is applied to the articulated part
274             specified by the Articulated Part ID attribute. If this flag is set to False
275             (0), the rate is applied to the entity.
276              
277             False 0
278             True 1
279              
280             =cut
281              
282             sub apply_to_articulated_part() {
283 1     1 1 3 my ($self,$nv) = @_;
284 1 50       4 if (defined($nv)) {
285 1 50 33     9 if (($nv==0) or ($nv==1)) {
286 1         3 $self->{'applyToArticulatedPart'} = $nv;
287 1         2 $self->{'_bitfields1'} |= $nv &0x01;
288             } else {
289 0         0 carp "apply_to_articulated_part must be 0 (False), or 1 (True).";
290             }
291             }
292 1         3 return ($self->{'_bitfields1'} & 0x01);
293             }
294              
295             #==============================================================================
296              
297             =item sub x_linear_rate([$newValue])
298              
299             $value = $rate_ctl->x_linear_rate($newValue);
300              
301             X Linear Rate.
302              
303             This attribute specifies the X component of a linear velocity vector.
304              
305             =cut
306              
307             sub x_linear_rate() {
308 1     1 1 5 my ($self,$nv) = @_;
309 1 50       4 if (defined($nv)) {
310 1         2 $self->{'xLinearRate'} = $nv;
311             }
312 1         3 return $self->{'xLinearRate'};
313             }
314              
315             #==============================================================================
316              
317             =item sub y_linear_rate([$newValue])
318              
319             $value = $rate_ctl->y_linear_rate($newValue);
320              
321             Y Linear Rate.
322              
323             This attribute specifies the Y component of a linear velocity vector.
324              
325             =cut
326              
327             sub y_linear_rate() {
328 1     1 1 6 my ($self,$nv) = @_;
329 1 50       4 if (defined($nv)) {
330 1         2 $self->{'yLinearRate'} = $nv;
331             }
332 1         3 return $self->{'yLinearRate'};
333             }
334              
335             #==============================================================================
336              
337             =item sub z_linear_rate([$newValue])
338              
339             $value = $rate_ctl->z_linear_rate($newValue);
340              
341             Z Linear Rate.
342              
343             This attribute specifies the Z component of a linear velocity vector.
344              
345             =cut
346              
347             sub z_linear_rate() {
348 1     1 1 6 my ($self,$nv) = @_;
349 1 50       4 if (defined($nv)) {
350 1         8 $self->{'zLinearRate'} = $nv;
351             }
352 1         4 return $self->{'zLinearRate'};
353             }
354              
355             #==============================================================================
356              
357             =item sub roll_angular_rate([$newValue])
358              
359             $value = $rate_ctl->roll_angular_rate($newValue);
360              
361             Roll Angular Rate.
362              
363             This attribute specifies the angle of rotation of the articulated part submodel
364             about its X axis after yaw and pitch have been applied.
365              
366             =cut
367              
368             sub roll_angular_rate() {
369 1     1 1 5 my ($self,$nv) = @_;
370 1 50       3 if (defined($nv)) {
371 1         2 $self->{'rollAngularRate'} = $nv;
372             }
373 1         3 return $self->{'rollAngularRate'};
374             }
375              
376             #==============================================================================
377              
378             =item sub pitch_angular_rate([$newValue])
379              
380             $value = $rate_ctl->pitch_angular_rate($newValue);
381              
382             Pitch Angular Rate.
383              
384             This attribute specifies the angle of rotation of the articulated part submodel
385             about its Y axis after yaw has been applied.
386              
387             =cut
388              
389             sub pitch_angular_rate() {
390 1     1 1 4 my ($self,$nv) = @_;
391 1 50       4 if (defined($nv)) {
392 1         2 $self->{'pitchAngularRate'} = $nv;
393             }
394 1         3 return $self->{'pitchAngularRate'};
395             }
396              
397             #==============================================================================
398              
399             =item sub yaw_angular_rate([$newValue])
400              
401             $value = $rate_ctl->yaw_angular_rate($newValue);
402              
403             Yaw Angular Rate.
404              
405             This attribute specifies the angle of rotation of the articulated part about
406             its Z axis when its X axis is parallel to that of the entity.
407              
408             =cut
409              
410             sub yaw_angular_rate() {
411 1     1 1 4 my ($self,$nv) = @_;
412 1 50       4 if (defined($nv)) {
413 1         3 $self->{'yawAngularRate'} = $nv;
414             }
415 1         3 return $self->{'yawAngularRate'};
416             }
417              
418             #==========================================================================
419              
420             =item sub pack()
421              
422             $value = $rate_ctl->pack();
423              
424             Returns the packed data packet.
425              
426             =cut
427              
428             sub pack($) {
429 1     1 1 11 my $self = shift ;
430            
431 1         8 $self->{'_Buffer'} = CORE::pack($self->{'_Pack'},
432             $self->{'packetType'},
433             $self->{'packetSize'},
434             $self->{'entityIdent'},
435             $self->{'articulatedPartIdent'},
436             $self->{'_bitfields1'}, # Includes bitfields unused10, coordinateSystem, and applyToArticulatedPart.
437             $self->{'_unused11'},
438             $self->{'xLinearRate'},
439             $self->{'yLinearRate'},
440             $self->{'zLinearRate'},
441             $self->{'rollAngularRate'},
442             $self->{'pitchAngularRate'},
443             $self->{'yawAngularRate'},
444             );
445              
446 1         3 return $self->{'_Buffer'};
447             }
448              
449             #==========================================================================
450              
451             =item sub unpack()
452              
453             $value = $rate_ctl->unpack();
454              
455             Unpacks the packed data packet.
456              
457             =cut
458              
459             sub unpack($) {
460 0     0 1   my $self = shift @_;
461            
462 0 0         if (@_) {
463 0           $self->{'_Buffer'} = shift @_;
464             }
465 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Pack'},$self->{'_Buffer'});
466 0           $self->{'packetType'} = $a;
467 0           $self->{'packetSize'} = $b;
468 0           $self->{'entityIdent'} = $c;
469 0           $self->{'articulatedPartIdent'} = $d;
470 0           $self->{'_bitfields1'} = $e; # Includes bitfields unused10, coordinateSystem, and applyToArticulatedPart.
471 0           $self->{'_unused11'} = $f;
472 0           $self->{'xLinearRate'} = $g;
473 0           $self->{'yLinearRate'} = $h;
474 0           $self->{'zLinearRate'} = $i;
475 0           $self->{'rollAngularRate'} = $j;
476 0           $self->{'pitchAngularRate'} = $k;
477 0           $self->{'yawAngularRate'} = $l;
478              
479 0           $self->{'coordinateSystem'} = $self->coordinate_system();
480 0           $self->{'applyToArticulatedPart'} = $self->apply_to_articulated_part();
481              
482 0           return $self->{'_Buffer'};
483             }
484              
485             #==========================================================================
486              
487             =item sub byte_swap()
488              
489             $obj_name->byte_swap();
490              
491             Byte swaps the packed data packet.
492              
493             =cut
494              
495             sub byte_swap($) {
496 0     0 1   my $self = shift @_;
497            
498 0 0         if (@_) {
499 0           $self->{'_Buffer'} = shift @_;
500             } else {
501 0           $self->pack();
502             }
503 0           my ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l) = CORE::unpack($self->{'_Swap1'},$self->{'_Buffer'});
504              
505 0           $self->{'_Buffer'} = CORE::pack($self->{'_Swap2'},$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l);
506 0           $self->unpack();
507              
508 0           return $self->{'_Buffer'};
509             }
510              
511             1;
512             __END__