当前位置:网站首页>[ROS advanced chapter] Lecture 9 programming optimization of URDF and use of xacro
[ROS advanced chapter] Lecture 9 programming optimization of URDF and use of xacro
2022-07-25 12:24:00 【Life is like Zhaoxu】
【ROS Advanced 】 About 9 URDF Programming optimization Xacro Use

List of articles
Preface
In the last blog section, we learned systematically URDF Specific use methods and example exercises , But in the process of learning, we can also find direct editing URDF There are many problems in the document , for example Joint parameters and code reusability , This blog mainly introduces one About XML Programming optimization method of language ,Xacro, In practice URDF Popular optimization methods in programming , From the basic concept 、 Grammar explanation to actual robot examples for in-depth discussion .
One 、Xacro Basic concepts of
Concept :XML Macros Abbreviation , Essentially, A kind of XML Macro language , It's programmable XML
Purpose : solve URDF Inherent problems in building robot models :
1. connecting rod 、 Calculation of important parameters of joints : Manually calculate through a fixed formula , Prone to mistakes , And the efficiency is very low ;
2. Highly repetitive content : For the same robot part ,URDF The file code is the same , But it needs to be programmed repeatedly , Lack of reusability ;
- principle : Optimize the code construction process through variables and functions
1. Declare variables : Calculate important parameters through mathematical operations , Record data in variables , Improve efficiency and safety ;
2. Packaging function : Use process control sequence , Encapsulate fixed logic , Improve code reusability
effect : Improve writing efficiency , By using macro commands, we can build shorter and more readable XML file , Expand to greater XML Expression range
characteristic :
\qquad 1. Provides a programmable interface , Contains variable declaration calls 、 Syntax implementation such as function declaration and call ;
\qquad 2. In the use of xacro When generating a file , Root tag robot Namespace declaration must be included :xmlns:xacro="http://wiki.ros.org/xacro"
Two 、Xacro A detailed explanation of the grammar of
1. Attributes and arithmetic operations :
\qquad effect : encapsulation URDF In the field , For example, car size 、 Wheel radius, etc
\qquad Attribute definitions : Declare variables , The definition format is as follows
<xacro:property name="xxxx" value="yyyy" />
\qquad Calling a : Variable call format :${ The attribute name }
\qquad Arithmetic operations : Variable calculation format :${ Mathematical expression }
2. macro :
\qquad effect : Function implementation , Improve code reuse rate , Optimize code structure , Improve safety
\qquad Macro definition : Function definition , The definition format is as follows
<xacro:macro name=" Macro name " params=" parameter list ( Multiple parameters are separated by spaces )">
.....
Parameter call format : ${ Parameter name }
</xacro:macro>
\qquad Macro call : Function call format :
<xacro: Macro name Parameters 1=xxx Parameters 2=xxx/>
3. The file contains integration :
\qquad effect : Package the different parts of the robot into separate xacro file , Integrate files into a complete robot , You can use File Inclusion to implement
\qquad The file contains the format :
<robot name="xxx" xmlns:xacro="http://wiki.ros.org/xacro">
<xacro:include filename="my_base.xacro" />
<xacro:include filename="my_camera.xacro" />
<xacro:include filename="my_laser.xacro" />
....
</robot>
3、 ... and 、 Examples of actual robot models
1. Target robot and implementation process :
- The goal is : It has two driving wheels 、 A cylindrical car with two supporting wheels , And add cameras and radar sensors , The effect is as follows :

