follow the line issue
Page 1 of 1

Author:  strinda [ Fri Oct 12, 2012 2:44 am ]
Post subject:  follow the line issue

I am trying to make my real NXT robot follow a line. To do that I use two light sensors.
At the same time i can't take my physical robot around all the time (it is rather big)
So i decided to install VW
In virtual worlds all sample robots have only one light sensor (which is used sometimes as a linetracker). But In my real life I have no such sensor (i have two lightsensors), so it seems my program for a virtual robot will be pretty useless for a real one.
Where is my mistake?
Thank you.

Author:  MHTS [ Fri Oct 12, 2012 3:42 am ]
Post subject:  Re: follow the line issue

Since you cannot define your own robot in the virtual world, you can't try something that is unique to your real robot design. Having said that, it does have one light sensor. You can certainly follow line with one light sensor. Two would make it smoother but one is sufficient. In fact, we tried using one with PID control, it went pretty smooth too.

Author:  strinda [ Fri Oct 12, 2012 5:27 am ]
Post subject:  Re: follow the line issue

Yeah, thank you.

When you say that you can make the robot folow the line with just one sensor, do you mean this: ... 20LEGO.pdf

Author:  MHTS [ Fri Oct 12, 2012 1:29 pm ]
Post subject:  Re: follow the line issue

Yes, that's the idea. Strictly speaking, one light sensor does not allow you to "follow the line", it allows you to "follow the edge of a line". However, the algorithm outlined in that tutorial does not follow the edge very smoothly. It is doing the zigzagging pattern. If you use PID control, you will get much smoother edge following (i.e. instead of setting the wheels to 80% power one way or the other, the wheel power differential should be proportional to the difference of the light sensor reading and the THRESHOLD). You need to determine the threshold precisely by sampling the "white" value and the "dark" value and calculating the threshold by THRESHOLD = (whiteValue + darkValue)/2. Then use the threshold in your code, something like this:
#define THRESHOLD 45
#define KP        1.0
#define BASESPEED 30
while (true)
    int error = SensorValue[lightSensor] - THRESHOLD;
    int powerDiff = error*KP;
    motor[motorC] = BASESPEED + powerDiff;
    motor[motorB] = BASESPEED - powerDiff;

Tune the KP value and the BASESPEED value until it follows the line smoothly. Also, depending on whether it is a white line on black floor or black line on white floor or if motorC is the left wheel or motorC is the right wheel, the above algorithm will either follow the left edge or the right edge of the line.
Tips on tuning the parameters:
Do the initial tuning on a straight line. Start with a reasonably small BASESPEED (e.g. 30). Increase KP until the robot starts zigzagging, then decrease KP just enough to make it smooth again. If you want the robot to follow the line faster, increase the BASESPEED, but you need to tune KP again for the new BASESPEED. If the line has a curve and robot always loses the line when following the curve, then you need to decrease BASESPEED (and of course tune KP again).

Author:  jbflot [ Fri Oct 12, 2012 5:17 pm ]
Post subject:  Re: follow the line issue

I know that you're using the NXT, but one of the nice things about ROBOTC is that programming for the NXT vs. the VEX is very similar. If you switch your Platform Type to VEX (you may need to go to Help > Manage Licenses > Add license > ROBOTC Virtual Worlds - VEX Cortex and PIC), the RVW Curriculum Companion includes robots that have three light sensors. You could choose to ignore the center sensor and use your existing algorithms.

Author:  half_pirate [ Thu Oct 25, 2012 4:21 am ]
Post subject:  Re: follow the line issue

What does 'KP' stand for?

Author:  rcahoon [ Thu Oct 25, 2012 10:01 am ]
Post subject:  Re: follow the line issue

half_pirate wrote:
What does 'KP' stand for?

A PID controller consists of three different terms that contribute to the control signal (output), Proportional, Integral, and Derivative (which is where the name PID controller comes from). The amount that each contribute to the output is controlled by three scaling factors that are usually called KP, KI, and KD, respectively.

The code that MHTS posted implements just the Proportional controller, as the control signal is a scaled version of the error signal. You can see the KP defined constant in the code. The error signal is the difference between where you want the measured value (such as a sensor reading) to be (this desired value is called the setpoint) and where it actually is right now. The Integral controller uses a scaled version of the error that has been summed over time (if you have a calculus background, it's actually the time integral of the error signal). The Derivative controller uses a scaled version of how much the error signal has changed recently (again, with calculus, this is actually the time derivative of the error signal).

If you're interested in implementing a full PID controller instead of just the P controller that MHTS provided, there's some pseudocode in the Wikipedia article I linked above, or you can check out a great document called "PID Without a PhD."

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group