The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  UAV::Pilot::Commands

SYNOPSIS

    my $device; # Some UAV::Pilot::Control instance, defined elsewhere
    my $cmds = UAV::Pilot::Commands->new({
        device => $device,
        controller_callback_ardrone     => \&make_ardrone_controller,
        controller_callback_wumpusrover => \&make_wumpusrover_controller,
    });
    
    $cmds->load_lib( 'ARDrone' );
    $cmds->run_cmd( 'takeoff;' );
    $cmds->run_cmd( 'land;' );

DESCRIPTION

Provides an interface for loading UAV extensions and running them, particularly for REPL shells.

METHODS

new

    new({
        condvar                         => $cv,
        controller_callback_ardrone     => sub { ... },
        controller_callback_wumpusrover => sub { .. },
    })

Constructor. The condvar parameter is an AnyEvent::Condvar.

The controller_callback_* parameters take a sub ref. The subroutines take a the parameters ($cmd, $cv, $easy_event), where $cmd is this UAV::Pilot::Commands instance, $cv is the condvar passed above, and $easy_event is an UAV::Pilot::EasyEvent instance. It should return a UAV::Pilot::Control object of the associated type (generally one of the *::Event types with init_event_loop() called).

Note that this API is likely to change to a factory pattern in the near future.

load_lib

    load_lib( 'ARDrone', {
        pack => 'AR',
    })

Loads an extension by name. The pack paramter will load the library into a specific namespace. If you don't specify it, you won't need to qualify commands with a namespace prefix. Example:

    load_lib( 'ARDrone', { pack => 'AR' } );
    run_cmd( 'takeoff;' );     # Error: no subroutine named 'takeoff'
    run_cmd( 'AR::takeoff;' ); # This works
    
    load_lib( 'ARDrone' );
    run_cmd( 'takeoff;' );     # Now this works, too

Any other parmaeters you pass will be passed to the module's uav_module_init() subroutine.

run_cmd

    run_cmd( 'takeoff;' )

Executes a command. Note that this will execute arbitrary Perl statements.

COMMANDS

Commands provide an easy interface for writing simple UAV programms in a REPL shell. They are usually thin interfaces over a UAV::Pilot::Control. If you're writing a complicated script, it's suggested that you skip this interface and write to the UAV::Pilot::Control directly.

load

    load 'ARDrone', {
        namespace => 'AR',
    };

Direct call to load_lib. The namespace paramter will load the library into a specific namespace. If you don't specify it, you won't need to qualify commands with a namespace prefix. Example:

    load 'ARDrone', { namespace => 'AR' };
    takeoff;     # Error: no subroutine named 'takeoff'
    AR::takeoff; # This works
    
    load ARDrone;
    takeoff;     # Now this works, too

Any other parmaeters you pass will be passed to the module's uav_module_init() subroutine.

WRITING YOUR OWN EXTENSIONS

When calling load_lib( 'Foo' ), we look for UAV::Pilot::Foo::Commands in the current @INC.

You write them much like any Perl module, but don't use a package statement--the package will be controlled by UAV::Pilot::Command when loaded. Like a Perl module, it should return true as its final statement (put a 1; at the end).

Likewise, be careful not to make any assumptions about what package you're in. Modules may or may not get loaded into different, arbitrary packages.

For ease of use, it's recommended to use function prototypes to reduce the need for parens.

The method uav_module_init() is called with the package name as the first argument. Subsquent arguments will be the hashref passed to load()/load_lib(). After being called, this sub will be deleted from the package.

The method uav_module_quit() is called when the REPL is closing.