| Author |
Message |
|
jagadeeshstel
Rookie
Joined: Sat Jul 30, 2011 10:03 am Posts: 7
|
 Line follower
I need a line follower programing guide. am the beginner so i need clear explanation about the program and hard ware assembling
|
| Sat Jul 30, 2011 10:07 am |
|
 |
|
DiMastero
Expert
Joined: Wed Jun 30, 2010 7:15 am Posts: 179
|
 Re: Line follower
Check out this tutorial over here: http://www.inpharmix.com/jps/PID_Contro ... obots.htmlIt's focused mainly on NXT-G, but the creator (J. Sulka) puts most of the stuff in pseudo code, which you can easily convert to RobotC. If you use this and tune it well, it'll give you great results; very fast and smooth line following
_________________leonoverweel.com
|
| Sat Jul 30, 2011 3:04 pm |
|
 |
|
mmckee
Moderator
Joined: Thu Jun 09, 2011 10:14 am Posts: 7 Location: Pittsburgh, PA
|
 Re: Line follower
Not sure which Robot type you're using, but for NXTs, check out: http://www.education.rec.ri.cmu.edu/pre ... index.htmland choose the red "Sensing" button on the top of the page, and then choose "Line Tracking" on the left menu. It has a series of print and video lessons on line tracking using the NXT and ROBOTC.
_________________Matt McKee Robotics Academy Carnegie Mellon University ROBOTC homepage Robotics Academy homepage
|
| Mon Aug 08, 2011 8:42 am |
|
 |
|
jagadeeshstel
Rookie
Joined: Sat Jul 30, 2011 10:03 am Posts: 7
|
 Re: Line follower
 |  |  |  | Code: #pragma config(Sensor, S2, lightSensorleft, sensorLightActive) #pragma config(Sensor, S3, lightSensorright, sensorLightActive) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() { nMotorEncoder[motorC] = 0; nMotorEncoder[motorB] = 0; while(time1[T1] < 3000000) { float i = SensorValue(lightSensorleft); float k = SensorValue(lightSensorright);
if(i < 45) // if i is Lessthan 45 motor left motorC is reduce power to 0 and motor right motorB gets power to 80 { nxtDisplayCenteredTextLine(1, "SensorLt50: %d", SensorValue[lightSensorleft]); nxtDisplayCenteredTextLine(6, "SensorRt: %d", SensorValue[lightSensorright]); motor[motorC] = 0; motor[motorB] = 80; }
else if(k > 45)// if i is Greaterthan 45 motor left motorC gets power to 80 and motor right motorB is reduce power to 0 { nxtDisplayCenteredTextLine(1, "SensorLt50: %d", SensorValue[lightSensorleft]); nxtDisplayCenteredTextLine(6, "SensorRt: %d", SensorValue[lightSensorright]);
motor[motorC] = 80; motor[motorB] = 0; } } motor[motorC] = 0; motor[motorB] = 0; } |  |  |  |  |
|
| Wed Aug 17, 2011 8:48 pm |
|
 |
|
rdj_thesis
Rookie
Joined: Tue Dec 06, 2011 9:12 pm Posts: 2
|
 Re: Line follower
