Page 2 of 2

Re: Cosine function

Posted: 24 Dec 2010, 16:17
by m-goldberg
Another approach to dealing with the problems you describe is put the US sensor in single-shot or ping mode. In this mode it will return up to eight values each time it is "fired". The values show detections of objects from closest to farthest or 255 which means no detection. In my own experiments I have never found more than four useful values, but there may be situations where more than four are useful. Here is some code that will let you experiment with ping mode.

//

Code: Select all

#define MAX_BYTES 4

const byte ping_cmnd[] = {0x2, 0x41, 0x1}; // sensor one-shot-mode command
const byte register_select[] = {0x2, 0x42}; // sensor data register

// Wait until Select button is bumped.
void wait_for_select()
{
   until (ButtonPressed(BTNCENTER, true));
   while (ButtonPressed(BTNCENTER, true));
   PlayFile("! Click.rso");
}

// Ping the US sensor when the Select button is bumped.
task main()
{
   byte data[MAX_BYTES];
   byte data_size = MAX_BYTES;
   SetSensorLowspeed(IN_4); // sensor is connected to port 4
   while (true)
   {
      wait_for_select();
      ClearScreen();
      I2CWrite(IN_4, 0, ping_cmnd); // send the ping command
      Wait(MS_100); // give sensor time to do the ping
      // Read and display the range data produced by the ping
      if (I2CBytes(IN_4, register_select, data_size, data))
      {
         for (int i = 0; i < MAX_BYTES; ++i)
            NumOut(40, 56 - 8 * i, data[i]);
      }
      else TextOut(0, LCD_LINE1, "Sensor Error");
   }
}
// 

Re: Cosine function

Posted: 24 Dec 2010, 17:39
by HaWe
m_g...
indeed with your method you get up to 8 values - but now you have 8 values of which you still don't know where the echoes actually came from in that wide field of view... :roll:

Re: Cosine function

Posted: 24 Dec 2010, 23:52
by m-goldberg
doc-helmut wrote:m_g...
indeed with your method you get up to 8 values - but now you have 8 values of which you still don't know where the echoes actually came from in that wide field of view... :roll:
But a least one knows there is more than one reflecting target in front of the sensor and have some idea their distances. Do you feel that the additional information is useless?

Re: Cosine function

Posted: 25 Dec 2010, 15:19
by HaWe
well, it's actually not MY problem.
But if I HAD the problem to detect the closest object straight ahead of the sensor (within a small angle) I could imagine that it wasn't very helpful to detect this anywhere in a +/- 30° angle and just knowing that there are 7 more objects anywhere else in this area which are not that close.

To my opinion it would help more to have 2 different US sensors which rotate and tringulate triangulate the closest echo - if you don't have a couple of IR sensors.

Otherwise I would (and actually DO ) use a series of Sharp GP2D12(0) IR sensors which have a smaller detection angle and attach them to a Mightyboard Sharp sensor muxer (up to 8 devices on each muxer) ;)

Re: Cosine function

Posted: 25 Dec 2010, 15:26
by mightor
Otherwise I would (and actually DO ) use a series of Sharp GP2D12(0) IR sensors which have a smaller detection angle and attach them to a Mightyboard Sharp sensor muxer (up to 8 devices on each muxer)
More info about the Mightyboard can be found here: http://mightor.wordpress.com/2009/03/02 ... mux-board/

- Xander