构建用于gazebo的机器人URDF模型文件

构建用于gazebo的机器人URDF模型文件

构建机器人模型文件URDF
本节例程可以通过网盘下载学习:

链接:https://pan.baidu.com/s/1sin3lI4QbnLL2QfY3qSyyQ

提取码:jmkf

Unified Robot Description Format,统一机器人描述格式,简称为URDF。ROS中的urdf功能包包含一个URDF的C++解析器,URDF文件使用XML格式描述机器人模型。

URDF由一些不同的功能包和组件组成,下图描述了这些组件之间的联系,该文件的主要功能就是描述机器人各个部分(link)与关节(joint)的属性。

在这里插入图片描述
1,创建ROS的工作空间,如果之前学习过程中已经创建,那么进行下一步:

mkdir -p ~/catkin_ws/src

cd ~/catkin_ws/

catkin_make

2,在catkin_ws中创建一个包,名称这里为gazebo_ros_demos

cd ~/catkin_ws/src

catkin_create_pkg gazebo_ros_demos

编译程序包

catkin_make

3,在程序包里创建rrbot.xacro文件

cd gazebo_ros_demos

mkdir urdf

cd urdf

建立rrbot.xacro文件,加入加单的link,内容如下:

<?xml version="1.0"?>

<robot name="rrbot"xmlns:xacro=“http://www.ros.org/wiki/xacro”>

<xacro:propertyname=“PI” value=“3.1415926535897931”/>

<xacro:propertyname=“mass” value=“1” />

<xacro:propertyname=“width” value=“0.1” />

<xacro:propertyname=“height1” value=“2” />

<xacro:propertyname=“height2” value=“1” />

<xacro:propertyname=“height3” value=“1” />

<xacro:propertyname=“camera_link” value=“0.05” />

<xacro:propertyname=“axel_offset” value=“0.05” />

<linkname=“link1”>

<collision>

  <origin xyz="0 0 ${height1/2}"rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height1}"/>

  </geometry>

</collision>



<visual>

  <origin xyz="0 0${height1/2}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height1}"/>

  </geometry>

  <materialname="orange"/>

</visual>



<inertial>

  <origin xyz="0 0${height1/2}" rpy="0 0 0"/>

  <massvalue="${mass}"/>

  <inertia

  ixx="${mass / 12.0 * (width*width +height1*height1)}" ixy="0.0" ixz="0.0"

  iyy="${mass / 12.0 * (height1*height1 +width*width)}" iyz="0.0"

  izz="${mass / 12.0 * (width*width +width*width)}"/>

</inertial>

<linkname=“link2”>

<collision>

  <origin xyz="0 0${height2/2 - axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height2}"/>

  </geometry>

</collision>



<visual>

  <origin xyz="0 0${height2/2 - axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height2}"/>

  </geometry>

  <materialname="black"/>

</visual>



<inertial>

  <origin xyz="0 0${height2/2 - axel_offset}" rpy="0 0 0"/>

  <massvalue="${mass}"/>

  <inertia

  ixx="${mass / 12.0 * (width*width +height2*height2)}" ixy="0.0" ixz="0.0"

  iyy="${mass / 12.0 * (height2*height2 +width*width)}" iyz="0.0"

  izz="${mass / 12.0 * (width*width +width*width)}"/>

</inertial>
<collision>

  <origin xyz="0 0${height3/2 - axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height3}"/>

  </geometry>

</collision>



<visual>

  <origin xyz="0 0${height3/2 - axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height3}"/>

  </geometry>

  <materialname="orange"/>

</visual>



<inertial>

  <origin xyz="0 0${height3/2 - axel_offset}" rpy="0 0 0"/>

  <massvalue="${mass}"/>

  <inertia

  ixx="${mass / 12.0 * (width*width +height3*height3)}" ixy="0.0" ixz="0.0"

  iyy="${mass / 12.0 * (height3*height3 +width*width)}" iyz="0.0"

  izz="${mass / 12.0 * (width*width +width*width)}"/>

</inertial>

link包含的元素在第四章已经有解释,可以参照说明去理解,上面中有些宏定义,因为link里面有些内容是相同的,比如经常重复的参数,不使用宏我们修改的时候很耗费精力,用了xacro之后,一切都变得简单。

