Robotics StackExchange | Archived questions

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

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.

Asked by Jaskirat Singh on 2017-07-06 04:47:08 UTC

Comments

Answers

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.

Asked by chapulina on 2017-07-06 10:09:55 UTC

Comments