Camera plugin not working . Topic created in sdf file does not publish

camera plugin not working . Topic created in sdf file does not publish

Hi,

Here I place a xacro file code used in ROS2 humble to give among other things a camera sensor, hope it helps:

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


  <xacro:macro name="camera_rgb" params="robot_name parent_name origin_xyz camera_ROLL camera_PITCH camera_YAW">

    <link name="${robot_name}_rgb_camera_link_frame">
        <!-- <visual>
        <geometry>
            <cylinder length="0.01" radius="0.005"/>
        </geometry>
        </visual> -->
    </link>

    <joint name="${robot_name}_rgb_camera_link_frame_joint" type="fixed">
        <origin rpy="${camera_ROLL} ${camera_PITCH} ${camera_YAW}" xyz="${origin_xyz}"/>
        <parent link="${parent_name}" />
        <child link="${robot_name}_rgb_camera_link_frame" />
        <axis xyz="0 0 0"/>
    </joint>

    <gazebo reference="${robot_name}_rgb_camera_link_frame">
        <sensor name="${robot_name}_high_resolution_camera" type="camera">
          <camera>
            <horizontal_fov>1.3962634</horizontal_fov> <!-- Field of view -->
            <image>
              <width>400</width>
              <height>400</height>
              <format>R8G8B8</format>
            </image>
            <clip>
              <near>0.01</near>
              <far>6.0</far>
            </clip>
          </camera>
          <plugin name="high_resolution_camera_controller" filename="libgazebo_ros_camera.so">
            <ros>
              <namespace>${robot_name}</namespace>
            </ros>
            <cameraName>${robot_name}_rgb_camera_high_resolution</cameraName>
            <imageTopicName>image_raw</imageTopicName>
            <cameraInfoTopicName>camera_info</cameraInfoTopicName>
            <frameName>${robot_name}_rgb_camera_link_frame</frameName>
            <hackBaseline>0.07</hackBaseline>
          </plugin>
        </sensor>
    </gazebo>


    <gazebo reference="${robot_name}_rgb_camera_link_frame">
        <sensor name="${robot_name}_low_resolution_camera" type="camera">
          <camera>
            <horizontal_fov>1.3962634</horizontal_fov> <!-- Field of view -->
            <image>
              <width>4</width>
              <height>4</height>
              <format>R8G8B8</format>
            </image>
            <clip>
              <near>0.01</near>
              <far>6.0</far>
            </clip>
          </camera>
          <plugin name="low_resolution_camera_controller" filename="libgazebo_ros_camera.so">
            <ros>
              <namespace>${robot_name}</namespace>
            </ros>
            <cameraName>${robot_name}_rgb_camera_low_resolution</cameraName>
            <imageTopicName>image_raw</imageTopicName>
            <cameraInfoTopicName>camera_info</cameraInfoTopicName>
            <frameName>${robot_name}_rgb_camera_link_frame</frameName>
            <hackBaseline>0.07</hackBaseline>
          </plugin>
        </sensor>
    </gazebo>

  </xacro:macro>


  
  <xacro:macro name="laser_scan" params="robot_name parent_name origin_xyz sensor_YAW">
      <link name="${robot_name}_laser_scan_model_link">
        <visual name="${robot_name}_visual_laser_scan_link">
          <origin rpy="0 0 0" xyz="0 0 0"/>
          <geometry>
            <mesh filename="package://deepmind_bot_description/meshes/laser.dae" scale="1.0 1.0 1.0"/>
          </geometry>
        </visual>

        <collision name="${robot_name}_collision_laser_scan_link">
          <origin rpy="0 0 0" xyz="0 0 0.0204"/>
          <geometry>
            <cylinder length="0.0758" radius="0.03"/>
          </geometry>
        </collision>

        <inertial>

          <mass value="0.01"/>
          <origin rpy="0 0 0" xyz="0 0 0.0204"/>
          <inertia ixx="6.066578520833334e-06" ixy="0" ixz="0" iyy="6.066578520833334e-06" iyz="0" izz="9.365128684166666e-06"/>
        </inertial>
      </link>


    <joint name="${robot_name}_laser_scan_model_link_joint" type="fixed">
        <origin xyz="${origin_xyz}" rpy="0 0 ${sensor_YAW}" />
        <parent link="${parent_name}" />
        <child link="${robot_name}_laser_scan_model_link" />
    </joint>

    <link name="${robot_name}_laser_scan_frame">
    </link>

    <joint name="${robot_name}_laser_scan_frame_joint" type="fixed">
        <origin xyz="0 0 0.03" rpy="0 0 ${sensor_YAW}" />
        <parent link="${robot_name}_laser_scan_model_link" />
        <child link="${robot_name}_laser_scan_frame" />
    </joint>

    <gazebo reference="${robot_name}_laser_scan_frame">
      <sensor name="sensor_ray" type="ray">
          <pose>0 0 0 0 0 0</pose>
          <ray>
            <scan>
              <horizontal>
                <samples>200</samples>
                <resolution>1.0</resolution>
                <min_angle>-2.2</min_angle>
                <max_angle>2.2</max_angle>
              </horizontal>
            </scan>
            <range>
              <min>0.1</min>
              <max>30.0</max>
            </range>
          </ray>
          <always_on>true</always_on>
          <visualize>true</visualize>
          <update_rate>100.0</update_rate>
          <plugin name="laser" filename="libgazebo_ros_ray_sensor.so">
            <ros>
              <namespace>${robot_name}</namespace>
              <remapping>~/out:=laser_scan</remapping>
            </ros>
            <frame_name>${robot_name}_laser_scan_frame</frame_name>
            <output_type>sensor_msgs/LaserScan</output_type>
          </plugin>
        </sensor>
    </gazebo>

  </xacro:macro>


