LEGO-NXT
view release on metacpan or search on metacpan
lib/LEGO/NXT.pm view on Meta::CPAN
$NXT_RET,
$NXT_SENSOR1,
100,
$NXT_MOTORON|$NXT_REGULATED,
$NXT_REGULATION_MODE_MOTOR_SPEED, 0,
$NXT_MOTOR_RUN_STATE_RUNNING, 0,
);
=head1 DESCRIPTION
This module provides low-level control of a LEGO NXT brick over bluetooth
using the Direct Commands API. This API will not enable you to run programs
on the NXT, rather, it will connect to the NXT and issue real-time commands
that turn on/off motors, retrieve sensor values, play sound, and more.
Users will leverage this API to control the NXT directly from an external box.
This is known to work on Linux. Other platforms are currently untested,
though it should work on any system that has the Net::Bluetooth module.
=head1 MANUAL
There is a manual for this module with an introduction, tutorials, plugins,
FAQ, etc. See L<LEGO::NXT::Manual>.
=head1 SUPPORT
If you would like to get some help join the #lego-nxt IRC chat room
on the MagNET IRC network (the official perl IRC network). More
information at:
L<http://www.irc.perl.org/>
=head1 PLUGINS
LEGO::NXT supports the ability to load plugins.
use LEGO::NXT qw( Scorpion );
Plugins provide higher level and more sophisticated means of handling
your NXT. Likely you will want to use a plugin if you want to control
your NXT as the methods in LEGO::NXT itself are very low level and
tedious to use by themselves.
Please see L<LEGO::NXT::Manual::Plugins> for more details about how to
use plugins (and write your own!) as well as what plugins are available
to you.
=cut
my %error_codes = (
0x20 => "Pending communication transaction in progress",
0x40 => "Specified mailbox queue is empty",
0xBD => "Request failed (i.e. specified file not found)",
0xBE => "Unknown command opcode",
0xBF => "Insane packet",
0xC0 => "Data contains out-of-range values",
0xDD => "Communication bus error",
0xDE => "No free memory in communication buffer",
0xDF => "Specified channel/connection is not valid",
0xE0 => "Specified channel/connection not configured or busy",
0xEC => "No active program",
0xED => "Illegal size specified",
0xEE => "Illegal mailbox queue ID specified",
0xEF => "Attempted to access invalid field of a structure",
0xF0 => "Bad input or output specified",
0xFB => "Insufficient memory available",
0xFF => "Bad arguments"
);
=head1 METHODS
=head2 new
$nxt = LEGO::NXT->new( 'xx:xx:xx:xx:xx:xx', 1 );
Creates a new NXT object, however a connection is not established until
the first direct command is issued. Argument 1 should be the bluetooth
address of your NXT (from "hcitool scan" for instance). Argument 2 is
the channel you wish to connect on -- 1 or 2 seems to work.
=cut
sub new
{
my ($pkgnm,$btaddr,$channel) = @_;
my $this = {
'btaddr' => $btaddr,
'channel' => $channel,
'fh' => undef,
'error' => undef,
'errstr' => undef,
'status' => undef,
'result' => undef
};
bless $this, $pkgnm;
return $this;
}
=head2 initialize_ultrasound_port
$nxt->initialize_ultrasound_port($NXT_SENSOR_4);
Sets the port of your choosing to use the ultrasound digital sensor.
=cut
sub initialize_ultrasound_port
{
my ($this,$port) = @_;
$this->set_input_mode($NXT_RET,$port,$NXT_LOW_SPEED_9V,$NXT_RAW_MODE);
}
=head2 get_ultrasound_measurement_units
$nxt->get_ultrasound_measurement_units($NXT_SENSOR_4);
Returns the units of measurement the US sensor is using (cm? in?)
=cut
( run in 2.113 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )