yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
EAI X3 Pro LiDAR📖
01.Linux basic course
  • 1.Introduction to Linux system
  • 2.Ubuntu file system
  • 3.Ubuntu common commands
  • 4.Ubuntu common editors
  • 5.Ubuntu software operation commands
  • 6.Virtual machine installation
  • 7.SSH remote control
  • 8.VNC remote control
  • 9.Transfer files remotely
  • 10.Driver library and communication
  • 11.Static IP and hotspot mode
  • 12.Bind device ID
  • 13.Capacity expansion and resource allocation
  • 14.Update system software sources
  • 15.Set root user password
  • 16.sudo free password
  • 17.Connect to WiFi network
  • 18.View system version
  • 19.Customized service management
  • 20.Back up system image
02.ROS1 basic course
  • 1.ROS introduction
  • 2.ROS installation
  • 3.ROS common command tools
  • 4.ROS workspace
  • 5.ROS function package
  • 6.ROS node
  • 7.ROS topic publisher
  • 8.ROS topic subscribers
  • 9.ROS service client
  • 10.ROS service server
  • 11.ROS action client
  • 12.ROS action server
  • 13.ROS custom message reception
  • 14.ROS-launch file
  • 15.ROS-TF transformation
  • 16.ROS parameter service
  • 17.ROS-rviz use
  • 18.ROS-rqt tool usage
  • 19.Topic message recording and playback
  • 20.urdf model introduction
  • 21.gazebo introduction
  • 22.ROS distributed communication
03.ROS1 lidar course
  • 0.Instructions before use
  • 1.Preparation
  • 2.Handheld lidar mapping
  • 3.Lidar avoiding
  • 4.Lidar guard
  • 5.Lidar follow
  • 6.Lidar mapping
  • 7.rrt_exploration mapping algorithm
  • 8.Navigation
  • 9.APP Mapping and Navigation
  • 10.RTAB 3D mapping and navigation
04.ROS2 basic course
  • 1. Introduction to ROS2
  • 2.ROS2 install Humble
  • 3.ROS2 development environment
  • 4.ROS2 workspace
  • 5.ROS2 function package
  • 6.ROS2 node
  • 7.ROS2 topic communication
  • 8.ROS2 service communication
  • 9.ROS2 action communication
  • 10.ROS2 custom interface message
  • 11.ROS2 parameter service case
  • 12.ROS2 meta-function package
  • 13.ROS2 distributed communication
  • 14.ROS2 DDS
  • 15.ROS2 time related API
  • 16.ROS2 common command tools
  • 17.ROS2 rviz2 use
  • 18.ROS2 rqt toolbox
  • 19.ROS2 Launch startup file configuration
  • 20.ROS2 recording and playback tool
  • 21.ROS2 URDF model
  • 22.ROS2 Gazebo simulation platform
  • 23.ROS2 TF2 coordinate transformation
05.ROS2 lidar course
  • 0.ReadMe
  • 1.Preparation
  • 2.Handheld lidar mapping
  • 3.Lidar avoiding
  • 4.Lidar follow
  • 5.Lidar guard
  • 6.Lidar patrol
  • 7.gmapping mapping
  • 8.cartographer mapping
  • 9.Navigation and avoiding
  • 10.APP Mapping and Navigation
  • 11.RTAB 3D mapping and navigation
06.RPi 5 Docker course
  • 1.Overview and installation
  • 2.Common commands
  • 3.Understand and publish images
  • 4.Hardware interaction data processing
  • 5.Enter docker container
  • 6.Update docker images
  • 7.Docker container to install ROS using accessories
07.RDK course
  • 0.ReadMe before use
  • 1.Environment Construction
  • 2.Handheld Lidar Mapping
Download
  • ROS1-Code
  • ROS2-Code
  • ROS1-VMFile
  • ROS2-VMFile
  • PC Software
  • 3D_Model_File
  • RDK_Code
  • ROS2_Basic_VM
Download ZIP

Welcome to EAI X3 Pro LiDAR repository

5.Lidar follow

Lidar follow

The following workspace contains the entire ydlidar_ws function package.

If you need to transplant it to your own main development board, you need to copy all the function packages to the src of the workspace for compilation, and install the corresponding environment.

Note: This course uses Rosmaster-X3Plus as an example. Users need to modify it according to their own motion model. The course only explains the implementation method.

