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

How do you change a rosservice parameter in python?

asked 2016-07-10 22:03:18 -0500

M@t gravatar image

updated 2016-07-12 00:04:41 -0500

I'm using the robot_localization package, specifically the ekf_localization and navsat_transform nodes. I want to re-set the datum parameter in navsat_transform, I know that I can achieve this using:

rosservice call /datum <tab>

But I want to also be able to re-set it from a python script. The datum has a service to re-set it (the service message is here). I've tried working it out by working through the ROS python service tutorials, and the closest I've got to success is this:

    geo_pose = rospy.ServiceProxy('datum', GeoPose)
    geo_pose = preset_pose
except rospy.ServiceException, e:
    print "Service call failed: %s"%e

Which is definitely wrong because it produces this error message:

Traceback (most recent call last):
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 239, in     <module>
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 230, in run
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 201, in execute_user_command
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 146, in set_frame_origin
    geo_pose = rospy.ServiceProxy('datum', GeoPose)
   File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/", line 404, in __init__
    super(ServiceProxy, self).__init__(name, service_class)
   File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/", line 59, in __init__
    self.request_class = service_class._request_class
AttributeError: type object 'GeoPose' has no attribute '_request_class'

And I'm not sure If the message is telling me that I've got the syntax/code wrong or if I can't actually change the datum parameter via rospy. For reference, here are my system details:

Robot: Clearpath Jackal UGV

OS: Ubuntu 14.04 on laptop, Ubuntu server on robot

ROS distro: Indigo Igloo

robot_localization version: 2.2.2 binaries

Thank you in advance for any advice or help!


In response to ahendrix's answer:

Thanks for the help again ahendrix! When I try the code you posted as-is I get this error:

 Traceback (most recent call last):
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 397, in <module>
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 388, in run
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 306, in execute_user_command
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 255, in reset_map_frame
     geo_pose = rospy.ServiceProxy('datum', SetDatum)
 NameError: global name 'SetDatum' is not defined

Now obviously this is because nothing has defined 'SetDatum' yet, and I assume this has to be defined by SetDatum.srv, but when I try to import it I just get this error:

Traceback (most recent call last):
  File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/", line 22, in <module>
    from SetDatum.srv import *
ImportError: No module named SetDatum.srv

Despite that the file does exist in the ROS files. I've also found a file in the robot_localization services folder labelled, in that ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-07-10 22:53:42 -0500

ahendrix gravatar image

updated 2016-07-12 00:53:04 -0500

The error message is telling you that GeoPose isn't a serivce type.

If you want to call a service with the SetDatum type, you should create your service proxy with the SetDatum type:

    geo_pose = rospy.ServiceProxy('datum', SetDatum)
    response = geo_pose(preset_pose) # preset_pose should be a GeoPose object
except rospy.ServiceException, e:
    print "Service call failed: %s"%e


The proper import for SetDatum should be:

from robot_localization.srv import SetDatum
edit flag offensive delete link more


Yeap, that did the trick, thanks again ahendrix!

M@t gravatar image M@t  ( 2016-07-12 23:22:05 -0500 )edit

Question Tools

1 follower


Asked: 2016-07-10 22:03:18 -0500

Seen: 1,312 times

Last updated: Jul 12 '16