Timm Murray > UAV-Pilot-0.8 > UAV::Pilot::Commands

Download:
UAV-Pilot-0.8.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  2
View/Report Bugs
Source   Latest Release: UAV-Pilot-1.0

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', {
        pack => 'AR',
    };

Direct call to load_lib. 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 'ARDrone', { pack => '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 ^

Extensions should go in the directory specified by:

    File::ShareDir::dist_dir( 'UAV-Pilot' )

They should have a .uav extension.

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.

syntax highlighting: