0
$\begingroup$

Rosanswers logo

I have followed the tutorial to create a tf broadcaster.

Here is the code:

   void poseCallback(const sensor_msgs::PointCloud2::ConstPtr& msg){
     static tf::TransformBroadcaster br;
     tf::Transform transform;
     transform.setOrigin( tf::Vector3(0.0, 0.0, 0.0) );
     tf::Quaternion q;
     q.setRPY(0, 0, 0);
     transform.setRotation(q);
     br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "xtion_link", "camera_link"));
   }


  int main(int argc, char **argv)
  {
    ros::init(argc, argv, "subscribe_and_publish");
   
    ros::NodeHandle node;
    ros::Subscriber sub = node.subscribe("/camera/depth/points", 10, &poseCallback);

    ros::Rate loop_rate(10);

    while (ros::ok()) {

      ros::spinOnce();
      loop_rate.sleep();

    }

    return 0;
  }

The problem is that the transform does not seem to work, properly atleast. When I run the program and the rosbag file and use rosrun tf view_frames I get a nice tree with all the components in it. However the broadcast time between "xtion_link" and "camera_link" is around 4 seconds while time between other broadcasters is around 0.2 seconds.

If i try to visualize the whole thing in rviz and set xtion_link as fixed frame, it shows that all transforms are OK, except the ones below camera_link. If I set camera_link as fixed frame, it shows that xtion_link is OK and others below it but it says that there is no transform from broadcasters above xtion_link.

I don't know if it's caused by the rosbag file or a programmatic error. Rosbag works perfectly in other aspects.


Originally posted by RosFan19 on ROS Answers with karma: 107 on 2015-03-03

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

A few things:

  1. Would your use case be better served by static_transform_publisher?

  2. If not, do you have the parameter use_sim_time set to true before you start your node?

  3. In your call to sendTransform, try this:

    br.sendTransform(tf::StampedTransform(transform, msg->header.stamp, "xtion_link", "camera_link"));


Originally posted by Tom Moore with karma: 13689 on 2015-03-03

This answer was ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.