View unanswered posts | View active topics It is currently Fri Apr 18, 2014 12:42 am






Reply to topic  [ 29 posts ]  Go to page Previous  1, 2
Line follower 
Author Message
Rookie

Joined: Thu Dec 08, 2011 12:13 pm
Posts: 10
Post Re: Line follower
thanx!!but i dnt evn kno the motor range!!3 sensors are calibrated equally!!dats wat the manufacturer told me!!
now,regardin sensor readings:
low readin means white,
high readin is black!!
plz give me the idea to tune the pid parameters!! :cry:
It is impossible to tune it!!!
plz help!!


Thu Dec 15, 2011 6:08 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
In your current code, your Kp is 2. Imagine this. If your robot is off the line to the left, the largest input value you get is 2 which means the largest error you can ever get is +/- 2. This means your left and right wheel velocity difference is 4 at the maximum. Do you think your robot will really respond to the line curving to the left or right with so little difference between the left and right wheel which is running at the value of 100. According to your algorithm, you either turn one way with left=100, right=104 or turn another way with left=96 and right=100. This will hardly turn the robot.
Also, if your motor range maximum is 100, then the value 104 has no meaning. Your motor will still just run at 100. That's why I ask for your motor range.
I would first set the scenter_left and scenter_rite values to 50 so it will give me some margin to work with. Then I would set the initial Kp to at least 10 to see if the robot is really responding to the line curving. If the robot is turning away from the line, I would check the polarity of error (i.e. Input_value - T_pos instead). If the robot is responding to the curve too quickly (overshooting), zig zag around the line, then I would start decreasing Kp slowly to minimize the overshooting.
Tuning Ki and Kd is a little harder. Most of the people would be happy with just tuning Kp and leave Ki and Kd zero.


Last edited by MHTS on Thu Dec 15, 2011 6:43 pm, edited 1 time in total.



Thu Dec 15, 2011 6:18 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
tanishasaha5 wrote:
regardin sensor readings:
low readin means white,
high readin is black!!

Also, you did not tell me whether you are following a white line on black floor or black line on white floor?


Thu Dec 15, 2011 6:25 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
tanishasaha5 wrote:
thanx!!but i dnt evn kno the motor range!!

You really should find out the motor range. It is a crucial piece of information.
tanishasaha5 wrote:
3 sensors are calibrated equally!!dats wat the manufacturer told me!!

I don't think the manufacture would say that. All sensors are manufactured with slight variations. In addition, there are also environment differences. For example, one light sensor is mounted slightly higher than the other ones. Do the light sensors have their own light source or do they rely on ambient lighting? The light sources could have variation as well. In any case, there should be no harm to calibrate the light sensors. Put one of the light sensors on the line and read its values. Put that sensor off the line and read its value again. Sum its on-the-line and off-the-line value and divide it by 2. That's the threshold value for that light sensor. Repeat the process for the other two sensors. I'd bet you will have slightly different thresholds for each sensor. Note that if your ambient lighting has change, you may need to calibrate again. Meaning if you calibrate it to some thresholds at home, you may have to calibrate it again at the competition because the lighting environment is different.


Thu Dec 15, 2011 6:38 am
Profile
Rookie

Joined: Thu Dec 08, 2011 12:13 pm
Posts: 10
Post Re: Line follower
Thanx!!
My objective:velocity control of wheeled robots!!
Aim:
White line following on a black floor with PID control
Motor range +130 to -130
Sensor have their own light source.
Sensor calibration doubt:
If I place the left sensor on a white surface it gives a reading on LCD =008
If I place the left sensor on a black surface reading: 210
Remaining sensors are giving the same reading for black & white surface.
Logically the thresold is:(8+210)/2=109;
Is 109 in decimal or in HEX?
Do I need to convert to hex?
But the manufacturer told me it is 0x25
So I am confused which one to select?
Yesterday I ran the same program on the robot that I gave you!!
Results:
sometimes it is tracking the white line and coming to a stop at the black!!
But at times it is not able to judge the line and going straight or in curves!!
One thing is correct according to you i.e 104 and 100/96 and 100 will hardly make it follow a curved line!!
Regarding error=Input_value - T_pos?
or error=T_pos - Input_value?
Are u telling me to substitute the previous in place of mine?
Will it add ne difference?
Next,Input_value:
Like if the left sensor reads black m assignin +1;
if left and central sensor reads black m assignin +2 to it?
are u telling me to increase the Input_value? or your askin me to increase Kp?
PLZ helpp!! :evil:
Hope I have provided with all my questions!!m on the middle of my project can't quit!!


Sat Dec 17, 2011 2:35 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
tanishasaha5 wrote:
White line following on a black floor with PID control
Motor range +130 to -130
Sensor have their own light source.

