Ask Your Question

how to get turtlebot pose

asked 2015-09-08 03:09:03 -0500

baowei lin gravatar image

updated 2015-09-09 01:51:34 -0500

I would like to get turtlebot poses when it walking. The following codes are used, but there is no responds. I guess it was the problem of topic "/odom". could anybody give me some ideas to fix it? thanks.

virtual void onInit()
      ros::NodeHandle& nh = getNodeHandle();
      ros::NodeHandle& private_nh = getPrivateNodeHandle();           
      cmdpub_ = private_nh.advertise<geometry_msgs::Twist> ("cmd_vel", 1);
      sub_= nh.subscribe<PointCloud>("depth/points", 1, &TurtlebotFollower::cloudcb, this);
      ros::Subscriber sub  = nh.subscribe("/odom",10, &TurtlebotFollower::poseCallback,this);

void poseCallback(const geometry_msgs::TwistPtr& msg){
      std::cout << msg.linear.x << "\t" <<msg.linear.y<< "\t" << 0.0 << "\t" << std::endl;

I found that if I put above codes into the onInit() virtual function, it will be failed. But if I put it in an main() function, it will be succeed. What is the difference?

edit retag flag offensive close merge delete


Did your poseCallback work even if the message type is geometry_msgs::Twist? You are trying to use nodelets. You have to run them differently. Please follow the link to learn about running nodelets.

Willson Amalraj gravatar image Willson Amalraj  ( 2015-09-09 02:56:15 -0500 )edit

sorry, the "succeed" means that I've changed them to nav_msgs. I will check nodelets, thank you Willson.

baowei lin gravatar image baowei lin  ( 2015-09-09 07:10:34 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-09-09 19:34:45 -0500

baowei lin gravatar image

I fixed the problem by changing getNodeHandle() to getMTNodeHandle(), which means if you want to subscribe multiple topics, you need a multiple thread callback queue. Thank you Willson again.

edit flag offensive delete link more

answered 2015-09-08 04:15:55 -0500

Willson Amalraj gravatar image

updated 2015-09-08 04:17:06 -0500

Check the type of "/odom" topic. Use rostopic type /odom. I donot have access to my turtlebot at present. But if I am not wrong, /odom topic is of type nav_msgs/Odometry.

Try the following

void poseCallback(const nav_msgs::OdometryConstPtr& msg){  std::cout << msg->pose.pose.position.x << std::endl }
edit flag offensive delete link more


Thank you Willson, but I failed based on your code. It seems that poseCallback could not be called. Do I need to configure anywhere else?

baowei lin gravatar image baowei lin  ( 2015-09-08 19:15:17 -0500 )edit

I cannot comment on that without seeing your TutlebotFollower class. May be you comment out all other subscribers and publishers to check if poseCallback works. (on a side note, instead of using two callbacks you can use message_filters to send messages from two topics to the same callback)

Willson Amalraj gravatar image Willson Amalraj  ( 2015-09-08 20:23:35 -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


Asked: 2015-09-08 03:09:03 -0500

Seen: 892 times

Last updated: Sep 09 '15