URDF 文件是一个标准的 XML 文件,在 ROS 中预定义了一系列的标签用于描述机器人模型,机器人模型可能较为复杂,但是 ROS 的 URDF 中机器人的组成却是较为简单,可以主要简化为两部分:连杆 (link标签) 与 关节 (joint标签),接下来我们就通过案例了解一下 URDF 中的不同标签:
robot
name: 指定机器人模型的名称
其他标签都是子级标签
<robot name = "mycar">
<link name = "base_link">
<visual>
<geometry>
<mesh filename = "package://urdf01_rviz/meshes/autolabor_mini.stl"/>
geometry>
<origin xyz = "0 0 0" rpy = "1.57 0 1.57" />
<material name = "car_color">
<color rgba = "0 1 0 1" />
material>
visual>
link>
robot>
<launch>
<param name = "robot_description" textfile = "$(find urdf01_rviz)/urdf/urdf/demo02_link.urdf" />
<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find urdf01_rviz)/config/show_mycar.rviz"/>
launch>
cd demo03_ws/
source ./devel/setup.bash
roslaunch urdf01_rviz demo02_link.launch
<robot name = "mycar">
<link name = "base_link">
<visual>
<geometry>
<box size = "0.3 0.2 0.1" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0" />
<material name = "car_color">
<color rgba = "0.8 0.5 0 0.5" />
material>
visual>
link>
<link name = "camera">
<visual>
<geometry>
<box size = "0.02 0.05 0.05" />
geometry>
<origin xyz = "0 0 0.025" rpy = "0 0 0" />
<material name = "camera_color">
<color rgba = "0 0 1 0.5" />
material>
visual>
link>
<joint name = "camera2base" type = "continuous">
<parent link = "base_link" />
<child link = "camera" />
<origin xyz = "0.12 0 0.05" rpy = "0 0 0" />
<axis xyz = "0 0 1" />
joint>
robot>
<launch>
<param name = "robot_description" textfile = "$(find urdf01_rviz)/urdf/urdf/demo03_joint.urdf" />
<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find urdf01_rviz)/config/show_mycar.rviz"/>
<node pkg = "joint_state_publisher" type = "joint_state_publisher" name = "joint_state_publisher" />
<node pkg = "robot_state_publisher" type = "robot_state_publisher" name = "robot_state_publisher" />
<node pkg = "joint_state_publisher_gui" type = "joint_state_publisher_gui" name = "joint_state_publisher_gui"/>
launch>
sudo apt-get install ros-melodic-joint-state-publisher-gui
不加 关节状态节点 和 机器人状态节点 出现的问题
cd demo03_ws/
source ./devel/setup.bash
roslaunch urdf01_rviz demo03_joint.launch
<robot name = "mycar">
<link name = "base_footprint">
<visual>
<geometry>
<box size = "0.001 0.001 0.001" />
geometry>
visual>
link>
<link name = "base_link">
<visual>
<geometry>
<box size = "0.3 0.2 0.1" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0" />
<material name = "car_color">
<color rgba = "0.8 0.5 0 0.5" />
material>
visual>
link>
<link name = "camera">
<visual>
<geometry>
<box size = "0.02 0.05 0.05" />
geometry>
<origin xyz = "0 0 0.025" rpy = "0 0 0" />
<material name = "camera_color">
<color rgba = "0 0 1 0.5" />
material>
visual>
link>
<joint name = "link2footprint" type = "fixed">
<parent link = "base_footprint" />
<child link = "base_link" />
<origin xyz = "0 0 0.05" rpy = "0 0 0" />
joint>
<joint name = "camera2base" type = "continuous">
<parent link = "base_link" />
<child link = "camera" />
<origin xyz = "0.12 0 0.05" rpy = "0 0 0" />
<axis xyz = "0 0 1" />
joint>
robot>
<launch>
<param name = "robot_description" textfile = "$(find urdf01_rviz)/urdf/urdf/demo04_base_footprint.urdf" />
<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find urdf01_rviz)/config/show_mycar.rviz"/>
<node pkg = "joint_state_publisher" type = "joint_state_publisher" name = "joint_state_publisher" />
<node pkg = "robot_state_publisher" type = "robot_state_publisher" name = "robot_state_publisher" />
launch>
cd demo03_ws/
source ./devel/setup.bash
roslaunch urdf01_rviz demo04_base_footprint.launch
问题1:命令行输出如下错误提示
UnicodeEncodeError: 'ascii' codec can't encode characters in position 463-464: ordinal not in range(128)
[joint_state_publisher-3] process has died [pid 4443, exit code 1, cmd /opt/ros/melodic/lib/joint_state_publisher/joint_state_publisher __name:=joint_state_publisher __log:=/home/rosmelodic/.ros/log/b38967c0-0acb-11eb-aee3-0800278ee10c/joint_state_publisher-3.log].
log file: /home/rosmelodic/.ros/log/b38967c0-0acb-11eb-aee3-0800278ee10c/joint_state_publisher-3*.log
<launch>
<param name = "robot_description" textfile = "$(find urdf01_rviz)/urdf/urdf/demo05_test.urdf" />
<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find urdf01_rviz)/config/show_mycar.rviz"/>
<node pkg = "joint_state_publisher" type = "joint_state_publisher" name = "joint_state_publisher" />
<node pkg = "robot_state_publisher" type = "robot_state_publisher" name = "robot_state_publisher" />
<node pkg = "joint_state_publisher_gui" type = "joint_state_publisher_gui" name = "joint_state_publisher_gui" />
launch>
<link name = "base_footprint">
<visual>
<geometry>
<sphere radius = "0.001" />
geometry>
<material name = "car_color">
<color rgba = "1 0 0 0.5" /> 红色
material>
visual>
link>
<link name = "base_link">
<visual>
<geometry>
<cylinder radius = "0.1" length = "0.08" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "baselink_color">
<color rgba = "1 0.5 0.2 0.5" />
material>
visual>
link>
<joint name = "link2footprint" type = "fixed">
<parent link = "base_footprint" />
<child link = "base_link" />
<origin xyz = "0 0 0.055" rpy = "0 0 0" />
joint>
<link name = "left_wheel">
<visual>
<geometry>
<cylinder radius = "0.0325" length = "0.015" />
geometry>
<origin xyz = "0 0 0" rpy = "1.5708 0 0"/>
<material name = "wheel_color">
<color rgba = "0 0 0 0.3" />
material>
visual>
link>
<link name = "right_wheel">
<visual>
<geometry>
<cylinder radius = "0.0325" length = "0.015" />
geometry>
<origin xyz = "0 0 0" rpy = "1.5708 0 0"/>
<material name = "wheel_color">
<color rgba = "0 0 0 0.3" />
material>
visual>
link>
<joint name = "lest2link" type = "continuous">
<parent link = "base_link" />
<child link = "left_wheel" />
<origin xyz = "0 0.1 -0.0225" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
<joint name = "right2link" type = "continuous">
<parent link = "base_link" />
<child link = "right_wheel" />
<origin xyz = "0 -0.1 -0.0225" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
<link name = "front_wheel">
<visual>
<geometry>
<sphere radius = "0.0075" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "wheel_color">
<color rbga = "0 0 0 0.3" />
material>
visual>
link>
<link name = "back_wheel">
<visual>
<geometry>
<sphere radius = "0.0075" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "wheel_color">
<color rbga = "0 0 0 0.3" />
material>
visual>
link>
<joint name = "front2link" type = "continuous">
<parent link = "base_link" />
<child link = "front_wheel" />
<origin xyz = "0.08 0 -0.0475" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
<joint name = "back2link" type = "continuous">
<parent link = "base_link" />
<child link = "back_wheel" />
<origin xyz = "-0.08 0 -0.0475" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
<robot name = "mycar">
<link name = "base_footprint">
<visual>
<geometry>
<sphere radius = "0.001" />
geometry>
<material name = "car_color">
<color rgba = "1 0 0 0.5" />
material>
visual>
link>
<link name = "base_link">
<visual>
<geometry>
<cylinder radius = "0.1" length = "0.08" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "baselink_color">
<color rgba = "1 0.5 0.2 0.5" />
material>
visual>
link>
<joint name = "link2footprint" type = "fixed">
<parent link = "base_footprint" />
<child link = "base_link" />
<origin xyz = "0 0 0.055" rpy = "0 0 0" />
joint>
<link name = "left_wheel">
<visual>
<geometry>
<cylinder radius = "0.0325" length = "0.015" />
geometry>
<origin xyz = "0 0 0" rpy = "1.5708 0 0"/>
<material name = "wheel_color">
<color rgba = "0 0 0 0.3" />
material>
visual>
link>
<link name = "right_wheel">
<visual>
<geometry>
<cylinder radius = "0.0325" length = "0.015" />
geometry>
<origin xyz = "0 0 0" rpy = "1.5708 0 0"/>
<material name = "wheel_color">
<color rgba = "0 0 0 0.3" />
material>
visual>
link>
<joint name = "lest2link" type = "continuous">
<parent link = "base_link" />
<child link = "left_wheel" />
<origin xyz = "0 0.1 -0.0225" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
<joint name = "right2link" type = "continuous">
<parent link = "base_link" />
<child link = "right_wheel" />
<origin xyz = "0 -0.1 -0.0225" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
<link name = "front_wheel">
<visual>
<geometry>
<sphere radius = "0.0075" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "wheel_color">
<color rbga = "0 0 0 0.3" />
material>
visual>
link>
<link name = "back_wheel">
<visual>
<geometry>
<sphere radius = "0.0075" />
geometry>
<origin xyz = "0 0 0" rpy = "0 0 0"/>
<material name = "wheel_color">
<color rbga = "0 0 0 0.3" />
material>
visual>
link>
<joint name = "front2link" type = "continuous">
<parent link = "base_link" />
<child link = "front_wheel" />
<origin xyz = "0.08 0 -0.0475" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
<joint name = "back2link" type = "continuous">
<parent link = "base_link" />
<child link = "back_wheel" />
<origin xyz = "-0.08 0 -0.0475" rpy = "0 0 0" />
<axis xyz = "0 1 0" />
joint>
robot>
在 ROS 中,提供了一些工具来方便 URDF 文件的编写,比如:
进入urdf 文件所属目录,调用:check_urdf urdf 文件,如果不抛出异常,说明文件合法,否则非法。
check_urdf demo05_test.urdf 显示层级关系
urdf_to_graphiz demo05_test.urdf
evince mycar.pdf