Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

Yes, a google search does reveal that there are some models available for simulation of the realsense camera. See these links:
https://github.com/intel/gazebo-realsense
https://github.com/SyrianSpock/realsense_gazebo_plugin

That said, for most applications, you probably don't need that. I've been using the Asus Xtion Pro simulation of the camera, based on the libgazebo_ros_openni_kinect.so plugin, for emulating a realsense camera and it's working well. I based it on this project here: https://github.com/rosbook/effective_robotics_programming_with_ros/blob/master/chapter7_tutorials/rosbook_arm_description/urdf/sensors/xtion_pro_live.gazebo.xacro .

To make this plugin emulate your camera, modify the .gazebo.xacro file to provide parameters like your horizontal FOV, minimum depth, maximum depth, etc. I've left those parameters default in my simulation but have modified the topic names to be the same as my actual camera. See my files below.

Here is the xtion_pro_live.gazebo.xacro file. Note that I replaced the mesh files with a realsense mesh, from the links above. <robot xmlns:xacro="http://ros.org/wiki/xacro"> <xacro:include filename="$(find robot_description)/urdf/deg_to_rad.xacro"/>

  <xacro:macro name="xtion_pro_live_rgbd_camera_gazebo" params="name">
    <gazebo reference="${name}_link">

      <static>true</static>
      <turnGravityOff>true</turnGravityOff>

      <!-- RGB + Depth -->
      <sensor type="depth" name="${name}_frame_sensor2">
        <always_on>true</always_on>
        <update_rate>6.0</update_rate>

        <camera>
          <horizontal_fov>${58.0 * deg_to_rad}</horizontal_fov>
          <image>
            <format>R8G8B8</format>
            <width>640</width>
            <height>480</height>
          </image>
          <clip>
            <near>0.05</near>
            <far>4.0</far>
          </clip>
          <noise>
            <type>gaussian</type>
            <mean>0.0</mean>
            <stddev>0.005</stddev>
          </noise>
        </camera>

        <plugin name="${name}_frame_controller" filename="libgazebo_ros_openni_kinect.so">
          <alwaysOn>true</alwaysOn>
          <updateRate>6.0</updateRate>
          <cameraName>${name}</cameraName>
          <imageTopicName>color/image_raw</imageTopicName>
          <depthImageTopicName>depth/image_rect_raw</depthImageTopicName>
          <cameraInfoTopicName>color/camera_info</cameraInfoTopicName>
          <depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName>
          <pointCloudTopicName>depth_registered/points</pointCloudTopicName>
          <frameName>${name}_color_optical_frame</frameName>
          <pointCloudCutoff>0.05</pointCloudCutoff>
          <rangeMax>4.0</rangeMax>
        </plugin>
      </sensor>
    </gazebo>
  </xacro:macro>
</robot>

Here is the xtion_pro_live.urdf.xacro file:

<?xmlversion="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:include filename="$(find robot_description)/urdf/sensors/xtion_pro_live.gazebo.xacro"/>
  <xacro:include filename="$(find robot_description)/urdf/deg_to_rad.xacro"/>

  <xacro:macro name="dummy_inertial">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <mass value="0.001"/>
      <inertia ixx="0.00001" ixy="0" ixz="0"
               iyy="0.00001" iyz="0"
               izz="0.00001"/>
    </inertial>
  </xacro:macro>

  <xacro:macro name="xtion_pro_live" params="name parent_link *origin *optical_origin">

    <!-- frames in the center of the camera -->
    <joint name="${name}_joint" type="fixed">
      <xacro:insert_block name="origin"/>
      <parent link="${parent_link}"/>
      <child link="${name}_link"/>
    </joint>

    <link name="${name}_link">
      <inertial>
        <origin xyz="-0.00936000000 -0.00003000000 -0.00273000000" rpy="0 0 0"/>
        <mass value="0.21970000000"/>
        <inertia ixx="0.00000429247" ixy="0.00000000000" ixz="0.00000002565"
                 iyy="0.00000008027" iyz="0.00000000000"
                 izz="0.00000427339"/>
      </inertial>
      <visual>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <geometry>
          <mesh filename="package://robot_description/meshes/realsense/intel_d415.dae"/>
        </geometry>
        <material name="DarkGrey"/>
      </visual>
    </link>

    <joint name="${name}_optical_joint" type="fixed">
      <xacro:insert_block name="optical_origin"/>
      <parent link="${name}_link"/>
      <child link="${name}_optical_frame"/>
    </joint>

    <link name="${name}_optical_frame">
      <dummy_inertial/>
    </link>

    <!-- Depth sensor frames -->
    <joint name="${name}_depth_joint" type="fixed">
      <origin xyz="0.0 0.049 0.0" rpy="0 0 0"/>
      <parent link="${name}_link"/>
      <child link="${name}_depth_frame"/>
    </joint>

    <link name="${name}_depth_frame">
      <dummy_inertial/>
    </link>

    <joint name="${name}_depth_optical_joint" type="fixed">
      <origin xyz="0 0 0" rpy="${-90.0 * deg_to_rad} 0.0 ${-90.0 * deg_to_rad}"/>
      <parent link="${name}_depth_frame"/>
      <child link="${name}_depth_optical_frame"/>
    </joint>

    <link name="${name}_depth_optical_frame">
      <dummy_inertial/>
    </link>

    <!-- RGB sensor frames -->
    <joint name="${name}_color_joint" type="fixed">
      <origin xyz="0.0 0.022 0.0" rpy="0 0 0"/>
      <parent link="${name}_link"/>
      <child link="${name}_color_frame"/>
    </joint>

    <link name="${name}_color_frame">
      <dummy_inertial/>
    </link>

    <joint name="${name}_color_optical_joint" type="fixed">
      <origin xyz="0 0 0" rpy="${-90.0 * deg_to_rad} 0.0 ${-90.0 * deg_to_rad}"/>
      <parent link="${name}_color_frame"/>
      <child link="${name}_color_optical_frame"/>
    </joint>

    <link name="${name}_color_optical_frame">
      <dummy_inertial/>
    </link>

    <xacro:xtion_pro_live_rgbd_camera_gazebo name="${name}"/>
  </xacro:macro>

