UAV::Pilot::SDL::Joystick
my $condvar = AnyEvent->condvar; my $events = UAV::Pilot::EasyEvent->new({ condvar => $condvar, }); my $control = UAV::Pilot::Controller::ARDrone->new( ... ); my $joy = UAV::Pilot::SDL::Joystick->new({ condvar => $condvar, events => $events, conf_path => '/path/to/config.yml', # optional }); my $sdl_events = UAV::Pilot::SDL::Events->new({ condvar => $condvar, }); $sdl_events->register( $joy ); # Capture joystick movements in EasyEvent $events->add_event( UAV::Pilot::SDL::Joystick->EVENT_NAME, sub { my ($args) = @_; my $joystick_num = $args->{joystick_num}; my $roll = $args->{roll}; my $pitch = $args->{pitch}; my $yaw = $args->{yaw}; my $throttle = $args->{throttle}; my @buttons = @{ $args->{buttons} }; ... });
Handles joystick control for SDL joysticks. This does the role UAV::Pilot::EventHandler, so it can be passed to <UAV::Pilot::Events-register()>>. It's recommended to also add the UAV::Pilot::SDL::Events handler to the events object, as that will take care of the SDL_QUIT events. Without that, there's no way to stop the process other than kill -9.
UAV::Pilot::EventHandler
<UAV::Pilot::Events-
UAV::Pilot::SDL::Events
SDL_QUIT
kill -9
Joystick configuration will be loaded from a YAML config file. You can find the path with <UAV::Pilot-default_config_dir()>>. If the file does not exist, it will be created automatically.
YAML
<UAV::Pilot-
Joystick movements are sent over EasyEvent. The event name is specified in the EVENT_NAME constant in this package. See the SYNOPSIS for the argument list.
EVENT_NAME
The config file is in YAML format. It contains the following keys:
The SDL joystick number to use
Axis number of joystick to use for pitch.
Axis number of joystick to use for roll.
Axis number of joystick to use for yaw.
Axis number of joystick to use for throttle.
This is a mapping of button numbers to some kind of action, such as takeoff/land or flip. The format is "btn_num: action". Actions are:
takeoff_land
emergency
wave
flip_ahead
flip_behind
flip_left
flip_right
These can be used to cut the inputs by a percentage. All should be numbers between 1.0 and -1.0, with negative numbers reversing the axis.
To install UAV::Pilot, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UAV::Pilot
CPAN shell
perl -MCPAN -e shell install UAV::Pilot
For more information on module installation, please visit the detailed CPAN module installation guide.