How to extract data from/points2 topics and send it to client through the service?

asked 2022-12-16 05:48:47 -0500

lfh gravatar image

Working environment: two computers of ubuntu20.04; Camera: azure kinect.

I need to use a computer as the service and another computer as the client ; As soon as the client sends a message, the service collects and processes all kinds of information and sends them back to the client for data calculation.

At present, I have successfully implemented the transmission of RGB data and depth data in list format, as well as width and height data in uint16.

Now I need to add the function of transmitting point cloud data, but I don't know what to do.

At present, I have added "float32 [] pointcloud" to the srv file

I also added some things to the service program, but I tried many online tutorials and always reported errors.

def points_image(msg):
  global points_array
  points_data=point_cloud2.read_points_list(msg,field_names=("x","y","z","r","g","b","depth"))
  points_array = np.array(points_data,dtype=np.float32)
def execute():
  ... ...
  ... ...
  rospy.Subscriber("/points2", PointCloud2,callback=points_image,queue_size=5)
  time.sleep(2)
  points = list(points_array.reshape(-1))
  return Response(points,rgb,d,width,height)

How should I write it?

edit retag flag offensive close merge delete