Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable TF topics to view_frames #709

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tf2_ros/doc/cli_tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ In the current working folder, you should now have a file called "frames_$(data)

.. image:: images/view_frames.png


If you need to view the frames from non-standard topics, you can override them like so:

.. code-block:: bash

ros2 run tf2_tools view_frames --tf_topic=/foo --tf_static_topic=bar

Fields
~~~~~~
* Recorded at time: shows the absolute timestamp when this graph was generated.
Expand Down
15 changes: 11 additions & 4 deletions tf2_ros_py/tf2_ros/transform_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@
from tf2_msgs.msg import TFMessage
from threading import Thread

DEFAULT_TF_TOPIC = '/tf'
DEFAULT_STATIC_TF_TOPIC = '/tf_static'

class TransformListener:
"""
:class:`TransformListener` is a convenient way to listen for coordinate frame transformation info.
This class takes an object that instantiates the :class:`BufferInterface` interface, to which
it propagates changes to the tf frame graph.
it propagates changes to the tf frame graph. It listens to both static and dynamic
transforms.
"""
def __init__(
self,
Expand All @@ -54,7 +57,9 @@ def __init__(
*,
spin_thread: bool = False,
qos: Optional[Union[QoSProfile, int]] = None,
static_qos: Optional[Union[QoSProfile, int]] = None
static_qos: Optional[Union[QoSProfile, int]] = None,
tf_topic: str = DEFAULT_TF_TOPIC,
tf_static_topic: str = DEFAULT_STATIC_TF_TOPIC
) -> None:
"""
Constructor.
Expand All @@ -64,6 +69,8 @@ def __init__(
:param spin_thread: Whether to create a dedidcated thread to spin this node.
:param qos: A QoSProfile or a history depth to apply to subscribers.
:param static_qos: A QoSProfile or a history depth to apply to tf_static subscribers.
:param tf_topic: Which topic to listen to for dynamic transforms.
:param tf_static_topic: Which topic to listen to for static transforms.
"""
if qos is None:
qos = QoSProfile(
Expand All @@ -83,9 +90,9 @@ def __init__(
# from another callback in the same group.
self.group = ReentrantCallbackGroup()
self.tf_sub = node.create_subscription(
TFMessage, '/tf', self.callback, qos, callback_group=self.group)
TFMessage, tf_topic, self.callback, qos, callback_group=self.group)
self.tf_static_sub = node.create_subscription(
TFMessage, '/tf_static', self.static_callback, static_qos, callback_group=self.group)
TFMessage, tf_static_topic, self.static_callback, static_qos, callback_group=self.group)

if spin_thread:
self.executor = SingleThreadedExecutor()
Expand Down
10 changes: 9 additions & 1 deletion tf2_tools/tf2_tools/view_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import rclpy
from tf2_msgs.srv import FrameGraph
import tf2_ros
from tf2_ros.transform_listener import DEFAULT_STATIC_TF_TOPIC, DEFAULT_TF_TOPIC

import yaml

Expand All @@ -50,12 +51,19 @@ def main():
'--wait-time', '-t', type=float, default=5.0,
help='Listen to the /tf topic for this many seconds before rendering the frame tree')
parser.add_argument('-o', '--output', help='Output filename')
parser.add_argument('--tf_topic', help='Topic for dynamic transforms',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be tf_dynamic_topic. Open to either given the help text next to it says dynamic

default=DEFAULT_TF_TOPIC)
parser.add_argument('--tf_static_topic', help='Topic for static transforms',
default=DEFAULT_STATIC_TF_TOPIC)

parsed_args = parser.parse_args(args=args_without_ros[1:])

node = rclpy.create_node('view_frames')

buf = tf2_ros.Buffer(node=node)
listener = tf2_ros.TransformListener(buf, node, spin_thread=False)
listener = tf2_ros.TransformListener(buf, node, spin_thread=False,
tf_topic=parsed_args.tf_topic,
tf_static_topic=parsed_args.tf_static_topic)
listener # To quiet a flake8 warning

executor = rclpy.executors.SingleThreadedExecutor()
Expand Down