ros2 publish frame_id
I created a simple image publisher node like the one below
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self._bridge = CvBridge()
self.clock = Clock()
self.publisher_ = self.create_publisher(Image, 'topic')
timer_period = 2 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0
def timer_callback(self):
dtype = np.uint8
n_channels = 3
msg = Image()
msg.header.stamp.sec = self.clock.now().to_msg().sec
msg.header.stamp.nanosec = self.clock.now().to_msg().nanosec
msg.header.frame_id = (str(self.i))
im = np.ndarray(shape=(width, height, n_channels), dtype=dtype)
msg = self._bridge.cv2_to_imgmsg(im)
self.publisher_.publish(msg)
self.i += 1
but the frame id I publish is always empty. I am a newbie to ros2. Could any one suggest some solution. Thanks in advance.