0
$\begingroup$

Rosanswers logo

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 libgazebo_ros_factory.so in a first terminal. Then i spawn a model of a drone with : ros2 run gazebo_ros spawn_entity.py -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>
    <camera>
      <horizontal_fov>2.0</horizontal_fov>
      <image>
        <format>R8G8B8</format>
        <width>640</width>
        <height>360</height>
      </image>
      <clip>
        <near>0.05</near>
        <far>15000</far>
      </clip>
    </camera>
    <always_on>1</always_on>
    <update_rate>30</update_rate>
    <visualize>true</visualize>
    <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
        <alwaysOn>true</alwaysOn>
        <updateRate>0.0</updateRate>
        <cameraName>camera</cameraName>
        <imageTopicName>image_raw</imageTopicName>
        <cameraInfoTopicName>camera_info</cameraInfoTopicName>
        <frameName>camera_link</frameName>
        <hackBaseline>0.07</hackBaseline>
        <distortionK1>0.0</distortionK1>
        <distortionK2>0.0</distortionK2>
        <distortionK3>0.0</distortionK3>
        <distortionT1>0.0</distortionT1>
        <distortionT2>0.0</distortionT2>
    </plugin>
  </sensor>

I tried to use the ROS2 migration syntax that I found here https://github.com/ros-simulation/gazebo_ros_pkgs/wiki/ROS-2-Migration:-Camera but it gave me some errors.

After that I use :

ros2 topic list

and it gave me this output :

/camera/camera_info
/camera/image_raw
/clock
/parameter_events
/rosout

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):
        super().__init__('minimal_subscriber')
        self.subscription = self.create_subscription(
            Image,
            '/camera/image_raw',
            self.listener_callback,
            10)
        self.subscription  # prevent unused variable warning

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

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

if __name__ == '__main__':
    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.


Originally posted by Kreace on ROS Answers with karma: 5 on 2020-09-06

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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(
    Image,
    '/camera/image_raw',
    self.listener_callback,
    qos_profile_sensor_data)

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


Originally posted by dhood with karma: 621 on 2020-09-08

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Kreace on 2020-09-09:
Nice! That was the answer, thanks for your help dhood!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.