mirror of
https://github.com/6-robot/wpr_simulation.git
synced 2025-09-15 12:59:01 +08:00
19 lines
528 B
Python
Executable File
19 lines
528 B
Python
Executable File
#!/usr/bin/env python3
|
|
# coding=utf-8
|
|
|
|
import rospy
|
|
from sensor_msgs.msg import LaserScan
|
|
|
|
# 激光雷达回调函数
|
|
def lidar_callback(msg):
|
|
number = len(msg.ranges)
|
|
rospy.loginfo("雷达测距数量 = %d",number)
|
|
middle = number//2
|
|
rospy.logwarn("正前方测距数值 = %f 米",msg.ranges[middle])
|
|
|
|
# 主函数
|
|
if __name__ == "__main__":
|
|
rospy.init_node("lidar_data")
|
|
# 订阅激光雷达的数据话题
|
|
lidar_sub = rospy.Subscriber("scan",LaserScan,lidar_callback,queue_size=10)
|
|
rospy.spin() |