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.