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 / 26897
26896  |  26898
Subject: 
Re: FindLight
Newsgroups: 
lugnet.robotics
Date: 
Sun, 25 Feb 2007 17:29:18 GMT
Viewed: 
9282 times
  
Please try some semicolons on your lines!

Chris

linmix wrote:
> 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
            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 is in Reply To:
  FindLight
 
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 (...) (20 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
    

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