ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

subscibe from Model state in Gazebo

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

hmmm gravatar image

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

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
3

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

DimitriProsser gravatar image

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

You should have a look at the tutorials here.

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit

link is broken now.

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

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

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

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

hmmm gravatar image

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

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");

ros::spin();

return 0; }

edit flag offensive delete link more

Comments

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

mjcarroll gravatar image mjcarroll  ( 2012-03-07 01:14:50 -0600 )edit

Question Tools

Stats

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

Seen: 4,702 times

Last updated: Mar 22 '12