Hi. I'm trying to use the LEGO::NXT modules to control my NXT bot (over bluetooth). I installed just last week with CPAN. But my first run of the example program fails:
Code:
choward@adler /scratch/choward/robots/nxt $ ./test.pl
Use of uninitialized value in pack at /usr/lib/perl5/site_perl/5.8.8/LEGO/NXT.pm line 498.
Can't call method "type" without a package or object reference at /usr/lib/perl5/site_perl/5.8.8/LEGO/NXT.pm line 1442.
Here is the sample program:
Code:
#!/usr/bin/env perl
use LEGO::NXT;
# Create a new Bluetooth/NXT object by connecting to
# a specific bluetooth address and channel.
my $nxt = LEGO::NXT->new( '00:67:22:AB:32:98', 1 );
$nxt->play_sound_file($NXT_NORET, 0,'! Attention.rso');
$res = $nxt->get_battery_level($NXT_RET);
# Turn on Motor 1 to full power.
$res = $nxt->set_output_state(
$NXT_RET,
$NXT_SENSOR1,
100,
$NXT_MOTORON|$NXT_REGULATED,
$NXT_REGULATION_MODE_MOTOR_SPEED, 0,
$NXT_MOTOR_RUN_STATE_RUNNING, 0,
);
Here is the first offending function. Line 498 is the "my $ret = $this->_do_cmd(" line.
Code:
sub play_sound_file
{
my ($this,$needsret,$repeat,$file) = @_;
my $strlen = 1+length($file);
my $ret = $this->_do_cmd(
pack("CCCZ[$strlen]",$needsret,$NXT_PLAY_SOUND_FILE,$repeat,$file),
$needsret
);
return if $needsret==$NXT_NORET;
$this->_parse_generic_ret($ret);
}
Here is the second. The offending line is "if ($comm->type eq 'usb')"
Code:
sub _do_cmd
{
my ($this,$msg,$needsret) = @_;
my $comm = $this->{comm};
my $res;
if ($comm->type eq 'usb')
{
$res = $comm->do_cmd( $msg, $needsret );
#parsing functions expect prepended length bytes ala bluetooth
if (defined $res )
{
$res = pack('v',length($res)).$res;
}
}
if ($comm->type eq 'blue')
{
#bluetooth comm requires prepended length bytes
$res = $comm->do_cmd( pack( "v", length($msg) ) . $msg, $needsret );
}
$res;
}
My Perl is a little rusty, and I can't even remember what a pack is. Could somebody point me in the right direction?
[Edit: It is version 2.00 of the library... sample program was taken from the MAN pages installed by CPAN.]