How do you change a rosservice parameter in python?
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 ...