Ask Your Question
0

how to get turtlebot pose

asked 2015-09-08 03:09:03 -0600

baowei lin gravatar image

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

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

Comments

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 imageWillson Amalraj ( 2015-09-09 02:56:15 -0600 )edit

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

baowei lin gravatar imagebaowei lin ( 2015-09-09 07:10:34 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

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

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
1

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

Willson Amalraj gravatar image

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

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

Comments

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 imagebaowei lin ( 2015-09-08 19:15:17 -0600 )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 imageWillson Amalraj ( 2015-09-08 20:23:35 -0600 )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: 2015-09-08 03:09:03 -0600

Seen: 807 times

Last updated: Sep 09 '15