简体   繁体   English

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

[英]Turtlebot subscriber pointcloud2 shows color in Gazebo simulator but not in robot

I am subscribing to topic "/camera/depth/points" and message PointCloud2 on a turtlebot (deep learning version) with ASUS Xtion PRO LIVE camera. 我正在使用ASUS Xtion PRO LIVE相机在turbobot(深度学习版)上订阅主题"/camera/depth/points"和消息PointCloud2

I have used the python script below under the gazebo simulator environment and i can receive x, y, z and rgb values successfully. 我在凉亭模拟器环境下使用了下面的python脚本,我可以成功接收x,y,z和rgb值。

However, when i run it in the robot, the rgb values are missing. 但是,当我在机器人中运行它时,rgb值丢失了。

Is this a problem of my turtlebot version, or camera or is it that i have to specify somewhere that i want to receive PointCloud2 type="XYZRGB" ? 这是我的turtlebot版本或相机的问题,还是我必须指定要接收PointCloud2 type="XYZRGB" or is it a sync problem? 还是同步问题? Any clues please thanks! 任何线索,请谢谢!

#!/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()

The contents of Published topics are determined by the software that provides them - ie the drivers for your camera. 发布主题的内容由提供它们的软件(即相机的驱动程序)确定。 To fix this you therefore need to get the right driver and use the topic that it says contains the required information. 因此,要解决此问题,您需要获取正确的驱动程序,并使用其包含所需信息的主题。

You can find recommended drivers for your cameras on the ROS wiki or on some community websites - like this . 您可以在ROS Wiki或某些社区网站上找到推荐的相机驱动程序-像这样 In your case, the ASUS devices should use openni2 and set depth_registration:=true - as documented here . 在您的情况下,ASUS设备应使用openni2并设置depth_registration:=true 处所述

At this point, /camera/depth_registered/points should now show the combined xyz and RGB point cloud. 此时, /camera/depth_registered/points现在应该显示xyz和RGB点云的组合。 To use it, your new listener() code should look something like this: 要使用它,新的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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM