Re: [ros-users] Programmatically get ModelState from Gazebo

Top Page
Attachments:
Message as email
+ (text/plain)
+ (text/html)
+ gms.py (text/x-python)
Delete this message
Reply to this message
Author: User discussions
Date:  
To: User discussions
Subject: Re: [ros-users] Programmatically get ModelState from Gazebo
Hi Ian,
see attached simple python script for example, with pr2 running (roslaunch
pr2_gazebo pr2_empty_world.launch),
$ ./gms.py pr2 world
returnd x position -0.00678816834842

Also, can you please re-post your question on answers.ros.org? I think
that's where things should be these days.

Thanks,
John


On Mon, Apr 25, 2011 at 4:27 PM, Ian Jones <> wrote:

> Thanks for the reply, it worked as far as compilation went but I am still
> not positive at how to get at the data further in ModelState. For example I
> want to get Pose data more specifically position (x,y,z). Position is
> nested inside of pose which is nested inside ModelState, So if i wanted to
> just get the robots current x position, what sort of call would i need?
> Thank you for your time.
> Ian
>
> _______________________________________________
> ros-users mailing list
>
> https://code.ros.org/mailman/listinfo/ros-users
>
>

#!/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