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

How to get model state of gazebo object code not working.

asked 2017-07-06 04:47:08 -0600

Jaskirat Singh gravatar image

updated 2017-07-06 06:22:53 -0600

This code I wrote to find the position of the turtlebot using the rosservice gazebo_msgs/getmodelstate. But it always returns a failure. Please help.

ros::init(argc,argv,"finder");
ros::NodeHandle n;
ros::ServiceClient client=n.serviceClient<gazebo_msgs::GetModelState>("/gazebo_msgs/GetModelState");
gazebo_msgs::GetModelState gms;
gms.request.model_name="mobile_base";
if (client.call(gms))
{
    ROS_INFO("X= %lf ;",gms.response.pose.position.x);
}
else{
    ROS_INFO("FAILED");
}

Edit: the client.call() function returns zero, there is no other problem regarding messages,etc.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-06 10:09:55 -0600

The string you pass to serviceClient should be the /gazebo/get_model_state service, but you're passing the message type.

You can check the list of services available by calling rosservice list from another terminal.

Take a look at this tutorial for more information.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-07-06 04:47:08 -0600

Seen: 1,783 times

Last updated: Jul 06 '17