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

Exclude recorded /clock topic when --clock option is specified #1646

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from

Conversation

kosuke55
Copy link
Contributor

@kosuke55 kosuke55 commented May 9, 2024

As mentioned in #1645, if you play a rosbag containing /clock with --clock, it will be double-published.
This PR excludes /clock when --clock is specified.

ros2 bag play sample_bag --clock 100

before

---
clock:
  sec: 1715138101
  nanosec: 880998015
---
clock:
  sec: 1666578700
  nanosec: 606046430
---
clock:
  sec: 1666578700
  nanosec: 608539499
---
clock:
  sec: 1715138101
  nanosec: 891000787
---
clock:
  sec: 1666578700
  nanosec: 611041316

after

clock:
  sec: 1715138117
  nanosec: 244567726
---
clock:
  sec: 1715138117
  nanosec: 254594666
---
clock:
  sec: 1715138117
  nanosec: 264606514
---
clock:
  sec: 1715138117
  nanosec: 274554989
---
clock:
  sec: 1715138117
  nanosec: 284571707

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
@kosuke55 kosuke55 requested a review from a team as a code owner May 9, 2024 02:59
@kosuke55 kosuke55 requested review from gbiggs and jhdcs and removed request for a team May 9, 2024 02:59
@MichaelOrlov
Copy link
Contributor

@kosuke55 I am not convinced yet that we need this fix.
I'm curious as to why not use ros2 bag play sample_bag --clock 100 --exclude-topics /clock explicitly from CLI arguments in this case?

@kosuke55
Copy link
Contributor Author

kosuke55 commented May 9, 2024

@MichaelOrlov
Thanks, that is correct and can be solved by explicitly excluding it in the command.
This may be more like a personal situation, but when automating some process, some rosbags include /clock and some do not.
When processing such mixed rosbags, it is necessary to check if /clock is included as a preprocessing step and separate the commands (or always add --exclude-topics option). Although it requires a bit of additional work, adding this process solves the problem.
However, I can't think of a situation where I would want to publish the duplicate /clock, and usually that would cause a bug, so I thought it would be better to automatically exclude it.

@fujitatomoya
Copy link
Contributor

@kosuke55 i think automatic exclusion is user-friendly. as @MichaelOrlov mentioned, we can do this using options and checking topic information in rosbag file. but imo this provides less-burden for ros2bag user. after all, i think this is nice to have.

Comment on lines +219 to +220
if play_options.clock_publish_frequency > 0:
exclude_topics.append('/clock')
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we should explain this behavior in --clock option help field for sure, e.g If specified, /clock topic in the bag file is excluded to publish..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!! I updated option help in 2961ccc cc @MichaelOrlov

Comment on lines +219 to +221
if play_options.clock_publish_frequency > 0:
exclude_topics.append('/clock')
play_options.exclude_topics_to_filter = exclude_topics
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just do the following without any other changes above?

Suggested change
if play_options.clock_publish_frequency > 0:
exclude_topics.append('/clock')
play_options.exclude_topics_to_filter = exclude_topics
if play_options.clock_publish_frequency > 0:
play_options.exclude_topics_to_filter.append('/clock')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't been able to trace the cause in detail, but I couldn't add it directly 🤔

print(f"play_options.clock_publish_frequency: {play_options.clock_publish_frequency}")
if play_options.clock_publish_frequency > 0:
    print("Before appending:", play_options.exclude_topics_to_filter)
    play_options.exclude_topics_to_filter.append('/clock')
    print("After appending:", play_options.exclude_topics_to_filter)
print(f"Final state of exclude_topics_to_filter: {play_options.exclude_topics_to_filter}")
play_options.clock_publish_frequency: 100.0
Before appending: []
After appending: []
Final state of exclude_topics_to_filter: []

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

@kosuke55 Thanks for the detailed explanation about the reasoning for these changes.
Now, it does make sense to me.

I agree with @fujitatomoya that we need to put some notes in the CLI help section about this behavior to not surprise someone and not to be considered as a bug.

Also, I think we will need to wait until changes per #1633 will be merged and then rebase on top of it.

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
@kosuke55 kosuke55 changed the title Fix double clock publish Excluded recored /clock topic when --clock is specified May 9, 2024
@kosuke55 kosuke55 changed the title Excluded recored /clock topic when --clock is specified Exclude recorded /clock topic when --clock option is specified May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants