使用numpy数组发布自定义ROS消息时出现ROSSerializationException

时间:2018-07-27 15:54:20

标签: python numpy ros

我正在尝试发布使用我创建的自定义消息OccupancyGrid3D的ROS消息:

std_msgs/Header header
MapMetaData info
  time map_load_time
  float32 resolution
  float32[] time_resolutions
  uint32 depth
  uint32 width
  uint32 height
  geometry_msgs/Pose origin
int8[] data

我正在使用此发布者发布它:

from rospy.numpy_msg import numpy_msg
self.pub_motion_prediction = rospy.Publisher("motion_prediction", numpy_msg(OccupancyGrid3D), queue_size=3)

然后再调用它:

def pub_3d_grid(self, velocities):
    grid = OccupancyGrid3D()
    grid.header.stamp = rospy.Time.now()
    grid.header.frame_id = "map"
    grid.info.map_load_time = rospy.Time.now()
    grid.info.resolution = self.resolution
    grid.info.time_resolutions = velocities
    #grid.info.time_resolutions = np.array(velocities, dtype=np.float32)
    grid.info.depth = self.TIMES
    grid.info.width = self.shape_map[0]
    grid.info.height = self.shape_map[1]
    grid.info.origin.position.x = self.x0
    grid.info.origin.position.y = self.y0
    grid.info.origin.orientation.w = 1
    grid.data = np.minimum(100, self.probability_grid_3d.flatten().astype(np.int8), dtype=np.int8)
    self.pub_motion_prediction.publish(grid)

我的订户在一个单独的节点中如下:

rospy.Subscriber("motion_prediction", numpy_msg(OccupancyGrid3D), self.callback, queue_size=3)

但是,每当我运行具有该主题的侦听器的节​​点时,都会收到错误:ROSSerializationException: field data must be a list or tuple type,据我所知,这表示我在ROS想要发布时试图发布一个numpy数组。使用清单。但是我想使用一个numpy数组,以便可以指定数据类型。有人可以帮我弄清楚我在做什么错吗?

0 个答案:

没有答案