学习笔记27--在用于加载到gazebo的.world世界文件中添加actor活动人模型编写方法

环境:ubuntu16.04 ros-kinetic gazebo7.16

问题来源:
项目想仿真模拟机器人视觉避障能力,基本场景就是路上有人走来做去,移动机器人能快速停下避让.

解决方式:
在其 .world文件里面添加一个人在里面走来走去就ok了.当然,gazebo的确提供了相应的办法实现.

这个案例基于上一个笔记博客里面(链接:https://blog.csdn.net/qq_45701501/article/details/107466727)展开的.内容上就增加一个人在里面绕圈圈.预览一下效果图:
在这里插入图片描述

tingzi.world:

<?xml version="1.0" ?>
<sdf version='1.6'>
  <world name='default'>



     <include>
         <uri>model://ground_plane</uri>
      </include>
      <!-- A global light source -->
      <include>
         <uri>model://sun</uri>
      </include>



<!--tingzi-->
    <model name='tingzi'>
     <static>true</static>
      <link name='base_link'>
        <pose frame=''>0 0 -1 0 -0 0</pose>
        <inertial>
          <pose frame=''>0 0 0 0 -0 0</pose>
          <mass>1</mass>
          <inertia>
            <ixx>1</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>1</iyy>
            <iyz>0</iyz>
            <izz>1</izz>
          </inertia>
        </inertial>
        <collision name='base_link_collision'>
          <pose frame=''>0 0 0 0 -0 0</pose>
          <geometry>
            <box>
              <size>1e-05 1e-05 1e-05</size>
            </box>
          </geometry>
          <max_contacts>10</max_contacts>
          <surface>
            <contact>
              <ode/>
            </contact>
            <bounce/>
            <friction>
              <torsional>
                <ode/>
              </torsional>
              <ode/>
            </friction>
          </surface>
        </collision>
        <collision name='base_link_fixed_joint_lump__tingzi_collision_1'>
          <pose frame=''>0 0 0 0 -0 0</pose>
          <geometry>
            <mesh>
              <scale>1 1 1</scale>
              <uri>/home/web00/arobot_ws/src/rpy/meshes/tingzi.STL</uri>
            </mesh>
          </geometry>
          <surface>
            <contact>
              <ode/>
            </contact>
            <friction>
              <ode/>
              <torsional>
                <ode/>
              </torsional>
            </friction>
            <bounce/>
          </surface>
          <max_contacts>10</max_contacts>
        </collision>
        <visual name='base_link_fixed_joint_lump__tingzi_visual'>
          <pose frame=''>0 0 0 0 -0 0</pose>
          <geometry>
            <mesh>
              <scale>1 1 1</scale>
              <uri>/home/web00/arobot_ws/src/rpy/meshes/tingzi.STL</uri>
            </mesh>
          </geometry>
          <material>
            <script>
              <name>Gazebo/Orange</name>
              <uri>file://media/materials/scripts/gazebo.material</uri>
            </script>
          </material>
        </visual>
        <gravity>1</gravity>
        <velocity_decay/>
        <self_collide>0</self_collide>
        <kinematic>0</kinematic>
      </link>
      <pose frame=''>0 0 1 0 -0 0</pose>
    </model>

      <actor name="actor2">
         <skin>
            <filename>moonwalk.dae</filename>//actor活动样式,其他样式可以去找找叫啥替换上去OK了
            <scale>1.0</scale>
         </skin>
         <pose>0 0 0 0 0 0</pose>
         <animation name="walking">
            <filename>moonwalk.dae</filename>
            <scale>1.000000</scale>
            <interpolate_x>true</interpolate_x>
         </animation>
         <script>//下面开始就是定义actor活动的范围以及时间,简单理解就是定义一下位置坐标和时间,这一时刻在哪个坐标位置这样子
            <loop>true</loop>
            <delay_start>0.000000</delay_start>
            <auto_start>true</auto_start>
            <trajectory id="0" type="walking">
               <waypoint>
                  <time>0</time>//时间点
                  <pose>26.8 -1.8 0 0 0 -1.57</pose>//坐标
               </waypoint>
               <waypoint>
                  <time>4.5</time>
                  <pose>26.4 -6.7 4.9 0 0 -1.57</pose>
               </waypoint>
               <waypoint>
                  <time>5.5</time>
                  <pose>26.8 -7.3 5 0 0 -1.57</pose>
               </waypoint>
               <waypoint>
                  <time>5.6</time>
                  <pose>26.8 -7.3 5 0 0 0</pose>
               </waypoint>
               <waypoint>
                  <time>9.4</time>
                  <pose>29.5 -7.3 5 0 0 0</pose>
               </waypoint>
               <waypoint>
                  <time>9.5</time>
                  <pose>29.5 -7.3 5 0 0 3.14</pose>
               </waypoint>
               <waypoint>
                  <time>13.4</time>
                  <pose>26.8 -7.3 5 0 0 3.14</pose>
               </waypoint>
               <waypoint>
                  <time>13.5</time>
                  <pose>26.8 -7.3 5 0 0 1.57</pose>
               </waypoint>
               <waypoint>
                  <time>14</time>
                  <pose>26.8 -6.7 4.9 0 0 1.57</pose>
               </waypoint>
               <waypoint>
                  <time>18</time>
                  <pose>26.8 -1.8 0 0 0 1.57</pose>
               </waypoint>
            </trajectory>
         </script>
      </actor>


<!--actor-->
    <actor name="actor">
    <skin>
      <filename>moonwalk.dae</filename>
      <scale>1.0</scale>
    </skin>
    <animation name="walking">
      <filename>walk.dae</filename>
      <scale>1.000000</scale>
      <interpolate_x>true</interpolate_x>
    </animation>
    <script>
      <loop>true</loop>
      <delay_start>0.000000</delay_start>
      <auto_start>true</auto_start>
      <trajectory id="0" type="walking">
        <waypoint>
          <time>0.000000</time>
          <pose>0.000000 1.000000 0.000000 0.000000 0.000000 0.000000</pose>
        </waypoint>
        <waypoint>
          <time>0.500000</time>
          <pose>0.195090 0.980785 0.000000 0.000000 0.000000 -0.196350</pose>
        </waypoint>
        <waypoint>
           <time>1.000000</time>
           <pose>0.382683 0.923880 0.000000 0.000000 0.000000 -0.392699</pose>
        </waypoint>
        <waypoint>
           <time>1.500000</time>
           <pose>0.555570 0.831470 0.000000 0.000000 0.000000 -0.589049</pose>
        </waypoint>
        <waypoint>
           <time>2.000000</time>
           <pose>0.707107 0.707107 0.000000 0.000000 0.000000 -0.785398</pose>
        </waypoint>
        <waypoint>
           <time>2.500000</time>
           <pose>0.831470 0.555570 0.000000 0.000000 0.000000 -0.981748</pose>
        </waypoint>
        <waypoint>
           <time>3.000000</time>
           <pose>0.923880 0.382683 0.000000 0.000000 0.000000 -1.178100</pose>
        </waypoint>
        <waypoint>
           <time>3.500000</time>
           <pose>0.980785 0.195090 0.000000 0.000000 0.000000 -1.374450</pose>
        </waypoint>
        <waypoint>
           <time>4.000000</time>
           <pose>1.000000 0.000000 0.000000 0.000000 0.000000 -1.570800</pose>
        </waypoint>
        <waypoint>
           <time>4.500000</time>
           <pose>0.980785 -0.195090 0.000000 0.000000 0.000000 -1.767150</pose>
        </waypoint>
        <waypoint>
           <time>5.000000</time>
           <pose>0.923880 -0.382683 0.000000 0.000000 0.000000 -1.963500</pose>
        </waypoint>
        <waypoint>
           <time>5.500000</time>
           <pose>0.831470 -0.555570 0.000000 0.000000 0.000000 -2.159840</pose>
        </waypoint>
        <waypoint>
           <time>6.000000</time>
           <pose>0.707107 -0.707107 0.000000 0.000000 0.000000 -2.356190</pose>
        </waypoint>
        <waypoint>
           <time>6.500000</time>
           <pose>0.555570 -0.831470 0.000000 0.000000 0.000000 -2.552540</pose>
        </waypoint>
        <waypoint>
           <time>7.500000</time>
           <pose>0.382683 -0.923880 0.000000 0.000000 0.000000 -2.748890</pose>
        </waypoint>
        <waypoint>
           <time>8.500000</time>
           <pose>0.195090 -0.980785 0.000000 0.000000 0.000000 -2.945240</pose>
        </waypoint>
        <waypoint>
           <time>9.500000</time>
           <pose>0.000000 -1.000000 0.000000 0.000000 0.000000 -3.141590</pose>
        </waypoint>
        <waypoint>
           <time>10.500000</time>
           <pose>-0.195090 -0.980785 0.000000 0.000000 0.000000 2.945245</pose>
        </waypoint>
        <waypoint>
           <time>11.500000</time>
           <pose>-0.382683 -0.923880 0.000000 0.000000 0.000000 2.748895</pose>
        </waypoint>
        <waypoint>
           <time>12.000000</time>
           <pose>-0.555570 -0.831470 0.000000 0.000000 0.000000 2.552545</pose>
        </waypoint>
        <waypoint>
           <time>12.500000</time>
           <pose>-0.707107 -0.707107 0.000000 0.000000 0.000000 2.356195</pose>
        </waypoint>
        <waypoint>
           <time>13.000000</time>
           <pose>-0.831470 -0.555570 0.000000 0.000000 0.000000 2.159845</pose>
        </waypoint>
        <waypoint>
           <time>13.500000</time>
           <pose>-0.923880 -0.382683 0.000000 0.000000 0.000000 1.963495</pose>
        </waypoint>
        <waypoint>
           <time>14.000000</time>
           <pose>-0.980785 -0.195090 0.000000 0.000000 0.000000 1.767145</pose>
        </waypoint>
        <waypoint>
           <time>14.500000</time>
           <pose>-1.000000 0.000000 0.000000 0.000000 0.000000 1.570795</pose>
        </waypoint>
        <waypoint>
           <time>15.000000</time>
           <pose>-0.980785 0.195090 0.000000 0.000000 0.000000 1.374445</pose>
        </waypoint>
        <waypoint>
           <time>15.500000</time>
           <pose>-0.923880 0.382683 0.000000 0.000000 0.000000 1.178095</pose>
        </waypoint>
        <waypoint>
           <time>16.000000</time>
           <pose>-0.831470 0.555570 0.000000 0.000000 0.000000 0.981745</pose>
        </waypoint>
        <waypoint>
           <time>16.500000</time>
           <pose>-0.707107 0.707107 0.000000 0.000000 0.000000 0.785395</pose>
        </waypoint>
        <waypoint>
           <time>17.000000</time>
           <pose>-0.555570 0.831470 0.000000 0.000000 0.000000 0.589045</pose>
        </waypoint>
        <waypoint>
           <time>17.500000</time>
           <pose>-0.382683 0.923880 0.000000 0.000000 0.000000 0.392695</pose>
        </waypoint>
        <waypoint>
           <time>18.000000</time>
           <pose>-0.195090 0.980785 0.000000 0.000000 0.000000 0.196345</pose>
        </waypoint>
      </trajectory>
    </script>
      </actor>


  </world>
</sdf>

把这个世界加载到gazebo环境会发现了这个模型居然是没有碰撞属性的.的确,在gazebo7系列版本都是不支持的带有碰撞属性的actor模型的.

如果有兴趣的话可以把<actor>对应碰撞属性的插件加上,然后更新gazebo版本到8以上,然后会发现这个actor模型是带有碰撞属性的(亲测了gazebo9可以,后面因为需要配合其他仿真又重装回来gazebo7.16,否则模拟生产线是没有问题的).

<actor>带有碰撞属性编写样式:

<sdf>
<world>
......
<!--actor-->
    <actor name="actor">
    
    <plugin name="actor_collisions_plugin" filename="libActorCollisionsPlugin.so">//碰撞属性定义
      <scaling collision="LHipJoint_LeftUpLeg_collision" scale="
        0.01
        0.001
        0.001
      "/>
      <scaling collision="LeftUpLeg_LeftLeg_collision" scale="
        8.0
        8.0
        1.0
      "/>
      <scaling collision="LeftLeg_LeftFoot_collision" scale="
        8.0
        8.0
        1.0
      "/>
      <scaling collision="LeftFoot_LeftToeBase_collision" scale="
        4.0
        4.0
        1.5
      "/>
      <scaling collision="RHipJoint_RightUpLeg_collision" scale="
        0.01
        0.001
        0.001
      "/>
      <scaling collision="RightUpLeg_RightLeg_collision" scale="
        8.0
        8.0
        1.0
      "/>
      <scaling collision="RightLeg_RightFoot_collision" scale="
        8.0
        8.0
        1.0
      "/>
      <scaling collision="RightFoot_RightToeBase_collision" scale="
        4.0
        4.0
        1.5
      "/>
      <scaling collision="LowerBack_Spine_collision" scale="
        12.0
        20.0
        5.0
      " pose="0.05 0 0 0 -0.2 0"/>
      <scaling collision="Spine_Spine1_collision" scale="
        0.01
        0.001
        0.001
      "/>
      <scaling collision="Neck_Neck1_collision" scale="
        0.01
        0.001
        0.001
      "/>
      <scaling collision="Neck1_Head_collision" scale="
        5.0
        5.0
        3.0
      "/>
      <scaling collision="LeftShoulder_LeftArm_collision" scale="
        0.01
        0.001
        0.001
      "/>
      <scaling collision="LeftArm_LeftForeArm_collision" scale="
        5.0
        5.0
        1.0
      "/>
      <scaling collision="LeftForeArm_LeftHand_collision" scale="
        5.0
        5.0
        1.0
      "/>
      <scaling collision="LeftFingerBase_LeftHandIndex1_collision" scale="
        4.0
        4.0
        3.0
      "/>
      <scaling collision="RightShoulder_RightArm_collision" scale="
        0.01
        0.001
        0.001
      "/>
      <scaling collision="RightArm_RightForeArm_collision" scale="
        5.0
        5.0
        1.0
      "/>
      <scaling collision="RightForeArm_RightHand_collision" scale="
        5.0
        5.0
        1.0
      "/>
      <scaling collision="RightFingerBase_RightHandIndex1_collision" scale="
        4.0
        4.0
        3.0
      "/>
    </plugin>

    <skin>
      <filename>moonwalk.dae</filename>
      <scale>1.0</scale>
    </skin>
    <animation name="walking">
      <filename>walk.dae</filename>
      <scale>1.000000</scale>
      <interpolate_x>true</interpolate_x>
    </animation>
    <script>
      <loop>true</loop>
      <delay_start>0.000000</delay_start>
      <auto_start>true</auto_start>
      <trajectory id="0" type="walking">
        <waypoint>
          <time>0.000000</time>
          <pose>0.000000 1.000000 0.000000 0.000000 0.000000 0.000000</pose>
        </waypoint>
        <waypoint>
          <time>0.500000</time>
          <pose>0.195090 0.980785 0.000000 0.000000 0.000000 -0.196350</pose>
        </waypoint>
        <waypoint>
           <time>1.000000</time>
           <pose>0.382683 0.923880 0.000000 0.000000 0.000000 -0.392699</pose>
        </waypoint>
        <waypoint>
           <time>1.500000</time>
           <pose>0.555570 0.831470 0.000000 0.000000 0.000000 -0.589049</pose>
        </waypoint>
        <waypoint>
           <time>2.000000</time>
           <pose>0.707107 0.707107 0.000000 0.000000 0.000000 -0.785398</pose>
        </waypoint>
        <waypoint>
           <time>2.500000</time>
           <pose>0.831470 0.555570 0.000000 0.000000 0.000000 -0.981748</pose>
        </waypoint>
        <waypoint>
           <time>3.000000</time>
           <pose>0.923880 0.382683 0.000000 0.000000 0.000000 -1.178100</pose>
        </waypoint>
        <waypoint>
           <time>3.500000</time>
           <pose>0.980785 0.195090 0.000000 0.000000 0.000000 -1.374450</pose>
        </waypoint>
        <waypoint>
           <time>4.000000</time>
           <pose>1.000000 0.000000 0.000000 0.000000 0.000000 -1.570800</pose>
        </waypoint>
        <waypoint>
           <time>4.500000</time>
           <pose>0.980785 -0.195090 0.000000 0.000000 0.000000 -1.767150</pose>
        </waypoint>
        <waypoint>
           <time>5.000000</time>
           <pose>0.923880 -0.382683 0.000000 0.000000 0.000000 -1.963500</pose>
        </waypoint>
        <waypoint>
           <time>5.500000</time>
           <pose>0.831470 -0.555570 0.000000 0.000000 0.000000 -2.159840</pose>
        </waypoint>
        <waypoint>
           <time>6.000000</time>
           <pose>0.707107 -0.707107 0.000000 0.000000 0.000000 -2.356190</pose>
        </waypoint>
        <waypoint>
           <time>6.500000</time>
           <pose>0.555570 -0.831470 0.000000 0.000000 0.000000 -2.552540</pose>
        </waypoint>
        <waypoint>
           <time>7.500000</time>
           <pose>0.382683 -0.923880 0.000000 0.000000 0.000000 -2.748890</pose>
        </waypoint>
        <waypoint>
           <time>8.500000</time>
           <pose>0.195090 -0.980785 0.000000 0.000000 0.000000 -2.945240</pose>
        </waypoint>
        <waypoint>
           <time>9.500000</time>
           <pose>0.000000 -1.000000 0.000000 0.000000 0.000000 -3.141590</pose>
        </waypoint>
        <waypoint>
           <time>10.500000</time>
           <pose>-0.195090 -0.980785 0.000000 0.000000 0.000000 2.945245</pose>
        </waypoint>
        <waypoint>
           <time>11.500000</time>
           <pose>-0.382683 -0.923880 0.000000 0.000000 0.000000 2.748895</pose>
        </waypoint>
        <waypoint>
           <time>12.000000</time>
           <pose>-0.555570 -0.831470 0.000000 0.000000 0.000000 2.552545</pose>
        </waypoint>
        <waypoint>
           <time>12.500000</time>
           <pose>-0.707107 -0.707107 0.000000 0.000000 0.000000 2.356195</pose>
        </waypoint>
        <waypoint>
           <time>13.000000</time>
           <pose>-0.831470 -0.555570 0.000000 0.000000 0.000000 2.159845</pose>
        </waypoint>
        <waypoint>
           <time>13.500000</time>
           <pose>-0.923880 -0.382683 0.000000 0.000000 0.000000 1.963495</pose>
        </waypoint>
        <waypoint>
           <time>14.000000</time>
           <pose>-0.980785 -0.195090 0.000000 0.000000 0.000000 1.767145</pose>
        </waypoint>
        <waypoint>
           <time>14.500000</time>
           <pose>-1.000000 0.000000 0.000000 0.000000 0.000000 1.570795</pose>
        </waypoint>
        <waypoint>
           <time>15.000000</time>
           <pose>-0.980785 0.195090 0.000000 0.000000 0.000000 1.374445</pose>
        </waypoint>
        <waypoint>
           <time>15.500000</time>
           <pose>-0.923880 0.382683 0.000000 0.000000 0.000000 1.178095</pose>
        </waypoint>
        <waypoint>
           <time>16.000000</time>
           <pose>-0.831470 0.555570 0.000000 0.000000 0.000000 0.981745</pose>
        </waypoint>
        <waypoint>
           <time>16.500000</time>
           <pose>-0.707107 0.707107 0.000000 0.000000 0.000000 0.785395</pose>
        </waypoint>
        <waypoint>
           <time>17.000000</time>
           <pose>-0.555570 0.831470 0.000000 0.000000 0.000000 0.589045</pose>
        </waypoint>
        <waypoint>
           <time>17.500000</time>
           <pose>-0.382683 0.923880 0.000000 0.000000 0.000000 0.392695</pose>
        </waypoint>
        <waypoint>
           <time>18.000000</time>
           <pose>-0.195090 0.980785 0.000000 0.000000 0.000000 0.196345</pose>
        </waypoint>
      </trajectory>
    </script>
      </actor>

</world>
</sdf>

以上就是怎么创建一个人在 .world世界文件中活动的创建办法.

注意,代码中出现的中文注释,使用时候一定要去掉,否则容易出现未知错误;或者把注释翻译成英文,然后使用<!-- -->包含起来也是可以的.
#########################
好记性不如烂笔头
–20200721

  • 3
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值