Ask Your Question
0

How to get gazebo topic using c++ and ros ?

asked 2016-03-09 10:16:38 -0500

zuygar gravatar image

Hi, I am using ROS, gazebo and c++ together to perform some tasks. In gazebo I launched "turtlebot_world.launch. It published " /gazebo/default/pose/info " which gives the information of robots position in gazebo. How can I take this topic in c++, does anyone knows ?

Also I have the function below but doesn't take any information or topic:

void subscribe_gazebo_pose()
{
    ros::NodeHandle ndh;
    ros::ServiceClient gms_c = ndh.serviceClient<gazebo_msgs::GetModelState>("gazebo/default/pose/info");
    //gms_c.waitForExistence();
    gazebo_msgs::GetModelState getmodelstate;
    gms_c.call(getmodelstate);

    geometry_msgs::Pose pose;
    pose.position.x = getmodelstate.response.pose.position.x;
    pose.position.y = getmodelstate.response.pose.position.y;
    cout << pose.position.x << endl;
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-03-10 03:56:37 -0500

I think you might be confusing message topics with services. is /gazebo/default/pose/info a topic, can you see if when you run "rostopic list" from a command line?

The code you have posted above attaches to a service provider not a message topic.

edit flag offensive delete link more

Comments

I can't see any topic like above running "rostopic list". But if I run "gztopic list" I can see some topics like this:

/gazebo/default/pose/local/info

/gazebo/default/pose/info

/gazebo/default/gui

/gazebo/default/response

/gazebo/default/world_stats

/gazebo/default/selection

zuygar gravatar imagezuygar ( 2016-03-10 06:54:23 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-09 10:16:38 -0500

Seen: 651 times

Last updated: Mar 10 '16