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 / 3574
3573  |  3575
Subject: 
Re: LONG!!! - RCX Radarbots and distance measurement
Newsgroups: 
lugnet.robotics
Date: 
Mon, 8 Feb 1999 16:07:36 GMT
Original-From: 
John Cooper <robots@jpsc.co.STOPSPAMuk>
Reply-To: 
robots@jpsc.co.uk!spamless!
Viewed: 
1377 times
  
This is the best yet!

I have taken the liberty of converting it to NQC and removing the motor
control commands. This gives a task that publishes DEFCON and AVG_AMBIENT
that can be used in a monitor loop. This is so sensitive that DEFCON 1
is pretty much unusable as it may be triggered by tufts in the carpet.

I slow down on DEFCON 2, change direction slightly on DEFCON 3 and take major
avoiding action (back up) on DEFCON 4 and above.

/*
The basic strategy is to measure DEFCON. Converted from code by Mark R. David
(markdavid@mediaone.net)


The variables used are:

AVG_AMBIENT - Maintains the initial ambient light value, and a moving
average of same

DEFCON - The higher DEFCON gets, the closer we are to the object.

DiffRaw - The difference - a number that represents how much brighter
the raw reading has to be to raise DEFCON one level.

ThisRaw - the latest light sensor raw reading

MinRaw - The current effective minimum (brightest) raw reading

RisingMins - Flag that indicates that our most recent minimum was
actually higher (darker) than the currently effective minimum. We might
no longer be getting closer to the object, but we'll give it one more
chance.

LastRaw - the reading prior to ThisRaw, used to determine if things are
getting brighter or darker

DescendingRaw - a flag that readings are currently descending (getting
brighter)

*/

#define RAW_LIGHT    IN_2

#define FALSE        0
#define TRUE         1
#define SAMPLE_COUNT 30

int AVG_AMBIENT,DiffRaw,ThisRaw,DEFCON,MinRaw,RisingMins,LastRaw,DescendingRaw;
int Temp; // temporary variable

task ProximityDriver
{
  Sensor(RAW_LIGHT, IN_CFG(STYPE_LIGHT, SMODE_RAW));
  IRMode(IR_HI);

  Temp = 0;
  repeat (SAMPLE_COUNT) {
    ThisRaw = RAW_LIGHT;
    Temp += ThisRaw;
  }
  Temp /= SAMPLE_COUNT;
  AVG_AMBIENT = Temp;              // average starting ambient light value

  DEFCON = 0;                      //    DEFCON - number of diffs the last min is below ambient
  MinRaw = AVG_AMBIENT;            // The current minimum flash read - init to ambient
  RisingMins = FALSE;              //    Flag that the last min was higher than the one before
  LastRaw = AVG_AMBIENT;           // Previous raw reading
  DescendingRaw = FALSE;           //    Flag that raw readings are descending

  while (true) {                   // monitor forever
    ThisRaw = RAW_LIGHT;           //      Take ambient reading ...
    Temp = AVG_AMBIENT;
    Temp *= 4;
    Temp += ThisRaw;
    Temp /= 5;
    AVG_AMBIENT = Temp;            // ... and keep a moving avg of it

    DiffRaw = 615;
    DiffRaw -= AVG_AMBIENT;
    DiffRaw /= 6;                  //    DiffRaw = The diff - a meaningful difference in light reading
    if (DiffRaw > -6) {            //         Is negative and no greater than -5
      DiffRaw = -6;                // DiffRaw = Min(-6, (615 - AVG_AMBIENT) / 6)
    }

    SendMessage(255);              // Flash
    Sleep(3);
    ThisRaw = RAW_LIGHT;
    if (ThisRaw < MinRaw) {        //  New minimum!
      MinRaw = ThisRaw;            // Reset the effective min
      RisingMins = FALSE;          //     Clear the rising mins flag
      DescendingRaw = TRUE;        //     Set the descending flag
      Temp = MinRaw;
      Temp -= AVG_AMBIENT;
      Temp /= DiffRaw;             // Calculate DEFCON
      DEFCON = Temp;               // DEFCON = (MinRaw - AVG_AMBIENT) / DiffRaw
    } else {
      if (ThisRaw > LastRaw) {     //   Ascending
        if (DescendingRaw==TRUE) { //      Was descending must be a higher min
          if (RisingMins==TRUE) {  //       It's the second one! Reset the effective min
            MinRaw = LastRaw;      // Reset the effective min
            Temp = MinRaw;
            Temp -= AVG_AMBIENT;
            Temp /= DiffRaw;       // Calculate DEFCON
            DEFCON = Temp;
          } else {
            RisingMins = TRUE;
          }
        }
        DescendingRaw = FALSE;
      } else {
        DescendingRaw = TRUE;      //                  Descending
      }
    }

    LastRaw = ThisRaw;
  } //loop forever
}
--
John & James Cooper, Wallington, UK


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



Message is in Reply To:
  LONG!!! - RCX Radarbots and distance measurement
 
RCX Radarbots and distance measurement While I like the idea of a radarbot, most of the algorithms I've seen for implementing it were basically "You're close when the return signal starts to get really noisy." I wanted to know more about what was (...) (26 years ago, 5-Feb-99, to lugnet.robotics)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
12 hours ago
Custom Search

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