4,加入joints

在ros中,joint_state_publisher这个节点会通过joint来了解到每个link之间的连接关系,从而根据一个link值推算出所有的link的TF状态,为开发人员省去了不少时间。

继续在上面的文件中加入joint(关节),demo文件中加入了camera,本节不做说明,有兴趣读者可以自行在官网中查看,加入joint后文件如下:

<?xml version="1.0"?>

<robot name="rrbot"xmlns:xacro=“http://www.ros.org/wiki/xacro”>

<xacro:propertyname=“PI” value=“3.1415926535897931”/>

<xacro:propertyname=“mass” value=“1” />

<xacro:propertyname=“width” value=“0.1” />

<xacro:propertyname=“height1” value=“2” />

<xacro:property name="height2"value=“1” />

<xacro:propertyname=“height3” value=“1” />

<xacro:propertyname=“camera_link” value=“0.05” />

<xacro:propertyname=“axel_offset” value=“0.05” />

<xacro:includefilename="$(find rrbot_description)/urdf/rrbot.gazebo" />

<xacro:includefilename="$(find rrbot_description)/urdf/materials.xacro" />

<linkname=“world”/>

<joint name="fixed"type=“fixed”>

<parentlink="world"/>

<childlink="link1"/>
<collision>

  <origin xyz="0 0${height1/2}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height1}"/>

  </geometry>

</collision>



<visual>

  <origin xyz="0 0${height1/2}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height1}"/>

  </geometry>

  <materialname="orange"/>

</visual>



<inertial>

  <origin xyz="0 0${height1/2}" rpy="0 0 0"/>

  <massvalue="${mass}"/>

  <inertia

  ixx="${mass / 12.0 * (width*width +height1*height1)}" ixy="0.0" ixz="0.0"

  iyy="${mass / 12.0 * (height1*height1 +width*width)}" iyz="0.0"

  izz="${mass / 12.0 * (width*width +width*width)}"/>

</inertial>

<jointname=“joint1” type=“continuous”>

<parentlink="link1"/>

<childlink="link2"/>

<origin xyz="0${width} ${height1 - axel_offset}" rpy="0 0 0"/>

<axis xyz="0 10"/>

<dynamicsdamping="0.7"/>

<linkname=“link2”>

<collision>

  <origin xyz="0 0${height2/2 - axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height2}"/>

  </geometry>

</collision>



<visual>

  <origin xyz="0 0${height2/2 - axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height2}"/>

  </geometry>

  <materialname="black"/>

</visual>



<inertial>

  <origin xyz="0 0${height2/2 - axel_offset}" rpy="0 0 0"/>

  <massvalue="${mass}"/>

  <inertia

  ixx="${mass / 12.0 * (width*width +height2*height2)}" ixy="0.0" ixz="0.0"

  iyy="${mass / 12.0 * (height2*height2 +width*width)}" iyz="0.0"

  izz="${mass / 12.0 * (width*width +width*width)}"/>

</inertial>

<jointname=“joint2” type=“continuous”>

<parent link="link2"/>

<childlink="link3"/>

<origin xyz="0${width} ${height2 - axel_offset*2}" rpy="0 0 0"/>

<axis xyz="0 10"/>

<dynamicsdamping="0.7"/>

<linkname=“link3”>

<collision>

  <origin xyz="0 0 ${height3/2- axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width}${width} ${height3}"/>

  </geometry>

</collision>



<visual>

  <origin xyz="0 0${height3/2 - axel_offset}" rpy="0 0 0"/>

  <geometry>

<box size="${width} ${width}${height3}"/>

  </geometry>

  <materialname="orange"/>

</visual>



<inertial>

  <origin xyz="0 0${height3/2 - axel_offset}" rpy="0 0 0"/>

  <massvalue="${mass}"/>

  <inertia

  ixx="${mass / 12.0 * (width*width + height3*height3)}"ixy="0.0" ixz="0.0"

  iyy="${mass / 12.0 * (height3*height3 +width*width)}" iyz="0.0"

  izz="${mass / 12.0 * (width*width +width*width)}"/>

