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 / 26899
26898  |  26900
Subject: 
Re: FindLight
Newsgroups: 
lugnet.robotics
Date: 
Sun, 25 Feb 2007 20:24:33 GMT
Original-From: 
linmix <linmix@gmail.comSAYNOTOSPAM>
Viewed: 
3635 times
  
Thanks for the reply.
I see I overlooked something significant there.
Going over it all again I think I don't need 'light'
Also, the parse errors are due to my omitting the ; at the end of each
statement
I've also discovered that I should put some sort of switch off command
for the motors at the end.
After making all these changes the code looks as follows:

//findlight.nqc

#define A OUT_A
#define C OUT_C

int maxlight = 0;
int time = 0;
int turntime = 46; //change to accomodate 1 turn

task main()
{
   SetSensor (SENSOR_2, SENSOR_LIGHT);
   ClearTimer (0);
   while (Timer (0) < turntime)
   {
     maxlight = SENSOR_2;
     OnFwd (A);
     OnRev (C);

     if (SENSOR_2 > maxlight)
        {
             maxlight = SENSOR_2;  // 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
   Off (A+C);
}


I've run into a new obstacle though.
The first move commands are executed just fine, but the second set never
runs - or so it seems.
I've tried to use the 'watching the brick' tool in BricxCC, but the
final value for 'time' is always 45.
That can mean two things: something is wrong with the way 'time' is
established or there's a trick with that monitor function I'm not aware
of. Also, maybe the wait command can't handle the parameters it gets.

Thansk for your time and patience

linmix


John Barnes wrote:
     if (SENSOR_2 > maxlight)
        {
             maxlight = light  // set maxlight to new max value



I don't see where "light" ever gets set.

JB





Message has 1 Reply:
  Re: FindLight
 
(...) Looks like you're setting maxlight = SENSOR_2, then testing if (SENSOR_2 > maxlight), which will rarely (if ever) be true, because the value of SENSOR_2 is unlikely to change in such a short time. I think the first maxlight = SENSOR_2 (...) (18 years ago, 25-Feb-07, to lugnet.robotics)

Message is in Reply To:
  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

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