0
$\begingroup$

Rosanswers logo

I want to request this service, so I wrote a snippet of code to do this:

Edit (The code works if you create a package named generate_semantic_map by "roscreate-pkg generate_semantic_map mod_semantic_map, and put this file in the package)

#!/usr/bin/env python
import roslib; 
roslib.load_manifest('generate_semantic_map') #For loading srv in generate_semantic_map 

import rospy
from mod_semantic_map.srv import *
from mod_semantic_map.msg import *

rospy.wait_for_service('/knowrob_semantic_map_to_owl/generate_owl_map')
request_sem_map=rospy.ServiceProxy('knowrob_semantic_map_to_owl/generate_owl_map', GenerateSemanticMapOWL)

request = GenerateSemanticMapOWLRequest()
request.map.header.frame_id = "map"
request.map.objects = [SemMapObject(id=1, type='Cupboard', width=1.0, depth=1.0, height=1.0, pose = [0.99999856179, -8.178859999999999e-07, -0.0016959996980000001, 1.0, 3.18211e-06, 0.99999902838, 0.00139399691, 1.0, 0.00169599691, -0.001394000302, 0.999997590174, 1.0, 0, 0, 0, 1])]

owlmap = request_sem_map(request)
print owlmap

The question is, I don't know how to generate the request. I know how to request simple service type since I already learn from the tutorial, but I don't know how to handle structural request.

In C++, I can create a object of request type and fill the data member in this object, and then send this object as request, but I don't know how to do this in python.

This seems to be a stupid question...but I don't know how to solve it, thanks in advance.


Originally posted by Po-Jen Lai on ROS Answers with karma: 1371 on 2012-10-23

Post score: 1


Original comments

Comment by Lorenz on 2012-10-24:
Note that your pose matrix is invalid.

Comment by Po-Jen Lai on 2012-10-24:
Oh thanks, I should use the function static double [] edu::tum::cs::ias::knowrob::tutorial::ROSClient::quaternionToMatrix(Point p,Quaternion q) to get the matrix. The weird thing is, I can visualize the object in visualization canvas now, maybe the visualizer ignores this error?

Comment by Lorenz on 2012-10-24:
Possibly. The method you mention is a java method not a python method, right? And it will give you only a 3x3 matrix which is missing the translational component.

Comment by Po-Jen Lai on 2012-10-24:
Yes it is a java method. On this page, http://ros.informatik.uni-freiburg.de/roswiki/doc/api/knowrob_tutorial/html/classedu_1_1tum_1_1cs_1_1ias_1_1knowrob_1_1tutorial_1_1ROSClient.html, it says the Returns of quaternionToMatrix is a 4x4 pose matrix.

Comment by Lorenz on 2012-10-24:
You are right. The name just confused me :)

Comment by Po-Jen Lai on 2012-10-24:
Thanks for reminding me of the matrix~ I 'll update the code once I got the valid value: )

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

As mentioned in the other answer already, you need to use the explicit style:

request = GenerateSemanticMap()
request.map.header.frame_id = "map"
request.map.objects = [SemMapObject(id=1, type='Cupboard')]
request_sem_map(request)

Note that the code above is not complete. The slot objects should contain a list of all objects and I didn't put all required initializers in the construction of SemMapObject. Also note that in contrast to normal ROS standards, the pose is a flat array representing a 4x4 homogeneous transformation matrix, row based instead of a geometry_msgs/Pose. In the code above, it will be a list with 16 numbers.


Originally posted by Lorenz with karma: 22731 on 2012-10-23

This answer was ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.