Remotely reading NXT's ultrasonic sensor from PC

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

Moderators: 99jonathan, roger, imaqine

Remotely reading NXT's ultrasonic sensor from PC

Postby puusilmae » Fri Feb 07, 2014 3:04 pm

Hello,
I'm trying to read NXT's ultrasonic remotely via Bluetooth from a PC using RemoteSensorPort. All the other sensors can be read easily just by creating a related sensor object (TouchSensor, SoundSensor, ColorSensor) and passing a RemoteSensorPort instance to it. But, for some reason UltrasonicSensor does not work this way even if RemoteSensorPort should implement I2CPort interface, which is apparently required for UltrasonicSensor. Whenever I try, I'll just get 'Failed to open connection to the NXT' -message.

So is there some other way UltrasonicSensor should be read remotely? Or some further magic that needs to be done with RemoteSensorPort when using it with UltrasonicSensor? Or is using sensor objects this way when not running the code on NXT brick just abuse?

Code: Select all
NXTConnector connector = new NXTConnector();
connector.connectTo(null, address, NXTCommFactory.BLUETOOTH);
NXTCommRequest commRequest = this.connector.getNXTComm();
TouchSensor touchSensor = new TouchSensor(new RemoteSensorPort(new NXTCommand(commRequest), 0)); //works
UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(new RemoteSensorPort(new NXTCommand(commRequest), 1)); //does not work in any port


Trying to read values, raw or otherwise, from just RemoteSensorPort where UltrasonicSensor is connected does not give any meaningful values.

Also, Is RemoteNXT class only working when running the program on NXT brick? It would make sense to use it also when remotely controlling NXT from PC, but it just throws an exception.

Code: Select all
Exception in thread "main" java.lang.NoSuchMethodError: lejos.nxt.NXT.getUserPages()I
   at lejos.nxt.Flash.<clinit>(Flash.java:16)
   at lejos.nxt.SystemSettings.<clinit>(SystemSettings.java:32)
   at lejos.nxt.comm.NXTCommDevice.loadSettings(NXTCommDevice.java:165)
   at lejos.nxt.comm.NXTCommDevice.<clinit>(NXTCommDevice.java:20)
   at learning.NXT.<init>(NXT.java:50)
   at learning.NXT.main(NXT.java:130)
puusilmae
New User
 
Posts: 1
Joined: Fri Feb 07, 2014 2:35 pm

Re: Remotely reading NXT's ultrasonic sensor from PC

Postby gloomyandy » Fri Feb 07, 2014 3:35 pm

Have you tried just using the Ultrasonic sensor without also creating the Touch sensor? I don't think it is a good idea to create multiple NXTCommand objects in this way. Better to create one and use it for both sensors.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3645
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Remotely reading NXT's ultrasonic sensor from PC

Postby skoehler » Fri Feb 07, 2014 5:50 pm

puusilmae wrote:Also, Is RemoteNXT class only working when running the program on NXT brick? It would make sense to use it also when remotely controlling NXT from PC, but it just throws an exception.

For some weired reason, you have the classes.jar in your project's classpath. However, that JAR file is for NXT-side programs only.
If you're using Eclipse, create a leJOS PC project. It automatically adds the right JAR files to your project.
If you're not using Eclipse, well, then either use our command like tools (nxjpcc for compiling, nxjpc for running programs) or fix your build process to only include JARs from the lib/pc folder in the classpath while compiling / running programs.

Also, if consulting our documentation for the classes available on the PC-side (http://www.lejos.org/nxt/pc/api/index.html), you'll see that there is no RemoteNXT class. It's only available on the NXT. I believe, the PC-side and NXT-side APIs for remote control have never been brought in line with each other.
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff