本文内容:
在 Ubuntu 18.04 虚拟机中,基于安装配置好 ROS Melodic 上,进行 URDF 机器人建模的详细步骤,并配置 camera、kinect、Lidar 这三个传感器。
说明:
本文及后面几篇 ROS 文章都是在以下这三篇博客基础之上的延伸:
1、Ubuntu18.04 虚拟机配置 ROS Melodic 详细步骤
2、ROS 三种通信编程入门:【话题通信】【服务通信】【动作通信】
3、Ubuntu 18.04 下使用 RViz 显示出摄像头视频教程
配置好了ROS
、工作空间
、RViz
即可开始学习机器人仿真了。
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
< link >标签:
标签 | 简介 |
---|---|
inertial | 描述机器人 link 的惯性参数 |
visual | 描述机器人 link 部分的外观参数 |
collision | 描述机器人 link 的碰撞属性 |
< joint >标签:
关节类型 | 描述 |
---|---|
continuous | 旋转关节,可以围绕单轴无线旋转 |
revolute | 旋转关节,类似于continuous,但是有旋转的角度限制 |
prismatic | 滑动关节,沿某一轴线移动的关节,带有位置极限 |
planar | 平面关节,允许在平面正交方向上平移或者旋转 |
floating | 浮动关节,允许进行平移、旋转运动 |
fixed | 固定关节,不允许运动的特殊关节 |
标签 | 简介 |
---|---|
calibration | 关节的参考位置,用来校准关节的绝对位置 |
dynamics | 描述关节的物理属性,例如阻尼值、物理静摩擦力等,经常在动力学仿真中用到 |
limit | 描述运动的一些极限值,包括关节运动的上下限位置、速度限制、力矩限制等 |
mimic | 描述该关节与已有关节的关系 |
safety_controller | 描述安全控制器参数 |
< robot >标签:
cd ./catkin_ws/src/
catkin_create_pkg mbot_description urdf xacro
cd ~/catkin_ws/src/mbot_description
mkdir urdf
mkdir meshes
mkdir launch
mkdir config
文件名 | 作用 |
---|---|
urdf | 存放机器人模型的 URDF 或 xacro 文件 |
meshes | 放置 URDF 中引用的模型渲染文件,机器人外观纹理,让外观和实际更相似 |
launch | 保存相关启动文件 |
config | 保存 rviz 的配置文件、功能包的配置文件 |
cd ~/catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_base_urdf.launch
<launch>
<!-- 加载的参数名字叫robot_description,具体内容是urdf相关模型的路径 -->
<param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_base.urdf" />
<!-- 设置GUI参数,显示关节控制插件 -->
<param name="use_gui" value="true"/>
<!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
<!-- 运行robot_state_publisher节点,发布tf -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<!-- 运行rviz可视化界面,保存每次打开之后的相关插件,保存到config文件夹下面 -->
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" />
</launch>
2.3.1.1 创建小车底盘
cd ~/catkin_ws/src/mbot_description/urdf
sudo gedit mbot_base.urdf
<?xml version="1.0" ?>
<robot name="mbot">
<link name="base_link">
<visual>
<origin xyz=" 0 0 0" rpy="0 0 0" />
<!-- link坐标位置,放在最中央 ,xyz单位是米,rpy单位是弧度-->
<geometry>
<cylinder length="0.16" radius="0.20"/>
</geometry>
<!-- 机器人的外观效果,使用圆柱体,高0.16,半径0.20 -->
<material name="yellow">
<color rgba="1 0.4 0 1"/>
</material>
<!-- 通过rgba来描述颜色,颜色命名为yellow,a为1是不透明-->
</visual>
<!--visual指的是一些物理属性的标签 -->
</link>
</robot>
roslaunch mbot_description display_mbot_base_urdf.launch
sudo apt-get install ros-melodic-joint-state-publisher-gui
下载安装(针对 Melodic 版的 ROS)。2.3.1.2 创建左侧车轮
sudo gedit mbot_base.urdf
<joint name="left_wheel_joint" type="continuous">
<!-- joint名字为left_wheel_joint,属性为continuous,即无限旋转-->
<origin xyz="0 0.19 -0.05" rpy="0 0 0"/>
<!-- 坐标位置,在base_link基础上,Y偏移0.19,z偏移-0.05-->
<parent link="base_link"/>
<child link="left_wheel_link"/>
<!-- 主关节:base_link,上面的圆柱形车体-->
<!-- 子关节:left_wheel_link,左轮-->
<!-- 主关节最后是一个,本代码是base_link-->
<axis xyz="0 1 0"/>
<!--left_wheel_link绕某一个轴做旋转,指定为Y轴 -->
</joint>
<!--joint用来连接两个link-->
<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>
<!--左轮信息-->
roslaunch mbot_description display_mbot_base_urdf.launch
2.3.1.3 创建右侧车轮
sudo gedit mbot_base.urdf
<joint name="right_wheel_joint" type="continuous">
<origin xyz="0 -0.19 -0.05" rpy="0 0 0"/>
<!-- 坐标位置,在base_link基础上,Y偏移-0.19,z偏移-0.05,与左轮正好相反-->
<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>
roslaunch mbot_description display_mbot_base_urdf.launch
2.3.1.4 创建前后支撑轮
sudo gedit mbot_base.urdf
<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>
roslaunch mbot_description display_mbot_base_urdf.launch
2.3.2.1 加入摄像头(Camera)
cd ~/catkin_ws/src/mbot_description/urdf
sudo gedit mbot_with_camera.urdf
<?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" />
<!--外观是个盒子模拟成摄像头,长宽高分别是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>
cd ~/catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_with_camera_urdf.launch
<launch>
<param name="robot_description" textfile="$(find mbot_description)/urdf/mbot_with_camera.urdf" />
<param name="use_gui" value="true"/>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" />
</launch>
roslaunch mbot_description display_mbot_with_camera_urdf.launch
cd ./catkin_ws/src/mbot_description/urdf
sudo gedit mbot_with_laser.urdf
<?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>
cd ./catkin_ws/src/mbot_description/launch
sudo gedit display_mbot_with_laser_urdf.launch
<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" pkg="joint_state_publisher" type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" />
</launch>
roslaunch mbot_description display_mbot_with_laser_urdf.launch
cd ./catkin_ws/src/mbot_description/urdf
sudo gedit mbot_with_kinect.urdf
<?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="laser_joint" type="fixed">
<origin xyz="0.15 0 0.11" rpy="0 0 0"/>
<parent link="base_link"/>
<child link="kinect_link"/>
</joint>
</robot>
cd ./catkin_ws/src/mbot_description/launch
sudo gedit mbot_with_kinect.launch
<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" pkg="joint_state_publisher" type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_description)/config/mbot_urdf.rviz" required="true" />
</launch>
roslaunch mbot_description mbot_with_kinect.launch
urdf_to_graphiz + [要检查的 urdf 文件]
。urdf_to_graphiz mbot_with_camera.urdf
sudo apt install liburdfdom-tools
cd ~/catkin_ws/src/mbot_description/urdf/
urdf_to_graphiz mbot_with_camera.urdf
evince mbot.pdf
[1] urdf_百度百科
[2] ROS——URDF机器人建模