Hello, I am trying to programmatically get information about the pose of a PR2 in Gazebo. The examples on the wiki seem to be based upon command line using rosservice. Based upon the Publisher/Subscriber example on the ROS wiki I would imagine it would be something like:
rospy.Subscriber("gazebo/model_states", Pose, callback)
but when I try something similar to this Gazebo sends and error msg and breaks the connection. I would think it is just finding the right combination of topic and msg but I am having troubles figuring that out. Any help would be appreciate.
gazebo expects a ModelStates topic, not Pose, try changing your callback to accept ModelStates and see if it fixes the issue. To access the returned variables, please take a look at the following python service client example:
#!/usr/bin/env python
import roslib; roslib.load_manifest('gazebo')
import sys
import rospy
from gazebo.srv import *
def gms_client(model_name,relative_entity_name):
rospy.wait_for_service('/gazebo/get_model_state')
try:
gms = rospy.ServiceProxy('/gazebo/get_model_state', GetModelState)
resp1 = gms(model_name,relative_entity_name)
return resp1
except rospy.ServiceException, e:
print "Service call failed: %s"%e
def usage():
return "%s [model_name] [relative_entity_name]"%sys.argv[0]
if __name__ == "__main__":
if len(sys.argv) == 3:
model_name = sys.argv[1]
relative_entity_name = sys.argv[2]
else:
print usage()
sys.exit(1)
res = gms_client(model_name,relative_entity_name)
print "returnd x position ",res.pose.position.x
Asked: 2011-04-20 11:24:00 -0500
Seen: 288 times
Last updated: Apr 26 '11
ROS Answers is licensed under Creative Commons Attribution 3.0 Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.