To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcxOpen lugnet.robotics.rcx in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / 40
39  |  41
Subject: 
Re: Light sensor initialization?
Newsgroups: 
lugnet.robotics.rcx
Date: 
Thu, 15 Jul 1999 14:25:02 GMT
Viewed: 
2029 times
  
Matthew's program takes one reading at initialization time to
determine a baseline value. Any reading that falls 7 units
below this is assumed to be a dark line.

I take a somewhat more conservative approach, taking 10
readings over one second and averaging them to get
a baseline value. This is done once at initialization.
I then detect a dark line by testing for a
reading that is 3 below the baseline. Here's the code I've
been using to calculate an average baseline value:

-----
#define NUMBER_OF_SAMPLES 10
int i;
int runningTotal;
int averageLight;

inline calibrateLightSensor {
  // Take an average light reading.
  i = 0;
  runningTotal = 0;
  while (i < NUMBER_OF_SAMPLES) {
    runningTotal += LIGHT_SENSOR;
    Sleep(10);
    i += 1;
  }
  averageLight = runningTotal / NUMBER_OF_SAMPLES;
}
-----

Then I look for the black line with code like this:

    if (LIGHT_SENSOR < averageLight - 3) {

It works well. I really like getting a baseline light value
at runtime, for two reasons:

1. You might want to run your robot at different times
   of day and have it work right. Hardcoded values will
   probably fail you here.
2. Different light sensors produce different readings
   for the same amount of light. Doing a runtime calibration
   increases the chances that your program can work on
   someone else's robot.

There's really only one drawback: you have to assume that
your robot is over a white part of the driving surface
when the program runs. If it's over a black line, your
calibration will be all screwed up.

Jonathan



Matthew Miller wrote:

Tim Rueger <rueger@io.com> wrote:
I'd like my 'bot to measure ambient light levels, and make light/gray/dark
decisions based on those levels. • [snip]
I'd like to avoid hard-coding these numbers. Has any one done this?

Yes -- check out my RoboTag program at
http://www.mattdm.org/mindstorms/robotag.shtml

In RoboTag, the sensor is pointing at the ground, which is probably
grey/brown/white, with black border lines. My program reads the light level
at start, and assumes that it isn't on a line. This works well enough,
assuming the operator knows this. (If you wanted to make it smarter, you
certainly could.)

--
Matthew Miller                      --->                  mattdm@mattdm.org
Quotes 'R' Us                       --->             http://quotes-r-us.org/



Message has 3 Replies:
  Re: Light sensor initialization?
 
(...) Wow. I feel I should point out that experimentally my method works 100% of the time. :) On the other hand, mine is a special-case application: the light sensor is used to read color values from a surface, which presumably will have very little (...) (25 years ago, 15-Jul-99, to lugnet.robotics.rcx)
  Re: Light sensor initialization?
 
(...) This is my inspiration for adding on-the-fly init code, btw. RoboTag uses two seperate robots, and it turns out that my friend -- the source of the second mindstorms kit -- has a light sensor which reads about 10 "darker" than mine. (25 years ago, 15-Jul-99, to lugnet.robotics.rcx)
  Re: Light sensor initialization?
 
(...) That's why I suggested a solution that works in all cases. It's not much harder than your solution either. (URL) Robert Munafo (25 years ago, 15-Jul-99, to lugnet.robotics.rcx)

Message is in Reply To:
  Re: Light sensor initialization?
 
(...) [snip] (...) Yes -- check out my RoboTag program at (URL) RoboTag, the sensor is pointing at the ground, which is probably grey/brown/white, with black border lines. My program reads the light level at start, and assumes that it isn't on a (...) (25 years ago, 14-Jul-99, to lugnet.robotics.rcx)

10 Messages in This Thread:




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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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