gazebosim / sdf_tutorials

SDFormat documentation and proposals.
http://sdformat.org
27 stars 15 forks source link

How to get parameter passing runnable and set up environment with correct libsdformat version? #90

Closed khaep closed 1 year ago

khaep commented 1 year ago

Dear sdf-tutorial contributors,

I am using a Gazebo simulation (11.10.2) with ros-humble-gazebo-plugins and I am trying to instantiate sensors multiple times with adjusted parameters in a nested robot model. Therefore, I want to use the proposed parameter passing as described in your tutorial, but it seems to be difficult to get it runnable.

Assuming the following model.sdf file describes a camera sensor.

<?xml version='1.0'?>
<sdf version='1.7'>
  <model name='my_camera'>
      <link name="link">
        <visual name="visual">
          <geometry>
            <box>
              <size>0.1 0.1 0.1</size>
            </box>
          </geometry>
          <material>
            <ambient>0 1 0 1</ambient>
            <diffuse>0 1 0 1</diffuse>
            <specular>0 1 0 1</specular>
            <emissive>0 1 0 1</emissive>
          </material>
        </visual>
        <sensor name="camera" type="camera">
          <update_rate>10</update_rate>
          <visualize>true</visualize>
          <!-- camera parameters -->
          <camera>
            <model>pinhole</model>
            <intrinsics> 
              <fx>2382.52</fx>
              <fy>2385.37</fy>
              <cx>1095.98</cx>
              <cy>511.137</cy>
              <s>0</s>
            </intrinsics>
            <image>
              <width>2048</width>
              <height>1024</height>
              <format>R8G8B8</format>
            </image>
          </camera>
          <!-- plugin to publish cam topics in ros2 -->
          <plugin name="camera_controller" filename="libgazebo_ros_camera.so">
            <imageTopicName>image_raw</imageTopicName>
            <cameraInfoTopicName>camera_info</cameraInfoTopicName>
            <frameName>camera_link_optical</frameName>
          </plugin>
        </sensor>
      </link>
  </model>
</sdf>  

The aim is to include an instance of the camera with some different parameters in the robot's model.sdf file. For example, with a different housing color specified within the <material> tag.

<?xml version='1.0'?>
<sdf version='1.7' xmlns:experimental="http://sdformat.org/schemas/experimental">
  <model name='my_robot'>
    <link name='base'>
       <!-- description of my_robot link -->
    </link>

    <include>
      <uri>model://my_camera</uri>
      <pose>1.6 0 3.2 0 0.2 0</pose>
      <name>cam_one</name>
      <static>false</static>
      <experimental:params>
        <visual element_id="link::visual">
          <material action="modify">
            <ambient>0 0 255 1</ambient>
            <diffuse>0 0 255 1</diffuse>
            <specular>0 0 255 1</specular>
            <emissive>0 0 255 1</emissive>
          </material>
        </visual>  
      </experimental:params>
    </include>

    <joint name="cam_one_joint" type="fixed">
      <child>cam_one::link</child>
      <parent>base</parent>
      <pose>0 0 0 0 0 0</pose>
      <physics>
        <!-- description of joint physics -->
      </physics>
    </joint>
  </model>
</sdf>

The code of the robot's model.sdf file mentioned above does not change anything. The camera still has its default color. Now the question is how to get the parameter passing runnable?

Another point to mention is that you specified libsdformat version 10 and sdf version 1.7 in the tutorial. But the ros-humble-gazebo-plugins are related to libsdformat9-9 if it is installed with apt install. I described that format problem in a Gazebo Answers post here. So how can I set up an environment with ros-humble-gazebo-plugins, libsdformat version 10 and sdf version 1.7 to use parameter passing successfully? Is the parameter passing still a draft, or is it a more robust version?

It would be very nice if you can give me some advice or hints to make progress on this topic.

I look forward to hearing from you.

Best regards.

azeey commented 1 year ago

Hi @KHeap25, I've answered the question here. I'll go ahead and close this issue.