Gazebo筆記(五)

Chien-lin.Tseng
My learning note
Published in
25 min readJul 25, 2019

2019年7月25日(四)

目錄:

一、 參考的網站

二、 弄懂 gazebo_ros_demos 裡的三個 package

三、 先跑 ros 網頁的 urdf 教學

四、 urdf tutorial (1) —
Building a Visual Robot Model with URDF from Scratch

四、 urdf tutorial (2) —
Building a Movable Robot Model with URDF

四、 urdf tutorial (3) —
Adding Physical and Collision Properties to a URDF Model

四、 urdf tutorial (4) —
Using Xacro to Clean Up a URDF File

四、 urdf tutorial (5) —
Using a URDF in Gazebo

五、 有關 rrbot_description

六、 有關 rrbot_control

七、 有關 rrbot_gazebo

一、參考的網站

(1) ros 網頁的 urdf 教學

(2) <link> 的相關介紹

(3) rpy (roll, pitch , yaw) 介紹

(4) <rosparam> 在roslaunch xml 中的用法

(5) <param> 在 roslaunch xml 中的用法

(6) <arg> 在 roslaunch xml 中的用法

(7) <include> 在 roslaunch xml 中的用法

(8) roslaunch 檔的介紹

(9)

(10)

二、弄懂 gazebo_ros_demos 裡的三個 package

gazebo_ros_demos 裡有三個 package,分別是 rrbot_description、rrbot_control、 rrbot_gazebo 。

rrbot_description 內有urdf 相關的檔案。

rrbot_control 內有 controller 相關的檔案。

最後會依序講述這三個 package。

三、 先跑 ros 網頁的 urdf 教學

這個網頁的 urdf tutorial 比 gazebo 網頁那裡的清楚很多。

下面是urdf tutorial的筆記。

四、urdf tutorial (1) —
Building a Visual Robot Model with URDF from Scratch

(1) 安裝 urdf_tutorial package

cd ~/catkin_ws/src
git clone https://github.com/ros/urdf_tutorial.git
cd ~/catkin_ws
catkin_make

(2) One Shape

在 /urdf_tutorial/urdf 中,可以看到 01-myfirst.urdf 這個檔案:

檔案敘述:
this is a robot with the name myfirst, that contains only one link (a.k.a. part), whose visual component is just a cylinder 0.6 meters long with a 0.2 meter radius.

執行 roslaunch,在 rviz 中看一下這份 urdf 所建立的模型:

roslaunch urdf_tutorial display.launch model:=urdf/01-myfirst.urdf注意:要記得在 urdf_tutorial 中執行,不然會出現錯誤 (因為要顧慮到model的路徑)

看一下 display.launch 中寫了什麼:

rosed urdf_tutorial display.launch
<arg name="model" default="$(find urdf_tutorial)/urdf/01-myfirst.urdf"/>這行宣告了"model"變數, 預設值為 "$(find urdf_tutorial)/urdf/01-myfirst.urdf"。 可以透過在執行roslaunch時,改變這個"model"變數值(後面有)

所以這個roslaunch,做了三個事情:

  • Loads the specified model into the parameter server
  • Runs nodes to publish sensor_msgs/JointState and transforms
  • Starts Rviz with a configuration file

結果圖:

  • The visual element (the cylinder) has its origin at the center of its geometry as a default. Hence, half the cylinder is below the grid.
    ( 一半的圓柱體在方格線的下面)

(3) Multiple Shapes

有多個link、有joint的urdf。

看一下位於路徑 /catkin_ws/src/urdf_tutorial/urdf 的
02-multipleshapes.urdf :

  • Note how we defined a 0.6m x 0.1m x 0.2m box.
    ( <box size > 那行)
  • The joint is defined in terms of a parent and a child. URDF is ultimately a tree structure with one root link. This means that the leg’s position is dependent on the base_link’s position.
    ( 使用 parent link 和 child link 來建立 joint )

執行 roslaunch:

roslaunch urdf_tutorial display.launch model:=urdf/02-multipleshapes.urdf// 我們在 command line,指定 model 的變數值

