ROBOTC.net forums
http://www.robotc.net/forums/

Linerunner evolving - trying to make the program more robust
http://www.robotc.net/forums/viewtopic.php?f=1&t=8072
Page 1 of 1

Author:  MrLovellFord [ Thu Feb 27, 2014 2:14 am ]
Post subject:  Linerunner evolving - trying to make the program more robust

Taking into consideration the suggestions given to me in my last post, I am attempting to use variables to indicate when the bot goes from light into dark and only count at those transition locations. Following is my logic which makes the bot go forward and count once, but then continues onto fail. I am still missing something. Thanks in advance for any help and explanations.
Sincerely
Jim LovellFord
The following is just a function, not the whole task main()

void Forward(int target) // function to make bot go forward
{
int count = 0;
int lastSeen = 1;
int seeing;
while(count<target)
{
motor(motorB) = 75;
motor(motorC) = 75;

if(SensorValue(lightSensor)<59)
{
seeing = 1;
}
else
{
seeing = 0;
}
if(seeing<lastSeen)
{
count = count + 1;
lastSeen = seeing;
}
}
}

It will count the first line but goes through the second and then fails.

Author:  BurningLights [ Thu Feb 27, 2014 10:17 am ]
Post subject:  Re: Linerunner evolving - trying to make the program more ro

Think about this section of code:

Code:
if(seeing<lastSeen)
 {
 count = count + 1;
 lastSeen = seeing;
 }


The variable lastSeen starts out at 1, so the only way this if statement will be true is when the robot sees white (and you set seeing to 0). Then, you increase count by one and set lastSeen to seeing (making it 0). After that, seeing must be -1 or less for the above if statement to be true, but you only ever set it to 0 or 1. You're on the right track, but I would suggest a rearrange of your code to something like the following (pseudo code):
Code:
if (sensorValue[lightSensor]<59)
{
  if (!Previously over line)
  {
    // Increment count
    // Previously over line = true
  }
}
else
{
  // Previously over line = false
}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/