ROS1学习笔记--xacro_ros1python xacroduoche_喵喵三三的博客-程序员宅基地

技术标签: ROS学习笔记  

        xacro文件是urdf文件的进阶版,可以通过宏定义文件包含来精简模型文件。还可以通过定义常量、变量等来反复调用,相当有用哦~~

先贴代码:

<?xml version="1.0" ?>
<robot name="fourwheelrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">
 <!--Defineing namespace-->

  <!--property list -->
  <xacro:property name="M_PI" value="3.141592"/>
  <xacro:property name="base_mass"   value="20" /> 
  <xacro:property name="base_length" value="0.80"/>
  <xacro:property name="base_width" value="0.550"/>
  <xacro:property name="base_height" value="0.30"/>

  <xacro:property name="wheel_mass"   value="2" />
  <xacro:property name="wheel_radius" value="0.122"/>
  <xacro:property name="wheel_length" value="0.062"/>
  <xacro:property name="wheel_joint_x" value="0.25"/>
  <xacro:property name="wheel_joint_y" value="0.306"/>
  <xacro:property name="wheel_joint_z" value="-0.1"/> 

  <!--Defineing the colors-->
  <material name="black">
    <color rgba="0 0 0 1"/>
  </material>
  <material name="yellow">
    <color rgba="1 0.4 0 1"/>
  </material>

  <!-- Macro for inertia matrix -->
   <xacro:macro name="cylinder_inertial_matrix" params="m r h">
     <inertial>
        <mass value="${m}" />
        <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}" /> 
        </inertial>
    </xacro:macro>

    <xacro:macro name="box_inertial_matrix" params="m a b c">
       <inertial>
          <mass value="${m}" />
           <inertia ixx="${m*(b*b+c*c)/12}" ixy = "0" ixz = "0"
              iyy="${m*(c*c+a*a)/12}" iyz = "0"
              izz="${m*(a*a+b*b)/12}" /> 
       </inertial>
    </xacro:macro>

  
  <!--Macro for the wheel -->
  <xacro:macro name="wheel" params="prefix1 prefix2 reflect1 reflect2">
     <joint name="${prefix1}_${prefix2}_wheel_joint" type="continuous">
       <origin xyz="${reflect1*wheel_joint_x} ${reflect2*wheel_joint_y} ${wheel_joint_z}"/>
       <parent link="base_link"/>
       <child link="${prefix1}_${prefix2}_wheel_link"/>
       <axis xyz="0 1 0"/>
     </joint>

     <link name="${prefix1}_${prefix2}_wheel_link">
       <visual>
         <origin xyz="0 0 0" rpy="${M_PI/2} 0 0" />
         <geometry>
            <cylinder radius="${wheel_radius}" length="${wheel_length}"/>
         </geometry>
         <material name="black"/>
      </visual>
      <collision>
         <origin xyz="0 0 0" rpy="${M_PI/2} 0 0" />
           <geometry>
               <cylinder radius="${wheel_radius}" length = "${wheel_length}"/>
           </geometry>
      </collision>
      <cylinder_inertial_matrix  m="${wheel_mass}" r="${wheel_radius}" h="${wheel_length}" />
     </link>
    
     <gazebo reference="${prefix1}_${prefix2}_wheel_link">
       <material>Gazebo/Black</material>
     </gazebo>

  <!-- Transmission is important to link the joints and the controller -->
     <transmission name="${prefix1}_${prefix2}_wheel_joint_trans">
         <type>transmission_interface/SimpleTransmission</type>
         <joint name="prefix1}_${prefix2}_wheel_joint" >
             <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
         </joint>
         <actuator name="${prefix1}_${prefix2}_wheel_joint_motor">
             <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
             <mechanicalReduction>1</mechanicalReduction>
         </actuator>
      </transmission>
  </xacro:macro>

  <!--start -->
   <xacro:macro name="fourwheelrobot_base_gazebo">
  <link name="base_footprint">
     <visual>
        <origin xyz="0 0 0" rqy="0 0 0"/>
         <geometry>
            <box size="0.001 0.001 0.001"/>
         </geometry>
     </visual>
   </link>

  <gazebo reference="base_footprint">
     <turnGravityOff>false</turnGravityOff>
  </gazebo>


  <joint name="base_footprint_joint" type="fixed">
            <origin xyz="0 0 ${base_height/2}" rpy="0 0 0" />        
            <parent link="base_footprint"/>
            <child link="base_link" />
   </joint> 

  <link name="base_link">
    <visual>
      <origin xyz="0 0 0" rqy="0 0 0"/>
      <geometry>
        <box size="${base_length} ${base_width} ${base_height}"/>
      </geometry>
      <material name="yellow"/>
    </visual>
   <collision>
      <origin xyz=" 0 0 0" rpy="0 0 0" />
      <geometry>
        <box size="${base_length} ${base_width} ${base_height}"/>
      </geometry>
   </collision>   
   <box_inertial_matrix  m="${base_mass}" a="${base_length}" b="${base_width}"  c="${base_height}" />
  </link>
 
  <gazebo reference="base_link">
     <material>Gazebo/Yellow</material>
  </gazebo>
    <wheel prefix1="left" prefix2="front" reflect1="1" reflect2="1"/>
    <wheel prefix1="left" prefix2="back" reflect1="-1" reflect2="1"/>
    <wheel prefix1="right" prefix2="front" reflect1="1" reflect2="-1"/>
    <wheel prefix1="right" prefix2="back" reflect1="-1" reflect2="-1"/>
<gazebo>
  <plugin name="skid_steer_drive_controller" filename="libgazebo_ros_skid_steer_drive.so">
      <rosDebugLevel>Debug</rosDebugLevel> 
       <publishWheelTF>true</publishWheelTF>
       <publishTf>1</publishTf>
       <publishWheelJointState>true</publishWheelJointState> 
       <alwaysOn>true</alwaysOn> 
    <updateRate>100.0</updateRate>
    <robotNamespace>/</robotNamespace>
    <leftFrontJoint>left_front_wheel_joint</leftFrontJoint>
    <rightFrontJoint>right_front_wheel_joint</rightFrontJoint>
    <leftRearJoint>left_back_wheel_joint</leftRearJoint>
    <rightRearJoint>right_back_wheel_joint</rightRearJoint>
    <wheelSeparation>${wheel_joint_y*2}</wheelSeparation>
    <wheelDiameter>${2*wheel_radius}</wheelDiameter>
        <broadcastTF>1</broadcastTF> 
    <robotBaseFrame>base_footprint</robotBaseFrame>
    <torque>20</torque>
    <topicName>cmd_vel</topicName>
    <odometryFrame>odom</odometryFrame> 
    <odometryTopic>odom</odometryTopic>
   
   </plugin>
</gazebo>

 


     
  </xacro:macro>
</robot>

 

 

 

 

 

 

 

 

 

1.常量定义:

 <xacro:property name="M_PI" value="3.141592"/>

  常量使用:

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

2.变量定义:

 变量使用:

(这次例子中没有哎~0-0)

3.宏定义:

<xacro:macro name="cylinder_inertial_matrix" params="m r h">
     <inertial>
        <mass value="${m}" />
        <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}" /> 
        </inertial>
    </xacro:macro>

宏定义调用:

  <box_inertial_matrix  m="${base_mass}" a="${base_length}" b="${base_width}"  c="${base_height}" />

这个例子中还添加了传动件(transmission),滑动驱动控制器插件(plugin),

<!-- Transmission is important to link the joints and the controller -->
     <transmission name="${prefix1}_${prefix2}_wheel_joint_trans">
         <type>transmission_interface/SimpleTransmission</type>
         <joint name="prefix1}_${prefix2}_wheel_joint" >
             <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
         </joint>
         <actuator name="${prefix1}_${prefix2}_wheel_joint_motor">
             <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
             <mechanicalReduction>1</mechanicalReduction>
         </actuator>
      </transmission>
