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

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

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

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

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 *

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.

edit retag flag offensive close merge delete

Comments

Note that your pose matrix is invalid.

Lorenz gravatar image Lorenz  ( 2012-10-24 02:24:52 -0600 )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 -0600 )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 -0600 )edit

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.

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

You are right. The name just confused me :)

Lorenz gravatar image Lorenz  ( 2012-10-24 02:57:18 -0600 )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 -0600 )edit

2 Answers

Sort by » oldest newest most voted
3

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

Lorenz gravatar image

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.

edit flag offensive delete link more
0

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

Albert K gravatar image

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

From this rospy overview:

http://www.ros.org/wiki/rospy/Overview/Services

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

Comments

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 -0600 )edit

Question Tools

Stats

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

Seen: 2,490 times

Last updated: Oct 24 '12