ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

subscibe from Model state in Gazebo

asked 2012-03-06 02:53:06 -0500

hmmm gravatar image

updated 2012-03-06 05:57:13 -0500

mjcarroll gravatar image

how can i subscribe to /gazebo/model_states ? Sorry, i am a beginner an did not understand it, yet.I read the tutorial but it does not help me.I want to get the x,y and z Position of my model. For beginning i write this.But how to go on ?

ros::Subscriber xyz_subscriber_;

void ModelStatecallback(const gazebo_msgs::ModelStates::ConstPtr& msg)


xyz_subscriber_ = node_handle_.subscribe</gazebo/model_states>("currentposition", 1, ModelStatecallback);


edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2012-03-06 05:51:00 -0500

DimitriProsser gravatar image

updated 2012-03-06 05:51:20 -0500

You should have a look at the tutorials here.

edit flag offensive delete link more


hi, i read that tutorial, but i dont understand,wheter the topicname is a standard name or just free created?it would be very helpful to understand this stuff ,by explaning me at this special example.

hmmm gravatar image hmmm  ( 2012-03-06 08:37:32 -0500 )edit

The topic names are set by the nodes that host those topics. Gazebo defines its own topic names, and you must subscribe to them. If you look in the documentation for any node, it lists the services and topics that it hosts and how to use them.

DimitriProsser gravatar image DimitriProsser  ( 2012-03-06 08:58:52 -0500 )edit

link is broken now.

malharjajoo gravatar image malharjajoo  ( 2018-04-09 13:33:31 -0500 )edit
Dayo gravatar image Dayo  ( 2021-04-27 19:35:17 -0500 )edit

answered 2012-03-22 15:55:50 -0500

hsu gravatar image

Hi, the topic you need to subscribe to is listed here. In this case, you probably want to do something like below:

xyz_subscriber_ = node_handle_.subscribe("/gazebo/model_states", 10, ModelStatecallback);

hope this helps.

edit flag offensive delete link more

answered 2012-03-06 20:08:24 -0500

hmmm gravatar image

updated 2012-03-06 20:10:01 -0500

Is this the write way? i cant find the mistake.Can anyone please help me , especially at this example?

ros::NodeHandle node_handle_; ros::Subscriber xyz_subscriber_;

xyz_subscriber_ = node_handle_.subscribe("ModelStates", 10, ModelStatecallback);

void ModelStatecallback(const gazebo_msgs::ModelStates::ConstPtr& msg) { double actual_value_x=msg.pose[0].position.x; double actual_value_y=msg.pose[0].position.y; double actual_value_z=msg.pose[0].position.z; }

int main(int argc, char **argv) { ros::init(argc, argv, "positioncontrol");


return 0; }

edit flag offensive delete link more


Please don't use answers to continue a conversation. Instead, please edit your original question to add more information, if necessary. Thanks for keeping organized.

mjcarroll gravatar image mjcarroll  ( 2012-03-07 01:14:50 -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


Asked: 2012-03-06 02:53:06 -0500

Seen: 4,384 times

Last updated: Mar 22 '12