ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ros2 publish frame_id

asked 2021-04-16 06:39:29 -0600

ros2 gravatar image

I created a simple image publisher node like the one below

class MinimalPublisher(Node):

def __init__(self):
    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 =
    msg.header.stamp.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.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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-04-16 11:50:20 -0600

shonigmann gravatar image

it looks like you are setting the msg frame ID, then just 2 lines later you are overwriting the contents of msg and publishing the new contents.

edit flag offensive delete link more


haaaa. sorry my mistake. Thanks a lot!!

ros2 gravatar image ros2  ( 2021-04-20 02:46:32 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-04-16 06:32:19 -0600

Seen: 879 times

Last updated: Apr 16 '21