ROS2 Image subscriber
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/gaz... 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.