Skip to content

Instantly share code, notes, and snippets.

@Martzi
Last active January 21, 2021 16:39
Show Gist options
  • Save Martzi/90d8943a93cb91fd54327f5f1602450b to your computer and use it in GitHub Desktop.
Save Martzi/90d8943a93cb91fd54327f5f1602450b to your computer and use it in GitHub Desktop.
def point_cloud_msg(points, parent_frame='base_link'):
ros_dtype = sensor_msgs.PointField.FLOAT32 # csak ezt eszi meg az rviz
dtype = np.float32
itemsize = np.dtype(dtype).itemsize
data = points.astype(dtype).tobytes()
fields = [sensor_msgs.PointField(
name=n, offset=i*itemsize, datatype=ros_dtype, count=1)
for i, n in enumerate('rgbxyza')]
header = std_msgs.Header(frame_id=parent_frame, stamp=rospy.Time.now())
return sensor_msgs.PointCloud2(
header=header,
height=points.shape[0],
width=points.shape[1],
is_dense=False,
is_bigendian=False,
fields=fields,
point_step=points.dtype.itemsize,
row_step=(points.dtype.itemsize * points.shape[1]),
data=data
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment