Cosine function

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: Cosine function

Post 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");
   }
}
// 
Regards, Morton
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Cosine function

Post 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:
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: Cosine function

Post 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?
Regards, Morton
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Cosine function

Post 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) ;)
Last edited by HaWe on 25 Dec 2010, 17:19, edited 1 time in total.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: Cosine function

Post 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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests