Ultrasonic Sensor Mode

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

Moderators: 99jonathan, roger, imaqine

Ultrasonic Sensor Mode

Postby nxtfan » Sun Jul 01, 2012 6:51 pm

Hi all,

I had some questions regarding the ultrasonic sensor as I tried to use 4 US sensors mounted on a omni drive.
The 4 US sensors are facing 4 different angles ( +- 45 degrees and +- 135 degrees) to detect obstacles and I used the Hitechnic SensorMux to connect the 4 US sensor to NXT.
My first question is, how should I set the US sensor mode to "capture mode"? I checked either the SensorMux.class or the UltrasonicSensor.class and this mode is not implemented...

I googled it and some say that to use the Event Capture Mode:
To use the Ultrasonic Sensor's "Mode 3" with NXC, you need to use I2CWrite(PORTnumber, 0×41, 0×03) to turn on and initialise the sensor. You can the then use SensorUS(PORTnumber) to read the distance to object. To turn the Sensor Off again, you need to use I2CWrite(PORTnumber, 0×41, 0×00). You need to repeat these commands for each Ultrasonic Sensor you are using. It pays to initialise all your Ultrasonic Sensors to the Off state when the program starts.


My second question is if I use SensorMux class how could I set the sensor mode?

Thanks a lot!
Dennis
nxtfan
New User
 
Posts: 11
Joined: Sat Jun 09, 2012 10:36 am

Re: Ultrasonic Sensor Mode

Postby gloomyandy » Sun Jul 01, 2012 7:17 pm

Are you sure you want to use capture mode? It my make more sense to simply use ping mode on each sensor in turn. The driver does support capture mode via the capture method. No idea if any of these modes are supported by the sensor mux though as I've never used one...

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

Re: Ultrasonic Sensor Mode

Postby skoehler » Sun Jul 01, 2012 9:07 pm

The SensorMux doesn't implement what you might expect it implements. It does NOT allow the NXT to talk to all four connected sensors which would be necessary to switch the US sensor to ping or capture mode.
Instead, the SensorMux communicated and configured all attached devices. The US sensor is ALWAYS in continuous mode. There is no way to switch modes.
The NXT must read the values provided by the SensorMux from the SensorMux internal registers, which are regularly updated by the SensorMux itself.

In result, when the US sensor is connected to the SensorMux, the UltraSonic class is completely useless. You have to use the SensorMux class.
skoehler
leJOS Team Member
 
Posts: 1430
Joined: Thu Oct 30, 2008 4:54 pm

Re: Ultrasonic Sensor Mode

Postby nxtfan » Mon Jul 02, 2012 2:22 pm

gloomyandy wrote:Are you sure you want to use capture mode? It my make more sense to simply use ping mode on each sensor in turn. The driver does support capture mode via the capture method. No idea if any of these modes are supported by the sensor mux though as I've never used one...

Andy


Yes I think if one US sensor sends out a single ping and it rotates, instead of the first US sensor the second US sensor will capture part of the echos which it should not do. This would cause some interferences within the US sensors. Thanks for the hint! I didn't notice the capture() method. Maybe I would try it out.

skoehler wrote:The SensorMux doesn't implement what you might expect it implements. It does NOT allow the NXT to talk to all four connected sensors which would be necessary to switch the US sensor to ping or capture mode.
Instead, the SensorMux communicated and configured all attached devices. The US sensor is ALWAYS in continuous mode. There is no way to switch modes.
The NXT must read the values provided by the SensorMux from the SensorMux internal registers, which are regularly updated by the SensorMux itself.

In result, when the US sensor is connected to the SensorMux, the UltraSonic class is completely useless. You have to use the SensorMux class.


OK. Then It probably means if I used 4 US sensors and one IRLink sensor (to control 4 PF motors) at the same time, I cannot set the mode of the US sensor... Is there any better options?
nxtfan
New User
 
Posts: 11
Joined: Sat Jun 09, 2012 10:36 am

Re: Ultrasonic Sensor Mode

Postby skoehler » Mon Jul 02, 2012 3:00 pm

