View unanswered posts | View active topics It is currently Wed Oct 21, 2020 1:29 am

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Linerunner evolving - trying to make the program more robust
Author Message
Rookie

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

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Re: Linerunner evolving - trying to make the program more ro

 Code:if(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://bluechariotsoffire.com/.

Thu Feb 27, 2014 10:17 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning