Advertisements
The following is an example to publish two points. To publish more than two points, simply stack the points vertically in a nx3 ndarray.
#!/usr/bin/env python
import rospy
import math
import sys
from sensor_msgs.msg import PointCloud2
import std_msgs.msg
import sensor_msgs.point_cloud2 as pcl2
if __name__ == '__main__':
rospy.init_node('node_name')
pcl_pub = rospy.Publisher("/your_PC_topic", PointCloud2)
cloud_with_two_points= [[1.0, 1.0, 0.0],[1.0, 2.0, 0.0]]
#header
header = std_msgs.msg.Header()
header.stamp = rospy.Time.now()
header.frame_id = 'your_frame'
#create pcl using cloud_with_two_points
scaled_polygon_pcl = pcl2.create_cloud_xyz32(header, cloud_with_two_points)
#publish
pcl_pub.publish(scaled_polygon_pcl)
To check if you are publishing the points, you could open Rviz and add the topic to the visualizer. To only check if the topic is published, echo the data from the topic:
Advertisements
rostopic echo /your_PC_topic
Good luck!
Advertisements
Want to receive notifications when I post?
Leave a comment