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

ros2 topic pub starts publishing right away. #626

Merged
merged 1 commit into from
May 12, 2021
Merged
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
21 changes: 13 additions & 8 deletions ros2topic/ros2topic/verb/pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,16 @@ def timer_callback():
print('publishing #%d: %r\n' % (count, msg))
pub.publish(msg)

timer = node.create_timer(period, timer_callback)
while times == 0 or count < times:
rclpy.spin_once(node)

# give some time for the messages to reach the wire before exiting
time.sleep(keep_alive)

node.destroy_timer(timer)
# give some time for discovery process
time.sleep(0.1)
timer_callback()
if times != 1:
timer = node.create_timer(period, timer_callback)
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
while times == 0 or count < times:
rclpy.spin_once(node)
# give some time for the messages to reach the wire before exiting
time.sleep(keep_alive)
node.destroy_timer(timer)
else:
# give some time for the messages to reach the wire before exiting
time.sleep(keep_alive)