NAME
UAV::Pilot::SDL::Joystick
SYNOPSIS
my $condvar = AnyEvent->condvar;
my $event = UAV::Pilot::Events->new({
condvar => $condvar,
});
my $easy_event = UAV::Pilot::EasyEvent->new({
condvar => $condvar,
});
my $sdl_events = UAV::Pilot::SDL::Events->new({
condvar => $condvar,
});
$events->register( $sdl_events );
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
});
$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} };
...
});
DESCRIPTION
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
.
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.
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.
CONFIGURATION FILE
The config file is in YAML
format. It contains the following keys:
joystick_num
The SDL joystick number to use
pitch_axis
Axis number of joystick to use for pitch.
roll_axis
Axis number of joystick to use for roll.
yaw_axis
Axis number of joystick to use for yaw.
throttle_axis
Axis number of joystick to use for throttle.
btn_action_map
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
Axis Corrections
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.