Ask Your Question

ROS2 Image subscriber

asked 2020-09-06 04:08:48 -0500

Kreace gravatar image

Hello i'm pretty new to ROS2, i would like to make a simple Image subscriber of a ROS2 topic which come from a camera (which is on a drone) in a Gazebo simulation.

I'm using ROS2 foxy and Gazebo11.

First i launch the Gazebo simulator with : gzserver --verbose -s in a first terminal. Then i spawn a model of a drone with : ros2 run gazebo_ros -entity TITI -x 0 -y 0 -z 0.5 -file ~/src_sitl_gazebo/sitl_gazebo/models/typhoon_h480/typhoon_h480.sdf I have modify the .sdf file in order to make it communicate with ROS2 here is the modification

<sensor name="camera" type="camera">
    <pose>0.0 0 -0.162 0 0 0</pose>
    <plugin name="camera_controller" filename="">

I tried to use the ROS2 migration syntax that I found here but it gave me some errors.

After that I use :

ros2 topic list

and it gave me this output :


So I guess the Image Publisher is created but maybe I'm wrong there. Then I wrote a script which is a simple subscriber :

import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Image

class MinimalSubscriber(Node):

    def __init__(self):
        self.subscription = self.create_subscription(
        self.subscription  # prevent unused variable warning

    def listener_callback(self):
        print("In callback")

    def main(args=None):
        minimal_subscriber = MinimalSubscriber()
       # Destroy the node explicitly
       # (optional - otherwise it will be done automatically
       # when the garbage collector destroys the node object)

if __name__ == '__main__':

So in the callback I just print a message to see if the callback is working but i don't receive any message in the terminal.

Thank you in advance for helping me feel free to tell me if you need additional information my post is already long i don't want to overload it.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2020-09-08 17:40:06 -0500

dhood gravatar image

I think you might be running into Quality of Service (QoS) incompatibilities.

As far as I know the gazebo plugin publishes with the "sensor data" QoS profile ("best effort" reliability), and your subscriber is using "reliable" reliability. If you try to echo the message with ros2 topic echo /camera/image_raw --no-arr and you manage to see the image data, then that confirms the issue is with your MinimalSubscriber.

You can switch to the sensor data QoS profile by changing your subscription creation to:

self.subscription = self.create_subscription(

(Add from rclpy.qos import qos_profile_sensor_data to the top of your node to get that.)

edit flag offensive delete link more


Nice! That was the answer, thanks for your help dhood!

Kreace gravatar image Kreace  ( 2020-09-09 02:44:08 -0500 )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



Asked: 2020-09-06 04:08:48 -0500

Seen: 999 times

Last updated: Sep 08 '20