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

[ros2topic] fix pub rate reduced issue #141

Merged
merged 1 commit into from
Sep 1, 2018
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
17 changes: 12 additions & 5 deletions ros2topic/ros2topic/verb/pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,21 @@ def publisher(

print('publisher: beginning loop')
count = 0
while rclpy.ok():

def timer_callback():
nonlocal count
count += 1
if print_nth and count % print_nth == 0:
print('publishing #%d: %r\n' % (count, msg))
pub.publish(msg)
if once:
time.sleep(0.1) # make sure the message reaches the wire before exiting
break
time.sleep(period)

timer = node.create_timer(period, timer_callback)
if once:
rclpy.spin_once(node)
time.sleep(0.1) # make sure the message reaches the wire before exiting
else:
rclpy.spin(node)

node.destroy_timer(timer)
node.destroy_node()
rclpy.shutdown()