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 / 26894
26893  |  26895
Subject: 
FindLight
Newsgroups: 
lugnet.robotics
Date: 
Sun, 25 Feb 2007 16:40:17 GMT
Original-From: 
linmix <[linmix@gmail.]avoidspam[com]>
Viewed: 
3679 times
  
I'm trying to write a simple program to make a roverbot-like robot seek
for light.
My basic idea is to use a timer ( Timer(0) ) to keep track of how long
the robot has been turning and a variable (time) to remember the moment
when the brightest light was seen. I don't think there is anything
fundamentally wrong with this approach (any suggestions are welcome),
but I've run into an error and don't know what causes it.

Can anyone please explain what I'm doing wrong here?
Thanks in advance
linmix

This is my code:

//findlight.nqc

#define A OUT_A
#define C OUT_C

int light, maxlight, time;
int turntime = 500; //change to accomodate 1 turn

task main()
{
   SetSensor (SENSOR_2, SENSOR_LIGHT);
   ClearTimer (0);
   while (Timer (0) < turntime)
   {
     OnFwd (A);
     OnRev (C);
     if (SENSOR_2 > maxlight)
        {
             maxlight = light  // set maxlight to new max value

/* the following line produces a parse error */

             time = Timer(0)  // remember when maxlight was found
        }
   }
   OnRev (A)
   OnFwd (C)
   Wait (turntime - time)   // return to the point where the highest
light level was found
}



Message has 2 Replies:
  Re: FindLight
 
Please try some semicolons on your lines! Chris (...) //findlight.nqc #define A OUT_A #define C OUT_C int light, maxlight, time; int turntime = 500; //change to accomodate 1 turn task main() { SetSensor (SENSOR_2, SENSOR_LIGHT); ClearTimer (0); (...) (18 years ago, 25-Feb-07, to lugnet.robotics)
  Re: FindLight
 
(...) I don't see where "light" ever gets set. JB (18 years ago, 25-Feb-07, to lugnet.robotics)

10 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