To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.org.us.smartOpen lugnet.org.us.smart in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Organizations / United States / SMART / 266
265  |  267
Subject: 
Re: September 18th 2004 SMART Meeting Notes
Newsgroups: 
lugnet.org.us.smart
Date: 
Tue, 21 Sep 2004 06:18:32 GMT
Viewed: 
2282 times
  
Oh, for the BrickHeap Wars competition, I also provided a small snippet of
line-tracking code that teams could use if they wanted. The code isn't
guaranteed to work, and depends on the geometry of your robot, but it's a good
starting point if you're in a real hurry, like the teams were during the
competition, or if you've never written a line tracking robot before, and need a
place to start.

Here's the code:

Two-threshold Line Tracking
Sensor_1 is a light sensor, left and right motors are on A and C respectively.
The robot either starts with the light sensor on, or to the left of the line.
‘lightThreshold’ is a value close to the sensor’s reading for light, and
‘darkThreshold’ is a value close to the sensor’s reading for dark. Both motors
are off before entering the loop.
while( true ) // UNTESTED CODE!!!
  {
  On( OUT_A + OUT_B );
  While( SENSOR_1 < darkThreshold && SENSOR_1 > lightThreshold )
    ;
  Off( OUT_A + OUT_B );

  On( OUT_A ); // Start turning right
  while( SENSOR_1 > darkThreshold ) //   ...keep turning while on the line
    ;
  Off( OUT_A ); //   ...stop turning once off the line

  On( OUT_C ); // Start turning left
  while( SENSOR_1 < lightThreshold ) //   ...keep turning while off the line
    ;
  Off( OUT_C ); //   ...stop turning once on the line
  }


Note that when calibrating your robot, the thresholds should be moved 'towards'
each other; say 10% of the distance. Some calibration code might look like this:

int darkest = SENSOR_1;
int lightest = SENSOR_1;

int curr;

while( true )
  {
  curr = SENSOR_1;
  if( curr < lightest ) // assuming *raw* values
    lightest = curr;
  if( curr > darkest ) // assuming *raw* values
    darkest = curr;

  lightThreshold = lightest + (darkest-lightest) * 1 / 5;
  darkThreshold = darkest - (darkest-lightest) * 1 / 5;
  }


Hope those are useful! Don't be surprised if they'll need a bit of massaging
before they'll work for your robot. And don't forget to define your sensor
before using it. Something like:

SetSensorType (SENSOR_1, SENSOR_TYPE_LIGHT);
SetSensorMode (SENSOR_1, SENSOR_MODE_RAW);

should work.


--
  David Schilling



Message is in Reply To:
  September 18th 2004 SMART Meeting Notes
 
Our annual BrickHeap Wars competition this year was not as strongly attended as previous years, but the people who did attend had a ton of fun. The challenge given at the start of the meeting was to build a robot that would track a line and be able (...) (20 years ago, 21-Sep-04, to lugnet.org.us.smart)

2 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