您的位置:首页 > 其它

write a tf listener

2015-07-03 19:06 1206 查看
写tf listener时遇到的问题:

参考网页:http://wiki.ros.org/tf/Tutorials/Writing%20a%20tf%20listener%20%28C%2B%2B%29

1.
How to publish the pose (position) of the robot after having the tf listener to "listener.lookupTransform("/map", "/base_link", ros::Time(0), transform);"?

解决方法:

use the standard ROS messages to represent pose info. You can use either geometry_msgs/Pose (http://docs.ros.org/jade/api/geometry_msgs/html/msg/Pose.html)or
geometry_msgs/PoseWithCovariance (http://docs.ros.org/indigo/api/geometry_msgs/html/msg/PoseWithCovariance.html : if you need to publish pose together with its covariance )

so if you have populated transform variable with a call to lookupTransform, you can for example store the pose (without covariance) as follows,

geometry_msgs::Pose pose;

pose.position.x = transform.getOrigin().x();

pose.position.y = transform.getOrigin().y();

pose.position.z = transform.getOrigin().z();

// these two are valid only if the robot is operating in 2D

double yaw = tf::getYaw( transform.getRotation() );

pose.orientation = tf::createQuaternionMsgFromYaw( yaw );

now you can publish the 2D pose as a geometry_msgs/Pose message

2. 运行写好的程序时,遇到错误:"map" passed to lookupTransform argument target_frame does not exist.

解决方法:

- 加上listener.waitForTransform(...)

try {
listener.waitForTransform(destination_frame, original_frame, ros::Time(0), ros::Duration(10.0) );
listener.lookupTransform(destination_frame, original_frame, ros::Time(0), transform);
} catch (tf::TransformException ex) {
ROS_ERROR("%s",ex.what());
}

- 加include的头文件:

#include <nav_msgs/Odometry.h>

#include <tf/transform_listener.h>

再重新编译,就可以通过:./<nodename> 得到publish:; destination_frame和orginal_frame的 tf的topic了。

3. 运行写好的launch file to run publish the tf. 错误:ERROR: cannot launch node of type [learning_tf/pioneer_tf_listener]: can't locate node [pioneer_tf_listener] in package [learning_tf]

解决方法:需要在当前路径下 source ~/catkin_ws/devel/setup.bash
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: