ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

add camera plugin in gazebo

asked 2023-02-28 05:32:30 -0600

gurselturkeri gravatar image

updated 2023-02-28 05:32:54 -0600

Hi, I have added camera plugin in a .urdf file but then I could not added in a launch.py file because of that image topic not published. Is my urdf file correct? And how can I added launch file to publish image topic?

<joint name="camera_joint" type="fixed">
        <parent link="link_3"/>
        <child link="camera_link"/>
        <origin rpy="0 0 0" xyz="0 0 0.4"/>
    </joint>


<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>robotic_arm/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>
edit retag flag offensive close merge delete

Comments

Hello @gurselturkeri,

Is it possible to share your code so I can have a look what's the issue? It can be either full code or git repo.

Thanks

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2023-02-28 05:44:21 -0600 )edit
1
gurselturkeri gravatar image gurselturkeri  ( 2023-02-28 06:16:37 -0600 )edit

Tick the answer if you think it is right so it can help others in the community.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2023-02-28 06:41:08 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-02-28 06:40:15 -0600

Ranjit Kathiriya gravatar image

updated 2023-02-28 11:02:55 -0600

Hello @gurselturkeri,

have added camera plugin in a .urdf file but then I could not added in a launch.py

If you have added camera in urdf file then you don't need to add it to your launch file.

sudo apt-get install ros-humble-gazebo-plugins

Note: You need to add camera plugins for the gazebo also as you did in your urdf.

but then I could not added in a launch.py file because of that image topic not published. Is my urdf file correct?

I think you forgot to add camera link into your urdf which you have shared above.

<!-- Camera -->
  <link name="camera_link">
    <collision>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
    <box size="${camera_link} ${camera_link} ${camera_link}"/>
      </geometry>
    </collision>

    <visual>
      <origin xyz="0 0 0" rpy="0 0 0"/>
      <geometry>
    <box size="${camera_link} ${camera_link} ${camera_link}"/>
      </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>

<joint name="camera_joint" type="fixed">
    <axis xyz="0 1 0" />
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <parent link="link_4"/>
    <child link="camera_link"/>
  </joint>

And how can I added launch file to publish image topic?

It will publish frames based on the gazebo settings you are doing in your plugin on camera_controller. In your case, it will be automatically published when the gazebo start based on your code

You can check this by opening rviz2 by hitting command in your terminal ros2 run rviz2 rviz2 or by ros2 topic list

image description

image description

As you can see above image, you can see a boll and the robot base in the rviz image visualize.

Feel free to drop an comment if you have any question,

so, my full urdf file is below:

<?xml version="1.0"?>
<robot name="robot_1">

  <link name="world"/>

    <link name="base_link">
        <visual>
            <geometry>
                <cylinder length="0.05" radius="0.2"/>
            </geometry>
            <material name="Black">
                <color rgba="0 0 0 1"/>
            </material>
            <origin rpy="0 0 0" xyz="0 0 0.025"/>
        </visual>

    <collision>
        <geometry>
            <cylinder length="0.05" radius="0.2"/>
        </geometry>
        <origin rpy="0 0 0" xyz="0 0 0.025"/>
    </collision>

    <inertial>
        <origin rpy="0 0 0" xyz="0 0 0.025"/>
        <mass value="5.0"/>
        <inertia ixx="0.0135" ixy="0.0" ixz="0.0" iyy="0.0135" iyz="0.0" izz="0.05"/>
    </inertial>


    </link>

  <joint name="fixed" type="fixed">
    <parent link="world"/>
    <child link="base_link"/>
    <dynamics damping="10" friction="1.0"/>

  </joint>

  <link name="link_1">
    <visual>
        <geometry>
            <cylinder length="0.5" radius="0.08"/>
        </geometry>
        <material name="blue">
            <color rgba="0 0 0.8 1"/>
          </material>
        <origin ...
(more)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-02-28 05:32:30 -0600

Seen: 1,366 times

Last updated: Feb 28 '23