nxtfan wrote:OK. Then It probably means if I used 4 US sensors and one IRLink sensor (to control 4 PF motors) at the same time, I cannot set the mode of the US sensor... Is there any better options?


If you really need full control over 4 US sensors + and other I2C devices, then you need to build something like an I2C multiplexer for the NXT. Such chips exists, as far as I know, but for some reason none of the manufacturers has been smart enough to wire one to the NXT. I have never heard of anyone attempting this, and I cannot guarantee that the Lego US sensor is actually able to talk to standard I2C hosts. The I2C protocol implemented by the NXT is actually not quite standard.
http://ics.nxp.com/products/i2cmuxes/
skoehler
leJOS Team Member
 
Posts: 1430
Joined: Thu Oct 30, 2008 4:54 pm

Re: Ultrasonic Sensor Mode

Postby nxtfan » Mon Jul 02, 2012 4:53 pm

gloomyandy wrote:Are you sure you want to use capture mode? It my make more sense to simply use ping mode on each sensor in turn. The driver does support capture mode via the capture method. No idea if any of these modes are supported by the sensor mux though as I've never used one...

Andy


Sorry Andy, the capture() method is not implemented for both MODE_CAPTURE and MODE_OFF constant...see the following code.
Code: Select all
public int capture()
   {
      return setMode(MODE_CAPTURE);
   }


And the setMode():
Code: Select all
public int setMode(int mode)
   {
      int delay = 0;
      byte modeNew = (byte)mode;
      switch (mode)
      {
         case MODE_RESET:
            // Is off after a reset;
            modeNew = MODE_OFF;
            break;
         case MODE_PING:
            delay = DELAY_DATA_PING;
            break;
         case MODE_OFF:
         case MODE_CAPTURE:
         case MODE_CONTINUOUS:
            delay = DELAY_DATA_OTHER;
            break;
         default:
            throw new IllegalArgumentException("unknown mode");
      }

      byteBuff[0] = (byte)mode;
      int ret = sendData(REG_MODE, byteBuff, 1);
      if (ret == 0)
      {
         // Make a note of when the data will be available
         dataAvailableTime = System.currentTimeMillis() + delay;
         this.mode = modeNew;
      }
      return ret;
   }


skoehler wrote:
nxtfan wrote:OK. Then It probably means if I used 4 US sensors and one IRLink sensor (to control 4 PF motors) at the same time, I cannot set the mode of the US sensor... Is there any better options?


If you really need full control over 4 US sensors + and other I2C devices, then you need to build something like an I2C multiplexer for the NXT. Such chips exists, as far as I know, but for some reason none of the manufacturers has been smart enough to wire one to the NXT. I have never heard of anyone attempting this, and I cannot guarantee that the Lego US sensor is actually able to talk to standard I2C hosts. The I2C protocol implemented by the NXT is actually not quite standard.
http://ics.nxp.com/products/i2cmuxes/


Thanks for the link. You are saying that the this is due to the chip on the Hitechnic SensorMux not due to the leJOS API. Am I right?
nxtfan
New User
 
Posts: 11
Joined: Sat Jun 09, 2012 10:36 am

Re: Ultrasonic Sensor Mode

Postby gloomyandy » Mon Jul 02, 2012 5:09 pm

Hi,
I'm not sure what it is you are saying. Capture mode is implemented in the above code, it will send the appropriate mode command to the device via the sendData method. Perhaps you could explain why you think it is not implemented? The common code for OFF etc. is simply setting the inter command delay parameter, which happens to be the same for these commands. The sendData call later will send the mode to the device...

But as I said earlier I think you would be better off simply using ping for each sensor in turn. I don't think I've ever seen anyone use capture mode successfully!

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

Re: Ultrasonic Sensor Mode

Postby nxtfan » Mon Jul 02, 2012 7:40 pm

Oh yes the OFF, Capture and Continuous mode happen to share the same DELAY... Sorry I missed that. I'll consider your suggestions. Thanks very much!
nxtfan
New User
 
Posts: 11
Joined: Sat Jun 09, 2012 10:36 am


Return to NXJ Software

Who is online

Users browsing this forum: gloomyandy and 3 guests

more stuff