ROS Simulation Camera


Steps

  1. Create package dependent on urdf.
  2. 
    sudo apt-get install libopencv-dev
    cd ~/my_ws/src
    catkin_create_pkg camera_test urdf sensor_msgs cv_bridge rospy std_msgs
    cd ..
    mkdir launch urdf
        
  3. Paste the files into their respective folders urdf and launch.
  4. Run the model in simulation by,
  5. 
    roscore
    roslaunch gazebo_ros empty_world.launch
    roslaunch camera_test spawn.launch
    roslaunch camera_test rviz.launch
        
  6. Inside gazebo window, insert any models.
  7. Inside rviz window, add robotmodel and camera. Change Global Options Fixed Frame to camera_link, change Camera Image Topic to /arm_sensors/camera/image_raw
robot.urdf

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

  <xacro:property name="M_PI" value="3.1415926535897931" />

    <link name="camera_link">

      <collision>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
          <box size="0.1 0.1 0.1"/>
        </geometry>
      </collision>

      <visual>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
          <box size="0.1 0.1 0.1"/>
        </geometry>
        <material name="grey">
            <color rgba="0.2 0.2 0.2 1.0"/>
        </material>
      </visual>


      <inertial>
        <mass value="0.001" />
        <origin xyz="0.1 0 0" rpy="0 0 0" />
        <inertia ixx="0.0001" ixy="0" ixz="0" iyy="0.0001" iyz="0" izz="0.0001" />
      </inertial>

    </link>



    <gazebo reference="camera_link">
      <sensor type="camera" name="camera_camera_sensor">
        <update_rate>30.0</update_rate>
        <camera>
          <pose>0.035 0 0.078 0 ${-M_PI/2} 0</pose>
          <horizontal_fov>${85 * M_PI/180.0}</horizontal_fov>
          <image>
            <format>R8G8B8</format>
            <width>1020</width>
            <height>1020</height>
          </image>
          <clip>
            <near>0.01</near>
            <far>1000</far>
          </clip>
        </camera>

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

</robot>
    
spawn.launch

<?xml version="1.0" encoding="UTF-8" ?>
<launch>
  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find camera_test)/urdf/robot.urdf'"/>
  
  <arg name="x" default="0"/>
  <arg name="y" default="0"/>
  <arg name="z" default="1.5"/>

  <node name="my_robot_spawn" pkg="gazebo_ros" type="spawn_model" output="screen"
        args="-urdf -param robot_description -model my_robot -x $(arg x) -y $(arg y) -z $(arg z)"/>

</launch>
    
rviz.urdf

<?xml version="1.0" ?>
<launch>

  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find camera_test)/urdf/robot.urdf'"/>

  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
    <param name="use_gui" value="False"/>
  </node>

  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/>

  <node name="rviz" pkg="rviz" type="rviz"/>

</launch>
    

References


  1. ROS Answers -- Adding a camera to a model in Gazebo? (Beginner)
  2. Gazebo plugins in ROS
  3. Converting between ROS images and OpenCV images (Python)
  4. Adding a camera to my urdf
  5. urdf/XML/joint