Turtlebot订户pointcloud2在Gazebo模拟器中显示颜色,但在机器人中没有

far*_*edo 6 python rgb point-clouds ros point-cloud-library

我正在使用华硕Xtion PRO LIVE相机订阅turtlebot(深度学习版)上的主题"/camera/depth/points"和消息PointCloud2.

我在gazebo模拟器环境下使用了下面的python脚本,我可以成功接收x,y,z和rgb值.

但是,当我在机器人中运行它时,缺少rgb值.

这是我的turtlebot版本或相机的问题还是我必须指定我想要接收的地方PointCloud2 type="XYZRGB"?还是同步问题?有任何线索,谢谢!

#!/usr/bin/env python
import rospy
import struct
import ctypes
import sensor_msgs.point_cloud2 as pc2
from sensor_msgs.msg import PointCloud2

file  = open('workfile.txt', 'w')

def callback(msg):

    data_out = pc2.read_points(msg, skip_nans=True)

    loop = True
    while loop:
        try:
            int_data = next(data_out)
            s = struct.pack('>f' ,int_data[3])
            i = struct.unpack('>l',s)[0]
            pack = ctypes.c_uint32(i).value

            r = (pack & 0x00FF0000)>> 16
            g = (pack & 0x0000FF00)>> 8
            b = (pack & 0x000000FF)

            file.write(str(int_data[0])+","+str(int_data[1])+","+str(int_data[2])+","+str(r)+","+str(g)+","+str(b)+"\n")

        except Exception as e:
            rospy.loginfo(e.message)
            loop = False
            file.flush
            file.close

def listener():

    rospy.init_node('writeCloudsToFile', anonymous=True)
    rospy.Subscriber("/camera/depth/points", PointCloud2, callback)
    rospy.spin()

if __name__ == '__main__':
    listener()
Run Code Online (Sandbox Code Playgroud)

Pet*_*ain 2

已发布主题的内容由提供它们的软件决定,即相机的驱动程序。因此,要解决此问题,您需要获取正确的驱动程序并使用它所说的包含所需信息的主题。

您可以在ROS wiki或一些社区网站上找到为您的相机推荐的驱动程序 - 像这样。在您的情况下,华硕设备应使用 openni2 并设置depth_registration:=true- 如此处所述

此时,/camera/depth_registered/points应该显示组合的 xyz 和 RGB 点云。要使用它,您的新listener()代码应如下所示:

def listener():
    rospy.init_node('writeCloudsToFile', anonymous=True)
    # Note the change to the topic name
    rospy.Subscriber("/camera/depth_registered/points", PointCloud2, callback)
    rospy.spin()
Run Code Online (Sandbox Code Playgroud)