View unanswered posts | View active topics It is currently Tue Oct 21, 2014 9:41 am






Reply to topic  [ 2 posts ] 
Linerunner evolving - trying to make the program more robust 
Author Message
Rookie

Joined: Wed Feb 19, 2014 3:07 pm
Posts: 6
Post 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.


Thu Feb 27, 2014 2:14 am
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 136
Post 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
}

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://cof7468.weebly.com/.


Thu Feb 27, 2014 10:17 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.