param name=robot_description command= $(find xacro)/xacro --inorder ' $(arg model)' 到底什么意思
生活随笔
收集整理的這篇文章主要介紹了
param name=robot_description command= $(find xacro)/xacro --inorder ' $(arg model)' 到底什么意思
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天看到個代碼,讓我一臉懵逼。才發現這么常見的一句話,我竟然還不怎么清楚它的含義。經過探索,發現兩個xacro使用大法。
<param name="robot_description" command="$(find xacro)/xacro --inorder '$(arg model)'enable_logging:=$(arg enable_logging)enable_ground_truth:=$(arg enable_ground_truth)enable_mavlink_interface:=$(arg enable_mavlink_interface)log_file:=$(arg log_file)wait_to_record_bag:=$(arg wait_to_record_bag)mav_name:=$(arg mav_name)namespace:=$(arg namespace)"/>已知的
這句話的目的是給 robot_description賦值,從而使得rviz通過robo_description獲得機器人模型。
賦的值為:’$ (find xacro)/xacro --inorder’ 在輸入參數’為’$ (arg model)’ 情況下的的運行結果。類似于命令:
【注】- - inorder命令是jade版本才出現的,能夠匹配jade及之后的xacro。
然后后面那一堆參數是什么呢???
探索
在ros官網發現了端倪:
就是說,后面的幾個參數都是傳遞給xacro文件的。
然后我們再看看xacro文件
從中可以總結出兩個使用大法:
命名空間和文件路徑
將文件按照命名空間分類存放,依此索引文件。如
parent_link="${namespace}/base_link"模型組合
通過xacro文件里的< xacro:if value="$ (arg xxxx) ">和roslaunch里的xacro參數輸入,實現
模型和功能的組合。
備忘
參考官網,把到目前為止見過的xacro語法,稍加擴展記錄在這里,以備忘。有一些用法是jade及之后版本才有的。
<!----------------------property------------------------> <xacro:property name="the_radius" value="2.1" /> <xacro:property name="the_length" value="4.5" /><geometry type="cylinder" radius="${the_radius}" length="${the_length}" /><!--------------------property blocks--------------------> <xacro:property name="front_left_origin"><origin xyz="0.3 0 0" rpy="0 0 0" /> </xacro:property><pr2_wheel name="front_left_wheel"><xacro:insert_block name="front_left_origin" /> </pr2_wheel><!------------------------math---------------------------> <xacro:property name="R" value="2" /> <xacro:property name="alpha" value="${30/180*pi}" /> <circle circumference="${2 * pi * R}" pos="${sin(alpha)} ${cos(alpha)}" /> <limit lower="${radians(-90)}" upper="${radians(90)}" effort="0" velocity="${radians(75)}" /><!-----------------conditional blocks--------------------> <xacro:if value="<expression>"><... some xml code here ...> </xacro:if> <xacro:unless value="<expression>"><... some xml code here ...> </xacro:unless><xacro:property name="var" value="useit"/> <xacro:if value="${var == 'useit'}"/> <xacro:if value="${var.startswith('use') and var.endswith('it')}"/><xacro:property name="allowed" value="${[1,2,3]}"/> <xacro:if value="${1 in allowed}"/><!-------------------rospack commands--------------------> <foo value="$(find xacro)" /><xacro:arg name="myvar" default="false"/> <!--run as--> <param name="robot_description" command="$(find xacro)/xacro.py $(arg model) myvar:=true" /><!------------------------macros-------------------------> <xacro:macro name="pr2_caster" params="suffix *origin **content **anothercontent"><joint name="caster_${suffix}_joint"><axis xyz="0 0 1" /></joint><link name="caster_${suffix}"><xacro:insert_block name="origin" /><xacro:insert_block name="content" /><xacro:insert_block name="anothercontent" /></link> </xacro:macro><xacro:pr2_caster suffix="front_left"><pose xyz="0 1 0" rpy="0 0 0" /><container><color name="yellow"/><mass>0.1</mass></container><another><inertial><origin xyz="0 0 0.5" rpy="0 0 0"/><mass value="1"/><inertia ixx="100" ixy="0" ixz="0" iyy="100" iyz="0" izz="100" /></inertial></another> </xacro:pr2_caster> <!--The example declares a macro "pr2_caster", which takes two parameters: suffix and origin.Note that "origin" is starred. This indicates that origin is a block parameter instead of a simple text parameter. Look ahead to the use of pr2_caster. The suffix property is defined in the pr2_caster tag as an attribute, but no origin property is defined.Instead, origin refers to the first element inside (the "pose" block, in this case). The double-starred version ("content", "anothercontent") allows to insert an arbitrary number of elements that are passed within elements subsequently available ("container", "another" respectively in the example above). This example expands to the following: --> <joint name="caster_front_left_joint"><axis xyz="0 0 1" /> </joint> <link name="caster_front_left"><pose xyz="0 1 0" rpy="0 0 0" /><color name="yellow" /><mass>0.1</mass><inertial><origin xyz="0 0 0.5" rpy="0 0 0"/><mass value="1"/><inertia ixx="100" ixy="0" ixz="0" iyy="100" iyz="0" izz="100" /></inertial> </link><!--------------------default parameters---------------------> <xacro:macro name="foo" params="x:=${x} y:=${2*y} z:=0"/> <xacro:macro name="foo" params="p1 p2:=expr_a p3:=^ p4:=^|expr_b"> <!--The caret ^ indicates to use the outer-scope property (with same name). The pipe | indicates to use the given fallback if the property is not defined in outer scope. --><!--------------Including other xacro files------------------> <xacro:include filename="$(find package)/other_file.xacro" /> <xacro:include filename="other_file.xacro" ns="namespace"/><!-----------------------yaml support------------------------> <xacro:property name="props" value="${dict(a=1, b=2, c=3)}"/> <xacro:property name="numbers" value="${[1,2,3,4]}"/><xacro:property name="yaml_file" value="$(find package)/config/props.yaml" /> <xacro:property name="props" value="${load_yaml(yaml_file)}"/>總結
以上是生活随笔為你收集整理的param name=robot_description command= $(find xacro)/xacro --inorder ' $(arg model)' 到底什么意思的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《华为云NIST CSF实践指南》白皮书
- 下一篇: 什么是IDC服务器租用?