i'm a student of a college here in Philippines. i'm having my thesis with some colleagues. we are having trouble controlling the robot using the line follower. we just copied some codes and we add some. the robot should possess the capability of sorting objects(color-coded objects); we want the robot to avoid obstruction as well; but we don't know how; we tried possible codes but it won't satisfy our requirements. what will i do??? can anybody help me??? i'm begging.. we're on the point of giving up;  .. here's our code:  |  |  |  | Code: #include "NXCDefs.h" #include "NBCCommon.h"
#define MOTOR_LEFT OUT_B #define MOTOR_RIGHT OUT_C #define MOTOR_BOTH OUT_BC #define MOTOR_FORK OUT_A #define COLORSENSOR SENSOR_2 #define TOUCH SENSOR_3 #define ULSONIC SensorUS(IN_1) #define LIGHT_BLACK 115 #define LIGHT_WHITE 275
struct RGB { unsigned int red; unsigned int green; unsigned int blue; };
RGB get_color(int sensorPort) { RGB color; color.red = ColorSensorValue(sensorPort, INPUT_RED); color.green = ColorSensorValue(sensorPort, INPUT_GREEN); color.blue = ColorSensorValue(sensorPort, INPUT_BLUE); return color; }
unsigned int get_light(int sensorPort) { RGB color = get_color(sensorPort); float colorSum = color.red + color.green + color.blue; unsigned int light = colorSum / 3.0; return light; }
sub follow_line() { float kP = 1.0; //6.0 float kI = 0.0; //0.0001 float kD = 0.0; //400
float dT = 25; // Initialize the variables: int offset = LIGHT_WHITE - LIGHT_BLACK; int tP = 50; int proportional = 0; int integral = 0; int derivative = 0; int lastError = 0; while (2) { int lightValue = get_light(IN_2); int error = lightValue - offset; proportional = kP * error; integral = integral + error; derivative = (error - lastError) * dT; int output = proportional + kI * dT * integral + kD * derivative; int speedLeft = tP - output; int speedRight = tP + output;
int value = 0; if (speedLeft > 100) { speedLeft = 100; } else if (speedLeft < -100) { speedLeft = -100; } if (speedRight > 100) { speedRight = 100; } else if (speedRight < -100) { speedRight = -100; } lastError = error; while(COLORSENSOR == INPUT_BLUECOLOR){ Off(MOTOR_BOTH); while (ULSONIC == 32){ PlayTone(330,400); OnFwdSync(OUT_BC, 50, 0); Wait(1000); } while (COLORSENSOR == INPUT_GREENCOLOR) { value = 1; Off(MOTOR_BOTH); Wait(100); while (ULSONIC == 24) { PlayTone(330, 400); OnRev(MOTOR_FORK, 100); Wait(2500); RotateMotor(MOTOR_BOTH, 50, 400); Off(MOTOR_BOTH); OnFwd(MOTOR_FORK, 100); Wait(2500); while (TOUCH == 1) { OnFwd(MOTOR_LEFT, 80); OnRev(MOTOR_RIGHT,80); Wait(999); break; } } } while (COLORSENSOR == INPUT_REDCOLOR) { Off(MOTOR_BOTH); Wait(100); while(ULSONIC == 24) { PlayTone(330, 400); OnRev(MOTOR_FORK, 100); Wait(2500); RotateMotor(MOTOR_BOTH, 50, 400); Off(MOTOR_BOTH); OnFwd(MOTOR_FORK, 100); Wait(2500); while(TOUCH) { OnFwd(MOTOR_LEFT, 80); OnRev(MOTOR_RIGHT,80); Wait(900); break; } while(TOUCH == 0) { Off(MOTOR_BOTH); } } } while (COLORSENSOR == INPUT_YELLOWCOLOR) { Off(MOTOR_BOTH); Wait(100); while(ULSONIC == 24) { PlayTone(330, 400); OnRev(MOTOR_FORK, 100); Wait(2500); RotateMotor(MOTOR_BOTH, 50, 400); Off(MOTOR_BOTH); OnFwd(MOTOR_FORK, 100); Wait(2500); while(TOUCH) { OnFwd(MOTOR_LEFT, 80); OnRev(MOTOR_RIGHT,80); Wait(900); break; } while (TOUCH == 0){ Off(MOTOR_BOTH); } } } }
OnFwd(MOTOR_LEFT, speedLeft); OnFwd(MOTOR_RIGHT, speedRight); } } void setup() { SetSensorColorFull(IN_2); SetSensorLowspeed(IN_1); SetSensorTouch(IN_3); } void grab(){ OnFwd(MOTOR_FORK, 100); Wait(1000); Off(OUT_A); } sub not_touch(){ while(!TOUCH){ Off(MOTOR_BOTH); } } task main() { grab(); setup(); not_touch(); follow_line();
} |  |  |  |  |
please help us!!! have mercy.. we also want the robot to stop when it fails to grab the object;(meaning the touch sensor is not touched) the design of the robot is similar to the "Snatcher Robot" however we relocate the color sensor facing on the surface for the line following purposes while the touch sensor is placed in the former position of the color sensor;
|
| Tue Dec 06, 2011 9:43 pm |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2859 Location: Rotterdam, The Netherlands
|
 Re: Line follower
Your robot is programmed in NXC, not ROBOTC. You may have more luck with your question on the Mindboards forums. - Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Wed Dec 07, 2011 2:45 am |
|
 |
|
tanishasaha5
Rookie
Joined: Thu Dec 08, 2011 12:13 pm Posts: 10
|
 Re: Line follower
Sir I am new in robotics.Doin a project on wheeled mobile robots.I have to create a line follower for the robot in C.PLz help!!!
|
| Mon Dec 12, 2011 4:53 am |
|
 |
|
DiMastero
Expert
Joined: Wed Jun 30, 2010 7:15 am Posts: 179
|
 Re: Line follower
C or RobotC? If it's RobotC, you should make a new post/thread and put in as much info (sensors, motors, what the robot looks like, what platform you're using, etc.) as you can so we can help you. If it's C, some of us might be able to help, but these forums are RobotC-specific.
_________________leonoverweel.com
|
| Mon Dec 12, 2011 7:55 pm |
|
 |
|
tanishasaha5
Rookie
Joined: Thu Dec 08, 2011 12:13 pm Posts: 10
|
 Re: Line follower
