ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ros2 publish frame_id

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

ros2 gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Comments

haaaa. sorry my mistake. Thanks a lot!!

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

Question Tools

1 follower

Stats

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

Seen: 1,559 times

Last updated: Apr 16 '21