NXT Ultrasonic sensor not working with Bluetooth

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, 99jonathan, imaqine

NXT Ultrasonic sensor not working with Bluetooth

Postby amit.dgp12 » Thu Dec 23, 2010 7:36 am

hi everyone,

I am new to this forum, I have a problem in using ultrasonic sensor over bluetooth(icommand-0.7).
whenever iam trying to create an object of ultrasonic sensor it givs the following error:-

-----------------------------------------------------------------------------------------------
### command prompt OUTPUT ###

C:\icommand\samples\AMIT>java dtest
Properties location: C:\Documents and Settings\srl-amit\icommand.properties
BlueCove version 2.0.0 on winsock
Lets Start =====
Exception in thread "main" java.lang.NegativeArraySizeException
at icommand.nxt.comm.NXTCommand.LSRead(Unknown Source)
at icommand.nxt.I2CSensor.<init>(Unknown Source)
at icommand.nxt.UltrasonicSensor.<init>(Unknown Source)
at dtest.main(dtest.java:12)
BlueCove stack shutdown completed
-----------------------------------------------------------------------------------------------
the code for the above program is as shown below:-

import icommand.nxt.*;
import icommand.nxt.comm.NXTCommand;
public class dtest
{
private static final short[] note = { 2349, 115, 0, 5 };
public static void main(String[] args) throws Exception
{
NXTCommand.open();
NXTCommand.setVerify(true);
System.out.println("Lets Start ===== ");
TouchSensor t = new TouchSensor(SensorPort.S4);
UltrasonicSensor u = new UltrasonicSensor(SensorPort.S2);
LightSensor l = new LightSensor(SensorPort.S3);
SoundSensor s = new SoundSensor(SensorPort.S1);
System.out.println("Light Value = "+l.getLightValue());
System.out.println("Sound Value = "+s.getdB());
System.out.println("\nNow press the touch sensor for a sec sec.\n");
try {
Thread.sleep(2000);
} catch(InterruptedException ie) {}
if(t.isPressed())
{
System.out.println("touch sensor is pressed\n");
}
else
System.out.println("touch sensor is not pressed\n");
System.out.println("working!!\n\n");
NXTCommand.close();
}
}

and if i remove the line which creates object of ultrasonic sensor then it working, and the output of the above code after removing the line which creates object of ultrasonic sensor is :-

-----------------------------------------------------------------------------------------------
### command prompt OUTPUT ###

C:\icommand\samples\AMIT>java dtest
Properties location: C:\Documents and Settings\srl-amit\icommand.properties
BlueCove version 2.0.0 on winsock
Lets Start =====
Light Value = 378
Sound Value = 35

Now press the touch sensor for a sec sec.

touch sensor is pressed

working!!


BlueCove stack shutdown completed
-----------------------------------------------------------------------------------------------

i have changed the ultrasonic sensor by anther one and trying with the different sensor ports but the error is same (as shown above), more importantly the ultrasonic sensor and the nxt brick are working fine when i am running same type of program using nxj [lejos NXJ8.5](which displays the results on the NXT bricks screen), i also tested the above program in another nxt brick but the same problem occurs.

So please help me.............

AMIT KR MANDAL
[email - amit.dgp12@gmail.com]
Surface Robotics Laboretrary
Central Mechanical Engineering Research Institute
Durgapur, India[/code]
amit.dgp12
New User
 
Posts: 2
Joined: Thu Dec 23, 2010 6:43 am
Location: Durgapur

Postby gloomyandy » Thu Dec 23, 2010 12:06 pm

Hi,
iCommand is no longer supported. Instead you can use the leJOS PC API:
http://lejos.sourceforge.net/nxt/pc/api/index.html
There are various sample programs supplied with the 0.8.5 version of leJOS that show how you can use this API. I would recommend that you take a look at the SensorTest sample (search your PC for SensorTest.java). You can build and run these samples using the command line tools...
http://lejos.sourceforge.net/nxt/nxj/tu ... dRun.htm#6

Andy

PS I've moved this posting to the correct forum...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby amit.dgp12 » Fri Dec 24, 2010 11:53 am

thanks andy,
as per your recomandation it works, and i can access sensors data from my pc.

but it should work with icommand.....(according to Maximum LEGO NXT by Brian Bagnall).

once again thanks for the help.

Amit kr. Mandal
[email - amit.dgp12@gmail.com]
Surface Robotics Laboratory
Central Mechanical Engineering Research Institute
Durgapur, India
amit.dgp12
New User
 
Posts: 2
Joined: Thu Dec 23, 2010 6:43 am
Location: Durgapur

Postby gloomyandy » Fri Dec 24, 2010 2:15 pm

I'm glad you have it working...

As I said before, iCommand has been replaced by the leJOS PC side API. This provides a richer environment and is much easier to get connections working over Bluetooth and USB than it was with iCommand. I'm sure that it would have been possible to get things working with the older code but I doubt if anyone would have been interested in helping you sort things out. Brian's book is now a few years old and things have moved on a long way since then...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff