To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 2576
2575  |  2577
Subject: 
Re: IR Port as Proximity detector.
Newsgroups: 
lugnet.robotics
Date: 
Fri, 8 Jan 1999 21:37:07 GMT
Original-From: 
Joel A. Kunze <[joelak@]IHateSpam[sage.net]>
Viewed: 
1376 times
  
Just thought I would throw up yet another code sample for proximity
detection.
With the following code, and my Light sensor mounted 4 bricks above the RCX,
I get the following raw values in a dimly lit room with about 1 inch between
the RCX and the carpet floor. The wall is interior white house paint.

Distance, Raw value with IR Off, Raw value with IR On.
4ft, 808, 741
3ft, 808, 734
2ft, 820, 706
1ft, 825, 641
6in, 810, 597
3in, 793, 603

As the sensor approaches the wall, it looks like ambient light decrease,
then suddenly the red LED starts to have an effect at  3 inches.

Also, just wanted to say thank to Simen Svale Skogsrud for posting the
original information about using the Light sensor and IR port for this type
of sensing.

Joel Kunze



// code to ping with the IR Tx and the Light sensor.
// used to detect obstacles

#define BUTTON IN_1
#define RECEIVER IN_3

int RxM1;         // Magnitude of Rx Signal with IRTx Off
int RxM2;         // Magnitude of RX Signal with IRTx On
int RxD;          // more usable value;

int TimeoutCounter;
int Temp;

task main
{
  // setup inputs
  Sensor(BUTTON,IN_SWITCH);
  Sensor(RECEIVER, IN_CFG(STYPE_LIGHT,SMODE_RAW));

  SetDatalog(500);

  // wait for start command
  wait(BUTTON==1);
  wait(BUTTON==0);
  PlaySound(0);
  Display(3);
  ClearTimer(1);

  while(true)
  {

    if(BUTTON==1)
    {
      wait(BUTTON==0);

      PlaySound(0);

      // add signal level with no IR
      RxM1 = RECEIVER;
      Datalog(RxM1);

      RxM2 = RxM1;
      TimeoutCounter = 50;

      // get the lowest level with IR
      // in a reasonable amount of tries.
      // This is done to get around
      // the asynchronus nature of the the
      // IR transmit, and Light sensor sampling.
      while(true)
      {
        // What should be used here for
        // for most IR 'on time'?
        SendMessage(65535);
        Temp = RECEIVER;

        if(Temp < RxM2)
          RxM2 = Temp;

        TimeoutCounter -= 1;
        if(TimeoutCounter==0)
          break;
      }

      Datalog(RxM2);

      RxD = RxM1;
      RxD -= RxM2;

      // wait 1 second between each reading
      Sleep(100);

    }
  }
}



--
Did you check the web site first?: http://www.crynwr.com/lego-robotics



1 Message 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