Ask Your Question
0

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

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

Jaskirat Singh gravatar image

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

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 -0500

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 865 times

Last updated: Jul 06 '17