Actually am codin in C on AVr platform.My objective is to create a PID line follower.My rbot has 3 white line sensors!!left middle right!!main problem is that I have written a program in which it either loses white line at times or fails 2 stop on a black surface!!plz suggest!!i know its a RObot c platform!but u ppl are experienced & can help me in some way!! 
|
| Tue Dec 13, 2011 4:55 am |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Line follower
Don't know if this will help you but I have a generic PID controlled line follower library module written in RobotC for NXT. In conjunction with the generic PID controller module, it did a decent job in following line on the floor. You can find our library modules here. http://proj.titanrobotics.net/hg/Ftc/20 ... 857/ftclibThe line follower module is lnfollow.h. The PID controller module is pidctrl.h. You can find the test program that calls the line follower here: http://proj.titanrobotics.net/hg/Ftc/20 ... GobbMobileNote that although the test program uses only one light sensor (for edge following), the generic line follower can actually handle any number of sensors, in fact any type of sensors. Be it an array of light sensors or even a camera that "sees" the line. This is because the generic line follower is sensor agnostic. It calls a user supplied function PIDCtrlGetInput(). It is this function's responsibility to read whatever sensors and translates them to a floating point number indicating how far the robot is off the line and which direction. Once the line follower gets this number, it will apply PID control to steer the robot back onto the line. It even knows if it is a hard turn so it will slow down when making the turn. I am still slowly improving the algorithm. But it is doing a decent job in the current form. Let me know if you find it useful and need more explanation on how it works.
|
| Tue Dec 13, 2011 6:11 am |
|
 |
|
tanishasaha5
Rookie
Joined: Thu Dec 08, 2011 12:13 pm Posts: 10
|
 Re: Line follower
thanx 4 ur help!!it was gr8!!may be now I will be able to implement? will it work 4 curved white lines?
|
| Thu Dec 15, 2011 2:30 am |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Line follower
Yes, if it doesn't work for curved line, it wouldn't be a line follower. I might as well implement straight motor run.  BTW, it does white line on black floor or black line on white floor as well.
|
| Thu Dec 15, 2011 2:34 am |
|
 |
|
tanishasaha5
Rookie
Joined: Thu Dec 08, 2011 12:13 pm Posts: 10
|
 Re: Line follower
the program is complex!!i was following the pidctrl.h.I didnot understand why have u created functions!!could u help in simplifying this program or help me find flaws in the program that I wrote myself!! 
|
| Thu Dec 15, 2011 3:36 am |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Line follower
I am not familiar with the AVR platform, so it is difficult for me to pin-point what's wrong. But in general the algorithm seems a plausible implementation. The only comments I have are: 1. What is "motor speed range" of the AVR platform? If it is between -100 to 100, then you should initialize scenter_left and scenter_right to 50 instead of 100. 2. Since I am not familiar with the platform and your sensor values (e.g. large sensor value means light or dark), I am not sure about the polarity of things. If the robot is not following the line but running away from it, the polarity could be wrong. 3. Also, in PID control, it is important to tune the PID constants. That will affect how well the robot follows the line. If the constants are not properly tuned, it could lose the line. 4. In addition, light sensor calibration is very important. Since you have 3 light sensors, the threshold of each light sensor may be different. You are assuming they are equal at 0x25. In case one of them is wrong, it will flip one of the bits from 0 to 1 or from 1 to 0, then your index would be totally wrong. Since your 3 light sensors produces an index of 3 bits, there could be 8 possible values (0-7) but your code only handles value 0-5. Although 6 and 7 are impossible in theory, you should test those and print a warning if you hit those values. It may be an indication your light sensors are not calibrated correctly.
That's all I can find for now. Good luck.
|
| Thu Dec 15, 2011 5:36 am |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Line follower
Functions are your friends. They allow more readable code and code reuse. A monolithic program without using functions are very hard to understand and debug. Your code has functions too. Since pidctrl.h is a generic PID controller, it may be more complex than necessary if you write PID control for one particular scenario (e.g. line following) because the generic code has to handle many different scenarios. The main function in that module is PIDCtrlOutput. This is the function that applies the PID constants to calculate the output from the given input value. I consider the code straight forward and not overly complex. You must be wondering why I have functions such as PIDCtrlIsOnTarget or PIDCtrlSetPowerLimit. For line following, you probably don't need these at all, but as a generic PID controller, you need these in other scenarios. For example, when doing PID controlled drive of 10 ft, after calling PIDCtrlSetTarget of 10 ft, the caller must be able to tell if the robot has reached target. That's why I have some functions that may not make sense to you when doing line following.
|
| Thu Dec 15, 2011 6:03 am |
|
|
Who is online |
Users browsing this forum: No registered users and 3 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
|
|