Add camera to iris.sdf but no ros2 topic

UBUNTU 20.04
ROS2
GAZEBO 9

hi everyone,
i’m trying to modify the /PX4-Autopilot/Tools/sitl_gazebo/models/iris/iris.sdf in order to add a camera to the model and take its feed in ros2. In the end of the iris.sdf.jinja file i added the following:

<link name='cam_link'>
  <pose frame=''>-0.118317 0.002195 0.004205 -0 -0 -3.12703</pose>
  <inertial>
    <mass>0.1</mass>
    <inertia>
      <ixx>1</ixx>
      <ixy>0</ixy>
      <ixz>0</ixz>
      <iyy>1</iyy>
      <iyz>0</iyz>
      <izz>1</izz>
    </inertia>
    <pose frame=''>0 0 0 0 -0 0</pose>
  </inertial>
  <self_collide>0</self_collide>
  <kinematic>0</kinematic>
  <sensor name='camera1' type='camera'>
    <camera name="head">
      <horizontal_fov>1.3962634</horizontal_fov>
      <image>
        <width>800</width>
        <height>800</height>
        <format>R8G8B8</format>
      </image>
      <clip>
        <near>0.02</near>
        <far>300</far>
      </clip>
    </camera>
    <always_on>1</always_on>
    <update_rate>30</update_rate>
    <visualize>1</visualize>
    <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
    <alwaysOn>true</alwaysOn>
    <updateRate>0.0</updateRate>
    <cameraName>iris/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>
  </link>

i also delete the iris.sdf file before ‘make_px4_sitl_rtps gazebo’ such that the changes are overwritten. The compilation gives no problem, when gazebo starts i can see the ‘camera link’ and also the camera image in the gazebo topic visualization but there is no ‘image_raw’ topic in ros2 when i run ‘ros2 topic list’… i’m doing something wrong?? thanks.

1 Like

@FedeUnibo Simply adding a camera to the vehicle will not make it publish images as ros2 topics

Thanks, but i thought that using the ‘libgazebo_ros_camera’ plugin the topic will be published on ros2 enviroment but i’m wrong, any tip? I’m going crazy about this… i’ve seen a lot of question about this argument but all with reference to ros not ros2. Also in the ros2-Gazebo tutorial this is the code to add to the sdf file in order to get the image published in ros2. I’ve really no idea about how to solve it.

@FedeUnibo I can see two things going wrong from your descriptions

  • As far as I know, libgazebo_ros_camera is a plugin written for ROS1 and not ROS2. Therefore, you either need to use a ros1 to ros2 bridge or use a ros2 plugin to transfer your images to ros2 topics
  • You are launching the gazebo simulation with a make command. This will NOT start ros automatically. Therefore you would need to start PX4 simulation using a roslaunch / or you need to run this separately.

I hope these comments would be a useful hint for solving your problems.

2 Likes

You can use ROS2 gazebo plugins from foxy branch of gazebo_ros_pkgs repository:

Thanks @Jaeyoung-Lim , this make sense but the problem of launching the simulation with ‘roslaunch’ command holds? Or i can start the simalution with ‘ make px4_… gazebo’ ?

roslaunch is for ros1. you need a launch file for ros2. look at this. but to get to this point you will need to have a px4 ros2 bridge…

running make would not wrap Autopilot with ros2. to get all the topics of PX4 autopilot on ros2 you need micrortps agent and px4 ros2 bridge. look here

as for the sensor, migrate your design as per these guidelines. use the correct plugins for ros2. if you have already installed them then they can be found at /opt/ros/(distro)/lib

you can ofcourse work directly with the gazebo plugins and setting up the simulation environment first, or you can do the px4 ros2 bridge first. but to have the complete simulation environment for ros2 both will be needed.

hope this helps.

@aam_sheikh Sorry for late reply. i have tried to follow your steps but had some problem with porting the launch file in ros2 and have no idea about how to solve it. I’ve seen an interesting solution in https://github.com/PX4/PX4-SITL_gazebo/pull/707, i don’t understand why with this solution i avoid using the launch file but i will check out if it works in the next days. thanks.

Hello @FedeUnibo ,

At the end you was able to integrate the camera and stream the image?