Sensor AutoDetection

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Sensor AutoDetection

Post by dudmaster »

Hello, Peeps!

Haven't seen you in a while!
What I need to do now is detect if a sensor is present. I mean
by that is this:
(Example)

Code: Select all

task main() {
if (SensorDetect(S1) == NO_SENSOR)
{
V = 0;
}
else
{
V = 1;
}
Basically I need a program to detect is a sensor is plugged in.
2Labz.com, My Website
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Sensor AutoDetection

Post by muntoo »

dudmaster wrote:Haven't seen you in a while!
No, but we've been watching you...

Maybe it's something to do with SensorInvalid()?
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Sensor AutoDetection

Post by mattallen37 »

Electronically, not even all the sensors would support that. You'd have to go about it in different ways for the different sensors.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
lizard381
Posts: 44
Joined: 16 Nov 2010, 19:57

Re: Sensor AutoDetection

Post by lizard381 »

mattallen37 wrote:Electronically, not even all the sensors would support that. You'd have to go about it in different ways for the different sensors.
I've actually been curious about the possibility of auto dectection for sensors, could you expand on this? Specifically, is it that I2C sensors support autodetection? What are the different ways to do autodetection?

Kami
I haven't grown past my playing with Legos stage and I don't think I want to :)
Blog: http://nuhlikklebickle.blogspot.com
Kami
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Sensor AutoDetection

Post by mattallen37 »

The I2C sensors should be easy for the master to detect. Do a simple read request, and see if you get a response. For the Lego, HT, and Mindsensors I2C sensors, they have identification registers so the master can tell which one it is communicating with (which one is plugged in). Look at the datasheets to see what I mean.

For analog sensors, some of them would support detection. For example, the light sensor will never have infinite resistance, so if you are reading 1023 raw, then it is not connected. The same should also be true for the sound sensor. The (semi digital) 2.0 Lego color sensor should also be able to be read in RAW mode (though a different method) to detect presence. The touch sensors however are completely open circuits until pressed. There is no way to detect if they are attached (unless they are also pressed).

All the Lego sensors (other than maybe the color sensor) themselves support a variation of auto-detection, but unfortunately the NXT HW does not allow for it. All the sensors that I have a schematic for show that pins 2 and 3 are tied together in the sensors (I don't have the schematic for the color sensor). If you were to ground pin 3, then you could potentially read pin 2 to look for ground (the NXT PCB doesn't support this though).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
lizard381
Posts: 44
Joined: 16 Nov 2010, 19:57

Re: Sensor AutoDetection

Post by lizard381 »

mattallen37 wrote:The I2C sensors should be easy for the master to detect. Do a simple read request, and see if you get a response. For the Lego, HT, and Mindsensors I2C sensors, they have identification registers so the master can tell which one it is communicating with (which one is plugged in). Look at the datasheets to see what I mean.
So you still need to set the sensor port as digital right? Otherwise you can't send the read sensor type command...
mattallen37 wrote:For analog sensors, some of them would support detection. For example, the light sensor will never have infinite resistance, so if you are reading 1023 raw, then it is not connected. The same should also be true for the sound sensor. The (semi digital) 2.0 Lego color sensor should also be able to be read in RAW mode (though a different method) to detect presence. The touch sensors however are completely open circuits until pressed. There is no way to detect if they are attached (unless they are also pressed).

All the Lego sensors (other than maybe the color sensor) themselves support a variation of auto-detection, but unfortunately the NXT HW does not allow for it. All the sensors that I have a schematic for show that pins 2 and 3 are tied together in the sensors (I don't have the schematic for the color sensor). If you were to ground pin 3, then you could potentially read pin 2 to look for ground (the NXT PCB doesn't support this though).
Thanks for this explanation, very helpful!

Kami
I haven't grown past my playing with Legos stage and I don't think I want to :)
Blog: http://nuhlikklebickle.blogspot.com
Kami
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Sensor AutoDetection

Post by mattallen37 »

lizard381 wrote:So you still need to set the sensor port as digital right? Otherwise you can't send the read sensor type command...

Kami
Yes, it is an I2C transaction, the master reads the first 16 (I think 16 anyhow) registers. It would be like reading any other registers (like 0x42...).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
kvols
Posts: 29
Joined: 14 Oct 2010, 22:09

Re: Sensor AutoDetection

Post by kvols »

I've tried a bit of sensor detection myself. At least to ensure that the sensors I've plugged into the robot, just might be correctly connected.

As mentioned before, the I2C sensors are pretty straight forward. It's the analog sensors that may cause problems. The analog sensors may however behave quite different. If your robot is equipped with two I2C sensors (eg. the ultrasonic sensor and an accelerometer), and two analog sensors (eg. a sound sensor and the classic light sensor), you might be able to detect all sensors correctly, given some knowledge about your actual set-up:

1) Look for the I2C sensors, and reserve the ports for them.
2) The analog sensors must (should) be connected to the remaining two ports.

All you will need to do with the remaining two ports is to do some clever guessing. For each port, you could obtain three values:

1) No sensor connected
2) Classic light sensor connected
3) Sound sensor connected

Depending on your set-up, how the sensors are connected, you should get very different readings, depending on the state of the port. Both the light sensor and the sound sensor behaves very different in active mode and in passive mode, and the a port with a disconnected sensor should be very easy to spot as well.

I beleive that some simple clever guessing could do the trick in such a scenario - where you have a limited set of sensors.

Regardless, you can not safely guess any analog sensor, and you cannot distinguish between two identical sensors (eg. left and right light sensor). Likewise, you cannot tell the motors apart, unless you have some more knowledge about your actual set-up. But some clever guessing might just be enough in some situations..

Kind regards,

Povl
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Sensor AutoDetection

Post by mattallen37 »

I don't think the idea here is to detect what analog sensor is connected. I think the idea is to detect if a sensor is connected.

For the digital sensors, you can detect if they are there by reading them. The manufacturer will sometimes use several registers that you can read to determine specifically what kind of digital sensor is connected.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 9 guests