gazebo导入sdf模型

模型文件

模型文件结构:
-simple_car
  - -model.config
  - -model.sdf

model.config

<?xml version="1.0" ?>
<model>
    <name>simple_car</name>
    <version>1.0</version>
    <sdf version="1.6">model.sdf</sdf>
    <author>
        <name></name>
        <email></email>
    </author>
    <description></description>
</model>

model.sdf(添加有camera 和 controller,可以直接控制小车在gazebo中运动)

<?xml version='1.0'?>
<sdf version='1.6'>
    <model name='simple_car'>
      <link name='link_0'>
        <inertial>
          <mass>1</mass>
          <inertia>
            <ixx>0.166667</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>0.166667</iyy>
            <iyz>0</iyz>
            <izz>0.166667</izz>
          </inertia>
          <pose>0 0 0 0 -0 0</pose>
        </inertial>
        <pose>0.006 0 -0.005 0 -0 0</pose>
        <gravity>1</gravity>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <enable_wind>0</enable_wind>
        <visual name='visual'>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <box>
              <size>1 0.6 0.2</size>
            </box>
          </geometry>
          <material>
            <lighting>1</lighting>
            <script>
              <uri>file://media/materials/scripts/gazebo.material
              <name>Gazebo/Grey</name>
            </script>
            <shader type='pixel'>
              <normal_map>__default__</normal_map>
            </shader>
            <ambient>0.3 0.3 0.3 1</ambient>
            <diffuse>0.7 0.7 0.7 1</diffuse>
            <specular>0.01 0.01 0.01 1</specular>
            <emissive>0 0 0 1</emissive>
          </material>
          <transparency>0</transparency>
          <cast_shadows>1</cast_shadows>
        </visual>
        <collision name='collision'>
          <laser_retro>0</laser_retro>
          <max_contacts>10</max_contacts>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <box>
              <size>1 0.6 0.2</size>
            </box>
          </geometry>
          <surface>
            <friction>
              <ode>
                <mu>1</mu>
                <mu2>1</mu2>
                <fdir1>0 0 0</fdir1>
                <slip1>0</slip1>
                <slip2>0</slip2>
              </ode>
              <torsional>
                <coefficient>1</coefficient>
                <patch_radius>0</patch_radius>
                <surface_radius>0</surface_radius>
                <use_patch_radius>1</use_patch_radius>
                <ode>
                  <slip>0</slip>
                </ode>
              </torsional>
            </friction>
            <bounce>
              <restitution_coefficient>0</restitution_coefficient>
              <threshold>1e+06</threshold>
            </bounce>
            <contact>
              <collide_without_contact>0</collide_without_contact>
              <collide_without_contact_bitmask>1</collide_without_contact_bitmask>
              <collide_bitmask>1</collide_bitmask>
              <ode>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
                <max_vel>0.01</max_vel>
                <min_depth>0</min_depth>
              </ode>
              <bullet>
                <split_impulse>1</split_impulse>
                <split_impulse_penetration_threshold>-0.01</split_impulse_penetration_threshold>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
              </bullet>
            </contact>
          </surface>
        </collision>
      </link>
      <link name='link_1'>
        <inertial>
          <mass>1</mass>
          <inertia>
            <ixx>0.145833</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>0.145833</iyy>
            <iyz>0</iyz>
            <izz>0.125</izz>
          </inertia>
          <pose>0 0 0 0 -0 0</pose>
        </inertial>
        <pose>-0.394 0.35 -0.005 -1.5707 0 0</pose>
        <gravity>1</gravity>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <enable_wind>0</enable_wind>
        <visual name='visual'>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <cylinder>
              <radius>0.2</radius>
              <length>0.1</length>
            </cylinder>
          </geometry>
          <material>
            <lighting>1</lighting>
            <script>
              <uri>file://media/materials/scripts/gazebo.material
              <name>Gazebo/Grey</name>
            </script>
            <shader type='pixel'>
              <normal_map>__default__</normal_map>
            </shader>
            <ambient>0.3 0.3 0.3 1</ambient>
            <diffuse>0.7 0.7 0.7 1</diffuse>
            <specular>0.01 0.01 0.01 1</specular>
            <emissive>0 0 0 1</emissive>
          </material>
          <transparency>0</transparency>
          <cast_shadows>1</cast_shadows>
        </visual>
        <collision name='collision'>
          <laser_retro>0</laser_retro>
          <max_contacts>10</max_contacts>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <cylinder>
              <radius>0.2</radius>
              <length>0.1</length>
            </cylinder>
          </geometry>
          <surface>
            <friction>
              <ode>
                <mu>1</mu>
                <mu2>1</mu2>
                <fdir1>0 0 0</fdir1>
                <slip1>0</slip1>
                <slip2>0</slip2>
              </ode>
              <torsional>
                <coefficient>1</coefficient>
                <patch_radius>0</patch_radius>
                <surface_radius>0</surface_radius>
                <use_patch_radius>1</use_patch_radius>
                <ode>
                  <slip>0</slip>
                </ode>
              </torsional>
            </friction>
            <bounce>
              <restitution_coefficient>0</restitution_coefficient>
              <threshold>1e+06</threshold>
            </bounce>
            <contact>
              <collide_without_contact>0</collide_without_contact>
              <collide_without_contact_bitmask>1</collide_without_contact_bitmask>
              <collide_bitmask>1</collide_bitmask>
              <ode>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
                <max_vel>0.01</max_vel>
                <min_depth>0</min_depth>
              </ode>
              <bullet>
                <split_impulse>1</split_impulse>
                <split_impulse_penetration_threshold>-0.01</split_impulse_penetration_threshold>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
              </bullet>
            </contact>
          </surface>
        </collision>
      </link>
      <link name='link_2'>
        <inertial>
          <mass>1</mass>
          <inertia>
            <ixx>0.145833</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>0.145833</iyy>
            <iyz>0</iyz>
            <izz>0.125</izz>
          </inertia>
          <pose>0 0 0 0 -0 0</pose>
        </inertial>
        <pose>-0.394 -0.35 -0.005 -1.5707 0 0</pose>
        <gravity>1</gravity>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <enable_wind>0</enable_wind>
        <visual name='visual'>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <cylinder>
              <radius>0.2</radius>
              <length>0.1</length>
            </cylinder>
          </geometry>
          <material>
            <lighting>1</lighting>
            <script>
              <uri>file://media/materials/scripts/gazebo.material
              <name>Gazebo/Grey</name>
            </script>
            <shader type='pixel'>
              <normal_map>__default__</normal_map>
            </shader>
            <ambient>0.3 0.3 0.3 1</ambient>
            <diffuse>0.7 0.7 0.7 1</diffuse>
            <specular>0.01 0.01 0.01 1</specular>
            <emissive>0 0 0 1</emissive>
          </material>
          <transparency>0</transparency>
          <cast_shadows>1</cast_shadows>
        </visual>
        <collision name='collision'>
          <laser_retro>0</laser_retro>
          <max_contacts>10</max_contacts>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <cylinder>
              <radius>0.2</radius>
              <length>0.1</length>
            </cylinder>
          </geometry>
          <surface>
            <friction>
              <ode>
                <mu>1</mu>
                <mu2>1</mu2>
                <fdir1>0 0 0</fdir1>
                <slip1>0</slip1>
                <slip2>0</slip2>
              </ode>
              <torsional>
                <coefficient>1</coefficient>
                <patch_radius>0</patch_radius>
                <surface_radius>0</surface_radius>
                <use_patch_radius>1</use_patch_radius>
                <ode>
                  <slip>0</slip>
                </ode>
              </torsional>
            </friction>
            <bounce>
              <restitution_coefficient>0</restitution_coefficient>
              <threshold>1e+06</threshold>
            </bounce>
            <contact>
              <collide_without_contact>0</collide_without_contact>
              <collide_without_contact_bitmask>1</collide_without_contact_bitmask>
              <collide_bitmask>1</collide_bitmask>
              <ode>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
                <max_vel>0.01</max_vel>
                <min_depth>0</min_depth>
              </ode>
              <bullet>
                <split_impulse>1</split_impulse>
                <split_impulse_penetration_threshold>-0.01</split_impulse_penetration_threshold>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
              </bullet>
            </contact>
          </surface>
        </collision>
      </link>
      <link name='link_3'>
        <inertial>
          <mass>1</mass>
          <inertia>
            <ixx>0.1</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>0.1</iyy>
            <iyz>0</iyz>
            <izz>0.1</izz>
          </inertia>
          <pose>0 0 0 0 -0 0</pose>
        </inertial>
        <pose>0.306 0 -0.105 0 -0 0</pose>
        <gravity>1</gravity>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <enable_wind>0</enable_wind>
        <visual name='visual'>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <sphere>
              <radius>0.1</radius>
            </sphere>
          </geometry>
          <material>
            <lighting>1</lighting>
            <script>
              <uri>file://media/materials/scripts/gazebo.material
              <name>Gazebo/Grey</name>
            </script>
            <shader type='pixel'>
              <normal_map>__default__</normal_map>
            </shader>
            <ambient>0.3 0.3 0.3 1</ambient>
            <diffuse>0.7 0.7 0.7 1</diffuse>
            <specular>0.01 0.01 0.01 1</specular>
            <emissive>0 0 0 1</emissive>
          </material>
          <transparency>0</transparency>
          <cast_shadows>1</cast_shadows>
        </visual>
        <collision name='collision'>
          <laser_retro>0</laser_retro>
          <max_contacts>10</max_contacts>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <sphere>
              <radius>0.1</radius>
            </sphere>
          </geometry>
          <surface>
            <friction>
              <ode>
                <mu>0</mu>
                <mu2>0</mu2>
                <fdir1>0 0 0</fdir1>
                <slip1>0.01</slip1>
                <slip2>0</slip2>
              </ode>
              <torsional>
                <coefficient>1</coefficient>
                <patch_radius>0</patch_radius>
                <surface_radius>0</surface_radius>
                <use_patch_radius>1</use_patch_radius>
                <ode>
                  <slip>0</slip>
                </ode>
              </torsional>
            </friction>
            <bounce>
              <restitution_coefficient>0</restitution_coefficient>
              <threshold>1e+06</threshold>
            </bounce>
            <contact>
              <collide_without_contact>0</collide_without_contact>
              <collide_without_contact_bitmask>1</collide_without_contact_bitmask>
              <collide_bitmask>1</collide_bitmask>
              <ode>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
                <max_vel>0.01</max_vel>
                <min_depth>0</min_depth>
              </ode>
              <bullet>
                <split_impulse>1</split_impulse>
                <split_impulse_penetration_threshold>-0.01</split_impulse_penetration_threshold>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
              </bullet>
            </contact>
          </surface>
        </collision>
      </link>
      <link name='link_4'>
        <inertial>
          <mass>1</mass>
          <inertia>
            <ixx>0.166667</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>0.166667</iyy>
            <iyz>0</iyz>
            <izz>0.166667</izz>
          </inertia>
          <pose>0 0 0 0 -0 0</pose>
        </inertial>
        <pose>0.476 0 0.12 0 -0 0</pose>
        <gravity>1</gravity>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
        <enable_wind>0</enable_wind>
        <visual name='visual'>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <box>
              <size>0.03 0.1 0.05</size>
            </box>
          </geometry>
          <material>
            <lighting>1</lighting>
            <script>
              <uri>file://media/materials/scripts/gazebo.material
              <name>Gazebo/Grey</name>
            </script>
            <shader type='pixel'>
              <normal_map>__default__</normal_map>
            </shader>
            <ambient>0.01 0.6 0.9 1</ambient>
            <diffuse>0.7 0.7 0.7 1</diffuse>
            <specular>0.1 0.01 0.01 1</specular>
            <emissive>0 0 0 1</emissive>
          </material>
          <transparency>0</transparency>
          <cast_shadows>1</cast_shadows>
        </visual>
        <collision name='collision'>
          <laser_retro>0</laser_retro>
          <max_contacts>10</max_contacts>
          <pose>0 0 0 0 -0 0</pose>
          <geometry>
            <box>
              <size>0.03 0.1 0.05</size>
            </box>
          </geometry>
          <surface>
            <friction>
              <ode>
                <mu>1</mu>
                <mu2>1</mu2>
                <fdir1>0 0 0</fdir1>
                <slip1>0</slip1>
                <slip2>0</slip2>
              </ode>
              <torsional>
                <coefficient>1</coefficient>
                <patch_radius>0</patch_radius>
                <surface_radius>0</surface_radius>
                <use_patch_radius>1</use_patch_radius>
                <ode>
                  <slip>0</slip>
                </ode>
              </torsional>
            </friction>
            <bounce>
              <restitution_coefficient>0</restitution_coefficient>
              <threshold>1e+06</threshold>
            </bounce>
            <contact>
              <collide_without_contact>0</collide_without_contact>
              <collide_without_contact_bitmask>1</collide_without_contact_bitmask>
              <collide_bitmask>1</collide_bitmask>
              <ode>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
                <max_vel>0.01</max_vel>
                <min_depth>0</min_depth>
              </ode>
              <bullet>
                <split_impulse>1</split_impulse>
                <split_impulse_penetration_threshold>-0.01</split_impulse_penetration_threshold>
                <soft_cfm>0</soft_cfm>
                <soft_erp>0.2</soft_erp>
                <kp>1e+13</kp>
                <kd>1</kd>
              </bullet>
            </contact>
          </surface>
        </collision>
        <sensor name="camera" type="depth">
            <update_rate>20</update_rate>
            <camera>
              <horizontal_fov>1.047198</horizontal_fov>
              <image>
                <width>640</width>
                <height>480</height>
                <format>R8G8B8</format>
              </image>
              <clip>
                <near>0.05</near>
                <far>10</far>
              </clip>
            </camera>
            <plugin name="realsense_controller" filename="libgazebo_ros_openni_kinect.so">
             <baseline>0.2</baseline>
             <alwaysOn>true</alwaysOn>
             <updateRate>1.0</updateRate>
             <cameraName>realsense_f</cameraName>
             <imageTopicName>/camera/front/color/image_raw</imageTopicName>
             <cameraInfoTopicName>/camera/front/color/camera_info</cameraInfoTopicName>
             <depthImageTopicName>/camera/front/depth/image_raw</depthImageTopicName>
             <depthImageInfoTopicName>/camera/front/depth/camera_info</depthImageInfoTopicName>
             <pointCloudTopicName>/camera/front/depth/points</pointCloudTopicName>
             <frameName>rs_front</frameName>
             <pointCloudCutoff>0.5</pointCloudCutoff>
             <pointCloudCutoffMax>10.0</pointCloudCutoffMax>
             <distortionK1>0.00000001</distortionK1>
             <distortionK2>0.00000001</distortionK2>
             <distortionK3>0.00000001</distortionK3>
             <distortionT1>0.00000001</distortionT1>
             <distortionT2>0.00000001</distortionT2>
             <CxPrime>0</CxPrime>
             <Cx>0</Cx>
             <Cy>0</Cy>
             <focalLength>0</focalLength>
             <hackBaseline>0</hackBaseline>
           </plugin>
        </sensor>
      </link>
      <joint name='link_0_JOINT_0' type='revolute'>
        <parent>link_0</parent>
        <child>link_2</child>
        <pose>0 0 0 0 -0 0</pose>
        <axis>
          <xyz>0 0 1</xyz>
          <limit>
            <lower>-1.79769e+308</lower>
            <upper>1.79769e+308</upper>
            <effort>-1</effort>
            <velocity>-1</velocity>
          </limit>
          <dynamics>
            <spring_reference>0</spring_reference>
            <spring_stiffness>0</spring_stiffness>
            <damping>0</damping>
          </dynamics>
        </axis>
        <physics>
          <ode>
            <limit>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </limit>
            <suspension>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </suspension>
          </ode>
        </physics>
      </joint>
      <joint name='link_0_JOINT_1' type='revolute'>
        <parent>link_0</parent>
        <child>link_1</child>
        <pose>0 0 0 0 -0 0</pose>
        <axis>
          <xyz>0 0 1</xyz>
          <limit>
            <lower>-1.79769e+308</lower>
            <upper>1.79769e+308</upper>
            <effort>-1</effort>
            <velocity>-1</velocity>
          </limit>
          <dynamics>
            <spring_reference>0</spring_reference>
            <spring_stiffness>0</spring_stiffness>
            <damping>0</damping>
          </dynamics>
        </axis>
        <physics>
          <ode>
            <limit>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </limit>
            <suspension>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </suspension>
          </ode>
        </physics>
      </joint>
      <joint name='link_0_JOINT_2' type='fixed'>
        <parent>link_0</parent>
        <child>link_3</child>
        <pose>0 0 0 0 -0 0</pose>
        <physics>
          <ode>
            <limit>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </limit>
            <suspension>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </suspension>
          </ode>
        </physics>
      </joint>
      <joint name='link_0_JOINT_3' type='fixed'>
        <parent>link_0</parent>
        <child>link_4</child>
        <pose>0 0 0 0 -0 0</pose>
        <physics>
          <ode>
            <limit>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </limit>
            <suspension>
              <cfm>0</cfm>
              <erp>0.2</erp>
            </suspension>
          </ode>
        </physics>
      </joint>

      <include>
            <uri>model://hokuyo_lidar
            <pose>0.4 0 0.15 0 0 0</pose>
      </include>
      <joint name="hokuyo_joint" type="fixed">
        <child>hokuyo_lidar::link</child>
        <parent>link_0</parent>
      </joint>

      <plugin name="car_controller" filename="libgazebo_ros_diff_drive.so">
          <robotNamespace>/</robotNamespace>
          <updateRate>20</updateRate> 
          <leftJoint>link_0_JOINT_1</leftJoint>
          <rightJoint>link_0_JOINT_0</rightJoint>
          <wheelSeparation>0.7</wheelSeparation>
          <wheelDiameter>0.4</wheelDiameter>
          <alwaysOn>true</alwaysOn>
          <!-- Wheel acceleration, in rad/s^2, defaults to 0.0 rad/s^2 -->
          <wheelAcceleration>0.3</wheelAcceleration>
          <!-- Maximum torque which the wheels can produce, in Nm, defaults to 5 Nm -->
          <wheelTorque>20</wheelTorque>
          <!-- Topic to receive geometry_msgs/Twist message commands, defaults to `cmd_vel` -->
          <commandTopic>cmd_vel</commandTopic>
          <!-- Topic to publish nav_msgs/Odometry messages, defaults to `odom` -->
          <odometryTopic>odom</odometryTopic>
          <!-- Odometry frame, defaults to `odom` -->
          <odometryFrame>odom</odometryFrame>
          <!-- Robot frame to calculate odometry from, defaults to `base_footprint` -->
          <robotBaseFrame>link_0</robotBaseFrame>
          <!-- Set to true to publish transforms for the wheel links, defaults to false -->
          <publishWheelTF>true</publishWheelTF>
          <publishOdomTF>true</publishOdomTF>
          <!-- Set to true to publish transforms for the odometry, defaults to true -->
          <publishOdom>true</publishOdom>
          <publishWheelJointState>true</publishWheelJointState>
          <!-- Set to true to swap right and left wheels, defaults to true -->
          <legacyMode>false</legacyMode>
      </plugin>
      <static>0</static>
      <allow_auto_disable>1</allow_auto_disable>
    </model>
    <static>0</static>
</sdf>

添加到gazebo

1、启动gazebo,可以用roslaunch启动,也可以直接在终端输入:gazebo
gazebo导入sdf模型_第1张图片

2、insert模型
gazebo导入sdf模型_第2张图片

注意,这里只能在models这一层级目录open,不然gazebo找不到模型

下一步:
gazebo导入sdf模型_第3张图片从左侧拖动模型到环境里面,找到一个位置放下
gazebo导入sdf模型_第4张图片下一步:
gazebo导入sdf模型_第5张图片可以移动、旋转模型在环境中的 位置和姿态。

模型插入到世界中之后,可以保存一下世界文件,save as --> model.world,方便下一次直接加载使用

你可能感兴趣的:(ros,linux,ubuntu)