前言
系统环境: Ubuntu 18.04,硬盘安装。
ROS版本: melodic
深蓝学院(古月居)胡春旭ROS理论与实践笔记整理。
1. 机器人的定义与组成
其实就是之前学的AURU架构:
2. URDF建模方法
-
什么是URDF?
- Unified Robot Description Format,统一机器人描述格式;
- ROS中一个非常重要的机器人模型描述格式;
- 可以解析URDF文件中使用XML格式描述的机器人模型;
- 包含link和joint自身及其属性的描述信息;
- 对于一个桌子,其实也是有一个桌面link和四个桌腿link,以及固定的螺丝joint组成。
-
<link>
- 描述机器人某个刚体部分的外观和物理属性;
- 描述连杆尺寸(size)、颜色(color),形状(shape),惯性矩阵(inertial matrix),碰撞参数(collision properties)等。
- 每个Link会成为一个坐标。
-
<joint>
-
描述两个link之间的关系,分为六种类型;
-
包括关节运动的位置和速度限制;
-
描述机器人关节的运动学和动力学属性。
-
关节类型 |
描述 |
continous |
旋转关节,可以围绕儋州无限旋转 |
revolute |
旋转关节,类似于continuous,但是有旋转的角度极限 |
prismatic |
滑动关节,沿某一轴线移动的关节,带有位置极限 |
planar |
平面关节,允许在平面正交方向上平移或者旋转 |
floating |
浮动关节,允许进行平移、旋转运动 |
fixed |
固定关节,不允许运动的特殊关节 |
-
<robot>
- 完整机器人模型的最顶层标签
<link>
和<joint>
标签都必须包含在<robot>
标签内
- 一个完整的机器人模型,由一系列
<link>
和<joint>
组成
3. URDF机器人模型案例分析
3.1 创建一个机器人建模的功能包
输入$ catkin_create_pkg mbot_description urdf xacro
创建一个名为mbot_description的功能包,并在其中新建下列文件夹:
- urdf:存放机器人模型的URDF或xacro文件
- meshed:放置URDF中引用的模型渲染文件
- launch:保存相关启动文件
- config:保存rviz的配置文件
3.2 urdf文件夹中的示例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| <?xml version="1.0" ?> <robot name="mbot">
<link name="base_link"> <visual> <origin xyz=" 0 0 0" rpy="0 0 0" /> <geometry> <cylinder length="0.16" radius="0.20"/> </geometry> <material name="yellow"> <color rgba="1 0.4 0 1"/> </material> </visual> </link>
<joint name="left_wheel_joint" type="continuous"> <origin xyz="0 0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="left_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="left_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="right_wheel_joint" type="continuous"> <origin xyz="0 -0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="right_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="right_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="front_caster_joint" type="continuous"> <origin xyz="0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="front_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="front_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<joint name="back_caster_joint" type="continuous"> <origin xyz="-0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="back_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="back_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
</robot>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| <?xml version="1.0" ?> <robot name="mbot">
<link name="base_link"> <visual> <origin xyz=" 0 0 0" rpy="0 0 0" /> <geometry> <cylinder length="0.16" radius="0.20"/> </geometry> <material name="yellow"> <color rgba="1 0.4 0 1"/> </material> </visual> </link>
<joint name="left_wheel_joint" type="continuous"> <origin xyz="0 0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="left_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="left_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="right_wheel_joint" type="continuous"> <origin xyz="0 -0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="right_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="right_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="front_caster_joint" type="continuous"> <origin xyz="0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="front_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="front_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<joint name="back_caster_joint" type="continuous"> <origin xyz="-0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="back_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="back_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<link name="camera_link"> <visual> <origin xyz=" 0 0 0 " rpy="0 0 0" /> <geometry> <box size="0.03 0.04 0.04" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<joint name="camera_joint" type="fixed"> <origin xyz="0.17 0 0.10" rpy="0 0 0"/> <parent link="base_link"/> <child link="camera_link"/> </joint>
</robot>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| <?xml version="1.0" ?> <robot name="mbot">
<link name="base_link"> <visual> <origin xyz=" 0 0 0" rpy="0 0 0" /> <geometry> <cylinder length="0.16" radius="0.20"/> </geometry> <material name="yellow"> <color rgba="1 0.4 0 1"/> </material> </visual> </link>
<joint name="left_wheel_joint" type="continuous"> <origin xyz="0 0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="left_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="left_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="right_wheel_joint" type="continuous"> <origin xyz="0 -0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="right_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="right_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="front_caster_joint" type="continuous"> <origin xyz="0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="front_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="front_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<joint name="back_caster_joint" type="continuous"> <origin xyz="-0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="back_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="back_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<link name="kinect_link"> <visual> <origin xyz="0 0 0" rpy="0 0 1.5708"/> <geometry> <mesh filename="package://mbot_description/meshes/kinect.dae" /> </geometry> </visual> </link>
<joint name="kinect_joint" type="fixed"> <origin xyz="0.15 0 0.11" rpy="0 0 0"/> <parent link="base_link"/> <child link="kinect_link"/> </joint>
</robot>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| <?xml version="1.0" ?> <robot name="mbot">
<link name="base_link"> <visual> <origin xyz=" 0 0 0" rpy="0 0 0" /> <geometry> <cylinder length="0.16" radius="0.20"/> </geometry> <material name="yellow"> <color rgba="1 0.4 0 1"/> </material> </visual> </link>
<joint name="left_wheel_joint" type="continuous"> <origin xyz="0 0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="left_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="left_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="right_wheel_joint" type="continuous"> <origin xyz="0 -0.19 -0.05" rpy="0 0 0"/> <parent link="base_link"/> <child link="right_wheel_link"/> <axis xyz="0 1 0"/> </joint>
<link name="right_wheel_link"> <visual> <origin xyz="0 0 0" rpy="1.5707 0 0" /> <geometry> <cylinder radius="0.06" length = "0.025"/> </geometry> <material name="white"> <color rgba="1 1 1 0.9"/> </material> </visual> </link>
<joint name="front_caster_joint" type="continuous"> <origin xyz="0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="front_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="front_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<joint name="back_caster_joint" type="continuous"> <origin xyz="-0.18 0 -0.095" rpy="0 0 0"/> <parent link="base_link"/> <child link="back_caster_link"/> <axis xyz="0 1 0"/> </joint>
<link name="back_caster_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <sphere radius="0.015" /> </geometry> <material name="black"> <color rgba="0 0 0 0.95"/> </material> </visual> </link>
<link name="laser_link"> <visual> <origin xyz=" 0 0 0 " rpy="0 0 0" /> <geometry> <cylinder length="0.05" radius="0.05"/> </geometry> <material name="black"/> </visual> </link>
<joint name="laser_joint" type="fixed"> <origin xyz="0 0 0.105" rpy="0 0 0"/> <parent link="base_link"/> <child link="laser_link"/> </joint>
</robot>
|
3.3 meshes文件夹
该文件夹中有一些模型的渲染文件(例如由soliwork软件写好的渲染模型)。
3.4 config文件夹
rviz中左上角保存config存放的文件。
3.5 launch文件夹
- display_mbot_base_urdf.launch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <launch> <param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_base.urdf" />
<param name="use_gui" value="true"/> <node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" /> </launch>
|
- display_mbot_with_camera_urdf.launch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <launch> <param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_base.urdf" />
<param name="use_gui" value="true"/> <node name="joint_state_publisher_gui" pkg="joint_state_publishe_guir" type="joint_state_publisher_gui" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" /> </launch>
|
- display_mbot_with_kinect_urdf.launch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <launch> <param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_with_kinect.urdf" />
<param name="use_gui" value="true"/> <node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" /> </launch>
|
- display_mbot_with_laser_urdf.launch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <launch> <param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_with_laser.urdf" />
<param name="use_gui" value="true"/> <node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" /> </launch>
|
- 注意,这些launch文件中调用了GUI插件,如果想要运行,需要
$ sudo apt-get install ros-melodic-joint-state-publisher-gui
提前安装GUI插件。
3.6 开始仿真(以mbot_base为例)
- 输入下列指令:
1 2 3 4
| $ catkin_make
$ roslaunch mbot_description display_mbot_base_urdf.launch
|
- 点击Add,添加RobotModel。
- 在rviz界面下的Global Options下把 Fixed Frame改成base_link。
- 保存config(File-Save Config As),为mbot_urdf.rviz。
3.7 检查URDF模型整体结构
- 安装:
$ sudo apt install liburdfom-tools
- 运行:
$ urdf_to_graphiz mbot_base.urdf
- 查看:urdf文件夹中有两个文件出现,关键是pdf文件。
- 示例:
可能用到的网站:在线拾色器