View unanswered posts | View active topics It is currently Fri Feb 12, 2016 1:43 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Line tracking using two sensors
Author Message
Rookie

Joined: Fri Mar 25, 2011 11:45 am
Posts: 13
Line tracking using two sensors
Hello guys,
First I will introduce myself; I am Melvin, a 17-year old dutch student. Last year I won at the robocup junior, the Rescue League (green map, easiest). We had won that league with a program, programmed in Robolab, that was pretty easy.
This year we wanted to participate the rescue arena, therefor we switched to RobotC. Robolab was too limited to do program the things that the arena requires.

We've started with programming a line follow program with 2 sensors. But after 2 weeks programming, the program is still not working. I dont know where exactly the fault is because the program looks really logical. Below you'll see our program with some explanation. Could someone please take a look and help us out? Thanks!

 Code:task main (){  while (true){    int Left = SensorValue(EyeLeft);                      int Right = SensorValue (EyeRight);    //black = 12;    //white   = 3;    if (SensorValue(EyeLeft) == Left && SensorValue(EyeRight) == Right){      // both sensors see white, the robot must go straight      motor[MotorLeft] = 35;            motor[MotorRight] = 35;     }    if (SensorValue(EyeLeft) > Left ){                  // left sensor sees black, so the robot must go to the right               motor[MotorLeft] = -20;      motor[MotorRight] = 50;      }    if (SensorValue(EyeRight) > Right){                  // right sensor sees black, so the robot must go to the left      motor[MotorLeft] = 50;      motor[MotorRight] = -20;     }              }}

Fri Mar 25, 2011 12:54 pm

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Re: Line tracking using two sensors
Hi Melvin,

Rather than setting 'Left' and 'Right' to the current sensor reading, try using a fixed threshold value. A good threshold value is the sensor reading of dark, added to sensor reading of light, then all divided by 2 [ (Light + Dark) / 2 ].

Also linking the 'if' conditions together with 'else' and 'else if' may prove to work better than separating them.

Keep in mind that if you are using multiple sensors to follow the same line, combining their logic helps a lot too. You have 2 sensors each with 2 states (light or dark) so you have 2^2 possible outcomes:

LEFT = light, RIGHT = light: go forward
LEFT = light, RIGHT = dark: turn right
LEFT = dark, RIGHT = light: turn left
LEFT = dark, RIGHT = dark: ? stop ?

Remember if the sensors look like this: L | R where the '|' is the black line, then if L sees the line you need to turn back to the LEFT to straighten out.

Try this code instead:

 Code:task main (){  int LeftThreshold = 8;      // feel free to change this based on your own calculations!  int RightThreshold = 8;     // and this!  (I used the values you have below)      //black = 12;  //white   = 3;    while (true)  {    // LEFT = light, RIGHT = light:    if(SensorValue(EyeLeft) < LeftThreshold  &&  SensorValue(EyeRight) < RightThreshold)    {   // go FORWARD      motor[MotorLeft] = 35;      motor[MotorRight] = 35;    }    // LEFT = light, RIGHT = dark:    else if(SensorValue(EyeLeft) < LeftThreshold  &&  SensorValue(EyeRight) > RightThreshold)    {   // go LEFT               motor[MotorLeft] = -20;      motor[MotorRight] = 50;          }        // LEFT = dark, RIGHT = light:    else if(SensorValue(EyeLeft) > LeftThreshold  &&  SensorValue(EyeRight) < RightThreshold)    {   // go RIGHT      motor[MotorLeft] = 50;      motor[MotorRight] = -20;         }    // LEFT = dark, RIGHT = dark:    else    {   // do what you want here, I'm just putting a stop:      motor[MotorLeft] = 0;            motor[MotorRight] = 0;         }  }}

Remember to play around with the threshold values and motor speeds. I hope that this helps you get moving in the right direction.

_________________
Bence Feher

ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学

Tue Apr 05, 2011 10:58 am
Rookie

Joined: Sat Mar 01, 2014 3:52 am
Posts: 1
Re: Line tracking using two sensors
hey I have been getting this message:
Couldn't open '#include' file 'drivers/HTMAG-driver.h'

I can't find where to get the driver, or why it won't work for me.
Any help would be much appreciated.

Sat Mar 01, 2014 3:58 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3623
Location: Rotterdam, The Netherlands
Re: Line tracking using two sensors
Hi Matmccann,

Please create your own new thread, instead of tacking onto this one. Then give us a LOT more info about what it is was you were trying to do in the first place.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Sat Mar 01, 2014 4:25 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 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    2014 Robotics Academy Summer of Learning    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

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