Published topic data lost and not captured by subscriber

asked 2021-12-04 07:40:07 -0600

enyuin gravatar image

updated 2021-12-04 09:41:51 -0600

Hi, I am new in ROS2. Currently I faced some issue that my published data is lost and not being captured by the subscribers. Anyone can guide me on how to solve this issue?

def __init__(self):
    self.publisher_ = self.create_publisher(String, 'topic', 10)
    timer_period = 0.1  # seconds
    self.timer = self.create_timer(timer_period, self.timer_callback)
    self.set_operation_sub = self.create_subscription(Int16, 'set_operation_mode', self.set_operation_callback, 10)
    self.i = 0

def set_operation_callback(self, msg):

def timer_callback(self):
    msg = String() = 'Hello World: %d' % self.i
    self.get_logger().info('Publishing: "%s"' %
    self.i += 1

This is the sample code for my usage. I had one timer, one publisher and one subscriber. The timer is looped at 0.1s and some information is published when the timer is triggered. During this time, if someone pass some information on 'set_operation_mode', by right it should falls under the 'set_operation_callback', yet it did not. Sometimes, it works and sometimes it is not working.


edit retag flag offensive close merge delete