diff --git a/ros2bag/ros2bag/verb/play.py b/ros2bag/ros2bag/verb/play.py index 6491c64e6..7b1dfd262 100644 --- a/ros2bag/ros2bag/verb/play.py +++ b/ros2bag/ros2bag/verb/play.py @@ -87,7 +87,8 @@ def add_arguments(self, parser, cli_name): # noqa: D102 clock_args_group.add_argument( '--clock', type=positive_float, nargs='?', const=40, default=0, help='Publish to /clock at a specific frequency in Hz, to act as a ROS Time Source. ' - 'Value must be positive. Defaults to not publishing.') + 'Value must be positive. Defaults to not publishing.' + 'If specified, /clock topic in the bag file is excluded to publish.') clock_args_group.add_argument( '--clock-topics', type=str, default=[], nargs='+', help='List of topics separated by spaces that will trigger a /clock update ' @@ -212,8 +213,6 @@ def main(self, *, args): # noqa: D102 play_options.exclude_regex_to_filter = args.exclude_regex - play_options.exclude_topics_to_filter = args.exclude_topics if args.exclude_topics else [] - play_options.exclude_service_events_to_filter = \ convert_service_to_service_event_topic(args.exclude_services) @@ -221,6 +220,10 @@ def main(self, *, args): # noqa: D102 play_options.loop = args.loop play_options.topic_remapping_options = topic_remapping play_options.clock_publish_frequency = args.clock + exclude_topics = args.exclude_topics if args.exclude_topics else [] + if play_options.clock_publish_frequency > 0: + exclude_topics.append('/clock') + play_options.exclude_topics_to_filter = exclude_topics if args.clock_topics_all or len(args.clock_topics) > 0: play_options.clock_publish_on_topic_publish = True play_options.clock_topics = args.clock_topics