View unanswered posts | View active topics It is currently Thu Sep 18, 2014 7:41 am






Reply to topic  [ 7 posts ] 
follow the line issue 
Author Message
Rookie

Joined: Fri Oct 12, 2012 12:56 am
Posts: 2
Post follow the line issue
Hello,
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.


Fri Oct 12, 2012 2:44 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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.


Fri Oct 12, 2012 3:42 am
Profile
Rookie

Joined: Fri Oct 12, 2012 12:56 am
Posts: 2
Post 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:

http://www.robotc.net/education/curricu ... 20LEGO.pdf


Fri Oct 12, 2012 5:27 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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:
Code:
#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;
    wait1Msec(100);
}

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).


Last edited by MHTS on Wed Oct 24, 2012 6:53 pm, edited 1 time in total.



Fri Oct 12, 2012 1:29 pm
Profile
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 405
Post 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.

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Fri Oct 12, 2012 5:17 pm
Profile
Rookie

Joined: Wed Oct 24, 2012 2:51 pm
Posts: 8
Post Re: follow the line issue
What does 'KP' stand for?


Thu Oct 25, 2012 4:21 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post 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."

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Thu Oct 25, 2012 10:01 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

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.