UAV::Pilot::Commands
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;' );
Provides an interface for loading UAV extensions and running them, particularly for REPL shells.
new({ condvar => $cv, controller_callback_ardrone => sub { ... }, controller_callback_wumpusrover => sub { .. }, })
Constructor. The condvar parameter is an AnyEvent::Condvar.
condvar
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).
controller_callback_*
($cmd, $cv, $easy_event)
$cmd
$cv
$easy_event
UAV::Pilot::EasyEvent
UAV::Pilot::Control
*::Event
init_event_loop()
Note that this API is likely to change to a factory pattern in the near future.
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:
pack
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.
uav_module_init()
run_cmd( 'takeoff;' )
Executes a command. Note that this will execute arbitrary Perl statements.
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 '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_lib
namespace
load 'ARDrone', { namespace => 'AR' }; takeoff; # Error: no subroutine named 'takeoff' AR::takeoff; # This works load ARDrone; takeoff; # Now this works, too
When calling load_lib( 'Foo' ), we look for UAV::Pilot::Foo::Commands in the current @INC.
load_lib( 'Foo' )
UAV::Pilot::Foo::Commands
@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).
package
UAV::Pilot::Command
1;
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.
load()/load_lib()
The method uav_module_quit() is called when the REPL is closing.
uav_module_quit()
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.