Ask Your Question
0

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:

rospy.wait_for_service('datum')
try:
    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/waypoint_manager.py", line 239, in     <module>
    node.run()
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/waypoint_manager.py", line 230, in run
    self.execute_user_command()
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/waypoint_manager.py", line 201, in execute_user_command
    self.set_frame_origin()  
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/waypoint_manager.py", line 146, in set_frame_origin
    geo_pose = rospy.ServiceProxy('datum', GeoPose)
   File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 404, in __init__
    super(ServiceProxy, self).__init__(name, service_class)
   File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/service.py", 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!

UPDATE 1

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/waypoint_manager.py", line 397, in <module>
     node.run()
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/waypoint_manager.py", line 388, in run
     self.execute_user_command()
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/waypoint_manager.py", line 306, in execute_user_command
     self.reset_map_frame()
   File "/home/matt/autosys_repo1/custom_jackal_ws/src/waypoint_manager/src/waypoint_manager.py", 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/waypoint_manager.py", 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 _SetDatum.py, in that ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

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:

rospy.wait_for_service('datum')
try:
    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

EDIT

The proper import for SetDatum should be:

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

Comments

Yeap, that did the trick, thanks again ahendrix!

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 499 times

Last updated: Jul 12 '16