WumpusRover/Control.pm

filter: Statementstmt 71.0% 27 / 38 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 50.0% 1 / 2 totaltotal 71.4% 35 / 49 CC 1 SCAR 2.0
CC
1
Cov
71%
process_sdl_input
2.0
_map_values
2.0
BEGIN
1.0
CRAP 1.2
« WumpusRover/Driver.pm ↑ Summary WumpusRover/Video/Mock.pm »
1 # Copyright (c) 2014 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::WumpusRover::Control;
25 3 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use UAV::Pilot::WumpusRover::PacketFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31  
32 3 has 'turn' => (
33 is => 'rw',
34 isa => 'Int',
35 default => 0,
36 );
37 3 has 'throttle' => (
38 is => 'rw',
39 isa => 'Int',
40 default => 0,
41 );
42 3 has 'driver' => (
43 is => 'ro',
44 isa => 'UAV::Pilot::WumpusRover::Driver',
45 );
46  
47 3 with 'UAV::Pilot::ControlRover';
48 3 with 'UAV::Pilot::Logger';
49  
50  
51 sub process_sdl_input
52 {
53 0 ▶ my ($self, $args) = @_;
Subroutine process_sdl_input: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my $turn = $args->{roll};
55 0 my $throttle = $args->{throttle};
56  
57 # TODO Send output min/max settings in packet for initial setup, rather
58 # than hardcoding here
59 0 $turn = $self->_map_values( $self->JOYSTICK_MIN_AXIS_INT,
60 $self->JOYSTICK_MAX_AXIS_INT, 0, 180, $turn );
61 0 $throttle = $self->_map_values( $self->JOYSTICK_MIN_AXIS_INT,
62 $self->JOYSTICK_MAX_AXIS_INT, 0, 100, $throttle );
63  
64 0 $self->turn( $turn );
65 0 $self->throttle( $throttle );
66  
67 0 return 1;
68 }
69  
70 sub send_move_packet
71 {
72 5 ▶ my ($self) = @_;
Subroutine send_move_packet: called CC=1 SCAR=0.0
Pod documented
73 5 my @channels = (
74 $self->throttle,
75 $self->turn,
76 );
77 5 return $self->driver->send_radio_output_packet( @channels );
78 }
79  
80 sub _map_values
81 {
82 0 ▶ my ($self, $in_min, $in_max, $out_min, $out_max, $in) = @_;
Subroutine _map_values: not called CC=1 SCAR=6.9
83 0 my $output = ($in - $in_min) / ($in_max - $in_min)
84 * ($out_max - $out_min) + $out_min;
85 0 return $output
86 }
87  
88  
89 3 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 3 __PACKAGE__->meta->make_immutable;
91 3 1;
92 __END__
93  
94  
95 =head1 NAME
96  
97 UAV::Pilot::WumpusRover::Control
98  
99 =head1 SYNOPSIS
100  
101 my $driver = UAV::Pilot::WumpusRover::Driver->new({
102 host => $hostname,
103 });
104 $driver->connect;
105
106 my $control = UAV::Pilot::WumpusRover::Control::Event->new({
107 driver => $driver,
108 });
109  
110 $control->turn( 30 );
111 $control->throttle( 70 );
112  
113 =head1 DESCRIPTION
114  
115 B<NOTE>: You probably want to use C<UAV::Pilot::WumpusRover::Control::Event>
116 instead of this.
117  
118 A controller for the WumpusRover. Does the C<UAV::Pilot::ControlRover> and
119 C<UAV::Pilot::Logger> roles.
120  
121 =head1 METHODS
122  
123 =head2 send_move_packet
124  
125 Sends a packet using the passed C<driver> containing the current movement
126 settings.
127  
128 =head1 ATTRIBUTES
129  
130 =head2 turn
131  
132 A read/write attribute that takes values between 0 and 180. 0 is to the left
133 and 180 is to the right.
134  
135 =head2 throttle
136  
137 A read/write attribute that takes values between 0 and 100. 0 is stop or
138 full reverse (depending on how your ESC is setup). 100 is full speed ahead.
139  
140 =cut
« WumpusRover/Driver.pm ↑ Summary WumpusRover/Video/Mock.pm »