- Implementation process :
1. Write chassis xacro file ;
2. Write camera and radar xacro file ;
3. Write a portfolio , Assemble all parts of the trolley ;
4. To write launch File to start the Rviz According to the model ;
2. To write xacro file :
- The trolley chassis realizes :
<!-- Use xacro Optimize URDF Implementation of car chassis based on version : Realize the idea : 1. Put some constants 、 Variables are encapsulated as xacro:property such as :PI value 、 Trolley chassis radius 、 Distance from the ground 、 Wheel radius 、 Width .... 2. Use macro Encapsulate the driving wheel and supporting wheel to realize , Call relevant macros to generate driving wheel and supporting wheel -->
<!-- Root tag , You must declare xmlns:xacro -->
<robot name="my_base" xmlns:xacro="http://www.ros.org/wiki/xacro">
<!-- Encapsulate variables 、 Constant -->
<xacro:property name="PI" value="3.141"/>
<!-- macro : Black setting -->
<material name="black">
<color rgba="0.0 0.0 0.0 1.0" />
</material>
<!-- Chassis properties -->
<xacro:property name="base_footprint_radius" value="0.001" /> <!-- base_footprint radius -->
<xacro:property name="base_link_radius" value="0.1" /> <!-- base_link radius -->
<xacro:property name="base_link_length" value="0.08" /> <!-- base_link Long -->
<xacro:property name="earth_space" value="0.015" /> <!-- Distance from the ground -->
<!-- chassis -->
<link name="base_footprint">
<visual>
<geometry>
<sphere radius="${base_footprint_radius}" />
</geometry>
</visual>
</link>
<link name="base_link">
<visual>
<geometry>
<cylinder radius="${base_link_radius}" length="${base_link_length}" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
<material name="yellow">
<color rgba="0.5 0.3 0.0 0.5" />
</material>
</visual>
</link>
<joint name="base_link2base_footprint" type="fixed">
<parent link="base_footprint" />
<child link="base_link" />
<origin xyz="0 0 ${earth_space + base_link_length / 2 }" />
</joint>
<!-- Driving wheel -->
<!-- Drive wheel properties -->
<xacro:property name="wheel_radius" value="0.0325" /><!-- radius -->
<xacro:property name="wheel_length" value="0.015" /><!-- Width -->
<!-- Drive wheel macro implementation -->
<xacro:macro name="add_wheels" params="name flag">
<link name="${name}_wheel">
<visual>
<geometry>
<cylinder radius="${wheel_radius}" length="${wheel_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="${PI / 2} 0.0 0.0" />
<material name="black" />
</visual>
</link>
<joint name="${name}_wheel2base_link" type="continuous">
<parent link="base_link" />
<child link="${name}_wheel" />
<origin xyz="0 ${flag * base_link_radius} ${-(earth_space + base_link_length / 2 - wheel_radius) }" />
<axis xyz="0 1 0" />
</joint>
</xacro:macro>
<xacro:add_wheels name="left" flag="1" />
<xacro:add_wheels name="right" flag="-1" />
<!-- Supporting wheel -->
<!-- Support wheel properties -->
<xacro:property name="support_wheel_radius" value="0.0075" /> <!-- Radius of supporting wheel -->
<!-- Support wheel macro -->
<xacro:macro name="add_support_wheel" params="name flag" >
<link name="${name}_wheel">
<visual>
<geometry>
<sphere radius="${support_wheel_radius}" />
</geometry>
<origin xyz="0 0 0" rpy="0 0 0" />
<material name="black" />
</visual>
</link>
<joint name="${name}_wheel2base_link" type="continuous">
<parent link="base_link" />
<child link="${name}_wheel" />
<origin xyz="${flag * (base_link_radius - support_wheel_radius)} 0 ${-(base_link_length / 2 + earth_space / 2)}" />
<axis xyz="1 1 1" />
</joint>
</xacro:macro>
<xacro:add_support_wheel name="front" flag="1" />
<xacro:add_support_wheel name="back" flag="-1" />
</robot>
- camera xacro file :
<!-- Camera related xacro file -->
<robot name="my_camera" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- Camera properties -->
<xacro:property name="camera_length" value="0.01" /> <!-- Camera length (x) -->
<xacro:property name="camera_width" value="0.025" /> <!-- Camera width (y) -->
<xacro:property name="camera_height" value="0.025" /> <!-- Camera height (z) -->
<xacro:property name="camera_x" value="0.08" /> <!-- Camera installation x coordinate -->
<xacro:property name="camera_y" value="0.0" /> <!-- Camera installation y coordinate -->
<xacro:property name="camera_z" value="${base_link_length / 2 + camera_height / 2}" /> <!-- Camera installation z coordinate : Ride height / 2 + Camera height / 2 -->
<!-- Camera joints and link -->
<link name="camera">
<visual>
<geometry>
<box size="${camera_length} ${camera_width} ${camera_height}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="black" />
</visual>
</link>
<joint name="camera2base_link" type="fixed">
<parent link="base_link" />
<child link="camera" />
<origin xyz="${camera_x} ${camera_y} ${camera_z}" />
</joint>
</robot>
- radar xacro file :
<!-- Add radar to the car chassis -->
<robot name="my_laser" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- Radar support -->
<xacro:property name="support_length" value="0.15" /> <!-- Support length -->
<xacro:property name="support_radius" value="0.01" /> <!-- Support radius -->
<xacro:property name="support_x" value="0.0" /> <!-- Bracket mounted x coordinate -->
<xacro:property name="support_y" value="0.0" /> <!-- Bracket mounted y coordinate -->
<xacro:property name="support_z" value="${base_link_length / 2 + support_length / 2}" /> <!-- Bracket mounted z coordinate : Ride height / 2 + Support height / 2 -->
<link name="support">
<visual>
<geometry>
<cylinder radius="${support_radius}" length="${support_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="red">
<color rgba="0.8 0.2 0.0 0.8" />
</material>
</visual>
</link>
<joint name="support2base_link" type="fixed">
<parent link="base_link" />
<child link="support" />
<origin xyz="${support_x} ${support_y} ${support_z}" />
</joint>
<!-- Radar properties -->
<xacro:property name="laser_length" value="0.05" /> <!-- Radar length -->
<xacro:property name="laser_radius" value="0.03" /> <!-- Radar radius -->
<xacro:property name="laser_x" value="0.0" /> <!-- Radar installation x coordinate -->
<xacro:property name="laser_y" value="0.0" /> <!-- Radar installation y coordinate -->
<xacro:property name="laser_z" value="${support_length / 2 + laser_length / 2}" /> <!-- Radar installation z coordinate : Support height / 2 + Radar altitude / 2 -->
<!-- Radar joints and link -->
<link name="laser">
<visual>
<geometry>
<cylinder radius="${laser_radius}" length="${laser_length}" />
</geometry>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0" />
<material name="black" />
</visual>
</link>
<joint name="laser2support" type="fixed">
<parent link="support" />
<child link="laser" />
<origin xyz="${laser_x} ${laser_y} ${laser_z}" />
</joint>
</robot>
3. Combination and startup :
- Combined trolley model file :
<!-- Combine the car chassis with camera and radar -->
<robot name="my_car_camera" xmlns:xacro="http://wiki.ros.org/xacro">
<xacro:include filename="my_base.urdf.xacro" />
<xacro:include filename="my_camera.urdf.xacro" />
<xacro:include filename="my_laser.urdf.xacro" />
</robot>
- Integrate launch file :
\qquad 1) First convert to urdf Post file integration :
- First the xacro The file is parsed into urdf file :
rosrun xacro xacro xxx.xacro > xxx.urdf
- Direct integration launch file :
<launch> <param name="robot_description" textfile="$(find demo01_urdf_helloworld)/urdf/xacro/my_base_camera_laser.urdf.xacro" />" /> <node pkg="rviz" type="rviz" name="rviz" args="-d $(find demo01_urdf_helloworld)/config/helloworld.rviz" /> <node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher" output="screen" /> <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" output="screen" /> <node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" name="joint_state_publisher_gui" output="screen" /> </launch>
\qquad 2) stay launch Load directly into the file xacro
<launch>
<param name="robot_description" command="$(find xacro)/xacro $(find demo01_urdf_helloworld)/urdf/xacro/my_base_camera_laser.urdf.xacro" />
<node pkg="rviz" type="rviz" name="rviz" args="-d $(find demo01_urdf_helloworld)/config/helloworld.rviz" />
<node pkg="joint_state_publisher" type="joint_state_publisher" name="joint_state_publisher" output="screen" />
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" output="screen" />
<node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" name="joint_state_publisher_gui" output="screen" />
</launch>
summary
- Statement : The blog section of this section refers to CSDN User zhaoxuzuo ROS course , This paper mainly introduces URDF An optimized programming method for files , namely Xacro, Improve code security by declaring variables and functions 、 Efficiency and reusability , From the basic concepts 、 The grammar is explained in detail and the final actual robot example is analyzed in detail , In the following tutorial, we will also introduce about URDF File with the RVIZ and Gazebo The tutorial of Component Co simulation and the content about sensors and navigation , Coming soon .
边栏推荐
- 【5】 Page and print settings
- NLP知识----pytorch,反向传播,预测型任务的一些小碎块笔记
- R language uses the ggarrange function of ggpubr package to combine multiple images, and uses the ggexport function to save the visual images in JPEG format (width parameter specifies width, height pa
- 给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享
- Data transmission under the same LAN based on tcp/ip
- Behind the screen projection charge: iqiyi's quarterly profit, is Youku in a hurry?
- Sword finger offer 22. the penultimate node in the linked list
- Numpy first acquaintance
- Pytorch advanced training skills
- 水博士2
猜你喜欢

2.1.2 机器学习的应用

技术管理杂谈

WPF project introduction 1 - Design and development of simple login page

Word中的空白页,怎么也删不掉?如何操作?

记录一次线上死锁的定位分析

Feign use

搭建Vision Transformer系列实践,终于见面了,Timm库!

马斯克的“灵魂永生”:一半炒作,一半忽悠

Hydrogen entrepreneurship competition | Liu Yafang, deputy director of the science and Technology Department of the National Energy Administration: building a high-quality innovation system is the cor

3.2.1 what is machine learning?
随机推荐
Can't delete the blank page in word? How to operate?
Hystrix使用
[micro service ~sentinel] sentinel degradation, current limiting, fusing
Application of comparative learning (lcgnn, videomoco, graphcl, XMC GaN)
Eureka registration center opens password authentication - record
OSPF comprehensive experiment
【Flutter -- 实例】案例一:基础组件 & 布局组件综合实例
numpy初识
Scott+Scott律所计划对Yuga Labs提起集体诉讼,或将确认NFT是否属于证券产品
Data transmission under the same LAN based on tcp/ip
【9】 Coordinate grid addition and adjustment
利用wireshark对TCP抓包分析
Those young people who left Netease
selenium使用———xpath和模拟输入和模拟点击协作
【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020
Week303 of leetcode (20220724)
PyTorch项目实战—FashionMNIST时装分类
selenium使用———安装、测试
Eureka注册中心开启密码认证-记录
Plus版SBOM:流水线物料清单PBOM