ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to request a service with complex service type(in python)?

asked 2012-10-23 19:39:01 -0500

updated 2014-01-28 17:14:02 -0500

ngrennan gravatar image

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 *

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

request = GenerateSemanticMapOWLRequest() = "map" = [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.

edit retag flag offensive close merge delete


Note that your pose matrix is invalid.

Lorenz gravatar image Lorenz  ( 2012-10-24 02:24:52 -0500 )edit

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?

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-10-24 02:48:23 -0500 )edit

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.

Lorenz gravatar image Lorenz  ( 2012-10-24 02:50:42 -0500 )edit

Yes it is a java method. On this page,, it says the Returns of quaternionToMatrix is a 4x4 pose matrix.

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-10-24 02:55:43 -0500 )edit

You are right. The name just confused me :)

Lorenz gravatar image Lorenz  ( 2012-10-24 02:57:18 -0500 )edit

Thanks for reminding me of the matrix~ I 'll update the code once I got the valid value: )

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-10-24 03:00:11 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2012-10-23 22:37:18 -0500

Lorenz gravatar image

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

request = GenerateSemanticMap() = "map" = [SemMapObject(id=1, type='Cupboard')]

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.

edit flag offensive delete link more

answered 2012-10-23 20:45:35 -0500

Albert K gravatar image

updated 2012-10-23 20:47:12 -0500

From this rospy overview:

Scroll down and look at < 2.1 Calling services >

There are three different ways to call the service. I think it is the < Explicit style > that you may need.

edit flag offensive delete link more


The example in this overview is exactly the simple type of service I mentioned in my question, that is not a structural type.Anyway, thanks!

Po-Jen Lai gravatar image Po-Jen Lai  ( 2012-10-23 21:02:35 -0500 )edit

Question Tools


Asked: 2012-10-23 19:39:01 -0500

Seen: 2,435 times

Last updated: Oct 24 '12