yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
T-mini Plus 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.Raspberry Pi5 course
2.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
3.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
1.Docker course
  • 1. Overview and installation
  • 2. Common commands
  • 3. Docker images deeply understand and publish images
  • 4. Docker hardware interaction and data processing
  • 5. Enter the robot's docker container
Download
  • Code
  • VM_File
  • RPi5_SystemFile
  • Data Sheet
  • 3D_Model_File
  • PC_Software
  • ROS2_Basic_VM
Download ZIP

Welcome to T-mini Plus LiDAR repository

3.Lidar avoiding

Lidar guard

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.

Code path: ~/rplidar_ws/src/yahboomcar_laser

Lidar guard fucntion:

  • Set lidar detection angle and response distance
  • After turning on the car, the car faces the target closest to the car
  • When the distance between the target and the car is less than the response distance, the buzzer will sound until there is no target within the response distance.
  • Adjustable car angular speed PID to achieve the best car rotation effect

1. Start

Input following command:

roslaunch yahboomcar_laser laser_Warning.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_Warning.launch

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

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

Code path:~/ydlidar_ws/src/yahboomcar_laser/scripts

The core code part is as follows:

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)
        # 创建距离列表,将检测范围内的有效距离放入列表中
        # create distance list, put the effective distance within the detection range into the list
        minDistList = []
        # 创建序列号,将有效距离对应的ID放入列表中
        # Create a serial number and place the ID corresponding to the valid distance in the list
        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.laserAngle and ranges[i] != 0.0:
                minDistList.append(ranges[i])
                minDistIDList.append(angle)
        if len(minDistList) == 0: return
        # 找到最小距离
        # Find the minimum distance
        minDist = min(minDistList)
        # 找到最小距离对应的ID
        # Find the ID corresponding to the minimum distance
        minDistID = minDistIDList[minDistList.index(minDist)]
        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
        if minDist <= self.ResponseDist:
            if self.Buzzer_state == False:
                b = Bool()
                b.data = True
                self.pub_Buzzer.publish(b)
                self.Buzzer_state = True
        else:
            if self.Buzzer_state == True:
                self.pub_Buzzer.publish(Bool())
                self.Buzzer_state = False
        velocity = Twist()
        # 使用PID算法使得小车稳步移动到对应位置
        # The PID algorithm is used to make the car move to the corresponding position steadily
        ang_pid_compute = self.ang_pid.pid_compute((180 - abs(minDistID)) / 36, 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)

This part mainly involves entering the callback function after receiving the radar information. According to the value range of the radar data we set, find the smallest data, then find the ID corresponding to the minimum distance, and determine the distance of the ID with the minimum distance.

If it is greater than the set response speed value, the data will be released and the buzzer will sound.

Otherwise, calculate the pid based on the ID of the minimum distance, and publish the speed to the bottom layer so that the car moves with the identified object.

Handheld lidar mapping
Lidar guard

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/中文