</inertial>

这时候在命令行中输入如下语句就可以看到我们的link出现在RVIZ中(注意,输入命令的前提是你需要有urdf_tutorial的软件包,没有的话apt下载就行)

roslaunch urdf_tutorial display.launch model:=rrbot.xacro

或者下载了完整demo后可以运行如下代码打开rviz:

roslaunch rrbot_descriptionrrbot_rviz.launch
在这里插入图片描述

Rviz中显示的不是很好看,我们接下来就会介绍怎么加入颜色材料信息并在gazebo中显示出来,也就是编写上面文件中导入的两个文件:

rrbot.gazebo 是一个Gazebo特定文件,包含我们大多数特定于Gazebo的XML元素,包括 标签

materials.xacro 一个简单的Rviz颜色文件,用于存储rgba值,不是必需的,但是一个很好的约定

使模型可以在gazebo中显示
新建一个名为materials.xacro的文件,并加入以下内容

<?xml version="1.0"?>

<materialname=“black”>

<color rgba="0.0 0.00.0 1.0"/>

<materialname=“blue”>

<color rgba="0.0 0.00.8 1.0"/>

<materialname=“green”>

<color rgba="0.0 0.80.0 1.0"/>

<materialname=“grey”>

<color rgba="0.2 0.20.2 1.0"/>
<colorrgba="${255/255} ${108/255} ${10/255} 1.0"/>

<materialname=“brown”>

<colorrgba="${222/255} ${207/255} ${195/255} 1.0"/>

<materialname=“red”>

<color rgba="0.8 0.00.0 1.0"/>

<materialname=“white”>

<color rgba="1.0 1.01.0 1.0"/>

继续新建一个名为rrbot.gazebo的文件,并加入以下内容

<?xml version="1.0"?>

<gazeboreference=“link1”>

Gazebo/Orange

<gazeboreference=“link2”>

<mu1>0.2</mu1>

<mu2>0.2</mu2>

Gazebo/Black

<gazeboreference=“link3”>

<mu1>0.2</mu1>

<mu2>0.2</mu2>

Gazebo/Orange

再次打开rviz和gazebo,可以看到和之前不同的地方:
在这里插入图片描述
这里可能会有疑问,为什么rviz显示的和gazebo不一样,因为gazebo是依靠物理引擎来进行机器人仿真的,在启动的Gazebo窗口中,您应该看到机器人直立。尽管默认情况下物理模拟器中没有故意干扰,但数值误差应该开始增加并导致双倒立摆在几秒钟后下降。
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在Gazebo中启动机器人URDF模型,需要使用以下步骤: 1. 配置好机器人URDF文件,确保模型和关节描述正确。 2. 创建一个启动文件(launch file),并导入必要的ROS包和参数。 3. 在启动文件中添加一个Gazebo节点,指定需要加载的URDF模型文件,以及其他参数,例如仿真器的时间步长和模型的起始位置。 以下是一个简单的启动文件的示例,可以用来启动一个URDF模型Gazebo中: ``` <launch> <!-- Load URDF model --> <arg name="urdf_file" default="$(find my_robot_description)/urdf/my_robot.urdf" /> <param name="robot_description" command="$(find xacro)/xacro $(arg urdf_file)" /> <!-- Launch Gazebo with URDF model --> <include file="$(find gazebo_ros)/launch/empty_world.launch"> <arg name="world_name" value="$(find my_robot_gazebo)/worlds/my_robot_world.world" /> </include> <!-- Set initial robot pose --> <node name="set_initial_pose" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -param robot_description -model my_robot -x 0 -y 0 -z 0 -Y 0" /> </launch> ``` 其中,第一个参数`urdf_file`指定了URDF模型文件的路径。第二个参数`robot_description`使用ROS参数服务器来存储URDF模型的描述。接下来,使用Gazebo的`empty_world.launch`节点来加载仿真器,同时指定需要加载的URDF文件。最后,使用`spawn_model`节点来设置模型的初始位置和姿态。 注意,这只是一个示例启动文件,并且需要根据你的具体情况进行修改。同时,需要确保已经安装了必要的ROS包和Gazebo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wgqabc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值