UAV::Pilot::Commands
my $device; # Some UAV::Pilot::Control instance, defined elsewhere my $cmds = UAV::Pilot::Commands->new({ device => $device, }); $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({ device => $device })
Constructor. Takes a UAV::Pilot::Control instance.
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', { 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_lib
load 'ARDrone', { pack => 'AR' }; takeoff; # Error: no subroutine named 'takeoff' AR::takeoff; # This works load ARDrone; takeoff; # Now this works, too
Extensions should go in the directory specified by:
File::ShareDir::dist_dir( 'UAV-Pilot' )
They should have a .uav extension.
.uav
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()
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.