transformPointCloud unconnected to tf_broadcaster
I am using the code tf_broadcaster from the ROS tutorial, but I am using "base_link" and "velodyne" as parent and children in the transformation. I am using "velodyne" because is the frame_id of the pointcloud that my scanner is publishing, please let me know if it is not necessary to have the same name.
And I am using this code for subscribing a pointcloud2 and tf messages and publish a new pointcloud2:
ros::Publisher pub;
tf::Transform transform;
sensor_msgs::PointCloud2 msg2;
void chatterCallback(const sensor_msgs::PointCloud2::ConstPtr& msg)
{
tf::TransformListener tf_listener;
pcl_ros::transformPointCloud("velodyne", *msg, msg2, tf_listener);
pub.publish(msg2);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "pc2tfpc");
ros::NodeHandle n ;
ros::Subscriber sub = n.subscribe("velodyne_points", 1, chatterCallback);
pub=n.advertise<sensor_msgs::PointCloud2>("tfpc",1);
ros::spin();
return 0;
}
I can compile code and execute but the new pointcloud2 has not been transformed with the published tf (I checked it on rviz)
rostopic echo /tf shows the right transformation.
rosrun rqt_graph rqt_graph shows that my code is not subscribed to /tf
If I change the target_frame to "velodyne" ( pcl_ros::transformPointCloud("velodyne", *msg, msg2, tf_listener); ) then I get this error in the execution: "base_link" passed to lookupTransform argument target_frame does not exist.
Anybody has an idea about what is wrong? Thanks in advance.