PID Tutorials for Line Following

Hey there guys. This post is outdated. Visit https://www.robotshop.com/letsmakerobots/node/39972 for the updated tutorial.Hello LMRians,In this writeup, I will try to create a tutorial for tuning your robot using PID to follow a line. This tutorial won’t go deep down into the details of PID and


This is a companion discussion topic for the original entry at https://community.robotshop.com/blog/show/pid-tutorials-for-line-following

Pretty good tutorial. That

Pretty good tutorial. That reminds me that I need to dig into the PID a bit more to get some applications running.

Thanks Lumi. Can’t wait to

Thanks Lumi. Can’t wait to see what you come up with!

LOL, it will perhaps happen

LOL, it will perhaps happen this year :slight_smile: So many plans and so little time.

Really good tutorial!

Hi

How behaves your robot in case of  90 degree angle? Radius of angle is 0.

Is the robot able to follow the line.

Best regards.

 

Hello indrekm.A 90 degree

Hello indrekm.

A 90 degree turn is an extremely sharp turn. The PID parameters need to be tuned to near perfection in order to make a correct turn. But that is rather difficult. So, I suggest you set a 90 degree turn as a “special” case and work out a separate algorithm that varies from the PID routine. A simple “scan” left/right, “turn” left/right should do.

Kp and Kd constants

Kp = 0.2 and Kd = 5 worked for me as constants!

Stopping on a line?

I’m using this sensor for my senior project at my University and was wondering if you knew of a way to have the robot stop if it goes over a solid black line being read by all sensors at once?

QTRSensorsRC qtrrc((unsigned char[]) { 14, 15, 16, 17, 18, 19} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);

My code is not running because of this line. it says-

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: “Arduino/Genuino Uno”

LFR_QTR_TEST:21:1: error: ‘QTRSensorsRC’ does not name a type

QTRSensorsRC qtrrc((unsigned char[]) { 14, 15, 16, 17, 18} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);

^

LFR_QTR_TEST:21:61: error: expected unqualified-id before ‘,’ token

QTRSensorsRC qtrrc((unsigned char[]) { 14, 15, 16, 17, 18} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);

                                                         ^

LFR_QTR_TEST:8:22: error: expected unqualified-id before numeric constant

#define NUM_SENSORS 5 // number of sensors used

                  ^

D:\Arduino\Tests\LFR_QTR_TEST\LFR_QTR_TEST.ino:21:62: note: in expansion of macro ‘NUM_SENSORS’

QTRSensorsRC qtrrc((unsigned char[]) { 14, 15, 16, 17, 18} ,NUM_SENSORS, TIMEOUT, EMITTER_PIN);

                                                          ^

D:\Arduino\Tests\LFR_QTR_TEST\LFR_QTR_TEST.ino: In function ‘void loop()’:

LFR_QTR_TEST:47:18: error: ‘qtrrc’ was not declared in this scope

int position = qtrrc.readLine(sensors);

              ^

D:\Arduino\Tests\LFR_QTR_TEST\LFR_QTR_TEST.ino: In function ‘void manual_calibration()’:

LFR_QTR_TEST:88:5: error: ‘qtrrc’ was not declared in this scope

 qtrrc.calibrate(QTR_EMITTERS_ON);

 ^

LFR_QTR_TEST:88:21: error: ‘QTR_EMITTERS_ON’ was not declared in this scope

 qtrrc.calibrate(QTR_EMITTERS_ON);

                 ^

LFR_QTR_TEST:96:20: error: ‘qtrrc’ was not declared in this scope

   Serial.print(qtrrc.calibratedMinimumOn[i]);

                ^

LFR_QTR_TEST:103:20: error: ‘qtrrc’ was not declared in this scope

   Serial.print(qtrrc.calibratedMaximumOn[i]);

                ^

exit status 1
‘QTRSensorsRC’ does not name a type

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.