Robotics StackExchange | Archived questions

How can I make my objects/robot appear in image_raw topic when using Gazebo camera plugin?

Hi All,

I am currently trying to set up a camera in Gazebo, to display the content of the simulation in rviz. However, I cannot see anything in the camera image.

To do that, I use the universal robot package on ROS Kinetic, and modify the ur5_robot.urdf.xacro file. I simply added the camera links and joints + the gazebo tags, as presented in the Gazebo tutorial on cameras.

Here is the modified ur5_robot.urdf.xacro file that I use:

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

  <!-- Add a camera in the URDF -->
  <xacro:property name="camera_yaw_angle" value="${pi/2}" />  
  <xacro:property name="camera_roll_angle" value="${-pi/2 - pi/6}" />  
  <xacro:property name="camera_depth" value="0.05" />
  <xacro:property name="camera_height" value="0.07" />
  <xacro:property name="camera_length" value="0.15" />
  <xacro:property name="camera_z_offset" value="0.01" />
  <!-- Size of square 'camera' box -->
  <xacro:property name="camera_x" value="2" />
  <!-- x position of 'camera' box -->
  <xacro:property name="camera_y" value="0.05" />
  <!-- y position of 'camera' box -->
  <xacro:property name="camera_z" value="0.5" />
  <!-- z position of 'camera' box -->

  <joint name="camera_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="${camera_x} ${camera_y} ${camera_z}" rpy="${camera_roll_angle} 0 ${camera_yaw_angle}"/>
    <parent link="world"/>
    <child link="camera_link"/>
  </joint>

  <!-- Camera -->
  <link name="camera_link">
    <collision>
      <origin xyz="0 0 ${-1 * camera_depth - camera_z_offset}" rpy="0 0 0"/>
      <geometry>
        <box size="${camera_length} ${camera_height} ${camera_depth}"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 ${-1 * camera_depth - camera_z_offset}" rpy="0 0 0"/>
      <geometry>
        <box size="${camera_length} ${camera_height} ${camera_depth}"/>
      </geometry>
      <material name="red"/>
    </visual>

    <inertial>
      <mass value="1e-5" />
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
    </inertial>
  </link>

  <gazebo reference="camera_link">
    <sensor type="camera" name="camera1">
      <update_rate>30.0</update_rate>
      <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>
        <noise>
          <type>gaussian</type>
          <!-- Noise is sampled independently per pixel on each frame.
               That pixel's noise value is added to each of its color
               channels, which at that point lie in the range [0,1]. -->
          <mean>0.0</mean>
          <stddev>0.007</stddev>
        </noise>
      </camera>

      <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
        <alwaysOn>true</alwaysOn>
        <updateRate>0.0</updateRate>
        <cameraName>ur5/camera1</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>
  </gazebo>

  <xacro:arg name="transmission_hw_interface" default="hardware_interface/PositionJointInterface"/>

  <!-- common stuff -->
  <xacro:include filename="$(find ur_description)/urdf/common.gazebo.xacro" />

  <!-- ur5 -->
  <xacro:include filename="$(find ur_description)/urdf/ur5.urdf.xacro" />

  <!-- arm -->
  <xacro:ur5_robot prefix="" joint_limited="false" transmission_hw_interface="$(arg transmission_hw_interface)" />

  <link name="world" />

  <joint name="world_joint" type="fixed">
    <parent link="world" />
    <child link = "base_link" />
    <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
  </joint>

</robot>

The new code that I added to the ur5_robot.urdf.xacro file is everything up to

<xacro:arg name="transmission_hw_interface" default="hardware_interface/PositionJointInterface"/>

Everything else is the same.

Then, I launch the gazebo simulation by simply using this command.

roslaunch ur_gazebo ur5.launch

When I run rqt_image view, I see nothing in the camera image.

rosrun rqt_image_view rqt_image_view

When I add a camera into rviz, I see only the robot arm in the scene. If I add a cube or a sphere in gazebo in front of the camera, I cannot see the cube/sphere in rviz from the camera widget. Still only displaying the robot.

Can somebody explain to me what is going on here? I assume I am doing something wrong, but there is almost nothing in the file, so I am confused about why this isn't working.

Thank you!

Asked by Pinknoise2077 on 2020-04-16 16:23:37 UTC

Comments

Answers

Well, I think I found the issue. Somehow, I thought that the camera was displaying along the Z axis of the camera joint frame.

For people that are not clear with how the camera frame works, here is what I found:

The camera joint is what you should care about to position/orient the camera. The link is only for visualization, and actually does not influence how the camera looks at the scene.

The camera is looking in the direction of the X vector of the camera joint frame. The Y vector is in the direction of the width of the image, and the Z vector is in the direction of the height of the image.

So what is really important to set up the camera is to set the joint origin tag xyz and rpy parameters correctly.

More precisely, this part:

  <joint name="camera_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="${camera_x} ${camera_y} ${camera_z}" rpy="${camera_roll_angle} 0 ${camera_yaw_angle}"/>
    <parent link="world"/>
    <child link="camera_link"/>
  </joint>

I would also add that the axis tag has no influence on the camera at all in this case. Its only a filler.

Asked by Pinknoise2077 on 2020-04-16 16:41:49 UTC

Comments