With the info you gave me, it looks like your algorithm should work.
tanishasaha5 wrote:
Sensor calibration doubt:
If I place the left sensor on a white surface it gives a reading on LCD =008
If I place the left sensor on a black surface reading: 210
Remaining sensors are giving the same reading for black & white surface.
Logically the thresold is:(8+210)/2=109;
Is 109 in decimal or in HEX?
Do I need to convert to hex?
But the manufacturer told me it is 0x25
So I am confused which one to select?

Whether 109 is decimal or hex depends on if 8 and 210 are decimal or hex numbers. But the way you calculated it, it seems to be decimal. 0x25 is 37 in decimal. It should also work but having the threshold right in the middle of light and dark will give you plenty of margin on both sides for environmental variations. Using 37 will only give you 37 - 8 = 29 as the light margin and 210 - 37 = 173 as the dark margin. It means you tolerate a wide scale of dark and still consider dark but you don't tolerate too much variation on white. It may be acceptable, you will have to decide.
tanishasaha5 wrote:
Yesterday I ran the same program on the robot that I gave you!!
Results:
sometimes it is tracking the white line and coming to a stop at the black!!
But at times it is not able to judge the line and going straight or in curves!!

I think if tune Kp correctly, your robot will follow the line fine.
tanishasaha5 wrote:
One thing is correct according to you i.e 104 and 100/96 and 100 will hardly make it follow a curved line!!
Regarding error=Input_value - T_pos?
or error=T_pos - Input_value?
Are u telling me to substitute the previous in place of mine?

No, with the info you gave me, your original line "error=T_pos-Input_value;" is fine.
tanishasaha5 wrote:
Next,Input_value:
Like if the left sensor reads black m assignin +1;
if left and central sensor reads black m assignin +2 to it?
are u telling me to increase the Input_value? or your askin me to increase Kp?

I was saying increase Kp. Start with Kp = 15. This will give you a turn of 30 which will max out your motor range. If the robot wiggles back and forth a lot, then slowly decrease Kp until it follows the line smoothly.
Good luck.


Sat Dec 17, 2011 3:27 am
Profile
Rookie

Joined: Thu Dec 08, 2011 12:13 pm
Posts: 10
Post Re: Line follower
Thanx!!Due to you atleast I could show some progress!!But still there is no way out!!i m not getin ne help 4m nebdy!!THe robot is not stopping when it comes to black neither takes a turn.ALL it can do is to travel straight,without even boderin abt the white lne!!i am so confused!even my codin part is correct according to you!!The person who sold the robot is not telling the ideal readin for the sensors.The procedure by which I have found the sensor readings is as follows:
Place the bot on a black paper ,turnd on the robo,collected the readings for all the 3 leds at a time keeping room lights on!!
Is it the correct method or I will switch on 1 LED at a time?and note the readings for black and white surface respectively!!
Can you please tell me whether the while loop body is correct?
Sometimes by chance if the bot is taking a turn then it continues taking turn without noting the white line!!!
My mentor is telling me to work with the left and right sensor and forget abt the middle!!
HOw is it possible?
Plz help or give me any workin PID line follower code!!! :breakcomputer: :cry:


Thu Dec 22, 2011 5:35 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
tanishasaha5 wrote:
Thanx!!Due to you atleast I could show some progress!!But still there is no way out!!i m not getin ne help 4m nebdy!!THe robot is not stopping when it comes to black neither takes a turn.ALL it can do is to travel straight,without even boderin abt the white lne!!i am so confused!even my codin part is correct according to you!!

I am sorry. I only understand you partially. If I read your scenario correctly, it seems you need to do some debug printing to see what's going on. Since I am not familiar with your platform, I don't know if you have any type of debug console support that you can print the values of the light sensors, for example. It would be useful to add the following line in your code.
Code:
error=T_pos-Input_value;
Prop=error*Kp;   
integral=error+integral;
integral= Ki*integral;
rate= error - last_error;
derivative =  Kd*derivative;
Turn=Prop+derivative;
Turn=Turn+integral;
if(Turn> Limit)
{
    Turn=Limit;
}
else if(Turn < -Limit)
{
    Turn=-Limit;
}
printf("Index=%x,InputValue=%d,Error=%d,Turn=%d\n", Index, Input_value, error, Turn);

Also, I just noticed something. You declared all your variables "unsigned char". This only gives you an 8-bit value. In addition, you are also doing signed arithmetic. So unsigned char is not appropriate. You should change most of them to "int" instead. I can see the possibility of the compiler not generating correct code because of this.
tanishasaha5 wrote:
The person who sold the robot is not telling the ideal readin for the sensors.The procedure by which I have found the sensor readings is as follows:
Place the bot on a black paper ,turnd on the robo,collected the readings for all the 3 leds at a time keeping room lights on!!
Is it the correct method or I will switch on 1 LED at a time?and note the readings for black and white surface respectively!!
Can you please tell me whether the while loop body is correct?

The calibration should be done under the same environment. So if you have all 3 LEDs on at the same time, you should calibrate with all 3 on. It is difficult to just examine the code visually and tell if the code has bugs or not. Some bugs are obvious, some are not. Like I said, your variables are declared the wrong type. So that could cause some non-obvious bugs.
tanishasaha5 wrote:
My mentor is telling me to work with the left and right sensor and forget abt the middle!!
HOw is it possible?