</robot>

These 2 are xacro macros. Use them like this in a new urdf.xacro file:

<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro" name="rgbd_cam">

  <xacro:include filename="$(find robot_description)/urdf/deg_to_rad.xacro"/>
  <xacro:include filename="$(find robot_description)/urdf/camera_mount/camera_mount.urdf.xacro"/>
  <xacro:include filename="$(find robot_description)/urdf/sensors/xtion_pro_live.urdf.xacro"/>

  <xacro:property name="camera_tilt" value="45.0" />

  <!-- Define base -->
  <xacro:camera_mount name="camera_mount" />

  <!-- Define RGB-D sensor -->
  <xacro:xtion_pro_live name="camera" parent_link="camera_mount_mounting_link">
    <origin xyz="0.03 0 0.03" rpy="0 ${camera_tilt * deg_to_rad} 0"/>
    <origin xyz="0 0 0" rpy="${-90.0 * deg_to_rad} 0 ${-90.0 * deg_to_rad}"/>
  </xacro:xtion_pro_live>

</robot>

Yes, a google search does reveal that there are some models available for simulation of the realsense camera. See these links:
https://github.com/intel/gazebo-realsense
https://github.com/SyrianSpock/realsense_gazebo_plugin

To know more about plugins in Gazebo, take a look at the official Tutorial: Using Gazebo plugins with ROS.

That said, for most applications, you can probably don't need that. use the generic DepthCam or Kinect plugin. I've been using the Asus Xtion Pro simulation of the camera, based on the libgazebo_ros_openni_kinect.so plugin, for emulating a realsense camera and it's working well. I based it on this project here: https://github.com/rosbook/effective_robotics_programming_with_ros/blob/master/chapter7_tutorials/rosbook_arm_description/urdf/sensors/xtion_pro_live.gazebo.xacro . a project from the book Effective Robotics Programming with ROS.

To make this plugin emulate your camera, modify the .gazebo.xacro file elements in the <sensors> tag withing the <gazebo> tag to provide parameters like your horizontal FOV, minimum depth, maximum depth, etc. I've left those parameters default in my simulation but have modified the topic names to be the same as my actual camera. See my files below.

Here is the xtion_pro_live.gazebo.xacro file. Note that I replaced the mesh files with a realsense mesh, from the links above. <robot xmlns:xacro="http://ros.org/wiki/xacro"> <xacro:include filename="$(find robot_description)/urdf/deg_to_rad.xacro"/>

  <xacro:macro name="xtion_pro_live_rgbd_camera_gazebo" params="name">
    <gazebo reference="${name}_link">

      <static>true</static>
      <turnGravityOff>true</turnGravityOff>

      <!-- RGB + Depth -->
      <sensor type="depth" name="${name}_frame_sensor2">
        <always_on>true</always_on>
        <update_rate>6.0</update_rate>

        <camera>
          <horizontal_fov>${58.0 * deg_to_rad}</horizontal_fov>
          <image>
            <format>R8G8B8</format>
            <width>640</width>
            <height>480</height>
          </image>
          <clip>
            <near>0.05</near>
            <far>4.0</far>
          </clip>
          <noise>
            <type>gaussian</type>
            <mean>0.0</mean>
            <stddev>0.005</stddev>
          </noise>
        </camera>

        <plugin name="${name}_frame_controller" filename="libgazebo_ros_openni_kinect.so">
          <alwaysOn>true</alwaysOn>
          <updateRate>6.0</updateRate>
          <cameraName>${name}</cameraName>
          <imageTopicName>color/image_raw</imageTopicName>
          <depthImageTopicName>depth/image_rect_raw</depthImageTopicName>
          <cameraInfoTopicName>color/camera_info</cameraInfoTopicName>
          <depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName>
          <pointCloudTopicName>depth_registered/points</pointCloudTopicName>
          <frameName>${name}_color_optical_frame</frameName>
          <pointCloudCutoff>0.05</pointCloudCutoff>
          <rangeMax>4.0</rangeMax>
        </plugin>
      </sensor>
    </gazebo>
  </xacro:macro>
