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

roslibpy: why does TFClient seem to ignore the rate parameter?

asked 2019-01-25 21:47:27 -0600

Rick Armstrong gravatar image

updated 2019-01-25 21:50:09 -0600

Hello,

We're using roslibpy to capture tf messages from a robot via rosbridge, and rebroadcasting them on my local machine for viewing in rviz. So far, it works well, but I'd like to reduce bandwidth by lowering the message rate a little (we get them at about 10Hz). Setting the rate parameter in TFClient seems to have no effect. Here's the little TFSub class we're using:

class TFSub(object):
    """Manages a set of rosbridge callbacks associated with tfs
    on a remote robot."""
    def __init__(self, rosbridge_client):
        self.tf_client = TFClient(rosbridge_client, fixed_frame='map',
                                  angular_threshold=0.5,
                                  translation_threshold=0.5,
                                  rate=1.0)
        self.tf_client.subscribe('odom', self.tf_map_odom_cb)
        self.tf_client.subscribe('base_link', self.tf_map_base_link_cb)
        self.tb = tf.TransformBroadcaster()

    def tf_map_odom_cb(self, msg):
        rospy.logdebug("got a map->odom transform.")
        self.tb.sendTransform((msg['translation']['x'],
                               msg['translation']['y'],
                               msg['translation']['z']),
                              (msg['rotation']['x'],
                               msg['rotation']['y'],
                               msg['rotation']['z'],
                               msg['rotation']['w']),
                              rospy.Time.now(),
                              'odom',
                              'map')

    def tf_map_base_link_cb(self, msg):
        rospy.logdebug("got a map->base_link transform.")
        self.tb.sendTransform((msg['translation']['x'],
                               msg['translation']['y'],
                               msg['translation']['z']),
                              (msg['rotation']['x'],
                               msg['rotation']['y'],
                               msg['rotation']['z'],
                               msg['rotation']['w']),
                              rospy.Time.now(),
                              'base_link',
                              'map')

Here's our invocation of tf2_web_republisher, running on the remote robot:

<launch>
  <include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch" />
  <node name="tf2_web_republisher_node" pkg="tf2_web_republisher" type="tf2_web_republisher" />
</launch>

As you can see, we're setting the rate parameter to 1.0, and setting a large angular_threshold and translation_threshold, but stll getting messages at just over 10.0Hz.

We're running Python 2.7 at both ends of the bridge, Ubuntu 14, ROS Indigo.

edit retag flag offensive close merge delete

Comments

gramaziokohler/roslibpy#14 seems related / similar.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-27 03:52:13 -0600 )edit

Thanks, I posted a link back here for the authors.

Rick Armstrong gravatar image Rick Armstrong  ( 2019-01-28 13:07:04 -0600 )edit

@gvdhoorn: looks like a different issue from gramaziokohler/roslibpy#14. That one is about subscriptions, not TFClient. Thanks anyway.

Rick Armstrong gravatar image Rick Armstrong  ( 2019-01-28 14:53:48 -0600 )edit

Which topic do you get at a rate of 10 Hz? tf2_web_republisher seems to throttle properly,,

Mathias Lüdtke gravatar image Mathias Lüdtke  ( 2019-01-28 15:19:36 -0600 )edit

We're listening to two transforms: map->odom and map->base_link (code sample in the initial post). Setting the rate param to TFClient to a non-default value seems to make no difference.

Rick Armstrong gravatar image Rick Armstrong  ( 2019-01-28 15:38:56 -0600 )edit

please check rostopic hz /tf2_web_republisher/tf_repub_<X> (replace <X> accordingly).

Mathias Lüdtke gravatar image Mathias Lüdtke  ( 2019-01-28 17:01:43 -0600 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2019-01-28 17:23:05 -0600

Rick Armstrong gravatar image

Ugh, dumb mistake: I had a stray static_transform_publisher running. TFClient works exactly as documented. Thanks to those who chimed in, and apologies for the distraction.

edit flag offensive delete link more
0

answered 2019-01-28 15:51:04 -0600

Mathias Lüdtke gravatar image

TFClient works for me on melodic:

roslaunch rosbridge_server rosbridge_websocket.launch &
rosrun tf2_ros static_transform_publisher 1 0 0 0 0 0 1 link1_parent link1 &
rosrun tf2_web_republisher tf2_web_republisher &
python tf.py

With tf.py:

from __future__ import print_function
import roslibpy
import roslibpy.tf

client = roslibpy.Ros(host='localhost', port=9090)

tf_client = roslibpy.tf.TFClient(client, fixed_frame='link1_parent',
                            angular_threshold=0.0,
                            translation_threshold=0.0,
                            rate=1.0)

def start_listening():
    tf_client.subscribe('link1', print)

client.on_ready(start_listening, run_in_thread=True)
client.run_forever()

The data gets printed every second..

edit flag offensive delete link more

Comments

Thanks for checking. It's either 1) a difference between releases or 2) I'm doing something dumb.

Rick Armstrong gravatar image Rick Armstrong  ( 2019-01-28 16:30:23 -0600 )edit

Same result in a ros:indigo Docker container.

Mathias Lüdtke gravatar image Mathias Lüdtke  ( 2019-01-28 16:58:15 -0600 )edit

I'm setting the threshold params to non-zero values; that might be the wrong thing to do in this context.

Rick Armstrong gravatar image Rick Armstrong  ( 2019-01-28 17:02:59 -0600 )edit

Nope, that's not it, either. I'll keep poking around to figure out what I'm doing wrong. Thanks again for checking.

Rick Armstrong gravatar image Rick Armstrong  ( 2019-01-28 17:12:31 -0600 )edit

This should not increase the rate.

Mathias Lüdtke gravatar image Mathias Lüdtke  ( 2019-01-28 17:14:27 -0600 )edit

I was doing a rostopic hz /tf and getting >10Hz average because I had another component generating /tf messages at 10Hz. Feeling rather silly, actually.

Rick Armstrong gravatar image Rick Armstrong  ( 2019-01-28 17:25:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-25 21:47:27 -0600

Seen: 759 times

Last updated: Jan 28 '19