# How to code automatic line-following programs 

How to code automatic line-following programs

In the AI era, automatic line-following is a must for most robots. What is the principle of line following? This # How to tells you the answer. You can follow it to learn line-following programs.

mBot Neo & Line-following track mapLine-following programs keep a robot on the central axis of the line when it moves forwardQuad RGB Sensor

# Principle of line following #

--The lines don’t have to be black.--The background doesn’t have to be white. --The Quad RGB Sensor on mBot Neo can identify the RGB values of colors. So it can identify most colors. --Long press the button to change the color of the fill light. In low light, you can turn on the fill light to improve the line-following performance.Line-following programDownload base_power: Approximate forward speed kp: Adjustment value for left and right wheels during line following left_power: Actual speed of the left wheel right_power: Actual speed of the right wheelbase_power: Approximate forward speed kp: Adjustment value for left and right wheels during line following left_power: Actual speed of the left wheel right_power: Actual speed of the right wheel

Block explanation:

Multiplying

Multiplying "kp" by the deviation value can reduce the value returned by the Quad RGB Sensor, achieving the goal of fine-tuning the speed.

During line following, when mBot Neo deviates to the left, the deviation value is negative, and when it deviates to the right, the deviation value is positive. Therefore, when the robot deviates to the right, the left wheel needs to slow down to lead the center of the robot back to the center of the line. To achieve this,

During line following, when mBot Neo deviates to the left, the deviation value is negative, and when it deviates to the right, the deviation value is positive.
Therefore, when the robot deviates to the right, the left wheel needs to slow down to lead the center of the robot back to the center of the line.
To achieve this, "left_power" needs to increase by subtracting the deviation value (which is negative) from "base_power", making the left wheel speed up and the center of the robot return to the center of the line.
As the deviation value approaches zero, the robot speed approaches "base_power".

Since the left and right wheels are symmetrically installed, their rotating directions are opposite and their speed values have opposite signs.

Since the left and right wheels are symmetrically installed, their rotating directions are opposite and their speed values have opposite signs.

Assigning the speed values to the corresponding motors implements line following.

Assigning the speed values to the corresponding motors implements line following.

mBot Neo line following
Go have fun now! Share your achievements on social media~
Liquid error (sections/pf-3ff10bea line 65): product form must be given a product
×

Request for Quote

Quotation Notice

1. An email has been sent to you containing the quotation file and all other important files. Please check your mailbox.
2. The quote is valid for 30 days. Please generate your Purchase Order within this period. If the quote expires, a new quote will need to be generated.

Download W9

Download W9

More Support

If you need more help, kindly mail to vendor: us@makeblock.com