Detecting sensor type

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

Moderators: 99jonathan, roger, imaqine

Detecting sensor type

Postby Forceflow » Thu Oct 04, 2007 11:23 pm

As I've read in several other threads, there is no way of detecting which sensor is attached to which port with the standard API methods.

Would the following approach work ? (I am aware of the utter dumbness of it, but still)

new TouchSensor(SensorPort.S1)
new TouchSensor(SensorPort.S2)
new TouchSensor(SensorPort.S3)
new TouchSensor(SensorPort.S4)

And then do some kind of check or value read, and see where it works, and eliminate where it fails ?

The problem is: NXT brick = limited memory and no garbage collection. Oh joy :)

My apologies if this is a very stupid question, we've just started out experimenting with Lejos :)
Forceflow
New User
 
Posts: 1
Joined: Thu Oct 04, 2007 11:19 pm
Location: Belgium

Re: Detecting sensor type

Postby roger » Wed Oct 10, 2007 4:37 am

Forceflow wrote:As I've read in several other threads, there is no way of detecting which sensor is attached to which port with the standard API methods.

The problem is: NXT brick = limited memory and no garbage collection. Oh joy :)

My apologies if this is a very stupid question, we've just started out experimenting with Lejos :)


I don't think there is a software solution to the problem of incorrect connection of sensors to ports. I color-code my wires at the ends to make the eye ball solution more reliable.
If you think the NXT memory is limited, try programming the RCX. You can program to minimize memory leaks by never letting the keyword new appear in a method, only in the constructor. And remember that
LCD.drawString("hello world",0,0) creates a new string.
Roger
roger
Moderator
 
Posts: 363
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA

Postby bbagnall » Sat Oct 20, 2007 5:42 pm

Hi Forceflow,

If you are using I2C sensors you can use some methods in the I2CSensor class to query the sensor type:

getProductId()
getSensorType()
getVersion()

You are right about the lack of garbage collection - tread carefully when you are programming and it shouldn't be much of a factor.

I have no idea how you could troll for different analog sensors.
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm


Return to NXJ Software

Who is online

Users browsing this forum: Google [Bot], roger and 3 guests

more stuff