結果圖:

  • Both of the shapes overlap with each other, because they share the same origin. If we want them not to overlap we must define more origins.
    (兩個立體交疊在一起)

(4) Origins

So R2D2’s leg attaches to the top half of his torso, on the side. So that’s where we specify the origin of the JOINT to be. Also, it doesn’t attach to the middle of the leg, it attaches to the upper part, so we must offset the origin for the leg as well. We also rotate the leg so it is upright.
(這裡我們要改正 leg 的位置,並且旋轉 leg ,使 leg 是直立的)

看一下 03-origins.urdf :

  • 注意 rviz 圖中,每一個立體中都有個 座標軸圖案。
  • Let’s start by examining the joint’s origin. It is defined in terms of the parent’s reference frame. So we are -0.22 meters in the y direction (to our left, but to the right relative to the axes) and 0.25 meters in the z direction (up). This means that the origin for the child link will be up and to the right, regardless of the child link’s visual origin tag. Since we didn’t specify a rpy (roll pitch yaw) attribute, the child frame will be default have the same orientation as the parent frame.
    (joint的origin 是相對於 parent link。)
  • Now, looking at the leg’s visual origin, it has both a xyz and rpy offset. This defines where the center of the visual element should be, relative to its origin. Since we want the leg to attach at the top, we offset the origin down by setting the z offset to be -0.3 meters. And since we want the long part of the leg to be parallel to the z axis, we rotate the visual part PI/2 around the Y axis.
    (目前的解讀: joint的origin 就是 child link(right_leg)的origin。
    right_leg的center 的定義是相對於 right_leg的origin。
    right_leg的center 就是 長方體的正中心。
    rpy=”0 1.57075 0" 就是把y軸抓著轉1.57 rad,可以看上面rpy的網站。)
  • 若改變 joint的話? 待補…………………………………..

執行roslaunch:

roslaunch urdf_tutorial display.launch model:=urdf/03-origins.urdf

結果圖:

(5) Material

上顏色的指令。

注意 <material>

執行 roslaunch

roslaunch urdf_tutorial display.launch model:=urdf/04-materials.urdf

(6) Finishing the Model

程式的網址:

執行:

roslaunch urdf_tutorial display.launch model:=urdf/05-visual.urdf

結果圖:

  • 注意一下許多joint都是fixed,在下一個tutorial會改成其他形式(像是continuous)
  • 注意一下mesh的用法

四、urdf tutorial (2) —
Building a Movable Robot Model with URDF

在之前的model,joint 都是 fixed。
這個教學會介紹另外三個重要的形式:continuous, revolute and prismatic.

更改為 flexible joints 的程式:

roslaunch urdf_tutorial display.launch model:=urdf/06-flexible.urdf

結果圖:

會另外跳出一個控制視窗,我們可以透過調整參數,來使得機器人動作。(control the values of all the non-fixed joints)
後面會提到這些是如何做到的。

(1) The Head (可以旋轉)

  <joint name="head_swivel" type="continuous">
<parent link="base_link"/>
<child link="head"/>
<axis xyz="0 0 1"/>
<origin xyz="0 0 0.3"/>
</joint>
  • The connection between the body and the head is a continuous joint, meaning that it can take on any angle from negative infinity to positive infinity.
  • 指定旋轉軸 <axis xyz=”0 0 1"/> 。
    Since we want it to go around the z axis, we specify the vector “0 0 1”.

(2) The Gripper (夾爪)

Both the right and the left gripper joints are modeled as revolute joints.
This means that they rotate in the same way that the continuous joints do, but they have strict limits.
Hence, we must include the limit tag specifying the upper and lower limits of the joint (in radians). We also must specify a maximum velocity and effort for this joint but the actual values don’t matter for our purposes here.

(3) The Gripper Arm

  <joint name="gripper_extension" type="prismatic">
<parent link="base_link"/>
<child link="gripper_pole"/>
<limit effort="1000.0" lower="-0.38" upper="0" velocity="0.5"/>
<origin rpy="0 0 0" xyz="0.19 0 0.2"/>
</joint>

type 設成 prismatic,使這個手臂可以伸長或收縮。

四、urdf tutorial (3) —
Adding Physical and Collision Properties to a URDF Model

(1) 網站

和 collision、inertial 有關。

四、urdf tutorial (4) —
Using Xacro to Clean Up a URDF File

可以藉由使用 xacro,使的 urdf 精簡一點。

xacro 提供了三個好用的東西:

  • Constants (可以用宣告變數的方式,來寫urdf,這樣可以預防漏改了什麼參數)
  • Simple Math
  • Macros

(1) Using Xacro

As its name implies, xacro is a macro language. The xacro program runs all of the macros and outputs the result. Typical usage looks something like this:

xacro --inorder model.xacro > model.urdf

在 .launch 檔裡的話:

註: 可以透過更路徑,來變換 .xacro 檔。
目前我是把路徑改成 rrbot_myalltest.xacro 。
會不會有其他也需要改的地方呢?我目前還沒遇到。

在 urdf 檔裡的話,要加上namespace:

.xacro 的樣子: (可以發現多了 xmlns:xacro )<?xml version="1.0"?>
<!-- Revolute-Revolute Manipulator -->
<robot name="rrbot" xmlns:xacro="http://www.ros.org/wiki/xacro">
-----------------------------------------------------------------
一般 .urdf 的樣子:
<?xml version="1.0"?>
<robot name="origins">

(2) Constants

使用 xacro 前:

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

使用 xacro 後: (使用 property 當 constant)

<xacro:property name="width" value="0.2" />
<xacro:property name="bodylen" value="0.6" />
<link name="base_link">
<visual>
<geometry>
<cylinder radius="${width}" length="${bodylen}"/>
</geometry>
<material name="blue"/>
</visual>
<collision>
<geometry>
<cylinder radius="${width}" length="${bodylen}"/>
</geometry>
</collision>
</link>
  • 原本要改一個變數的話,需要改兩個地方以上,可能會忘記。用 xacro 就沒這問題了

(3) Math

You can build up arbitrarily complex expressions in the ${} construct using the four basic operations (+,-,*,/), the unary minus, and parenthesis.

<cylinder radius="${wheeldiam/2}" length="0.1"/>
<origin xyz="${reflect*(width+.02)} 0 0.25" />
註:多個 property 的話,一個 $ 就好

下面兩個是相等的:

<link name="${5/6}"/><link name="0.833333333333"/>

(4) Macros

(a) simple macro

<xacro:macro name="default_origin">
<origin xyz="0 0 0" rpy="0 0 0"/>
</xacro:macro>
<xacro:default_origin />
註: 前三行像是在宣告一樣,第四行像是 call function 。
-------------------------------------------------------
上面的程式會產生:
<origin rpy="0 0 0" xyz="0 0 0"/>

(b) Parameterized Macro

宣告:

    <xacro:macro name="default_inertial" params="mass">
<inertial>
<mass value="${mass}" />
<inertia ixx="1.0" ixy="0.0" ixz="0.0"
iyy="1.0" iyz="0.0"
izz="1.0" />
</inertial>
</xacro:macro>

使用:

<xacro:default_inertial mass="10"/>

四、urdf tutorial (5) —
Using a URDF in Gazebo

(1) 網頁

(2) 安裝 urdf_sim_tutorial

cd ~/catkin_ws/src
git clone https://github.com/ros/urdf_sim_tutorial.git
cd ~/catkin_ws
catkin_make

(3) Nonfunctional Gazebo Interface

執行 gazebo:

roslaunch urdf_sim_tutorial gazebo.launch

結果圖:

  • To get the robot to be interactive (with you and ROS), we need to specify two things: Plugins and Transmissions.

(4) Gazebo Plugin

To get ROS to interact with Gazebo, we have to dynamically link to the ROS library that will tell Gazebo what to do.

To link Gazebo and ROS, we specify the plugin in the URDF (這裡有 urdf_sim_tutorial 和 rrbot 兩個版本可以比較) :

  • (a) urdf_sim_tutorial 版本
    (在 urdf_sim_tutorial/urdf/09-publishjoints.urdf.xacro)
    (在</robot>之前)

註: <legacyModeNS>true</legacyModeNS>, 是為了解決
[ERROR] [1564377476.400799454, 0.223000000]: GazeboRosControlPlugin missing <legacyModeNS> while using DefaultRobotHWSim, defaults to true. 而加上去的。

  • (b) rrbot 版本
    ( 在 gazebo_ros_demos/rrbot_description/urdf/rrbot.gazebo)

註: rrbot 的 urdf 主體是放在 rrbot.xacro,透過引用的方式把 rrbot.gazebo 納入 rrbot.xacro。(所以 gazebo plugin 沒強制要放在同一個檔案)

執行 roslaunch:

roslaunch urdf_sim_tutorial gazebo.launch model:=urdf/09-publishjoints.urdf.xacro

接下來還要繼續加一些東西。

(5) Spawning Controllers

這裡的東西可以在 Gazebo筆記(六)_四、讓 joint 動起來 找到,
那裡有實際操作(手掌)。

(6) Transmissions

(7) Joint Control

(8) Another Controller

(9)

五、 有關 rrbot_description

(1) 在 gazebo_ros_demo 資料夾中,
有 rrbot_control 、 rrbot_description 、 rrbot_gazebo 三個資料夾(package)。

在 gazebo_ros_demo 資料夾中

(2) 在 rrbot_description 資料夾中,

有 urdf 、 launch、meshes,共三個資料夾。

在 rrbot_description 資料夾中

在 urdf 資料夾中,

有 materials.xacro 、 rrbot.xacro 、 rrbot.gazebo 、 rrbot.xml ,四個檔案
(其他是我自己創立的)。(rrbot.xml 不知道要做啥)

rrbot.xacro 是最重要的一個,裡面描述了整個機器人的架構,像是 link 、 joint 怎麼接、怎麼分佈等等。

rrbot.xacro 會去 include 另外的兩個檔案 materials.xacro 、 rrbot.gazebo 。

materials.xacro 和 顏色有關。
rrbot.gazebo 裡面有提到 Gazebo Plugin 、顏色設定、 mu。

在 urdf 資料夾中

在 meshes 資料夾中,

有個 .dae 檔,這和設定特殊材質、特殊形狀、特殊物體有關。

在 rrbot.xacro 中,有提到這個 .dae 檔。

在 mesh 資料夾中

在 launch 資料夾中,

有 rrbot_rviz.launch

在 launch 資料夾中

六、 有關 rrbot_control

(1) 在 rrbot_control 資料夾中,

有 config 、 launch , 共兩個資料夾。

在 rrbot_control 資料夾中

在 config 資料夾中,

有各種的 .yaml 檔。 這些檔案和 controller 的資訊(像是控制 joint)有關,
到時候 roslaunch 時會 load 這些 .yaml 檔進去。
( roslaunch rrbot_control rrbot_control.launch )
要有執行這個 roslaunch,才會有 /rrbot/joint1_position_controller/command 話題出現,才能發布消息到那個話題,來控制 joint 。

在 config 資料夾中

在 launch 資料夾中,

有 rrbot_control.launch ,和 controller 有關。

在 launch 資料夾中

七、 有關 rrbot_gazebo

(1) 在 rrbot_gazebo 資料夾中,

有 launch 、 worlds 兩個資料夾。

在 rrbot_gazebo 資料夾中

在 launch 資料夾中,

有 rrbot_world.lauch,roslaunch 這個檔可以打開 gazebo。
可以更改其中xacro (urdf) 的路徑,來建立不同的機器人模型。(目前是還沒遇到錯)
這個 launch 檔會去引入 worlds 資料夾的 rrbot.world 作為參數。

在 launch 資料夾中

在 worlds 資料夾中,

有 rrbot.world 。

存放著一些環境設定。

在 worlds 資料夾中

--

--