Lesson 5: Autonomous Line-Following Robot

In the future of intelligent transportation and automated logistics, autonomous driving technology is gradually transforming our lives. From self-driving cars to smart warehouse robots, one of the core technologies behind these innovations is line-following navigation. In this project, we will explore two different line-following methods to teach your UNIHIKER K10 car how to autonomously track a black line. This is not only an engaging programming challenge but also a starting point for exploring future smart transportation technologies. Through this project, you will learn how to enable a robot to perceive its environment and make decisions, laying a solid foundation for future innovation.

 

 

Task Objective

This task aims to implement two distinct line-following methods to enable the car to navigate along black lines on a colored map. The first method involves reading digital values from line-tracking sensors mounted on the baseboard, while the second method utilizes the built-in line-following algorithm of the UNIHIKER K10.

 

 

Knowledge Points

1. Understand the working principle and detection method of line-following sensors

2. Master the techniques for reading data from line-following sensors

3. Learn how to invoke the built-in line-following algorithm of Maqueen Plus V3

4. Compare the advantages and disadvantages between custom line-following and built-in algorithms

 

Materials List

Hardware Requirements:

 

HARDWARE LIST
1 Maqueen Plus V3
1 UNIHIKER K10

 

Software Requirements: Mind+ programming software (Version 1.8.1 RC1.0 or above) ×1

Download Link: https://mindplus.cc/

 

 

Practical Exercise

In this project, we will explore the line-following functionality through three progressive tasks. First, we will learn how to read digital values from the line-following sensors. Next, we will implement two distinct line-following methods—custom programming and built-in algorithms—to control the car's movement along the track.

 

Task 1: Read Digital Values from Line-Following Sensors

Read the digital values from the 5-channel line-following sensors and display them in real-time on the K10's screen.

 

Task 2: Basic Line-Following

Develop a control program based on the digital signals from the line-following sensors to achieve fundamental line-following functionality.

 

Task 3: Line-Following Using Built-In Algorithm

Utilize the built-in line-following algorithm provided by the UNIHIKER K10 to enable autonomous navigation, streamlining the development process.

 

Task 1: Reading Digital Values from Line-Following Sensors

1. Hardware Connection

  Connect the assembled car to your computer using a USB 3.0 to Type-C cable.

  Note: The Type-C end should be connected to the UNIHIKER K10.

 

 
2. Software Preparation

Launch Mind+ and complete the software setup as illustrated in the following diagram.

 

 

3. Programming

(1) Reading Line-Following Sensor Values

Use the "read line sensor L1 state" command to obtain the sensor's current digital signal (0 or 1).

 

 

Display the acquired line-following sensor values on the UNIHIKER K10 screen using the "Cache text" command. Set the "auto-clear" option to "yes" to ensure only the latest readings are displayed.

 

 

Use the "join" command to combine each sensor's status value into readable text (e.g., L1: [Read Line Sensor L1 Status]).

 

 

Finally, use the "show cached content" command to refresh the text content on the screen and activate the display. The complete program is as follows:

 

 
4. Program Execution

Before running the program, we need to reconfirm that the UNIHIKER K10 is properly connected to the computer via USB cable; after confirming the connection is correct, you can click the "Run" button in the software, and upon program execution completion, when the line-following sensors detect black lines, the indicator lights will illuminate (digital value = 1), whereas when no black lines are detected, the indicator lights will remain off (digital value = 0).

 

 

Task 2: Custom Line Following

1. Programming

This task builds upon the program from Task 1. To achieve basic line-following functionality, we will utilize only the front three sensors: L1, M, and R1. These sensors will determine the car's positional relationship with the black line and make corresponding adjustments.

Note: While the three line-following sensors can produce seven different combinations, this analysis will focus on three primary cases. The remaining scenarios can be explored independently.

 

 

Straight: When the M sensor detects the black line (value=1), it indicates the car is centered on the line. Use the "Set all motors direction rotate forward speed 100" command to control both motors moving forward simultaneously.

 

 

Right turn: When R1 detects the black line (1) while M detects white (0), it indicates the car is deviating left and should turn right. Use the "Set left motor direction rotate forward speed 100" command and "Set right motor direction rotate backward speed 50" command to make the car turn right.

 

 

Left turn: When L1 detects the black line (1) while M detects white (0), it indicates the car is deviating right and should turn left. Use the "Set left motor direction rotate backward speed 50" command and "Set right motor direction rotate forward speed 100" command to make the car turn left. The complete program is as follows:

 

 

2. Program Execution

Prior to running the program, please verify that the UNIHIKER K10 is properly connected to your computer via USB cable. Once the connection is confirmed, click the "Run" button in the software. After the program completes execution, place the car at the starting position on the map, and it will proceed to follow the black line on the map.

 

 

Task 3: Line Following Using Built-in Algorithm

1. Programming

In this task, we will utilize the built-in line-following functionality of the UNIHIKER K10 (based on DFRobot Maqueen Plus V2) to achieve autonomous line-following. This approach is relatively straightforward, as most of the line-following logic is already integrated into the hardware and firmware—we simply need to call the appropriate commands.

At the beginning of the program, use the "System Initialization module" command to initialize the system and ensure all modules function correctly.

 

 

During line following, use the "set up a patrol route speed" command to configure the tracking speed. This speed setting directly affects the car's movement velocity during operation.

 

Note: The speed parameter accepts values between 1-5, which can be adjusted based on actual requirements. Higher values result in faster movement, while lower values produce slower motion.

 

 

Finally, execute the "patrolling on" command to activate the built-in line-following functionality. The complete program implementation is as follows:

 

 

2. Program Execution

Prior to program execution, verify the UNIHIKER K10 is properly connected to your computer via USB cable. Upon successful connection, click the "Run" button in the software interface. After program initialization completes, position the vehicle at the designated starting point on the track map. The system will autonomously navigate along the predefined black trajectory.

 

Knowledge Corner

1. Understanding the Working Principle of Line-Following Sensors

Each line-following sensor module contains two infrared probes: one for infrared emission and another for infrared reception.

 

 

Line-following sensors operate based on the reflective properties of light. On a white surface, black line markings reflect more light while the white background reflects less. When the sensor detects a black line on the ground, it outputs a value of 1. Conversely, when detecting a white background, it outputs a value of 0.

 

 

2. Understanding Line-Following Sensor Calibration Methods

The line-following sensors on the Maqueen Plus V3 car are factory-calibrated and typically ready for immediate use. However, if abnormal detection is observed during operation (e.g., outputting 1 with indicator lights on in white areas), recalibration can be performed using the onboard calibration button.

 

Calibration Procedure:

Preparation: Place all front line-following sensors of the vehicle completely over a black surface, ensuring full coverage.

Calibration: Press and hold the line-following calibration button until the blue indicator lights on the sensors blink three times, indicating completed calibration.

 

 

Calibration Verification:

When placed on black surfaces, the corresponding indicator lights should illuminate.

When placed on white surfaces, the corresponding indicator lights should turn off.

 

 

This calibration process effectively corrects recognition errors caused by environmental lighting variations or component wear, ensuring accurate and stable line-following performance.

 

3. Understanding Application Scenarios of Line-Following Sensors

Line-following sensors are intelligent components capable of detecting variations in ground color or reflectivity, primarily used to enable robots to "recognize paths and follow designated routes." These sensors serve not only as core components for autonomous navigation in smart vehicles but also find extensive applications across various real-world scenarios.

 

In practical applications, line-following sensors have extensive uses. For instance, in logistics warehouses, automated guided vehicles (AGVs) utilize these sensors to efficiently transport and store goods along predefined black tracks, significantly improving logistics efficiency. In intelligent transportation systems, autonomous vehicles employ line-following sensors to detect road markings, ensuring safe lane-keeping and thereby enhancing the reliability of driver-assistance systems. Service robots, such as cleaning robots and hospital delivery robots, also rely on these sensors for autonomous indoor navigation, enabling efficient service delivery.

 

 

Moreover, in the field of education and research, line-following sensors serve as essential tools for teaching experiments and robotics competitions, enabling students and researchers to study sensor principles and control algorithms. In security monitoring systems, these sensors can detect boundaries of specific areas to prevent unauthorized access by personnel or objects, thereby ensuring safety. In smart agriculture applications, line-following sensors assist agricultural robots in performing irrigation, fertilization, and harvesting operations along predefined routes, significantly improving agricultural production efficiency.

 

 

Through these applications, line-following sensors not only enhance operational efficiency but also improve system reliability and safety, providing crucial support for the development of future intelligent technologies.

 

Challenge Yourself

In this project, we have mastered the basic line-following functionality of the car. However, in real-world applications, routes are rarely static. Imagine this scenario: the car may encounter crossroads, T-junctions, or even complex intersections with multiple converging paths.

Here's the challenge - when the car reaches these intersections, how should it determine the correct direction? And how can we program it to make the right decision?

Put on your thinking cap and try to devise a method to enable your smart car to autonomously "make decisions" when facing these "forks in the road"!

icon Lesson 5 Code.zip 498KB Download(0)
License
All Rights
Reserved
licensBg
0