<xacro:macro name="point_cloud_sensor" params="robot_name parent_name sensor_name origin_xyz sensor_YAW">

  <link name='${robot_name}_pointcloud_link'>
        <visual>
        <geometry>
            <cylinder length="0.01" radius="0.005"/>
        </geometry>
        </visual>
	</link>

  <joint name="${robot_name}_pointcloud_link_joint" type="fixed">
		<origin rpy="0 0 ${sensor_YAW}" xyz="${origin_xyz}"/>
		<parent link="${parent_name}"/>
		<child link="${robot_name}_pointcloud_link"/>
	</joint>


    <gazebo reference="${robot_name}_pointcloud_link">
        <sensor type="ray" name="${robot_name}_pointcloud_sensor">
            <ray>
            <scan>
                <horizontal>
                    <samples>50</samples>
                    <resolution>1.0</resolution>
                    <min_angle>-1.0</min_angle>
                    <max_angle>1.0</max_angle>
                </horizontal>
                <vertical>
                    <samples>50</samples>
                    <resolution>1.0</resolution>
                    <min_angle>-1.0</min_angle>
                    <max_angle>1.0</max_angle>
                </vertical>
            </scan>
            <range>
                <min>0.10</min>
                <max>5.0</max>
                <resolution>0.01</resolution>
            </range>
            <!-- Using gazebo's noise instead of plugin's -->
            <noise>
                <type>gaussian</type>
                <mean>0.0</mean>
                <stddev>0.01</stddev>
            </noise>
            </ray>
            <!-- Using gazebo's update rate instead of plugin's -->
            <update_rate>30</update_rate>
            <plugin name="gazebo_ros_block_laser_controller" filename="libgazebo_ros_ray_sensor.so">
            <!-- Change namespace and output topic so published topic is /rrbot/laser/pointcloud -->
            <ros>
                <namespace>${robot_name}</namespace>
                <argument>--ros-args --remap ~/out:=pointcloud</argument>
                
            </ros>
            <!-- Set output to sensor_msgs/PointCloud to get same output type as gazebo_ros_block_laser -->
            <output_type>sensor_msgs/PointCloud</output_type>
            <frame_name>${robot_name}_pointcloud_link</frame_name>
            <!-- min_intensity instead of hokuyoMinIntensity -->
            <min_intensity>100.0</min_intensity>
            </plugin>
        </sensor>
    </gazebo>


</xacro:macro>



</robot>

Next time, please give some more information, details and how to reproduce your issue, otherwise its more challenging to help you :wink:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.