[英]Turtlebot subscriber pointcloud2 shows color in Gazebo simulator but not in robot
我正在使用ASUS Xtion PRO LIVE相机在turbobot(深度学习版)上订阅主题"/camera/depth/points"
和消息PointCloud2
。
我在凉亭模拟器环境下使用了下面的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()
发布主题的内容由提供它们的软件(即相机的驱动程序)确定。 因此,要解决此问题,您需要获取正确的驱动程序,并使用其包含所需信息的主题。
您可以在ROS Wiki或某些社区网站上找到推荐的相机驱动程序-像这样 。 在您的情况下,ASUS设备应使用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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.