View unanswered posts | View active topics It is currently Thu Jun 21, 2018 7:43 pm

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
path following between two lines with one light sensor-help
Author Message
Rookie

Joined: Thu Jan 08, 2009 9:01 pm
Posts: 5
path following between two lines with one light sensor-help
hello, i started working with robotC just about a week and a half ago...ive also never programmed in my life before. i understand the basics (i think) from some of the tutorials found on the robotC website , but im stuck on one particular problem that i just cant seem to figure out.

the problem involves using one light sensors and two servo motors.

i need to program the robot i have built to travel along a path between two black lines. what i want the robot to do is this:

travel forward at a 45° angle from the start until it hits the black line on the right. then turn 90° to the LEFT and travel straight again until it hits the black line on the left. now i need the robot to turn RIGHT and travel straight until it hits the line on the right, turn 90° to the LEFT....and so on and so forth.

what i need help with is programming the light sensor so that when it hits the line the first time it turns the robot left and the second time turns right. Or programming the light sensor so that it will turn the robot left when the light sensor reads the black line on the odd counts (1,3,5 etc.) and turns the robot right on the even counts (2,4,6) of the light sensor reading the black line. any idea's?

if i had two light sensors this problem wouldn't be a problem, but i only have one. basically what i need to do is use one light sensor to do run two tasks alternatingly.

if there is another simpler approach to this problem, please let me know.

Thu Jan 08, 2009 9:29 pm
Expert

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Re: path following between two lines with one light sensor-help
Following a line with one light sensor is tricky and if you want to make an exact solution your program can be quite complex. If you are new to computer programming, I don't suggest to start with this task. Not because you could not understand it, but because of the traps might be well hidden in it.

The idea behind the single sensor line follower canbe like this.

If you mount the light sensor on your robot on such a way that it is close but not very close to the surface, the red light will illuminate up to a square inch on the paper. If you just check the light sensor reading within the "Try me" menu as you gently push your robot to cross the black stripe, you can see the sensor reading is continuously change as the illuminated area reaches the black stripe.

Exploiting this smooth transition you can make a program that tries to steer the robot to keep sensor reading within a "gray" range i.e. the robot will follow the edge of the black stripe.

If you want to make a decision whether your robot hit the left or right edge of the black stripe you will have to drive the robot very slowly a bit left and a bit right, as if a mouse were just "sniffing around". Should a subtle left turn "blacken" (and a subtle right turn lighten) the sensor reading the robot met the right edge of the black stripe.

Fri Jan 09, 2009 7:06 pm
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Re: path following between two lines with one light sensor-help
You should start with giving your robot a state that describes its current position in respect to the two lines. You could use these states: To the left, on the left line, in the middle, on the right line, to the right.
Then u must decide from which to which state you can go: from in the middle to to the left, etc.
Then you must detect when you go from one state to another. Say light sensor reports less light.
Then you must decide how to react to it. I would suggest, turn left.
Then, start all over again, apply what you have learned and code it well this time.

The last one is just personal experience.

_________________
My most recent blog: A grain of sugar

Fri Jan 09, 2009 7:37 pm
Rookie

Joined: Thu Jan 08, 2009 9:01 pm
Posts: 5
Re: path following between two lines with one light sensor-help
thanks for your input guys =)

After looking over the tutorial video's and PDF's (found on the robotC website) about a hundred more times, i came up with this..and it works! =) .....at least i think so..when i tested it out on the course it worked. (attachment)

please, if you will, leave comments and critique on how i can make this better. Thanks.

 Attachments: File comment: drawing of what robot does robot track code.jpg [ 28.75 KiB | Viewed 4921 times ] File comment: CODE robot track code.c [2.75 KiB] Downloaded 281 times
Sat Jan 10, 2009 1:17 am
Rookie

Joined: Thu Jan 08, 2009 9:01 pm
Posts: 5
Re: path following between two lines with one light sensor-help

 Code:#pragma config(Sensor, S1,     lightsensor,         sensorLightActive)#pragma config(Sensor, S2,     touchsensor,         sensorTouch)  //other sensors will be used later#pragma config(Sensor, S3,     sonar,               sensorSONAR)  //in different sections of the course#pragma config(Sensor, S4,     sound,               sensorSoundDB)//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//task main(){  int lightcount = 0; //a counter for the light sensor? or a counter used for tasks with the light sensor?  nMotorPIDSpeedCtrl[motorA] = mtrSpeedReg;  //keep the wheels going the same speed (no unwanted turning! finally =) )  nMotorPIDSpeedCtrl[motorB] = mtrSpeedReg;  nMotorEncoder[motorA] = 0;        //for turning control, probably not going to be used now..yet..maybe  nMotorEncoder[motorB] = 0;  while(nMotorEncoder[motorA] < 10800)  //motor A (right motor) turns 30 times before stopping  {     if(lightcount == 0)  //the counter starts at zero...should this be an "if" statement or a "while" statement?     {        if(SensorValue(lightsensor) > 49)  //light sensor reads lights object (white table)        {          motor[motorA] = 50;              //and so it moves forward at half speed...until...          motor[motorB] = 50;        }        else                               //it hits the black line        {          motor[motorA] = 50;              //so it turns to the right, off of the blasck line          motor[motorB] = -50;          wait1Msec(350);          lightcount = lightcount + 1;     // and adds "1" (one) to the lightcount value        }        if(lightcount == 1)  //now since the lightcount value is = 1, this next peice of code should run.        {                    //should i use "if(lightcount == 1)" or "while(lightcount == 1)" here?  does it matter?          if(SensorValue(lightsensor) > 49)           {                                //so the light sensors reads a light value, and tells the robot to move forward             motor[motorA] = 50;             motor[motorB] = 50;           }           else                             // this time when the light sensor reads a dark value....           {             motor[motorA] = -50;           // it turns the opposite direction as before             motor[motorB] = 50;             wait1Msec(350);             lightcount = lightcount -1;    //and reducing the lightcount value back to zero, so the first code can run again. =)           }        }    }  }}//conclusion://the robot zigzags in between the lines via two motors and one light sensor.//going forward on a light surface and turning one way on a dark surface//and turning the opposite way when it hits another dark surface// comments, and helpful critic is very much appretiated

Sat Jan 10, 2009 2:30 am
Expert

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Re: path following between two lines with one light sensor-help
wow.

really.

Sat Jan 10, 2009 8:40 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 6 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