Realsense D435 in Gazebo
I am trying to simulate a Realsense D435 in Gazebo 9, running ROS Melodic in Ubuntu 18.04.
I am using the ROS Wrapper from Realsense and the plugin from here.
Importing the _d435.urdf.xacro and _d435.gazebo.xacro files into my own xacro, I should be able to use the camera in Gazebo and see several topics being published. My file is
<?xml version="1.0"?>
<robot name="realsense2_camera" xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:arg name="use_nominal_extrinsics" default="false"/>
<xacro:include filename="$(find realsense2_description)/urdf/_d435.urdf.xacro" />
<xacro:include filename="$(find realsense2_description)/urdf/_d435.gazebo.xacro" />
<link name="base_link" />
<xacro:sensor_d435 parent="base_link" use_nominal_extrinsics="$(arg use_nominal_extrinsics)">
<origin xyz="0 0 0" rpy="0 0 0"/>
</xacro:sensor_d435>
<xacro:gazebo_d435 camera_name="camera" reference_link="camera" topics_ns="rs" depth_optical_frame="depth" color_optical_frame="color" infrared1_optical_frame="ired1" infrared2_optical_frame="ired2" >
</xacro:gazebo_d435>
</robot>
However, running like this causes Gazebo to crash at startup, while loading the plugin (at least it's after some text messages from the plugin). Looking at the _d435.gazebo.xacro file, I changed it slightly to include the gazebo reference when entering the plugin:
<?xml version="1.0"?>
<robot xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:macro name="gazebo_d435" params="camera_name reference_link topics_ns depth_optical_frame color_optical_frame infrared1_optical_frame infrared2_optical_frame" >
<!-- Load parameters to model's main link-->
<xacro:property name="deg_to_rad" value="0.01745329251994329577" />
<gazebo reference="${reference_link}">
<self_collide>0</self_collide>
<enable_wind>0</enable_wind>
<kinematic>0</kinematic>
<gravity>1</gravity>
<!--<mu>1</mu>-->
<mu2>1</mu2>
<fdir1>0 0 0</fdir1>
<!--<slip1>0</slip1>
<slip2>0</slip2>-->
<kp>1e+13</kp>
<kd>1</kd>
<!--<max_vel>0.01</max_vel>
<min_depth>0</min_depth>-->
<sensor name="${camera_name}color" type="camera">
<camera name="${camera_name}">
<horizontal_fov>${69.4*deg_to_rad}</horizontal_fov>
<image>
<width>1920</width>
<height>1080</height>
<format>RGB_INT8</format>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
</camera>
<always_on>1</always_on>
<update_rate>30</update_rate>
<visualize>1</visualize>
</sensor>
<sensor name="${camera_name}ired1" type="camera">
<camera name="${camera_name}">
<horizontal_fov>${85.2*deg_to_rad}</horizontal_fov>
<image>
<width>1280</width>
<height>720</height>
<format>L_INT8</format>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.05</stddev>
</noise>
</camera>
<always_on>1</always_on>
<update_rate>30</update_rate>
<visualize>0</visualize>
</sensor>
<sensor name="${camera_name}ired2" type="camera">
<camera name="${camera_name}">
<horizontal_fov>${85.2*deg_to_rad}</horizontal_fov>
<image>
<width>1280</width>
<height>720</height>
<format>L_INT8</format>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.05</stddev>
</noise>
</camera>
<always_on>1</always_on>
<update_rate>30</update_rate>
<visualize>0</visualize>
</sensor>
<sensor name="${camera_name}depth" type="depth">
<camera name="${camera_name}">
<horizontal_fov>${85.2*deg_to_rad}</horizontal_fov>
<image>
<width>1280</width>
<height>720</height>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.100</stddev>
</noise>
</camera>
<always_on>1</always_on>
<update_rate>30</update_rate>
<visualize>0</visualize>
</sensor ...