Function package path: ~/ydlidar_ws/src/yahboomcar_laser

Introduction to lidar following funtion:

  • Set lidar detection angle and distance.
  • After turning on the car, the car will follow the target closest to the car and keep a certain distance.
  • The PID can adjust the linear speed and angular speed of the car to make the car follow the best effect.

1. Start

Input following command:

roslaunch yahboomcar_laser laser_Tracker.launch

Input following command to debug dynamic parameters

xxxxxxxxxx
rosrun rqt_reconfigure rqt_reconfigure

View the node graph

xxxxxxxxxx
rqt_graph

2. Source code analysis

2.1 launch file

laser_Tracker.launch

xxxxxxxxxx
<launch>
    <!-- 启动base.launch文件 -->
    <!-- Launch the base.launch file -->
    <include file="$(find yahboomcar_laser)/launch/base.launch"/>
    <!-- 启动激光雷达跟随节点 -->
    <!-- Activate lidar follow node -->
    <node name='laser_Tracker' pkg="yahboomcar_laser" type="laser_Tracker.py" required="true" output="screen"/>
</launch>

The base.launch file is to start the car chassis and radar, mainly look at laser_Tracker.py

Source code path: ~/ydlidar_ws/src/yahboomcar_laser/scripts

The core code part is as follows. This part mainly enters the callback function after receiving the radar information.

xxxxxxxxxx
def registerScan(self, scan_data):
        if not isinstance(scan_data, LaserScan): return
        # 记录激光扫描并发布最近物体的位置(或指向某点)
        # Record the laser scan and publish the position of the nearest object (or point to a point)
        ranges = np.array(scan_data.ranges)
        offset = 0.5
        frontDistList = []
        frontDistIDList = []
        minDistList = []
        minDistIDList = []
        # 按距离排序以检查从较近的点到较远的点是否是真实的东西
        # if we already have a last scan to compare to:
        for i in range(len(ranges)):
            angle = (scan_data.angle_min + scan_data.angle_increment * i) * RAD2DEG
            # if angle > 90: print "i: {},angle: {},dist: {}".format(i, angle, scan_data.ranges[i])
            # 通过清除不需要的扇区的数据来保留有效的数据
            if abs(angle) < self.priorityAngle:
                if ranges[i] < (self.ResponseDist + offset) and ranges[i] != 0.0:
                    frontDistList.append(ranges[i])
                    frontDistIDList.append(angle)
            elif abs(angle) > self.priorityAngle and abs(angle) < self.laserAngle and ranges[i] != 0.0:
                minDistList.append(ranges[i])
                minDistIDList.append(angle
        # 找到最小距离和最小距离对应的ID
        # Find the minimum distance and the ID corresponding to the minimum distance
        if len(frontDistIDList) != 0:
            minDist = min(frontDistList)
            minDistID = frontDistIDList[frontDistList.index(minDist)]
        else:
            minDist = min(minDistList)
            minDistID = minDistIDList[minDistList.index(minDist)]
        # rospy.loginfo('minDist: {}, minDistID: {}'.format(minDist, minDistID))
        if self.ros_ctrl.Joy_active or self.switch == True:
            if self.Moving == True:
                self.ros_ctrl.pub_vel.publish(Twist())
                self.Moving = not self.Moving
            return
        self.Moving = True
        velocity = Twist()
        if abs(minDist - self.ResponseDist) < 0.1: minDist = self.ResponseDist
        velocity.linear.x = -self.lin_pid.pid_compute(self.ResponseDist, minDist)
        ang_pid_compute = self.ang_pid.pid_compute((180 - abs(minDistID)) / 72, 0)
        if minDistID > 0: velocity.angular.z = -ang_pid_compute
        else: velocity.angular.z = ang_pid_compute
        if ang_pid_compute < 0.02: velocity.angular.z = 0
        self.ros_ctrl.pub_vel.publish(velocity)

Among them, self.priorityAngle is the angle to be followed first. This value cannot be larger than self.laserAngle, otherwise it is meaningless.

After calculating the minimum ID, the speed data is released to the bottom layer through PID calculation, so that the car follows the movement of the nearest object.

The angle judgment here also needs to be modified based on the position of the radar at 0° angle.

Lidar guard
Lidar mapping

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文