You should be able to use all three sensors. The more sensors, the more accurate the robot can follow the line.
tanishasaha5 wrote:
Plz help or give me any workin PID line follower code!!! :breakcomputer: :cry:

I did point you to my code that I have tested and proved working. But you need to do some work to make it work on your platform. I can't help you on that since I don't know anything about your platform. Also, if you debug and fix your code, you may learn more. Like I said, when you don't understand why the robot is doing something or not doing something, the most basic debugging is to examine the states of some of the variables that cause it to make a certain decision. You will either see the variables are in the wrong states/wrong value or if they are in the correct states then your logic is faulty.


Thu Dec 22, 2011 7:38 am
Profile
Rookie

Joined: Thu Dec 08, 2011 12:13 pm
Posts: 10
Post Re: Line follower
I have modified the program
Here MAX SPEED =255,I came to know that after I called manufacturer.
so changed everything.Problem now is that only left wheel turns.dnt know why!!!! :eek:


Attachments:
1.txt [4.96 KiB]
Downloaded 245 times
Tue Dec 27, 2011 6:07 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
tanishasaha5 wrote:
Here MAX SPEED =255,I came to know that after I called manufacturer.

I think the problem is with your MAX SPEED = 255. In your timer5_init(), you have a comment about setting the PWM controller to "Fast 8-bit mode". Since I am not familiar with this platform, I don't know what it means in terms of the effect on the motor when you program different numbers. For example, what is the stop motor value? Is it 0 or is it 127? What is the max forward speed value? Is it 255 or is it 127? What is the max reverse speed value? Is it 0 or is it 255?
Regardless, control has a value between -30 to 30. So when control is a positive value, left wheel will slow down (assuming 255 is really the max forward speed) and the robot will turn left. When control is negative, right wheel will slow down and the robot will turn right. I am guessing this is your intention. But again, it is only correct if 255 is really the max forward speed. 255 could be interpreted as -1 in signed char and -1 could be interpreted as reverse the motor very slow if at all. Like I said, if you have the capability of doing debug print to some sort of console, you should print out the values of left, right and control. You can even comment out the velocity and forward lines so the motors don't really move. Then you can put the robot on the line and see what left, right and control values are. Then you put the robot slightly to the left and observe the values. Finally do the same when putting the robot slightly to the right. But of course, you need to figure out the PWM value range.


Tue Dec 27, 2011 3:51 pm
Profile
Rookie

Joined: Thu Dec 08, 2011 12:13 pm
Posts: 10
Post Re: Line follower
I tested the MaX speed is 255.It is an unsigned qty.So to make the robot reverse, we call velocity(255,255) followed by another reverse() funcn.By calling the velocity (256,256) it didnot move!!!so it is clear that 255 is the max speed.
The fast Pulse Width Modulation or fast PWM mode (WGM02:0 = 3 or 7) provides a high frequency
PWM waveform generation option. The fast PWM differs from the other PWM option by
its single-slope operation. The counter counts from BOTTOM to TOP then restarts from BOTTOM.
TOP is defined as 0xFF when WGM2:0 = 3, and OCR0A when WGM2:0 = 7. In noninverting
Compare Output mode, the Output Compare (OC0x) is cleared on the Compare Match
between TCNT0 and OCR0x, and set at BOTTOM. In inverting Compare Output mode, the output
is set on Compare Match and cleared at BOTTOM. Due to the single-slope operation, the
operating frequency of the fast PWM mode can be twice as high as the phase correct PWM
mode that use dual-slope operation. This high frequency makes the fast PWM mode well suited
for power regulation, rectification, and DAC applications. High frequency allows physically small
sized external components (coils, capacitors), and therefore reduces total system cost.
In fast PWM mode, the counter is incremented until the counter value matches the TOP value.
The counter is then cleared at the following timer clock cycle.
Now can you tell me the problem??


Wed Dec 28, 2011 5:13 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
Like I said, since I am not familiar with the platform, I can't tell what's wrong by just code inspection. If you are sure that 255 will give you maximum forward speed and anything smaller than 255 will slow down the wheels, then you really need to print out left, right and control values and see what's going on.


Wed Dec 28, 2011 5:22 am
Profile
Rookie

Joined: Tue Dec 06, 2011 9:12 pm
Posts: 2
Post Re: Line follower
can somebody give me a complete code of a line follower??... :mrgreen:
thanks ahead...


Wed Dec 28, 2011 11:54 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Line follower
rdj_thesis wrote:
can somebody give me a complete code of a line follower??... :mrgreen:
thanks ahead...

There are lots of them posted in different forums. You just need to look for them. There is even one in the RobotC tutorials.
http://www.robotc.net/teachingmindstorm ... dindex.htm


Thu Dec 29, 2011 12:41 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 29 posts ]  Go to page Previous  1, 2

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.