Receiving Meshes via ROS in Python
I am using Voxblox_ros
(https://github.com/ethz-asl/voxblox) which is a real-time mesh generator, and it saves a .ply
file under a folder.
What I want to achieve is to read the mesh that is saved under that folder. I've looked it up and found that there is a message type called shape_msgs/Mesh
, which sounded like something I could use. However, I am having question marks in my head about how exactly to fill in the data to this message.
I created a msg (MeshInfo.msg
):
string mesh_id
shape_msgs/Mesh part_mesh
and a srv(MeshArray.srv
):
---
MeshInfo[] mesh_array
which I refer in the code as:
self.mesh_srv = rospy.Service("voxblox_ros/generate_mesh", MeshArray, self.mesh_processor_srv) # get the mesh
I've come up with this kind of code which I have not tested yet, just wanted to illustrate what I have in mind:
def mesh_processor_srv(self, req):
# this service does not return anything by itself, it only saves the mesh to the designated folder
# so, one must implement a mechanism here to import the mesh which is saved in that folder
rospy.wait_for_service('voxblox_ros/generate_mesh')
MeshArrayResponse = rospy.ServiceProxy('voxblox_ros/generate_mesh', MeshArray)
# navigate to voxblox_ros package, under mesh_results, there should be mesh file stored as .ply
files = os.listdir(home + "/ros_ws/src/voxblox/voxblox_ros/mesh_results/") # get the mesh files
meshlist = [] # to keep the meshes in
# loop over each mesh, import and create our mesh object
for i in range(len(files)):
mesh = MeshInfo()
mesh.mesh_id = "mesh_" + os.path.splitext(os.path.basename(files[i]))[0] # get the mesh name from the file
mesh.part_mesh = PlyData.read(home + "/ros_ws/src/voxblox/voxblox_ros/mesh_results/" + files[i]) # get the mesh data
meshlist.append(mesh)
response = MeshArrayResponse()
response.mesh_array = meshlist
return response
which I am not sure of. Did someone have similar task and had somehow figured out how to crack?