ARDrone/Control.pm

filter: Statementstmt 96.5% 140 / 145 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 97.0% 33 / 34 Podpod 94.7% 18 / 19 totaltotal 92.1% 199 / 216 CC 7 SCAR 3.6
CC
7
Cov
93%
BUILD
3.8
take_picture
2.0
set_multiconfig
2.0
CRAP 1.4
« ARDrone/Video/Mock.pm ↑ Summary ARDrone.pm »
1 # Copyright (c) 2015 Timm Murray
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright notice,
8 # this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 # POSSIBILITY OF SUCH DAMAGE.
24 package UAV::Pilot::ARDrone::Control;
25 10 $UAV::Pilot::ARDrone::Control::VERSION = '1.0';
26 10 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 10 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 10 ▶use String::CRC32 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 10 ▶use UAV::Pilot::EasyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 10 ▶use UAV::Pilot::NavCollector::AckEvents;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34  
35 10 with 'UAV::Pilot::ControlHelicopter';
36  
37 10 ▶use constant NAV_EVENT_READ_TIME => 1 / 60;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39  
40 10 has 'video' => (
41 is => 'rw',
42 isa => 'Maybe[UAV::Pilot::ARDrone::Video]',
43 );
44 10 has 'session_id' => (
45 is => 'ro',
46 isa => 'Maybe[Str]',
47 writer => '_set_session_id',
48 );
49 10 has 'app_id' => (
50 is => 'ro',
51 isa => 'Maybe[Str]',
52 writer => '_set_app_id',
53 );
54 10 has 'user_id' => (
55 is => 'ro',
56 isa => 'Maybe[Str]',
57 writer => '_set_user_id',
58 );
59 10 has '_did_set_multiconfig' => (
60 is => 'rw',
61 isa => 'Bool',
62 default => 0,
63 );
64 10 has 'in_air' => (
65 is => 'ro',
66 isa => 'Bool',
67 default => 0,
68 writer => '_set_in_air',
69 );
70  
71 10 with 'UAV::Pilot::Logger';
72  
73  
74 sub BUILD
75 {
76 7 ▶ my ($self) = @_;
Subroutine BUILD: called CC=3 SCAR=13.3
Pod undocumented
77  
78 7 ▶ if( defined $self->user_id && defined $self->app_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->user_id and defined $self->app_id) 0 7 7
Condition33%1/3
defined $self->user_id and defined $self->app_id
!ll&&!rl&&r
700
MC/DC0%0/2
defined $self->user_id and defined $self->app_id
defined $self->user_id defined $self->app_id
Truth table33%1/3
A and B
A= defined $self->user_idB= defined $self->app_id
ABresult
0X0
100
111
79 0 $self->set_multiconfig( $self->user_id, $self->app_id,
80 $self->session_id );
81 }
82  
83 7 return 1;
84 }
85  
86  
87 sub takeoff
88 {
89 2 ▶ my ($self) = @_;
Subroutine takeoff: called CC=1 SCAR=0.0
Pod documented
90 2 $self->driver->at_ref( 1, 0 );
91 2 $self->_set_in_air( 1 );
92 2 return 1;
93 }
94  
95 sub land
96 {
97 2 ▶ my ($self) = @_;
Subroutine land: called CC=1 SCAR=0.0
Pod documented
98 2 $self->driver->at_ref( 0, 0 );
99 2 $self->_set_in_air( 0 );
100 2 return 1;
101 }
102  
103 sub pitch
104 {
105 2 ▶ my ($self, $pitch) = @_;
Subroutine pitch: called CC=1 SCAR=0.0
Pod documented
106 2 $self->driver->at_pcmd( 1, 0, 0, $pitch, 0, 0 );
107 }
108  
109 sub roll
110 {
111 2 ▶ my ($self, $roll) = @_;
Subroutine roll: called CC=1 SCAR=0.0
Pod documented
112 2 $self->driver->at_pcmd( 1, 0, $roll, 0, 0, 0 );
113 }
114  
115 sub yaw
116 {
117 2 ▶ my ($self, $yaw) = @_;
Subroutine yaw: called CC=1 SCAR=0.0
Pod documented
118 2 $self->driver->at_pcmd( 1, 0, 0, 0, 0, $yaw );
119 }
120  
121 sub vert_speed
122 {
123 2 ▶ my ($self, $speed) = @_;
Subroutine vert_speed: called CC=1 SCAR=0.0
Pod documented
124 2 $self->driver->at_pcmd( 1, 0, 0, 0, $speed, 0 );
125 }
126  
127 sub calibrate
128 {
129 2 ▶ my ($self) = @_;
Subroutine calibrate: called CC=1 SCAR=0.0
Pod documented
130 2 $self->driver->at_calib( $self->driver->ARDRONE_CALIBRATION_DEVICE_MAGNETOMETER );
131 }
132  
133 sub emergency
134 {
135 4 ▶ my ($self) = @_;
Subroutine emergency: called CC=2 SCAR=6.9
Pod documented
136 4 $self->driver->at_ref( 0, 1 );
137 4 ▶ $self->video->emergency_restart if defined $self->video;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->video 2 2 4
138 4 return 1;
139 }
140  
141 sub reset_watchdog
142 {
143 3 ▶ my ($self) = @_;
Subroutine reset_watchdog: called CC=1 SCAR=0.0
Pod documented
144 3 $self->driver->at_comwdg();
145 3 return 1;
146 }
147  
148 sub hover
149 {
150 2 ▶ my ($self) = @_;
Subroutine hover: called CC=1 SCAR=0.0
Pod documented
151 2 return 1;
152 }
153  
154 {
155 10 my $send = 'UAV::Pilot::ARDrone::Driver';
156 10 my @FLIGHT_ANIMS = (
157 {
158 name => 'phi_m30',
159 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_M30_DEG,
160 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_M30_DEG_MAYDAY,
161 },
162 {
163 name => 'phi_30',
164 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_30_DEG,
165 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_30_DEG_MAYDAY,
166 },
167 {
168 name => 'theta_m30',
169 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_M30_DEG,
170 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_M30_DEG_MAYDAY,
171 },
172 {
173 name => 'theta_30',
174 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_30_DEG,
175 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_30_DEG_MAYDAY,
176 },
177 {
178 name => 'theta_20deg_yaw_200',
179 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_20DEG_YAW_200DEG,
180 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_20DEG_YAW_200DEG_MAYDAY,
181 },
182 {
183 name => 'theta_20deg_yaw_m200',
184 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_20DEG_YAW_M200DEG,
185 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_20DEG_YAW_M200DEG_MAYDAY,
186 },
187 {
188 name => 'turnaround',
189 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_TURNAROUND,
190 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_TURNAROUND_MAYDAY,
191 },
192 {
193 name => 'turnaround_godown',
194 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_TURNAROUND_GODOWN,
195 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_TURNAROUND_GODOWN_MAYDAY,
196 },
197 {
198 name => 'yaw_shake',
199 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_YAW_SHAKE,
200 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_YAW_SHAKE_MAYDAY,
201 },
202 {
203 name => 'yaw_dance',
204 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_YAW_DANCE,
205 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_YAW_DANCE_MAYDAY,
206 },
207 {
208 name => 'phi_dance',
209 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_DANCE,
210 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_DANCE_MAYDAY,
211 },
212 {
213 name => 'theta_dance',
214 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_DANCE,
215 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_THETA_DANCE_MAYDAY,
216 },
217 {
218 name => 'vz_dance',
219 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_VZ_DANCE,
220 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_VZ_DANCE_MAYDAY,
221 },
222 {
223 name => 'wave',
224 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_WAVE,
225 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_WAVE_MAYDAY,
226 },
227 {
228 name => 'phi_theta_mixed',
229 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_THETA_MIXED,
230 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_PHI_THETA_MIXED_MAYDAY,
231 },
232 {
233 name => 'double_phi_theta_mixed',
234 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_DOUBLE_PHI_THETA_MIXED,
235 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_DOUBLE_PHI_THETA_MIXED_MAYDAY,
236 },
237 {
238 name => 'flip_ahead',
239 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_AHEAD,
240 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_AHEAD_MAYDAY,
241 },
242 {
243 name => 'flip_behind',
244 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_BEHIND,
245 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_BEHIND_MAYDAY,
246 },
247 {
248 name => 'flip_left',
249 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_LEFT,
250 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_LEFT_MAYDAY,
251 },
252 {
253 name => 'flip_right',
254 anim => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_RIGHT,
255 mayday => $send->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM_FLIP_RIGHT_MAYDAY,
256 },
257 );
258 10 foreach my $def (@FLIGHT_ANIMS) {
259 200 my $name = $def->{name};
260 200 my $anim = $def->{anim};
261 200 my $mayday = $def->{mayday};
262  
263 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
264 *$name = sub {
265 40 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
266 40 $self->send_config(
267 $self->driver->ARDRONE_CONFIG_CONTROL_FLIGHT_ANIM,
268 sprintf( '%d,%d', $anim, $mayday ),
269 );
270 200 };
271 }
272 }
273  
274 {
275 10 my $send = 'UAV::Pilot::ARDrone::Driver';
276  
277 10 my @LED_ANIMS = (
278 {
279 name => 'led_blink_green_red',
280 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_BLINK_GREEN_RED,
281 },
282 {
283 name => 'led_blink_green',
284 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_BLINK_GREEN,
285 },
286 {
287 name => 'led_blink_red',
288 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_BLINK_RED,
289 },
290 {
291 name => 'led_blink_orange',
292 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_BLINK_ORANGE,
293 },
294 {
295 name => 'led_snake_green_red',
296 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_SNAKE_GREEN_RED,
297 },
298 {
299 name => 'led_fire',
300 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_FIRE,
301 },
302 {
303 name => 'led_standard',
304 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_STANDARD,
305 },
306 {
307 name => 'led_red',
308 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_RED,
309 },
310 {
311 name => 'led_green',
312 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_GREEN,
313 },
314 {
315 name => 'led_red_snake',
316 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_RED_SNAKE,
317 },
318 {
319 name => 'led_blank',
320 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_BLANK,
321 },
322 {
323 name => 'led_right_missile',
324 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_RIGHT_MISSILE,
325 },
326 {
327 name => 'led_left_missile',
328 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_LEFT_MISSILE,
329 },
330 {
331 name => 'led_double_missile',
332 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_DOUBLE_MISSILE,
333 },
334 {
335 name => 'led_front_left_green_others_red',
336 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_FRONT_LEFT_GREEN_OTHERS_RED,
337 },
338 {
339 name => 'led_front_right_green_others_red',
340 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_FRONT_RIGHT_GREEN_OTHERS_RED,
341 },
342 {
343 name => 'led_rear_left_green_others_red',
344 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_REAR_LEFT_GREEN_OTHERS_RED,
345 },
346 {
347 name => 'led_rear_right_green_others_red',
348 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_REAR_RIGHT_GREEN_OTHERS_RED,
349 },
350 {
351 name => 'led_left_green_right_red',
352 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_LEFT_GREEN_RIGHT_RED,
353 },
354 {
355 name => 'led_left_red_right_green',
356 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_LEFT_RED_RIGHT_GREEN,
357 },
358 {
359 name => 'led_blink_standard',
360 anim => $send->ARDRONE_CONFIG_LED_ANIMATION_BLINK_STANDARD,
361 },
362 );
363 10 foreach my $def (@LED_ANIMS) {
364 210 my $name = $def->{name};
365 210 my $anim = $def->{anim};
366  
367 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
368 *$name = sub {
369 42 ▶ my ($self, $freq, $duration) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
370 42 $self->send_config(
371 $self->driver->ARDRONE_CONFIG_LEDS_LEDS_ANIM,
372 sprintf( '%d,%d,%d',
373 $anim,
374 $self->driver->float_convert( $freq ),
375 $duration,
376 ),
377 );
378 210 };
379 }
380 }
381  
382 sub start_userbox_nav_data
383 {
384 2 ▶ my ($self) = @_;
Subroutine start_userbox_nav_data: called CC=1 SCAR=0.0
Pod documented
385 2 $self->send_config(
386 $self->driver->ARDRONE_CONFIG_USERBOX_USERBOX_CMD,
387 $self->driver->ARDRONE_USERBOX_CMD_START,
388 );
389 2 return 1;
390 }
391  
392 sub stop_userbox_nav_data
393 {
394 2 ▶ my ($self) = @_;
Subroutine stop_userbox_nav_data: called CC=1 SCAR=0.0
Pod documented
395 2 $self->send_config(
396 $self->driver->ARDRONE_CONFIG_USERBOX_USERBOX_CMD,
397 $self->driver->ARDRONE_USERBOX_CMD_STOP,
398 );
399 2 return 1;
400 }
401  
402 sub cancel_userbox_nav_data
403 {
404 2 ▶ my ($self) = @_;
Subroutine cancel_userbox_nav_data: called CC=1 SCAR=0.0
Pod documented
405 2 $self->send_config(
406 $self->driver->ARDRONE_CONFIG_USERBOX_USERBOX_CMD,
407 $self->driver->ARDRONE_USERBOX_CMD_CANCEL,
408 );
409 2 return 1;
410 }
411  
412 sub take_picture
413 {
414 2 ▶ my ($self, $delay, $num_pics, $date) = @_;
Subroutine take_picture: called CC=2 SCAR=7.0
Pod documented
415 2 ▶ $date = DateTime->now->strftime( '%Y%m%d_%H%M%S' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 0 2 2
416 if ! defined $date;
417 2 $self->send_config(
418 $self->driver->ARDRONE_CONFIG_USERBOX_USERBOX_CMD,
419 sprintf( '%d,%d,%d,%s',
420 $self->driver->ARDRONE_USERBOX_CMD_SCREENSHOT,
421 $delay,
422 $num_pics,
423 $date,
424 ),
425 );
426 2 return 1;
427 }
428  
429 sub set_multiconfig
430 {
431 1 ▶ my ($self, $user_id, $app_id, $session_id) = @_;
Subroutine set_multiconfig: called CC=2 SCAR=6.9
Pod documented
432 1 ▶ $session_id //= $self->_generate_session_id;
Condition33%1/3
$session_id //= $self->_generate_session_id
l!l&&r!l&&!r
100
MC/DC0%0/2
$session_id //= $self->_generate_session_id
$session_id $self->_generate_session_id
Truth table33%1/3
A //= B
A= $session_idB= $self->_generate_session_id
ABresult
1X1
011
000
433 1 my $driver = $self->driver;
434  
435 1 $self->_logger->info( "Setting multiconfig keys. App ID [$app_id],"
436 . "User ID [$user_id], Session ID [$session_id]" );
437  
438 1 $driver->at_config_ids( $session_id, $user_id, $app_id );
439 1 $driver->at_config(
440 $driver->ARDRONE_CONFIG_CUSTOM_SESSION_ID, $session_id );
441 1 sleep 1;
442  
443 1 $driver->at_config_ids( $session_id, $user_id, $app_id );
444 1 $driver->at_config( $driver->ARDRONE_CONFIG_CUSTOM_PROFILE_ID, $user_id );
445 1 sleep 1;
446  
447 1 $driver->at_config_ids( $session_id, $user_id, $app_id );
448 1 $driver->at_config(
449 $driver->ARDRONE_CONFIG_CUSTOM_APPLICATION_ID, $app_id );
450 1 sleep 1;
451  
452 1 $self->_set_session_id( $session_id );
453 1 $self->_set_app_id( $app_id );
454 1 $self->_set_user_id( $user_id );
455 1 $self->_did_set_multiconfig( 1 );
456  
457 1 return 1;
458 }
459  
460 sub send_config
461 {
462 93 ▶ my ($self, $name, $value) = @_;
Subroutine send_config: called CC=2 SCAR=6.9
Pod documented
463 93 my $driver = $self->driver;
464 93 ▶ $driver->at_config_ids( $self->session_id, $self->user_id, $self->app_id )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_did_set_multiconfig 1 92 93
465 if $self->_did_set_multiconfig;
466 93 $driver->at_config( $name, $value );
467 93 return 1;
468 }
469  
470 sub record_usb
471 {
472 2 ▶ my ($self) = @_;
Subroutine record_usb: called CC=1 SCAR=0.0
Pod documented
473 2 $self->send_config(
474 $self->driver->ARDRONE_CONFIG_VIDEO_VIDEO_ON_USB,
475 'TRUE',
476 );
477 2 return 1;
478 }
479  
480 sub setup_read_nav_event
481 {
482 1 ▶ my ($self, $event) = @_;
Subroutine setup_read_nav_event: called CC=1 SCAR=0.0
Pod documented
483  
484 1 my $ack = UAV::Pilot::NavCollector::AckEvents->new({
485 easy_event => $event,
486 });
487 1 $self->driver->add_nav_collector( $ack );
488  
489 1 my $w; $w = AnyEvent->timer(
490 after => $self->NAV_EVENT_READ_TIME,
491 interval => $self->NAV_EVENT_READ_TIME,
492 cb => sub {
493 2 ▶ my $driver = $self->driver;
Subroutine __ANON__: called CC=1 SCAR=0.0
494 2 $driver->read_nav_packet;
495 2 $w;
496 },
497 1 );
498 1 return 1;
499 }
500  
501  
502 sub _generate_session_id
503 {
504 0 ▶ my ($self) = @_;
Subroutine _generate_session_id: not called CC=1 SCAR=6.9
505 0 my $id = String::CRC32::crc32( int rand 2**16 );
506 0 my $hex_id = sprintf '%x', $id;
507 0 return $hex_id;
508 }
509  
510  
511 10 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
512 10 __PACKAGE__->meta->make_immutable;
513 10 1;
514 __END__
515  
516  
517 =head1 NAME
518  
519 UAV::Pilot::ARDrone::Control
520  
521 =head1 SYNOPSIS
522  
523 my $driver = UAV::Pilot::ARDrone::Driver->new( ... );
524 $driver->connect;
525 my $dev = UAV::Pilot::ARDrone::Control->new({
526 driver => $driver,
527 });
528
529 $dev->takeoff;
530 $dev->pitch( 0.5 );
531 $dev->wave;
532 $dev->flip_left;
533 $dev->land;
534  
535 =head1 DESCRIPTION
536  
537 L<UAV::Pilot::ControlHelicopter> implementation for the Parrot AR.Drone.
538  
539 =head1 METHODS
540  
541 =head2 new
542  
543 B<NOTE>: It's highly recommended that you initialize the subclass
544 C<UAV::Pilot::ARDrone::Control::Event> instead of this one.
545  
546 new({
547 driver => $driver,
548 video => $video_driver,
549 });
550  
551 Constructor. As with C<UAV::Pilot::Control>, the C<driver> option is a mandatory
552 parameter with the value being a C<UAV::Pilot::Driver::ARDrone> object.
553  
554 The optional C<video> parameter is a C<UAV::Pilot::Driver::ARDrone::Video> object. When
555 the emergency mode is toggled on the ARDrone, the video stream needs to be restarted.
556 Placing the object here will call C<emergency_restart()> on the video object for you.
557  
558 =head2 takeoff
559  
560 Takeoff.
561  
562 =head2 land
563  
564 Land.
565  
566 =head2 pitch
567  
568 pitch( 0.5 )
569  
570 Pitch (front-to-back movement). Takes a floating point number between -1.0 and 1.0. On
571 the AR.Drone, negative numbers pitch the nose down and fly forward.
572  
573 =head2 roll
574  
575 roll( -1.0 )
576  
577 Roll (left-to-right movement). Takes a floating point number between -1.0 and 1.0. On
578 the AR.Drone, negative numbers go left.
579  
580 =head2 yaw
581  
582 yaw( -0.25 )
583  
584 Yaw (spin). Takes a floating point number between -1.0 and 1.0. On the AR.Drone,
585 negative numbers spin left.
586  
587 =head2 vert_speed
588  
589 vert_speed( 0.7 )
590  
591 Change the vertical speed. Takes a floating point number between -1.0 and 1.0. On the
592 AR.Drone, negative numbers make it go down.
593  
594 =head2 calibrate
595  
596 Calibrates the magnetometer. This must be done while in flight. The drone will spin
597 around (yaw movement) while it does this.
598  
599 =head2 emergency
600  
601 Toggles the emergency state. If your UAV goes out of control, call this to immediately
602 shut it off. When in the emergency state, it will not be responsive to further commands.
603 Call this again to bring it out of this state.
604  
605 =head2 reset_watchdog
606  
607 Sends a command to reset the watchdog process. You need to send some command at least
608 every 2 seconds, or else the AR.Drone thinks the connection was lost. If you don't have
609 anything else to send, send this one.
610  
611 If you run C<start_event_loop()>, the reset will happen for you.
612  
613 =head2 hover
614  
615 Stops the UAV and hovers in place.
616  
617 =head2 start_userbox_nav_data
618  
619 Starts saving navigation data on the UAV itself. The file will be in the directory:
620  
621 /boxes/flight_YYYYMMDD_hhmmss
622  
623 You can FTP into the AR.Drone to retrieve this.
624  
625 =head2 stop_userbox_nav_data
626  
627 Stops logging navigation data on the UAV.
628  
629 =head2 cancel_userbox_nav_data
630  
631 Stops logging navigation data on the UAV B<AND> deletes the log directory.
632  
633 =head2 take_picture
634  
635 take_picture( $delay, $num_pics )
636  
637 Saves a picture in JPG format to:
638  
639 /boxes/flight_YYYYMMDD_hhmmss/picture_YYYYMMDD_hhmmss.jpg
640  
641 You can FTP into the AR.Drone to retrieve this.
642  
643 =head2 record_usb
644  
645 Start recording the video stream to a USB stick attached to the AR.Drone's internal USB
646 port. The stick must have at least 100MB free.
647  
648 =head2 setup_read_nav_event
649  
650 setup_read_nav_event( $event );
651  
652 Pass a C<UAV::Pilot::EasyEvent> object. Sets up a
653 C<UAV::Pilot::NavCollector::AckEvents> and starts an event timer for reading
654 nav packets.
655  
656 =head2 set_multiconfig
657  
658 set_multiconfig( $user_id, $app_id, $session_id )
659  
660 B<NOTE>: This doesn't yet seem to work right. You can set the keys, but
661 the UAV won't respond to config commands after that. It should just be a
662 matter of sending C<AT*CONFIG_IDS> before each C<AT*CONFIG>, which is what
663 C<send_config()> will do for you. But it doesn't work. Still debugging . . .
664  
665 Pass a unique user, app, and session ID. The best way to generate these is
666 to take a string identifying your user and app and run it through a CRC32.
667 The C<$session_id> is optional; if passed, it should be unique to this
668 particular run.
669  
670 In the AR.Drone, "multiconfig" is a way to set configurations that are unique
671 to the user, app, or session. For backwards compatibility with old apps,
672 the AR.Drone only lets you set some keys when using multiconfig. See the
673 AR.Drone SDK docs for details.
674  
675 =head2 send_config
676  
677 send_config( $name, $value )
678  
679 Send a config name/value. If you used C<set_multiconfig()>, this will send
680 the necessary commands before the config setting.
681  
682 =head1 FLIGHT ANIMATION METHODS
683  
684 The Parrot AR.Drone comes preprogrammed with a bunch of "flight animations" (complicated
685 achrebatic manuevers). You can call the methods below to run them. Note that some of
686 these need a generous amount of horizontal and vertical space, so be sure to be in a
687 wide open area for testing.
688  
689 I find "wave" and "flip_behind" are particularly good ways to impress house guests :)
690  
691 phi_m30_deg
692 phi_30_deg
693 theta_m30_deg
694 theta_30_deg
695 theta_20deg_yaw_200deg
696 theta_20deg_yaw_m200deg
697 turnaround
698 turnaround_godown
699 yaw_shake
700 yaw_dance
701 phi_dance
702 theta_dance
703 vz_dance
704 wave
705 phi_theta_mixed
706 double_phi_theta_mixed
707 flip_ahead
708 flip_behind
709 flip_left
710 flip_right
711  
712 =head1 LED ANIMATION METHODS
713  
714 The LEDs on the Parrot AR.Drone can be directly controlled using these animation methods.
715 They all take two parameters: the frequency (in Hz) as a floating point number, and
716 the duration.
717  
718 led_blink_green_red
719 led_blink_green
720 led_blink_red
721 led_blink_orange
722 led_snake_green_red
723 led_fire
724 led_standard
725 led_red
726 led_green
727 led_red_snake
728 led_blank
729 led_right_missile
730 led_left_missile
731 led_double_missile
732 led_front_left_green_others_red
733 led_front_right_green_others_red
734 led_rear_right_green_others_red
735 led_rear_left_green_others_red
736 led_left_green_right_red
737 led_left_red_right_green
738 led_blink_standard
739  
740 =cut
« ARDrone/Video/Mock.pm ↑ Summary ARDrone.pm »