0
$\begingroup$

Rosanswers logo

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>

Originally posted by gurselturkeri on ROS Answers with karma: 25 on 2023-02-28

Post score: 0


Original comments

Comment by Ranjit Kathiriya on 2023-02-28:
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

Comment by gurselturkeri on 2023-02-28:
Launch file is same as in this question: https://answers.ros.org/question/412742/controller-manager-not-available-in-ros2/

Comment by Ranjit Kathiriya on 2023-02-28:
Tick the answer if you think it is right so it can help others in the community.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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 rpy="0 0 0" xyz="0 0 0.25"/>
    </visual>

    <collision>
        <geometry>
            <cylinder length="0.5" radius="0.08"/>
        </geometry>
        <origin rpy="0 0 0" xyz="0 0 0.25"/>
    </collision>
    
    <inertial>
        <origin rpy="0 0 0" xyz="0 0 0.25"/>
        <mass value="5.0"/>
        <inertia ixx="0.107" ixy="0.0" ixz="0.0" iyy="0.107" iyz="0.0" izz="0.0125"/>
    </inertial>

  </link>
  
  <joint name="joint_1" type="continuous">
    <axis xyz="0 0 1"/>
    <parent link="base_link"/>
    <child link="link_1"/>
    <origin rpy="0 0 0" xyz="0.0 0.0 0.05"/>
    <dynamics damping="10" friction="1.0"/>

  </joint>

<link name="link_2">
    <inertial>
        <origin rpy="0 0 0" xyz="0 0 0.2"/>
        <mass value="2.0"/>
        <inertia ixx="0.027" ixy="0.0" ixz="0.0" iyy="0.027" iyz="0.0" izz="0.0025"/>
    </inertial>

    <visual>
        <geometry>
        <cylinder length="0.1" radius="0.08"/>
        </geometry>
        <material name="Red">
            <color rgba="1 0 0 1"/>
          </material>
    </visual>

    <collision>
        <geometry>
            <cylinder length="0.1" radius="0.08"/>
        </geometry>
    </collision>

</link>

<joint name="joint_2" type="continuous">
<axis xyz="0 0 1"/>
<parent link="link_1"/>
<child link="link_2"/>
<origin rpy="0 1.5708 0" xyz="0.0 -0.005 0.58"/>
<limit lower="-0.25" upper="3.34" effort="10" velocity="0.5"/>
<dynamics damping="10" friction="1.0"/>

</joint>

<link name="link_3">
    <inertial>
        <origin rpy="0 0 0" xyz="0 0 0.2"/>
        <mass value="0.01"/>
        <inertia ixx="0.027" ixy="0.0" ixz="0.0" iyy="0.027" iyz="0.0" izz="0.0025"/>
    </inertial>
    
    <visual>
        <geometry>
        <cylinder length="0.4" radius="0.05"/>
        </geometry>
        <material name="blue">
            <color rgba="0.5 0.5 0.5 1"/>
          </material>
        <!-- <origin rpy="0 0 0" xyz="0 0 0.2"/> -->
        </visual>

    <collision>
        <geometry>
            <cylinder length="0.4" radius="0.05"/>
        </geometry>
    </collision>
</link>

<joint name="joint_3" type="fixed">
<parent link="link_2"/>
<child link="link_3"/>
<origin rpy="1.57 0 0" xyz="0.0 0.2 0 "/>
<dynamics damping="10" friction="1.0"/>

</joint>

<link name="link_4">
    <inertial>
        <origin rpy="0 0 0" xyz="0 0 0.2"/>
        <mass value="0.01"/>
        <inertia ixx="0.027" ixy="0.0" ixz="0.0" iyy="0.027" iyz="0.0" izz="0.0025"/>
    </inertial>

    <visual>
        <geometry>
        <cylinder length="0.1" radius="0.06"/>
        </geometry>
        <material name="Red">
            <color rgba="1 0 0 1"/>
          </material>
    </visual>

    <collision>
        <geometry>
            <cylinder length="0.1" radius="0.06"/>
        </geometry>
    </collision>

</link>

<joint name="joint_4" type="continuous">
<parent link="link_3"/>
<child link="link_4"/>
<origin rpy="1.57 0 0" xyz=" 0 0 -0.25"/>
<axis xyz=" 0 0 1"/>
<limit lower="-1.92" upper="1.92" effort="10" velocity="0.5"/>
<dynamics damping="10" friction="1.0"/>

</joint>




<link name="link_5">
    <inertial>
        <origin rpy="0 0 0" xyz="0 0 0.2"/>
        <mass value="0.01"/>
        <inertia ixx="0.027" ixy="0.0" ixz="0.0" iyy="0.027" iyz="0.0" izz="0.0025"/>
    </inertial>
    
    <visual>
        <geometry>
        <cylinder length="0.3" radius="0.03"/>
        </geometry>
        <material name="yello">
            <color rgba="0 1 0.5 1"/>
        </material>
        </visual>

    <collision>
        <geometry>
            <cylinder length="0.3" radius="0.03"/>
        </geometry>
    <dynamics damping="0.0" friction="0.0"/>
    
    </collision>
</link>

<joint name="joint_5" type="fixed">
<parent link="link_4"/>
<child link="link_5"/>
<origin rpy="1.57 0 0" xyz="0.0 -0.2 0 "/>
<dynamics damping="10" friction="1.0"/>

</joint>

<!-- 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>






<gazebo reference="base_link">
    <material>Gazebo/Black</material>
</gazebo>

<gazebo reference="link_1">
    <material>Gazebo/Orange</material>
</gazebo>

<gazebo reference="link_3">
    <material>Gazebo/Orange</material>
</gazebo>

<gazebo reference="link_2">
    <material>Gazebo/Red</material>
</gazebo>

<gazebo reference="link_4">
    <material>Gazebo/Red</material>
</gazebo>

<gazebo reference="link_5">
    <material>Gazebo/Orange</material>
</gazebo>


 <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>rrbot/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>


<gazebo>
  <plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
    <robot_sim_type>gazebo_ros2_control/GazeboSystem</robot_sim_type>
    <parameters>/home/airobo/ros2_ws/src/big_bazu/config/jtc.yaml</parameters>
  </plugin>
</gazebo>




<ros2_control name="GazeboSystem" type="system">
    <hardware>
      <plugin>gazebo_ros2_control/GazeboSystem</plugin>
</hardware>


<joint name="joint_1">
    <command_interface name="position">
      <param name="min">-3.14</param>
      <param name="max">3.14</param>
    </command_interface>
    <state_interface name="position"/>
    <param name="initial_position">0.0</param>  
  </joint>
  <joint name="joint_2">
    <command_interface name="position">
      <param name="min">-3.14</param>
      <param name="max">3.14</param>
    </command_interface>
    <state_interface name="position"/>
    <param name="initial_position">-1.57</param>  
  </joint>
  <joint name="joint_4">
    <command_interface name="position">
      <param name="min">-3.14</param>
      <param name="max">3.14</param>
    </command_interface>
    <state_interface name="position"/>
    <param name="initial_position">0.0</param>  
  </joint>

</ros2_control>

</robot>

Originally posted by Ranjit Kathiriya with karma: 1622 on 2023-02-28

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.