前一篇中,我們建立了一個機器人,並幫他的部件上色。這一節我們會為他加上一些限制:比如說,手臂不能360度旋轉,而只能在某個角度;頭部只能在一定範圍內旋轉等,這一類的限制我們在3D建模中叫做約束。

我們嘗試從上一個上過色的範例中更改一點點東西:

<?xml version="1.0"?>
<robot name="kotori">

  <material name="blue">
    <color rgba="0 0 0.8 1"/>
  </material>

  <material name="white">
    <color rgba="1 1 1 1"/>
  </material>

  <link name="base_link">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      </geometry>
      <material name="blue"/>
    </visual>
  </link>

  <link name="right_leg">
    <visual>
      <geometry>
        <box size="0.6 0.1 0.2"/>
      </geometry>
      <origin rpy="0 1.57075 0" xyz="0 0 -0.3"/>
      <material name="white"/>
    </visual>
  </link>

  <joint name="base_to_right_leg" type="revolute">
    <limit effort="1000.0" lower="-2	" upper="0" velocity="0.5"/>
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0 -0.22 0.25"/>
  </joint>

  <link name="left_leg">
    <visual>
      <geometry>
        <box size="0.6 0.1 0.2"/>
      </geometry>
      <origin rpy="0 1.57075 0" xyz="0 0 -0.3"/>
      <material name="white"/>
    </visual>
  </link>

  <joint name="base_to_left_leg" type="fixed">
    <parent link="base_link"/>
    <child link="left_leg"/>
    <origin xyz="0 0.22 0.25"/>
  </joint>

</robot>

其中,我們最主要的更改是:

  <joint name="base_to_right_leg" type="revolute">
    <limit effort="1000.0" lower="-2	" upper="0" velocity="0.5"/>
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin xyz="0 -0.22 0.25"/>
  </joint>

這地方我們將其中一邊的翅膀(?)關節型態改為旋轉,並指定他的下界為-2,上界為0(此處皆指弧度)。我們從RVIZ來看看這個設定的實際效果:

ros2 launch urdf_tutorial display.launch.py model:=test.urdf

可以注意到啟動後多了一個小視窗,並且可以拉動

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

從名稱可以看到,是剛剛我們更動的關節名稱。可以試著拉動底下的滑動條,觀察rviz中模型的變化。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

現在,我們有了一個有明確定義的模型,並且他的運動遵循我們剛剛定義的約束。