</robot>

Here is the xtion_pro_live.urdf.xacro file:

<?xmlversion="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:include filename="$(find robot_description)/urdf/sensors/xtion_pro_live.gazebo.xacro"/>
  <xacro:include filename="$(find robot_description)/urdf/deg_to_rad.xacro"/>

  <xacro:macro name="dummy_inertial">
    <inertial>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <mass value="0.001"/>
      <inertia ixx="0.00001" ixy="0" ixz="0"
               iyy="0.00001" iyz="0"
               izz="0.00001"/>
    </inertial>
  </xacro:macro>

  <xacro:macro name="xtion_pro_live" params="name parent_link *origin *optical_origin">

    <!-- frames in the center of the camera -->
    <joint name="${name}_joint" type="fixed">
      <xacro:insert_block name="origin"/>
      <parent link="${parent_link}"/>
      <child link="${name}_link"/>
    </joint>

    <link name="${name}_link">
      <inertial>
        <origin xyz="-0.00936000000 -0.00003000000 -0.00273000000" rpy="0 0 0"/>
        <mass value="0.21970000000"/>
        <inertia ixx="0.00000429247" ixy="0.00000000000" ixz="0.00000002565"
                 iyy="0.00000008027" iyz="0.00000000000"
                 izz="0.00000427339"/>
      </inertial>
      <visual>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <geometry>
          <mesh filename="package://robot_description/meshes/realsense/intel_d415.dae"/>
        </geometry>
        <material name="DarkGrey"/>
      </visual>
    </link>

    <joint name="${name}_optical_joint" type="fixed">
      <xacro:insert_block name="optical_origin"/>
      <parent link="${name}_link"/>
      <child link="${name}_optical_frame"/>
    </joint>

    <link name="${name}_optical_frame">
      <dummy_inertial/>
    </link>

    <!-- Depth sensor frames -->
    <joint name="${name}_depth_joint" type="fixed">
      <origin xyz="0.0 0.049 0.0" rpy="0 0 0"/>
      <parent link="${name}_link"/>
      <child link="${name}_depth_frame"/>
    </joint>

    <link name="${name}_depth_frame">
      <dummy_inertial/>
    </link>

    <joint name="${name}_depth_optical_joint" type="fixed">
      <origin xyz="0 0 0" rpy="${-90.0 * deg_to_rad} 0.0 ${-90.0 * deg_to_rad}"/>
      <parent link="${name}_depth_frame"/>
      <child link="${name}_depth_optical_frame"/>
    </joint>

    <link name="${name}_depth_optical_frame">
      <dummy_inertial/>
    </link>

    <!-- RGB sensor frames -->
    <joint name="${name}_color_joint" type="fixed">
      <origin xyz="0.0 0.022 0.0" rpy="0 0 0"/>
      <parent link="${name}_link"/>
      <child link="${name}_color_frame"/>
    </joint>

    <link name="${name}_color_frame">
      <dummy_inertial/>
    </link>

    <joint name="${name}_color_optical_joint" type="fixed">
      <origin xyz="0 0 0" rpy="${-90.0 * deg_to_rad} 0.0 ${-90.0 * deg_to_rad}"/>
      <parent link="${name}_color_frame"/>
      <child link="${name}_color_optical_frame"/>
    </joint>

    <link name="${name}_color_optical_frame">
      <dummy_inertial/>
    </link>

    <xacro:xtion_pro_live_rgbd_camera_gazebo name="${name}"/>
  </xacro:macro>

</robot>

These 2 are xacro macros. Use them like this in a new urdf.xacro file:

<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro" name="rgbd_cam">

  <xacro:include filename="$(find robot_description)/urdf/deg_to_rad.xacro"/>
  <xacro:include filename="$(find robot_description)/urdf/camera_mount/camera_mount.urdf.xacro"/>
  <xacro:include filename="$(find robot_description)/urdf/sensors/xtion_pro_live.urdf.xacro"/>

  <xacro:property name="camera_tilt" value="45.0" />

  <!-- Define base -->
  <xacro:camera_mount name="camera_mount" />

  <!-- Define RGB-D sensor -->
  <xacro:xtion_pro_live name="camera" parent_link="camera_mount_mounting_link">
    <origin xyz="0.03 0 0.03" rpy="0 ${camera_tilt * deg_to_rad} 0"/>
    <origin xyz="0 0 0" rpy="${-90.0 * deg_to_rad} 0 ${-90.0 * deg_to_rad}"/>
  </xacro:xtion_pro_live>

</robot>