<gazebo>
  <plugin name="skid_steer_drive_controller" filename="libgazebo_ros_skid_steer_drive.so">
      <rosDebugLevel>Debug</rosDebugLevel> 
       <publishWheelTF>true</publishWheelTF>
       <publishTf>1</publishTf>
       <publishWheelJointState>true</publishWheelJointState> 
       <alwaysOn>true</alwaysOn> 
    <updateRate>100.0</updateRate>
    <robotNamespace>/</robotNamespace>
    <leftFrontJoint>left_front_wheel_joint</leftFrontJoint>
    <rightFrontJoint>right_front_wheel_joint</rightFrontJoint>
    <leftRearJoint>left_back_wheel_joint</leftRearJoint>
    <rightRearJoint>right_back_wheel_joint</rightRearJoint>
    <wheelSeparation>${wheel_joint_y*2}</wheelSeparation>
    <wheelDiameter>${2*wheel_radius}</wheelDiameter>
        <broadcastTF>1</broadcastTF> 
    <robotBaseFrame>base_footprint</robotBaseFrame>
    <torque>20</torque>
    <topicName>cmd_vel</topicName>
    <odometryFrame>odom</odometryFrame> 
    <odometryTopic>odom</odometryTopic>
   
   </plugin>
</gazebo>

参考网站:

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_40863346/article/details/80498424

智能推荐

cisco ASA5510防火墙配置_iteye_3753的博客-程序员宅基地

ASA5510 配置手册使用console连接线登录方法1.使用cisco专用com连接线,连接设备的console口和计算机com口2.使用超级终端或secureCRT软件连接设备 串行选项: 波特率:9600 数据位:8 奇偶校验:无 停止位:1 数据流控制: RTS/CTS3.输入en,提示输入密码 show run 查看设备当前配置 configure ter 进入配置模式,输入前...

Python爬虫学到什么程度就可以去找工作了?_爬虫学到什么程度可以找工作_普通网友的博客-程序员宅基地

有朋友在群里和大家讨论,问的最多的问题就是,python 爬虫学到什么程度可以去找工作了,关于这点,和大家分享下我的理解。确立目标、了解需求首先我们要先定位自己的目标,当然我们先以爬虫工程师来做个说明。去招聘网上看看需求都有哪些,直接做个拉勾网爬虫(有需要的私信)出结果了:仔细看看,我们可以得出以下几点:1、 python 不是唯一可以做爬虫的,很多语言都可以,尤其是 java,同时掌握它们和拥有相关开发经验是很重要的加分项。最后,如果你的时间不是很紧张,并且又想快速的提高,最重要的是不怕_爬虫学到什么程度可以找工作

达梦数据库操作记录_【原创】达梦数据库DM7备份与恢复_weixin_39755003的博客-程序员宅基地

转载请注明出处:https://www.cnblogs.com/fengaix6/p/11996588.html数据库备份是非常重要的工作内容。DBA不仅要保证备份成功,还要保证一旦数据库发生故障时备份可还原可恢复。一、概述DM7数据库中的数据存储在数据库的物理数据文件中,数据文件按照页、簇和段的方式进行管理,数据页是最小的数据存储单元。任何一个对DM7数据库的操作,归根结底都是对某个数据文件页的..._达梦历史修改记录

linuxdeploy纯php,【eMMC运行Ubuntu性能测试】Ubuntu还是LinuxDeploy,如何选择?_胡萝卜伞的博客-程序员宅基地

本帖最后由 opengg 于 2018-5-31 03:56 编辑U盘启动Ubuntu,还是Android内置LinuxDeploy,怎么选?以下我通过测试对比来说明1. 刷入 Android ROM我刷入的是 webpad 的 2.0 系统,开机后斐讯设置里显示版本号是 2.27https://www.right.com.cn/forum/forum.php?mod=viewthread&..._linuxdeploy性能

Struts 2中if else iterator property标签的使用 ._tanshi的博客-程序员宅基地

为了控制输出Struts 2的ValueStack中封装的值,Struts 2提供了大量的标签。其中比较常用的标签有: if:该标签支持标签体,如果if标签里判断的表达式返回真,则输出标签体内容。 else:该标签不能独立使用,它需要与if标签结合使用,如果if标签内判断的表达式返回假,则输出该标签里的标签体。 iterator:主要用于迭代输出某个集合属性的各个集合元素。

