yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
PALMSLAM📖
1. Product Introduction
  • 0.Get started
  • 1. Learning route
  • 2. Frequently Questions
  • 3. Control panel introduction
  • 4. Introduction to LiDAR
  • 5. Robot charging and battery considerations
  • 6.Unboxing and reviewing
2. Assembly video
  • Installation Video
3. Basic configuration
  • 0. Get started quickly
  • 1. Write the firmware
  • 2. Virtual machine installation and startup system
  • 3. Expansion board configuration parameters
  • 4. How to choose the alarm level and radar model
  • 5. Connection Agent
4. LiDAR course
  • 0. Enter the same docker terminal
  • 1. Robot information release
  • 2. Robot URDF model
  • 3. Basic distance measurement function
  • 4. SLAM Gmapping
  • 5. SLAM Cartographer
  • 6. APP mapping
5. Linux operating system
  • 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
6. 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
Download
  • System_File
  • VM_File
  • Code
  • Software_Tool
  • Hareware_Info
  • 3D_Model_File
  • Instruction_Manual
  • ROS2_Basic_VM
Download ZIP

Welcome to PALMSLAM repository

3. Basic distance measurement function

Basic distance measurement function

Note: The virtual machine needs to be in the same LAN as the car, and the ROS_DOMAIN_ID needs to be consistent. You can view [Expansion Board Parameter Configuration] to set the IP and ROS_DOMAIN_ID on the board.

1. Program function description

When the car is connected to the proxy, the distance information directly in front of the radar will be automatically displayed below the OELD screen. After running the program, the radar on the car scans the nearest object in the front range. If the object is closer to the radar than the set distance, the buzzer on the car will sound as a warning. The dynamic parameter regulator can be used to adjust the parameters such as the radar detection range and the distance of the ranging detection.

2. Start and connect the agent

If you are using the factory virtual machine system, you can enter in the terminal:

xxxxxxxxxx
sh ~/start_agent_computer.sh

If you are using a third-party virtual machine system, you need to install the docker development environment first, and open the terminal to enter:

xxxxxxxxxx
sudo docker run -it --rm -v /dev:/dev -v /dev/shm:/dev/shm --privileged --net=host microros/micro-ros-agent:humble udp4 --port 8090 -v4

Then, turn on the car switch and wait for the car to connect to the agent. The connection is successful as shown in the figure below,

image-20241122122039580

3. OLED display distance

After selecting the warning level and radar model, the screen will display the selected radar, imu data, and the distance directly in front of the radar.

image-20241205153811127

4. Run the program

If it is the desktop version of Raspberry Pi and the desktop version of Jetson Nano and X5, you need to enter Docker in advance and enter in the terminal,

xxxxxxxxxx
sh ~/ros2_humble.sh

When the following interface appears, it means that you have successfully entered Docker,

image-20241129150643196

Then enter in the Docker terminal,

xxxxxxxxxx
ros2 run yahboomcar_laser laser_Warning --data 0.5

Take the matching virtual machine as an example, enter the following command in the terminal to start, 0.5 means that the buzzer will keep ringing when the obstacle in front is 0.5 meters away.

xxxxxxxxxx
ros2 run yahboomcar_laser laser_Warning --data 0.5

image-20241122163236543

After the program is started, it will search for the nearest object in the front range of the radar scan. If the distance is less than the set distance, the buzzer will sound an alarm

5. Code analysis

Source code reference path (taking the supporting virtual machine as an example):

xxxxxxxxxx
/home/yahboom/yahboomcar_ws/src/yahboomcar_laser/yahboomcar_laser

laser_Warnning.py, the core code is as follows,

xxxxxxxxxx
#ros lib
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import LaserScan
from std_msgs.msg import Bool,UInt16
#commom lib
import os
import sys
import math
import numpy as np
import time
from time import sleep
from yahboomcar_laser.common import *
print ("improt done")
RAD2DEG = 180 / math.pi
import argparse
​
class laserWarning(Node):
    def __init__(self,name):
        super().__init__(name)
        #create a sub
        #雷达回调函数:处理订阅到的雷达数据
        #Radar callback function: process subscribed radar data
        self.sub_laser = self.create_subscription(LaserScan,"/scan",self.registerScan,1)
        #create a pub
        self.pub_Buzzer = self.create_publisher(UInt16,'/beep',1)
        self.Buzzer_state = False
        
        self.parser = argparse.ArgumentParser()
        self.parser.add_argument('--data', type= float, help='Data to pass to the node')
        self.parsed_args = self.parser.parse_args()
        
        self.args = self.parsed_args.data
        print(self.args)
        
​
    def registerScan(self, scan_data):
        if not isinstance(scan_data, LaserScan): return
       
        ranges = np.array(scan_data.ranges)
        minDistList = []
        minDistIDList = []
        #根据设定的雷达检测角度,找到雷达检测范围内最近的物体
        #According to the set radar detection angle, find the nearest object within the radar detection range
        for i in range(len(ranges)):
            angle = (scan_data.angle_min + scan_data.angle_increment * i) * RAD2DEG
            if angle > 180: angle = angle - 360
            if  abs(angle)< 10 and ranges[i] > 0:
                minDistList.append(ranges[i])
                minDistIDList.append(angle)
                
        #print(minDistList)
        if len(minDistList) != 0: 
            minDist = min(minDistList)
            minDistID = minDistIDList[minDistList.index(minDist)]
        else:
            return
     
        print("minDist: ",minDist)
        print("minDistID: ",minDistID)
        #判断最小物体的雷达检测的距离是否小于设定的范围,随后做出判断是否需要让蜂鸣器响
        #Judge whether the radar detection distance of the smallest object is less than the set range, and then determine whether the buzzer needs to sound
        if minDist <= self.args:
            print("---------------")
            b = UInt16()
            b.data = 1
            self.pub_Buzzer.publish(b)
​
        else:
            print("no obstacles@")
            b = UInt16()
            b.data = 0
            self.pub_Buzzer.publish(UInt16())
            
        
​
def main():
    rclpy.init()
    laser_warn = laserWarning("laser_Warnning")
    print ("start it")
    try:
        rclpy.spin(laser_warn)
    except KeyboardInterrupt:
        pass
    finally:
        rclpy.shutdown()

 

 

 

 

 

 

 

 

 

Robot URDF model
SLAM Gmapping

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
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文