## myrobot_grazbo.xml
<?xml version="1.0"?>
<robot>
<gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<legacyMode>false</legacyMode>
<alwaysOn>true</alwaysOn>
<updateRate>20</updateRate>
<leftJoint>left_wheel_hinge</leftJoint>
<rightJoint>right_wheel_hinge</rightJoint>
<wheelSeparation>0.4</wheelSeparation>
<wheelDiameter>0.1</wheelDiameter>
<torque>20</torque>
<commandTopic>cmd_vel</commandTopic>
<odometryTopic>odom</odometryTopic>
<odometryFrame>odom</odometryFrame>
<robotBaseFrame>chassis</robotBaseFrame>
</plugin>
</gazebo>
<gazebo reference="chassis">
<material>Gazebo/Orange</material>
</gazebo>
</robot>
======================================
#分析 myrobot.gazebo 文件的內容#
myrobot.gazebo 文件是一個 XML 格式的文件,與 Gazebo 模擬器有關。
它包含機器人的 Gazebo 插件配置,特別是 differential drive (差動驅動) 控制器,這通常用於兩輪驅動的機器人,如自動導航小車。
文件內容說明:
1. <robot> 標籤:這是機器人模型的主要標籤,表示這個文件是為機器人設計的。
2. <gazebo> 標籤:這個部分包含與 Gazebo 模擬相關的設定。
3. <plugin> 插件:
○ name="differential_drive_controller":指定插件名稱,這裡使用的是 libgazebo_ros_diff_drive.so,這是 ROS (Robot Operating System) 提供的差動驅動插件。
○ <legacyMode>false</legacyMode>:表示該插件運行在非傳統模式下,適用於較新的 Gazebo 版本。
○ <alwaysOn>true</alwaysOn>:插件始終保持運行狀態。
○ <updateRate>20</updateRate>:設定更新頻率為 20 Hz。
○ <leftJoint>left_wheel_hinge</leftJoint>:指定左輪關節名稱。
○ <rightJoint>right_wheel_hinge</rightJoint>:指定右輪關節名稱。
○ <wheelSeparation>0.4</wheelSeparation>:左右輪之間的距離為 0.4 米。
○ <wheelDiameter>0.1</wheelDiameter>:輪子的直徑為 0.1 米。
○ <torque>20</torque>:設定輪子的最大扭矩為 20 Nm。
○ <commandTopic>cmd_vel</commandTopic>:機器人將透過 cmd_vel 該 ROS 訂閱主題來接收運動指令。
○ <odometryTopic>odom</odometryTopic>:機器人將透過 odom 該 ROS 主題發佈里程計資訊。
作用:
這個文件的主要作用是為 Gazebo 模擬器提供機器人差動驅動的參數設定,這樣機器人可以在模擬環境中根據 ROS 發送的速度指令 (cmd_vel) 來移動,並且回傳里程計數據 (odom)。
如果你需要修改某些參數,例如改變輪子的大小或驅動頻率,可以調整對應的 <wheelDiameter>、<updateRate> 或 <torque> 等數值。
#########################################################
## myrobot.urdf
<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- | This document was autogenerated by xacro from myrobot.xacro | -->
<!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | -->
<!-- =================================================================================== -->
<robot name="robot" xmlns:xacro="http://www.ros.org/wiki/xacro">
<gazebo>
<plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller">
<legacyMode>false</legacyMode>
<alwaysOn>true</alwaysOn>
<updateRate>20</updateRate>
<leftJoint>left_wheel_hinge</leftJoint>
<rightJoint>right_wheel_hinge</rightJoint>
<wheelSeparation>0.4</wheelSeparation>
<wheelDiameter>0.1</wheelDiameter>
<torque>20</torque>
<commandTopic>cmd_vel</commandTopic>
<odometryTopic>odom</odometryTopic>
<odometryFrame>odom</odometryFrame>
<robotBaseFrame>chassis</robotBaseFrame>
</plugin>
</gazebo>
<gazebo reference="chassis">
<material>Gazebo/Orange</material>
</gazebo>
<material name="black">
<color rgba="0.0 0.0 0.0 1.0"/>
</material>
<material name="blue">
<color rgba="0.0 0.0 0.8 1.0"/>
</material>
<material name="green">
<color rgba="0.0 0.8 0.0 1.0"/>
</material>
<material name="grey">
<color rgba="0.2 0.2 0.2 1.0"/>
</material>
<material name="orange">
<color rgba="1.0 0.423529411765 0.0392156862745 1.0"/>
</material>
<material name="brown">
<color rgba="0.870588235294 0.811764705882 0.764705882353 1.0"/>
</material>
<material name="red">
<color rgba="0.8 0.0 0.0 1.0"/>
</material>
<material name="white">
<color rgba="1.0 1.0 1.0 1.0"/>
</material>
<!--macro name="cylinder_inertia" params="m r h">
<inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"
iyy="${m*(3*r*r+h*h)/12}" iyz = "0"
izz="${m*r*r/2}"
/>
</macro>
<macro name="box_inertia" params="m x y z">
<inertia ixx="${m*(y*y+z*z)/12}" ixy = "0" ixz = "0"
iyy="${m*(x*x+z*z)/12}" iyz = "0"
izz="${m*(x*x+z*z)/12}"
/>
</macro>
<macro name="sphere_inertia" params="m r">
<inertia ixx="${2*m*r*r/5}" ixy = "0" ixz = "0"
iyy="${2*m*r*r/5}" iyz = "0"
izz="${2*m*r*r/5}"
/>
</macro>
<macro name="wheel" params="lr tY">
<link name="${lr}_wheel">
<collision>
<origin xyz="0 0 0" rpy="0 ${PI/2} ${PI/2}" />
<geometry>
<cylinder length="${wheelWidth}" radius="${wheelRadius}"/>
</geometry>
</collision>
<visual>
<origin xyz="0 0 0" rpy="0 ${PI/2} ${PI/2}" />
<geometry>
<cylinder length="${wheelWidth}" radius="${wheelRadius}"/>
</geometry>
<material name="black"/>
</visual>
<inertial>
<origin xyz="0 0 0" rpy="0 ${PI/2} ${PI/2}" />
<mass value="${wheelMass}"/>
<cylinder_inertia m="${wheelMass}" r="${wheelRadius}" h="${wheelWidth}"/>
</inertial>
</link>
<gazebo reference="${lr}_wheel">
<mu1 value="1.0"/>
<mu2 value="1.0"/>
<kp value="10000000.0" />
<kd value="1.0" />
<fdir1 value="1 0 0"/>
<material>Gazebo/Black</material>
</gazebo>
<joint name="${lr}_wheel_hinge" type="continuous">
<parent link="chassis"/>
<child link="${lr}_wheel"/>
<origin xyz="${-wheelPos+chassisLength/2} ${tY*wheelWidth/2+tY*chassisWidth/2} ${wheelRadius}" rpy="0 0 0" />
<axis xyz="0 1 0" rpy="0 0 0" />
<limit effort="10000" velocity="10000"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
<transmission name="${lr}_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${lr}_wheel_hinge">
<hardwareInterface>EffortJointInterface</hardwareInterface>
</joint>
<actuator name="${lr}Motor">
<hardwareInterface>EffortJointInterface</hardwareInterface>
<mechanicalReduction>10</mechanicalReduction>
</actuator>
</transmission>
</macro-->
<link name="chassis">
<pose>0 0 0.1 0 0 0</pose>
<inertial>
<mass value="10.0"/>
<origin rpy=" 0 0 0" xyz="0.0 0 0.1"/>
<inertia ixx="0.5" ixy="0" ixz="0" iyy="1.0" iyz="0" izz="0.1"/>
</inertial>
<collision name="collision">
<geometry>
<box size=".4 .2 .1"/>
</geometry>
</collision>
<visual name="chassis_visual">
<origin rpy=" 0 0 0" xyz="0 0 0"/>
<geometry>
<box size=".4 .2 .1"/>
</geometry>
</visual>
<collision name="caster_collision">
<origin rpy=" 0 0 0" xyz="-0.15 0 -0.05"/>
<geometry>
<sphere radius="0.05"/>
</geometry>
<surface>
<friction>
<ode>
<mu>0</mu>
<mu2>0</mu2>
<slip1>1.0</slip1>
<slip2>1.0</slip2>
</ode>
</friction>
</surface>
</collision>
<visual name="caster_visual">
<origin rpy=" 0 0 0" xyz="-0.15 0 -0.05"/>
<geometry>
<sphere radius="0.05"/>
</geometry>
</visual>
</link>
<link name="left_wheel">
<!--origin xyz="0.1 0.13 0.1" rpy="0 1.5707 1.5707"/-->
<collision name="collision">
<origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
</collision>
<visual name="left_wheel_visual">
<origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
</visual>
<inertial>
<origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
<mass value="5"/>
<cylinder_inertia h="0.05" m="5" r="0.1"/>
<inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
</inertial>
</link>
<link name="right_wheel">
<!--origin xyz="0.1 -0.13 0.1" rpy="0 1.5707 1.5707"/-->
<collision name="collision">
<origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
</collision>
<visual name="right_wheel_visual">
<origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
<geometry>
<cylinder length="0.05" radius="0.1"/>
</geometry>
</visual>
<inertial>
<origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
<mass value="5"/>
<cylinder_inertia h="0.05" m="5" r="0.1"/>
<inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>
</inertial>
</link>
<joint name="left_wheel_hinge" type="continuous">
<origin rpy="0 0 0" xyz="0.1 0.15 0"/>
<child link="left_wheel"/>
<parent link="chassis"/>
<axis rpy="0 0 0" xyz="0 1 0"/>
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
<joint name="right_wheel_hinge" type="continuous">
<origin rpy="0 0 0" xyz="0.1 -0.15 0"/>
<child link="right_wheel"/>
<parent link="chassis"/>
<axis rpy="0 0 0" xyz="0 1 0"/>
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
</robot>
======================================
#分析 myrobot.urdf 文件的內容#
myrobot.urdf 文件是一個 URDF (Unified Robot Description Format) 文件,用於描述機器人的結構和屬性。
從開頭的註解來看,這個文件是由 Xacro (myrobot.xacro) 自動生成的,這表示該文件是從更高層級的 xacro 文件轉換而來,手動修改可能會被覆蓋。
分析內容
1. XML 頭部
<?xml version="1.0" ?>
這是標準的 XML 頭部。
2. Xacro 產生的文件
<!-- =================================================================================== -->
<!-- | This document was autogenerated by xacro from myrobot.xacro | -->
<!-- | EDITING THIS FILE BY HAND IS NOT RECOMMENDED | -->
<!-- =================================================================================== -->
這段註解表明 這個 URDF 文件是從 myrobot.xacro 轉換來的,通常建議修改 xacro 文件,而不是直接編輯 urdf。
3. 機器人名稱
<robot name="robot" xmlns:xacro="http://www.ros.org/wiki/xacro">
○ name="robot":這是機器人的名稱。
○ xmlns:xacro:這表示它原本是使用 Xacro 擴展語法生成的。
4. Gazebo 插件
<gazebo>
<plugin filename="libgazebo_ros_diff_drive.so">
○ libgazebo_ros_diff_drive.so:這是 Gazebo 的 ROS 差動驅動插件,與 myrobot.gazebo 內的插件類似,用於控制機器人的移動。
可能的內容與功能
URDF 文件通常包含以下內容:
1. 鏈接 (<link>):描述機器人的不同部分,如底盤、輪子、感測器等。
2. 關節 (<joint>):描述如何將不同的 link 連接在一起(例如輪子如何與機身連接)。
3. 慣性 (<inertial>):描述機器人的物理屬性,如質量和慣性張量。
4. 可視化 (<visual>):描述機器人的外觀,通常使用 .dae 或 .stl 文件來顯示 3D 模型。
5. 碰撞 (<collision>):定義碰撞模型,用於物理模擬。
備註
1. URDF 是機器人描述的核心:
○ myrobot.urdf 定義了機器人的形狀、結構和運動學信息。
○ myrobot.gazebo 主要是 為 Gazebo 模擬提供額外的插件與參數。
2. 不要直接修改 URDF,而應修改 Xacro:
○ myrobot.urdf 是從 myrobot.xacro 生成的,因此應該編輯 myrobot.xacro,然後再重新生成 URDF。
3. 與 ROS 結合使用:
○ 這個 URDF 文件通常與 ROS (Robot Operating System) 一起使用,並通過 robot_state_publisher 來發布機器人的狀態。
4. 與 Gazebo 的關聯:
○ 這個 URDF 文件包含 Gazebo 插件,這意味著這台機器人將在 Gazebo 模擬器中運行,並可能使用 libgazebo_ros_diff_drive.so 來控制運動。
#####################################
## myrobot.xarco
<?xml version='1.0'?>
<robot name="robot" xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:include filename="$(find myrobot_description)/urdf/myrobot.gazebo" />
<xacro:include filename="$(find myrobot_description)/urdf/materials.xacro" />
<xacro:include filename="$(find myrobot_description)/urdf/macros.xacro" />
<link name='chassis'>
<pose>0 0 0.1 0 0 0</pose>
<inertial>
<mass value="10.0"/>
<origin xyz="0.0 0 0.1" rpy=" 0 0 0"/>
<inertia
ixx="0.5" ixy="0" ixz="0"
iyy="1.0" iyz="0"
izz="0.1"
/>
</inertial>
<collision name='collision'>
<geometry>
<box size=".4 .2 .1"/>
</geometry>
</collision>
<visual name='chassis_visual'>
<origin xyz="0 0 0" rpy=" 0 0 0"/>
<geometry>
<box size=".4 .2 .1"/>
</geometry>
</visual>
<collision name='caster_collision'>
<origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
<geometry>
<sphere radius="0.05"/>
</geometry>
<surface>
<friction>
<ode>
<mu>0</mu>
<mu2>0</mu2>
<slip1>1.0</slip1>
<slip2>1.0</slip2>
</ode>
</friction>
</surface>
</collision>
<visual name='caster_visual'>
<origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
<geometry>
<sphere radius="0.05"/>
</geometry>
</visual>
</link>
<link name="left_wheel">
<!--origin xyz="0.1 0.13 0.1" rpy="0 1.5707 1.5707"/-->
<collision name="collision">
<origin xyz="0 0 0" rpy="0 1.5707 1.5707"/>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
</collision>
<visual name="left_wheel_visual">
<origin xyz="0 0 0" rpy="0 1.5707 1.5707"/>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
</visual>
<inertial>
<origin xyz="0 0 0" rpy="0 1.5707 1.5707"/>
<mass value="5"/>
<cylinder_inertia m="5" r="0.1" h="0.05"/>
<inertia
ixx="1.0" ixy="0.0" ixz="0.0"
iyy="1.0" iyz="0.0"
izz="1.0"/>
</inertial>
</link>
<link name="right_wheel">
<!--origin xyz="0.1 -0.13 0.1" rpy="0 1.5707 1.5707"/-->
<collision name="collision">
<origin xyz="0 0 0" rpy="0 1.5707 1.5707"/>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
</collision>
<visual name="right_wheel_visual">
<origin xyz="0 0 0" rpy="0 1.5707 1.5707"/>
<geometry>
<cylinder radius="0.1" length="0.05"/>
</geometry>
</visual>
<inertial>
<origin xyz="0 0 0" rpy="0 1.5707 1.5707"/>
<mass value="5"/>
<cylinder_inertia m="5" r="0.1" h="0.05"/>
<inertia
ixx="1.0" ixy="0.0" ixz="0.0"
iyy="1.0" iyz="0.0"
izz="1.0"/>
</inertial>
</link>
<joint type="continuous" name="left_wheel_hinge">
<origin xyz="0.1 0.15 0" rpy="0 0 0"/>
<child link="left_wheel"/>
<parent link="chassis"/>
<axis xyz="0 1 0" rpy="0 0 0"/>
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
<joint type="continuous" name="right_wheel_hinge">
<origin xyz="0.1 -0.15 0" rpy="0 0 0"/>
<child link="right_wheel"/>
<parent link="chassis"/>
<axis xyz="0 1 0" rpy="0 0 0"/>
<limit effort="100" velocity="100"/>
<joint_properties damping="0.0" friction="0.0"/>
</joint>
</robot>
====================================
#分析 myrobot.xacro 文件的內容#
分析 myrobot.xacro 文件
這個 Xacro (XML Macro) 文件用於生成 URDF (Unified Robot Description Format),它提供了一種更靈活的方式來組織和管理機器人模型,並最終轉換為 myrobot.urdf。
文件內容解析
1. XML 頭部
<?xml version='1.0'?>
這是標準的 XML 宣告。
2. 機器人名稱與 Xacro 命名空間
<robot name="robot" xmlns:xacro="http://www.ros.org/wiki/xacro">
○ name="robot":定義機器人名稱。
○ xmlns:xacro:聲明 Xacro 命名空間,使其可以使用 Xacro 擴展語法。
3. 包含其他 Xacro 文件
<xacro:include filename="$(find myrobot_description)/urdf/myrobot.gazebo" />
<xacro:include filename="$(find myrobot_description)/urdf/materials.xacro" />
<xacro:include filename="$(find myrobot_description)/urdf/macros.xacro" />
○ 這些 xacro:include 指令引入了其他 Xacro 文件:
§ myrobot.gazebo:包含與 Gazebo 相關的模擬設定,如插件配置。
§ materials.xacro:可能包含機器人的顏色、紋理和材質定義。
§ macros.xacro:可能包含一些 Xacro 巨集 (macro),用於簡化模型的定義。
4. 機器人底盤 (chassis)
<link name='chassis'>
<pose>0 0 0.1 0 0 0</pose>
○ <link>:表示一個獨立的機器人部件,這裡是底盤 (chassis)。
○ <pose>:設定底盤的初始位置 (x, y, z, roll, pitch, yaw)。
5. 慣性 (inertial)
<inertial>
<mass value="10.0"/>
<origin xyz="0.0 0 0.1" rpy="0 0 0"/>
<inertia
ixx="0.1"
iyy="0.1"
izz="0.1"
ixy="0.0"
ixz="0.0"
iyz="0.0"/>
</inertial>
○ <mass value="10.0"/>:機器人的質量為 10 公斤。
○ <origin xyz="0.0 0 0.1" rpy="0 0 0"/>:設定慣性中心的位置。
○ <inertia>:定義機器人的慣性張量 (影響模擬中的物理行為)。
總結
1. myrobot.xacro 是 myrobot.urdf 的模板
○ 這個 Xacro 文件會轉換成 URDF,提供更靈活的機器人定義方式。
2. 使用 Xacro 巨集提高可讀性
○ 透過 xacro:include 引入其他文件,避免 URDF 太過冗長。
○ macros.xacro 可能包含 巨集函式,幫助重複使用組件。
3. 與 Gazebo 整合
○ myrobot.gazebo 被引入,表示這個機器人將在 Gazebo 模擬環境 中運行。
4. 定義了底盤 (chassis) 與物理屬性
○ chassis 是機器人的主體,包含慣性、質量、位置等設定。
建議與備註
• 如果你想要修改機器人的結構,應該編輯 myrobot.xacro,然後再轉換成 myrobot.urdf。
• 如果你要調整 材質,可以修改 materials.xacro。
• 如果你想要增加新的 關節 (joints) 或 零件 (links),可以在這個文件內新增 xacro:macro 來管理它們。
沒有留言:
張貼留言