Navicat Premium 连接Oracle 数据库(图文教程)_navicat premium 连接oracle数据库_爱吃鱼的猫^_^的博客-程序员宅基地

Navicat premium是一款数据库管理工具,是一个可多重连线资料库的管理工具,它可以让你以单一程式同时连线到 MySQL、SQLite、Oracle及PostgreSQL 资料库,让管理不同类型的资料库更加的方便。 一、需要准备的软件 1.Navicat premium 32位 官方下载地址:http://www.navicat.co_navicat premium 连接oracle数据库

随便推点

DOMAIN-A W ARE NEURAL LANGUAGE MODELS FOR SPEECH RECOGNITION_Ezio的学习之旅的博客-程序员宅基地

ABSTRACT随着语音助手变得越来越普遍,人们越来越希望它们能够支持不同领域的各种用例,并在这些用例中表现良好。我们提出了一个域感知的重新评分框架,适用于在生产环境中进行二次重新评分时实现域适配。在我们的框架中,我们在几个领域上微调一个领域通用神经语言模型,并使用基于lstm的领域分类模型选择合适的领域适应模型用于二次重评分。与域通用重评分相比,在三个单独的域(购物、导航和音乐)上,这种域感知重评分提高了单词错误率高达2.4%,槽位单词错误率高达4.1%。这些改进是在保持一般用例的准确性的同时获得

c#模拟看板控件_在Winform界面使用自定义用户控件及TabelPanel和StackPanel布局控件..._发际线退我不退的博客-程序员宅基地

在很多时候,我们做一些非常规化的界面的时候,往往需要创建一些用户控件,在其中绘制好一些基础的界面块,作为后续重复使用的一个单元,用户控件同时也可以封装处理一些简单的逻辑。在开发Winform各种类型项目,我都时不时需要定制一些特殊的用户控件,以方便在界面模块中反复使用。我们一般是在自定义的用户控件里面,添加各种各样的界面控件元素,或者封装一些特殊的函数处理共外部调用等。本篇随笔主要介绍基于DevE..._c# stackpanel

python的ttk如何添加图片_如何用python tkinter插入显示图片?_A菲拉格慕(小艳子)的博客-程序员宅基地

有时候小编觉得python的功能真的是无限强大,居然可以插入图片,今天小编就这个内容,给大家讲解下关于插入图片内容,想必很多小伙伴都很感兴趣吧~那就一起来看下吧~关于Tkinter:Tkinter 模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口 。代码演示# 配置,放在这里,那么主窗口的2个按钮就先显示出来# 要打开的图像image1="open.gif"#注意tk...

jenkins bash: jar: command not found 之环境变量_女神范儿的的博客-程序员宅基地

在操作 jenkins 的过程中,出现很多问题,自己做了个汇总,和大家分享一下:(1)出现问题原因1:目标服务器jar,命令不存在 解决方法: 安装 jar 命令 #cd /usr/bin #yum install jar 必须先进入/usr/bin,下同目标...

[编译原理]LL(1)分析法+例题 学习_踩踩芽的博客-程序员宅基地

LL(1)分析法LL(1) 分析法又称预测分析法 ,是 一种不带回溯的非递归自上而下分析法。LL(1)分析器LL(1)分析表LL(1)文法:分析表M不含多重定义入口的文法1、一个LL(1)文法所定义得语言恰好就是它的分析表所能识别的全部句子。2、一个上下文无关文法是LL(1)文法的充要条件(判断一个文法是否是LL(1)文法):对每一个非终结符A的任何两个不同的产生式A→α|β,有下面条件(都是避免了多重入口)成立(1)FIRST(α) ∩ FIRST(β) = ∅:A的每个候选是都不存_ll(1)分析法

第九章: TypeScript-for of循环_typescript for of_小仙女de成长的博客-程序员宅基地

forEach()for infor offorEach 这边只能打印出来1234 desc不能打出来var myArray = [1,2,3,4];myArray.desc = " four number ";myArray .forEach( value =&gt; console.log(value));for in 这个打印出来的是数组的下标跟属性的名字,也可以打印出..._typescript for of

推荐文章

热门文章

相关标签