ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your code shows this:

void odomCallback(const nav_msgs::Odometry::ConstPtr& msg)
{
    [..]

    tf::TransformBroadcaster broadcaster;

    [..]

    broadcaster.sendTransform(..);

    [..]
}

you're (re)creating the tf::TransformBroadcaster in every odomCallback(..).

As broadcasters essentially wrap regular ros::Publishers, the same requirements and constraints apply: never create Publishers inside the body of callbacks.

Setting up a publication takes time. Setting up subcriptions takes time. There is almost no time between creating the TransformBroadcaster and sending transforms with it in your code.

Create the TransformBroadcaster in a scope that has a longer lifetime than your callback -- such as your main(..), or use a class to wrap all of this -- and I expect things to start working properly.

Your code shows this:

void odomCallback(const nav_msgs::Odometry::ConstPtr& msg)
{
    [..]

    tf::TransformBroadcaster broadcaster;

    [..]

    broadcaster.sendTransform(..);

    [..]
}

you're (re)creating the tf::TransformBroadcaster in every odomCallback(..).

As broadcasters essentially wrap regular ros::Publishers, the same requirements and constraints apply: never create Publishers inside the body of callbacks.

Setting up a publication takes time. Setting up subcriptions takes time. There is almost no time between creating the TransformBroadcaster and sending transforms with it in your code.code. And even if the subscription is setup, the Publisher disappears almost immediately after the frames have been broadcast, which increases the chance that the data never actually reaches the subscriber(s).

Create the TransformBroadcaster in a scope that has a longer lifetime than your callback -- such as your main(..), or use a class to wrap all of this -- and I expect things to start working properly.