To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 1783
1782  |  1784
Subject: 
Re: Obstacle detection : infrared sensor ??
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sun, 25 Mar 2001 12:03:22 GMT
Viewed: 
1639 times
  

Is it possible to detect obstacles via the infrared sensor, before you
bump into them ?? Like measuring reflection of infrared light or
something...  If it is... how ?? can anybody guide me to where I can
find information? I am of course using LegOS.
I hope someone can help me.

We have done this in C using LegOS (it is much easier to get it off the
ground in nqc).  The principle is simple:

* Attach the light sensor in front of the brick, close to the IR tranceiver.
preferably in a low position, since you want to detect quite low obstacles.

* You need three tasks (at least) in your program:
  + One that sends on the IR port
  + One that reads the light sensor
  + One that drives the vehicle

The sending task should use "lnp_logical_send" to send four ZEROS, i.e. an
array like 'unsigned char a[4] = {0,0,0,0};'.  NOT the letter zero, real zeros!
This task will block each time the send function is called, letting the
sensor scan task execute.

The scanning task simply performs two reads from the light sensor in quick
succession.  If the difference is large, you have seen an IR-edge, and there
is something in front of you.  In this case, set some global variable that
the driving task can read.

  Code that worked for us (off the top of my head):

  int r;

  while(1)
  {
    r = read light sensor;
    msleep(10);              // need a little pause here
    r -= read light sensor;  // subtract next reading
    if(r<0) r = -r;          // compensate sign
    if(r>20) gCollision = 1; // set flag variable
  }

The driving task simply sleeps in a wait function that checks for gCollision
being 1.  After handling the collision (turning around, stopping, whatever),
clear the gCollision flag.

The constant '20' in the code above worked for us, but seems to depend on
the particular brick you're using.  Values up to 100 have been needed for
other people to reduce false alarms.

Hope this helps

/jakob



Message is in Reply To:
  Obstacle detection : infrared sensor ??
 
Hey.. I don't know if this is a LegOS question, but here it goes... Is it possible to detect obstacles via the infrared sensor, before you bump into them ?? Like measuring reflection of infrared light or something... If it is... how ?? can anybody (...) (24 years ago, 24-Mar-01, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR