Lesson 7: Multi-point Ranging Obstacle Avoidance Robot

In daily life, we often encounter various scenarios requiring obstacle avoidance. For example, when driving on narrow streets, we need to constantly monitor surrounding obstacles to prevent collisions. In home environments, robotic vacuum cleaners must intelligently navigate around furniture and barriers to efficiently complete cleaning tasks. So, can we employ technology to equip robots with such intelligent obstacle avoidance capabilities?

Next, we will implement a multi-point ranging obstacle avoidance robot using the Maqueen Plus V3 car and a matrix laser ranging sensor. With 64 laser points covering a 60° field, the vehicle can achieve cliff detection, obstacle circumvention, and line-following with obstacle avoidance. This is not only an engaging project but also helps us better understand the practical applications of intelligent obstacle avoidance technology. Let's explore how to accomplish this together!

Task Objectives

Through the two different modes (Matrix Mode and Obstacle Avoidance Mode) of the matrix laser ranging sensor, the smart car can achieve intelligent obstacle avoidance in various environments.

Matrix Mode: Use 1 laser beam to enable cliff detection for the car. Use 2 laser beams to enable obstacle circumvention for the car.

Obstacle Avoidance Mode: Combined with line-following functionality, the car automatically makes a U-turn when encountering an obstacle ahead during line-following.

Key Learning Points

1. Learn how to perform multi-point ranging using matrix laser ranging sensors

2. Implement obstacle avoidance strategies including cliff detection and obstacle circumvention

3. Understand PID angular control technology

4. Explore application scenarios for matrix laser ranging sensor

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/

 

 

Hands-on Practice

This project primarily utilizes two different modes of the matrix laser ranging sensor to achieve distinct functions. In Matrix Mode, we employ one laser beam for cliff detection and two beams for obstacle circumvention. In Obstacle Avoidance Mode, we integrate line-following functionality to enable automatic U-turns when encountering obstacles during path tracking. The implementation is divided into three sub-tasks.

 

Task 1: Cliff Detection

Using the Matrix Mode of the laser sensor, detect whether a cliff exists ahead. If detected, the vehicle turns right to avoid; otherwise, it continues straight.

 

Task 2: Obstacle Circumvention

Using Matrix Mode, detect obstacles on left/right sides and adjust the vehicle's direction accordingly. When left-side obstacles are detected, steer right; when right-side obstacles are detected, steer left.

 

Task 3: Line-Following with Obstacle Avoidance

Using the sensor's Obstacle Avoidance Mode combined with line-tracking, implement automatic U-turns upon obstacle detection during path following.

 

Task 1: Cliff Detection

1. Hardware Connection

Connect the assembled vehicle to the computer using a USB3.0 to Type-C cable.

Note: The Type-C end connects to the UNIHIKER K10.

 

 

2. Software Preparation

Open Mind+ and complete the software setup according to the illustrated procedure below.

 

 

3. Programming

(1) Sensor Initialization

Under the "UNIHIKER K10 On Start" section, use the "System Initialization" command and the "Initialize the I2C address 0x30 of the laserranging sensor in Matrix mode" command to initialize the vehicle and matrix laser module.

Note: The command provides four optional I2C addresses (0x30, 0x31, 0x32, 0x33), with 0x33 as default. For detailed I2C address confirmation methods, refer to the "Knowledge Base" section.

 

 

Create a "distance" variable to store real-time detected distance measurements, initializing its value with the distance reading from the matrix laser sensor upon vehicle startup.

 

 

 

Use the "Measure the distance of the specified point in matrix mode x: y: (mm)" command with specified laser beam coordinates (x:3, y:3) for distance detection. The matrix laser ranging sensor employs an 8×8 array totaling 64 laser measurement points as illustrated below:

 

 

 

This task primarily focuses on cliff detection, making the central laser beam (x3y3) ideal for distance measurement. Therefore, assign the "Measure the distance of the specified point in matrix mode x:3 y:3 (mm)" command output to the "distance" variable.

 

 

Create a new "initiate_distance" variable and initialize it with the value from the "distance" variable.

 

 

 

 

(2) Real-time Distance Measurement

After completing initialization, use the "Measure the distance of the specified point in matrix mode x:3 y:3 (mm)" command within the "forever" instruction to continuously monitor the distance detected by the x3y3 laser beam, assigning the measured value to the "distance" variable.

 

 

(3) Cliff Detection

To simulate a cliff environment, select a medium-sized cardboard box approximately 5cm high (adjust height according to your actual box dimensions). Position the vehicle on the box, treating areas beyond the box edges as cliffs.

 

 

During startup, a distance measurement "initiate_distance" is taken. When the matrix laser sensor detects "distance" greater than "initiate_distance"+ 50 (the height of the paper box), it indicates that the edge of the cliff has been reached.

Note: If the height of the paper box you are holding is 10cm, modify this value to 100.

 

 

When the condition is true (cliff edge detected), execute the "set left motor direction forward speed 150" and "set right motor direction forward speed 0" commands to make the vehicle turn right.

 

 

When the condition is false (no cliff detected), execute the "set all motor direction forward speed 100" command to maintain forward movement.

 

 

4. Program Execution

Before running the program, ensure the UNIHIKER K10 is properly connected to the computer via USB cable. After verification, click the "Run" button in the software. Once the program uploads successfully, place the vehicle on the prepared cardboard box. When the matrix laser ranging sensor detects a cliff edge, the vehicle will turn right; otherwise, it continues forward.

 

Notes:

1. The matrix laser ranging sensor requires approximately 3 seconds for initialization. The vehicle will remain inactive during this period. Please wait patiently for sensor initialization to complete.

2. Avoid performing image display operations on the UNIHIKER K10 screen within loop instructions. Screen updates may consume significant processing time, potentially affecting the distance detection performance of the laser ranging sensor.

 

 

Task 2: Obstacle Circumvention

1. Programming

(1) Sensor Initialization

Under the "UNIHIKER K10 On Start" section, use the "System Initialization module" command and the "Initialize the I2C address 0x30 of the laserranging sensor in Matrix mode" command to initialize the vehicle and matrix laser module.

 

 

Create variables "left" and "right", initializing both with a value of 0.

 

 

(2) Real-Time Distance Measurement

Using the "Measure the distance of the specified point in matrix mode x: y: (mm)" command, select the left (x:0 y:6) and right (x:7 y:6) laser beams for distance detection. Assign the measured left-side distance to variable "left" and the right-side distance to variable "right".

 

 

(3) Obstacle Circumvention

Next, implement obstacle avoidance using the "if...then ...else if...then... else" conditional command structure.

 

 

First, detect obstacles on the left side. When the value of variable "left" is less than 200 and greater than 0, this indicates an obstacle has been detected on the left.

 

 

If the condition is true (obstacle detected), execute the "set left motor direction forward speed 150" and "set right motor direction forward speed 0" commands to steer the vehicle to the right.

 

 

Otherwise, check for obstacles on the right side. When the value of variable "right" is less than 200 and greater than 0, this indicates an obstacle has been detected on the right. Execute the "set right motor direction forward speed 150" and "set left motor direction forward speed 0" commands to steer the vehicle to the left.

Note: The condition requiring variable "left" to be greater than 0 serves to filter out false detections.

 

 

If neither left nor right obstacles are detected (no obstacles present), execute the "set all motor direction forward speed 150" command to maintain forward motion. The complete program is as follows:

 

 

2. Program Execution

Before running the program, ensure the UNIHIKER K10 is properly connected to the computer via USB cable. After verification, click the "Run" button in the software. Once the program is successfully uploaded, place the vehicle on the ground. When the matrix laser ranging sensor detects an obstacle on the left, the vehicle will steer right; when detecting an obstacle on the right, it will steer left.

 

Task 3: Line Following with Obstacle Avoidance

In previous tasks, we've learned how to use the matrix laser ranging sensor for cliff detection and obstacle identification. Now we'll utilize the sensor's obstacle avoidance mode to implement line-following with obstacle avoidance functionality. Let's examine the differences between these two modes!

 

1. Programming

(1) Line Following Functionality This task requires programming the vehicle to follow a line. First, initialize the system using the "System Initialization module" command.

 

 

Execute the "set up a patrol route speed" command to set the vehicle's line-following speed to 3. Then activate the line-following functionality using the "Patrolling on" command.

 

 

(2) Obstacle Avoidance Functionality

Under the "UNIHIKER K10 On Start" section, use the "Initialize the I2C address 0x30 of the laserranging sensor in Obstacle avoidance mode" command to activate the matrix laser sensor's obstacle avoidance capability.

 

 

Within the "forever" instruction, utilize the "Acquire obstacle avoidance data" command to acquire real-time distance measurements between the matrix laser ranging sensor and detected obstacles.

 

 

Create a new variable "distance" initialized to 0. Employ the "Distance detection in obstacle avoidance mode Front (mm)" command to continuously measure frontal distances, storing the results in the "distance" variable.

 

 

(3) Line Tracking with Obstacle Avoidancee obstáculos

During line tracking, the vehicle determines whether the forward distance is less than the safety threshold (20cm). A measured distance below 20cm indicates frontal obstacle presence.

 

Implement conditional logic using the "If...Then" command structure. When the "distance" variable value is between 0 and 200, the condition evaluates as true, confirming obstacle detection. Execute the "Patrolling off" command to halt the vehicle's path-following operation.

 

 

After terminating line tracking, execute the "PID angle control angle 180° not allowed interruption" command to perform a 180-degree turning maneuver.

Note: The "not allowed interruption" parameter ensures no other operations will be permitted until the vehicle completes the full 180-degree rotation.

 

 

Upon completing the turn, reactivate line tracking using the "Patrolling on" command. The complete program implementation follows:

 

 

2. Program Execution

Before running the program, verify the UNIHIKER K10 is properly connected to your computer via USB cable. After confirmation, click the "Run" button in the software. Once the program uploads successfully, place the vehicle on the line-tracking course. During operation, when detecting frontal obstacles, the vehicle will execute an on-the-spot U-turn and resume line tracking after completing the maneuver.

 

 

Knowledge Base

1. How to Scan I2C Addresses

Since the matrix laser ranging sensor uses an I2C interface and the vehicle provides three I2C ports, we can connect to any available port. However, after connection, how do we determine the I2C address corresponding to the connected pin? The "Initialize Laser Ranging Sensor I2C Address Mode" command offers four address options: 0x30, 0x31, 0x32, and 0x33. Below are the detailed steps to identify the I2C address for the connected pin:

 

Step 1: Create a New Project and Prepare the Software Environment

Open the Mind+ software and create a new project.

Complete the software setup as shown in the diagram below, ensuring all necessary modules and libraries are correctly loaded.

 

 

Step 2: Add I2C Address Scanning Functionalityra de endereço I2C

Click "Extensions", locate the "I2C Scan" module under "Function" and complete the addition process.

 

 
Step 3: Program the Address Scanning Routine

Develop a simple I2C address scanning program to display detected addresses in the serial print area.

 

 

Step 4: Upload Program and View Resultsados

After successful program upload, open the serial monitor. The scanned I2C addresses will be displayed in the serial print area.

 

 

Step 5: Identify the Correct I2C Address

Multiple I2C addresses may appear in the serial print area, representing all connected I2C devices on the vehicle. Among these, only 0x30 corresponds to the address specified in the "Initialize Laser Ranging Sensor I2C Address Mode" command. Therefore, the matrix laser ranging sensor's connected I2C address is confirmed as 0x30.

 

 

2. Understanding PID Control Technology

PID (Proportional-Integral-Derivative) control is a closed-loop control algorithm widely used in industrial automation and robotics. It precisely adjusts control variables in real-time to ensure system output accurately reaches target values.

 

 

While it may sound complex, PID applications are actually commonplace in daily life: electric kettles' temperature control, self-balancing vehicles, smart tea makers, 3D printer temperature regulation—essentially any scenario requiring "maintaining a stable variable" can benefit from PID implementation.

 

 

(1)Water Heater Temperature Control Principle

For example, to maintain water temperature at 50℃, the simplest approach would be: heat when below 50℃; cut power when reaching or exceeding 50℃. This "ON-OFF control" method, while simple, yields poor stability. Applied to vehicle speed control, it would cause erratic acceleration/deceleration and passenger discomfort.

 

Why does this occur? Because systems possess inertia (residual heat in temperature, momentum in vehicles); sensors and controllers have finite response times, preventing instantaneous adjustments. This is where smarter algorithms—PID—become necessary.

 

(2) Description of PID Components:

P (Proportional): Larger errors trigger faster corrections; smaller errors gentler adjustments. Enables "gradual" control, avoiding abrupt changes.

I (Integral): Accumulates and corrects minor persistent errors, eliminating "negligible difference" issues like refusing to heat for tiny deviations.

D (Derivative): Predicts trends to prevent overshooting, e.g., reducing heating preemptively as temperature approaches target.

 

 

Thus, systems achieve smoother, more precise control of temperature, speed and other physical quantities. PID constitutes this classic methodology for "intelligent" control.

 

3. Understanding Application Scenarios of Matrix Laser Ranging Sensors

A matrix laser ranging sensor is capable of simultaneously acquiring distance information from multiple directions. Compared to traditional infrared, ultrasonic, or single-point laser ranging methods, it can establish a "two-dimensional field of view" within a certain angular range, functioning like vision-equipped "eyes" that perform rapid and precise environmental scanning.

 

(1) Physical Configuration and Capabilities

The sensor typically consists of a laser emitter array and receiver array. Our matrix laser ranging sensor employs an 8×8 matrix configuration, enabling simultaneous distance measurement across 64 directions within a 60° sector. It provides real-time detection of object positions and distances within its frontal coverage area. With advantages including high speed, precision, and immunity to ambient light interference, it essentially grants the equivalent of human peripheral vision for multi-directional obstacle detection - eliminating the need for "scan, rotate, then scan again" procedures.

 

 

(2) Practical Application Scenarios

 

 

Taking our robotic vehicle as an example: Previously using infrared or ultrasonic sensors limited to single-direction detection (forward-facing only). Now equipped with the matrix laser ranging sensor, the vehicle gains spatial awareness - detecting a 20cm obstacle at 45° left while confirming clear passage to the right, autonomously executing optimal detours. This two-dimensional "vision" enables precise obstacle avoidance and rational path planning, effectively granting true spatial perception capabilities.

 

Challenge Yourself

In Tasks 1 and 2, we learned how to use 1 laser beam for cliff detection and 2 beams for left/right obstacle detection. Now let's expand this functionality by utilizing 3 laser beams to detect obstacles in left, center, and right directions, enabling the vehicle to automatically navigate toward obstacle-free paths. This enhancement will significantly improve the vehicle's obstacle avoidance capabilities in complex environments.

Note: The three laser beams to be used are marked in the diagram.

 

 

icon Lesson 7 Program.zip 665KB Download(0)

Want to keep learning? Continue your learning journey with our other lessons.

Lesson 2: Design a Personalized Digital Pet

Lesson 3: Set Pet Interaction Mode

Lesson 4: Intelligent Environmental Monitoring Robot

Lesson 5: Autonomous Line-Following Robot

Lesson 6: Autonomous Robot for Complex Road Network Navigation

License
All Rights
Reserved
licensBg
0