#!/usr/bin/env python
#-*- coding:utf-8 -*-
import rospy
import time
from sensor_msgs.msg import LaserScan
lidar_points = None
def lidar_callback(data):
global lidar_points
lidar_points = data.ranges #주어진 각도마다 거리정보를 담고있는 리스트
rospy.init_node('my_lidar', anonymous=True)
rospy.Subscriber("/scan", LaserScan, lidar_callback, queue_size=1)
while not rospy.is_shutdown():
if lidar_points == None:
continue
rtn = ""
for i in range(12): # 30도씩 건너뛰면서 12개 거리값만 출력
rtn += str(format(lidar_points[i*30],'.2f')) + ", "
print(rtn[:-2])
time.sleep(1.0)
<launch>
<include file="$(find xycar_lidar)/launch/lidar_noviewer.launch" />
<node name="my_lidar" pkg="my_lidar" type="lidar_scan.py" output="screen"/>
</launch>
include 문 : xycar_lidar 패키지를 자동으로 찾아준다.