Giter Club home page Giter Club logo

xacro's Introduction

Xacro (XML Macros)

Xacro is an XML macro language

With xacro, you can construct shorter and more readable XML files by using macros that expand to larger XML expressions. Recent documentation can be found in the wiki. For older releases, have a look at the ROS wiki.

xacro's People

Contributors

ablasdel avatar adamheins avatar ahcorde avatar brunob81hk avatar bulwahn avatar codebot avatar cottsay avatar davetcoleman avatar de-vri-es avatar doomerdinger avatar hgaiser avatar jbohren avatar kartikmohta avatar kejxu avatar mikeferguson avatar mikepurvis avatar peci1 avatar piyushk avatar rhaschke avatar rmf-buildfarm avatar scpeters avatar sloretz avatar tfoote avatar wjwwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xacro's Issues

xacro script not available from devel space

Dear Morgan,

I just noticed, that my changes to the installation of xacro, don't work for roslaunch in devel space.
scripts/xacro is installed to:

  • bin/xacro via catkin_python_setup() / setup.py
  • lib/xacro/xacro via catkin_install_python()

However, the latter one is probably only called in install mode of catkin (I'm building with catkin tools 0.4. Not sure, what about catkin_make...). This results in lib/xacro/xacro not being available in devel space.
Hence roslaunch cannot find it with $(find xacro)/xacro.

Probably, that's the reason why people used $(find xacro)/xacro.py before. xacro.py was found in src then...

Do you have any idea, how to proceed?

Can't generate launch files with xacro include

xacro's old include syntax collides with roslaunch's include syntax, making it difficult to generate launch files using xacro.

When trying to generate launch files using xacro, I get:

DEPRECATED IN HYDRO:
  The <include> tag should be prepended with 'xacro' if that is the intended use
  of it, such as <xacro:include ...>. Use the following script to fix incorrect
  xacro includes:
     sed -i 's/<include/<xacro:include/g' `find . -iname *.xacro`
Traceback (most recent call last):
  File "/opt/ros/indigo/lib/xacro/xacro", line 53, in <module>
    xacro.main()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 687, in main
    process_includes(doc, os.path.dirname(args[0]))
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 271, in process_includes
    raise XacroException("included file \"%s\" could not be opened: %s" % (filename, str(e)))
xacro.XacroException: included file "" could not be opened: [Errno 2] No such file or directory: ''

Since xacro now has the <xacro:include> tag, would it make sense to add a flag to xacro which disables the deprecated include syntax?

Empty default value for args causes ArgException

The following xacro, when invoked with rosrun xacro xacro.py test.xacro, breaks with roslaunch.substitution_args.ArgException: foo
Seems like empty defaults are not treated properly (the URDF would be valid even with the default value of "empty string")

<?xml version="1.0"?>
<robot name="bar"
       xmlns:xacro="http://ros.org/wiki/xacro">
  <xacro:arg name="prefix" default=""/>
  <link name="$(arg foo)link" />>
</robot>

The equivalent launch file

<?xml version="1.0"?>
<launch>
  <arg name="prefix" default="" />
  <node pkg="tf"
        type="static_transform_publisher"
        name="$(arg prefix)pub"
        args="0 0 0 0 0 0 map base_link 100" />
</launch>

works as expected.

I can try and look into this myself, but won't get to it for a while (I've used a workaround for the original use case). If one of xacro's maintainers already knows where to make a fix, that would probably be quicker :)

xacro:macro name

I think the above is broken again. In the kinetic-dev branch I'm getting the error:

unknown macro name: xacro:base

(This is after running the fix script) The xacro file it looks like this:
<xacro:macro name>
...
</xacro:macro>

Just needs a 'replace' after line 499 in init.py??

Or maybe I just messed up my xacro file..

Don't evaluate substitution_args in conditional blocks with unsatisfied condition.

Hi, I write a piece of code that assembles a robot from various parts. My idea is to allow users to only download some repositories, and using Xacro arguments to specify which parts should be assembled into the URDF.

Thus the current behavior of Xacro is quite unpleasant for me, because it requires the user to have all the model packages downloaded even if he doesn't want to use models from some of them.

Here's an example:

<xacro:arg name="has_stuff" default="0" />
<xacro:if value="$(arg has_stuff)">  
    <xacro:include filename="$(find nonexistent)/urdf/model.urdf" />
</xacro:if>

The current implementation fails with not finding package nonexistent.

Citing from wiki.ros.org/xacro:

Additionally, the conditional has no effect on macro or property definitions, and is only used while constructing the final xml.

From this sentence, it's still not apparent to me if the behavior I address as a bug should be considered so. However, I think think supporting such things would be good for extending the possible use-cases for Xacro.

I know the fix won't be easy, but essentially I think most of it relates to the recently added support for <xacro:arg>. In my view, there should first be a run where all <xacro:arg>s would be evaluated, then the conditionals, and then the rest. However, I didn't have time to go through the Xacro source thoroughly, so there may be some catches I don't know - e.g. if there can be a property in the conditional test, then it'd need to be also evaluated before the conditionals...

Namespace warning messages

I've upgraded to Jade and my launch file now says:

Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see http://wiki.ros.org/xacro#Processing_Order

While the link is helpful, this warning should start with something like "xacro: " so that users know where the warning is coming from.

Warning: xacro.cmake being included automatically

When building a package depending on xacro, I get the following warning:

[rosbuild] WARNING: the file /opt/ros/groovy/stacks/xacro/cmake/xacro.cmake is being included automatically...

I found trac ticket #4792 about this issue that was never closed. I think the solution could be as simple as changing manifext.xml to use

<export>
  <rosbuild cmake_directory="${prefix}/cmake"/>
</export>

Oddly, even if I do that, and include rosbuild_include(xacro xacro) in my CMakeLists, I still get the warning. I don't know why that is.

CMake example on wiki is out of date

Clearly referencing a rosbuild workflow: http://wiki.ros.org/xacro#Building_from_CMakeLists.txt

There also needs to be attention drawn to the fact that with the catkin inversion, your workspace (and thus rospack) are not available at build time. This means no using $(find package) in your <xacro:include> tags if you intend to run the xacro at build time (at least on the buildfarm, anyway).

The workaround is to determine the path of the included file using catkin-generated CMake trickery, and then smuggle that into the xacro on the commandline for use as an $(arg).

Running xacro --includes on nested <xacro:include> adds xmlns:xacro tags to <xacro:macro>

Put these files into the same directory (.txt because otherwise GitHub complains):
main.xacro.txt
sublevel1.xacro.txt
sublevel2.xacro.txt

If you run xacro --includes main.xacro.txt > composed.xacro and then run xacro --inorder composed.xacro the second command gives the warning xacro:macro: unknown attribute(s): xmlns:xacro.

This is because xacro --includes adds the xmlns:xacro attribute to any <xacro:macro> with a nested <xacro:include>.

Ie,

<xacro:macro name="illustrating_macro">
  <xacro:include filename="sublevel2.xacro.txt" />
...

Becomes

<xacro:macro name="illustrating_macro" xmlns:xacro="http://ros.org/wiki/xacro">
...

which apparently does not sit well with xacro --inorder

xacro consumes <foo> as <xacro:foo>

The .xacro

<?xml version="1.0"?>
<robot name="davinci" xmlns:xacro="http://www.ros.org/wiki/xacro">
  <xacro:macro name="test">
    <macro-test/>
  </xacro:macro>
  <test/>
  <xacro:test/>
</robot>

produces

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from ./robots/test_description.xacro | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED                                 | -->
<!-- =================================================================================== -->
<robot name="davinci" xmlns:xacro="http://www.ros.org/wiki/xacro">
  <macro-test/>
  <macro-test/>
</robot>

preventing me from doing

<?xml version="1.0"?>
<robot name="davinci" xmlns:xacro="http://www.ros.org/wiki/xacro">
  <xacro:macro name="link">
    <link name="test"/>
  </xacro:macro>
  <xacro:link />
</robot>

resulting in

Traceback (most recent call last):
  File "/opt/ros/indigo/share/xacro/xacro.py", line 60, in <module>
    xacro.main()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 662, in main
    eval_self_contained(doc)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 597, in eval_self_contained
    eval_all(doc.documentElement, macros, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 533, in eval_all
    eval_all(body, macros, scoped)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 512, in eval_all
    (str(name), str(node.tagName)))
xacro.XacroException: Invalid parameter "name" while expanding macro "link"

Xacro adaptive globbing cmake functions

A small suite of cmake functions which allow packages to create named, templated glob XML files which they and their dependent packages can contribute fragments to, potentially conditional on a return code from a supplied executable. At setup time, the globs would be processed into files in /tmp, which would be pointed to by an environment variable.

To make this more concrete, the conceived use-case is for our platforms which have a lot of accessories:

  1. husky_bringup package creates globs called husky.launch and husky.urdf
  2. husky_accessories_imu contributes a launchfile fragment and urdf fragment which are included only when /dev/imu exists.
  3. husky_accessories_sick contributes appropriate fragments when pings are returned from our standard SICK IP addresses.
  4. When the user (or background upstart job) sources setup.bash on a robot, this series of hardware checks produces a launcher and urdf, and sets env vars to them, eg:
    HUSKY_LAUNCH=/tmp/<workspace path md5>/husky_bringup/husky.launch
    HUSKY_URDF=/tmp/<workspace path md5>/husky_bringup/husky.urdf
  5. At launch time, those env variables are read by roslaunch to produce a launcher and description customized to this platform based on hardware detection scripts.

Another conceived use is for users to add or override launchers which are part of the based platform bringup, a use case we current manage with robot_upstart's mklaunch wrapper.

This is a concept we've been tossing around at Clearpath and I'm curious if it's felt that this (or something like it) would be a good fit as an extension to the functionality provided by xacro, or as something which should live in a separate package?

Xacro at build time is broken

In Hydro. Example failure on the farm:

Executing command 'make'
Scanning dependencies of target flir_ptu_example_urdf
[ 33%] Generating ../../devel/share/flir_ptu_description/urdf/example.urdf
/bin/sh: 1: /opt/ros/hydro/lib/xacro/scripts/xacro.py: not found
make[2]: *** [devel/share/flir_ptu_description/urdf/example.urdf] Error 127
make[1]: *** [flir_ptu/flir_ptu_description/CMakeFiles/flir_ptu_example_urdf.dir/all] Error 2
make: *** [all] Error 2

There was a fix committed 2014-02-03 to make it look for xacro instead of xacro.py, but the path is still wrong in installspace, as it's not being installed in the scripts subfolder:

$ dpkg -L ros-hydro-xacro
...
/opt/ros/hydro/lib/xacro/xacro

Not sure if you want to change the install path or the cmake macro, but either way, this should be fixed in both hydro and indigo and released to both.

Regression in xml include handling

I encountered a xacro error when attempting to build my robot model (herb_description) with ROS Kinetic. I reduced it to the following minimal example:

$ cat a.xml
<root xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:include filename="b.xml" />
</root>

$ cat b.xml
<root xmlns:xacro="http://www.ros.org/wiki/xacro">
<xacro:macro name="b">
   <element />
</xacro:macro></root>

(note the lack of newline in b.xml between </xacro:macro> and </root>)

On ROS Kinetic, I get the following error:

$ rosrun xacro xacro.py --verbosity=4 a.xml
xacro: Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see http://wiki.ros.org/xacro#Processing_Order

when processing file: a.xml

Traceback (most recent call last):
  File "/opt/ros/kinetic/share/xacro/xacro.py", line 61, in <module>
    xacro.main()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 1031, in main
    doc = process_file(input_file_name, **vars(opts))
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 1008, in process_file
    process_doc(doc, **kwargs)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 952, in process_doc
    grab_macros(doc, macros)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 529, in grab_macros
    grab_macros(elt, macros)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 527, in grab_macros
    grab_macro(elt, macros)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 490, in grab_macro
    remove_previous_comments(elt)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/xacro/__init__.py", line 785, in remove_previous_comments
    node.parentNode.insertBefore(_empty_text_node, next)
  File "/usr/lib/python2.7/xml/dom/minidom.py", line 97, in insertBefore
    raise xml.dom.NotFoundErr()
xml.dom.NotFoundErr

Adding that newline to b.xml is a workaround. This example parses correctly with or without the newline on ROS Indigo. (I haven't tested on ROS Jade.)

xacro --includes gives warning to use --inorder processing, which is not possible

Running the xacro --includes command gives the warning

xacro: Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see http://wiki.ros.org/xacro#Processing_Order

But running xacro --includes --inorder gives the error

xacro: error: options --inorder and --includes are mutually exclusive

rosrun xacro xacro.py does not work

Brought up on the ros users mailing list after Tully announced new debs:

I'm not sure what all the cmake-wizardry is trying to do in xacro-extras.cmake, but it appears the problem here is actually that xacro.py in /lib/xacro/ is not executable as it would be if it were brought in via a "install(PROGRAMS ..." type of cmake command.

Ubuntu 12.04 DEB package: unnecessary dependencies. Subversion?

Recently while tinkering with some ROS builds my eye caught these kind
of lines:

$ dpkg -s ros-groovy-xacro
Package: ros-groovy-xacro
Depends: ros-groovy-ros (= 1.9.53-0precise-20140905-2256-+0000),
ros-groovy-ros-comm (= 1.9.55-0precise-20140906-0133-+0000), libc6,
build-essential, cmake, python-yaml, subversion.

After brief source-code review I
can't see any piece of code relevant or anyhow related to subversion. Is it really needed for ros-groovy-xacro runtime? The same applies to cmake and build-essential.

Operating System: Ubuntu 12.04 running stock ROS Groovy.

'string index out of range' with xacro macro param line breaks

Adding a linebreak within the xacro macro params quotes produces a 'string index out of range' error in the jade and latest version of xacro. In hydro this worked fine.

This no longer works:

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

<xacro:macro name="all_cameras" params="
  test
  ">
</xacro:macro>

<xacro:all_cameras test="0.5" />

</robot>

While this works:

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

<xacro:macro name="all_cameras" params="test">
</xacro:macro>

<xacro:all_cameras test="0.5" />

</robot>

https://github.com/lucasw/testbot/blob/master/testbot_description/urdf/param_test_linebreak.xacro
https://github.com/lucasw/testbot/blob/master/testbot_description/urdf/param_test_no_linebreak.xacro

http://answers.ros.org/question/219698/jade-xacro-macro-param-line-breaks-string-index-out-of-range/

rospack find xacro no longer finds the directory containing xacro.py

Catkinizing xacro moved the install directory of xacro.py so that it is no longer in the directory found by 'rospack find xacro' . This breaks launch files that previously loaded the urdfs into the parameter server using <param name="robot_description" command="xacro.py '$(find robot_dir)/robot_description.xacro' />

enforce xacro namespace for created macros if --xacro-ns flag is set

Calling rosrun xacro xacro --inorder --xacro-ns test.xacro with the following test.xacro

<test xmlns:xacro="http://www.ros.org/wiki/xacro">
    <xacro:macro name="printer" params="text" >
        <print what="${text}"/>
    </xacro:macro>
    <printer text="hello world"/>
</test>

results in

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from test.xacro                     | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED                                 | -->
<!-- =================================================================================== -->
<test xmlns:xacro="http://www.ros.org/wiki/xacro">
  <print what="hello world"/>
</test>

Is this intended?

This is especially a problem if you use the macro name inside the macro definition, e.g.:

<test xmlns:xacro="http://www.ros.org/wiki/xacro">
    <xacro:macro name="printer" params="text" >
        <printer what="${text}"/>
    </xacro:macro>
    <printer text="hello world"/>
</test

which results in

Invalid parameter "what"
when instantiating macro: printer (test.xacro)
instantiated from: printer (test.xacro)
in file: test.xacro

This issue is related to #115.

xacro-extras.cmake broken in Hydro

xacro-extras.cmake references the Xacro executable like so:

set(_xacro_py
  /opt/ros/hydro/lib/xacro/scripts/xacro.py
)

This file is not part of Xacro. I just checked the debian for raring and the misconfiguration was there. The fact that this has been wrong for so long leads me to believe that I'm missing something.

If I'm right, either the file should be installed, or (more likely) the path should be updated.

cmake: xacro_add_xacro_file() creates empty file on failure

If one uses the xacro_add_xacro_file() macro to generate URDF models from xacro at build-time, and the xacro file contains a syntax error (or xacro fails for some other reasons), the system still produces an empty output file. On the next build iteration (assuming the xacro document has not changed), make sees this file (which has newer timestamp than the source) and will not attempt to re-run xacro.

This can lead to confusion, which is why we have switched to invoking xacro on-the-fly using roslaunch to get the URDF model.

A fix would be to move the file opening right to the end of xacro, when we can be reasonably sure that everything is going to be okay, or to remove left-over files in the add_custom_command call in CMake by some construct like this:

add_custom_command(OUTPUT ${output}
COMMAND ${_xacro_py} ${input} > ${output} || rm ${output}
DEPENDS ${input} ${_xacro_deps_result})

I haven't tested that, though.

Conversion from .xacro -> .urdf does not update xmlns correctly

When a .xacro is converted to .urdf, the xmlns attribute on the robot tag is preserved as xmlns:xacro="http://www.ros.org/wiki/xacro

However, the URDF .xsd schema defines a targetNamespace attribute of http://www.ros.org. That means that a URDF's root robot tag should have xmlns="http://www.ros.org" and not xmlns:xacro="http://www.ros.org/wiki/xacro".

It's a small detail, however there exist many code generators/unmarshallers/validators/etc. that are very strict and will error out on this completely as if the generated XML document is malformed. An example of this is the JAXB tooling, which is built in to Java. If you use JAXB to generate Java bindings from the urdf.xsd and then try to use a JAXB unmarshaller on a .urdf with this bad xmlns then the unmarshalling process will hard fail and throw an exception.

auto-forward property definitions to macro parameters?

I often encounter the situation, that I need to pass existing properties to identically named macro parameters (e.g. var="${var}"). I can circumvent that by not declaring these parameters. However, as soon as they are declared, xacro expects the parameters to be explicitly provided.

I suggest to relax this strong constraint and only complain if a property is not defined at all, i.e. neither explicitly in the macro params nor implicitly in the outer scope.
This will facilitate to explicitly declare all used macro parameters while avoiding to explicitly provide them.

What do you think?

Feature request: index support into bundled params

Trying to write modular xacto definitions I find myself really wanting to be able to index bundled xyz or rpi params passed along into macros. This would greatly simplify making components.

To give an example here is a bioloid F2 bracket part used to compose composit links.

    <macro name="geometry_F2">
        <geometry>
            <mesh filename="package://${PACKAGE}/meshes/F2.stl" scale="${M_SCALE_3}"/>
        </geometry>
    </macro>
    <macro name="visual_F2" params="xyz rpy">
        <visual>
            <origin xyz="${xyz}" rpy="${rpy}" />
            <geometry_F2 />
            <color_grey60 />
        </visual>
    </macro>
    <macro name="collision_F2" params="xyz rpy">
        <collision_box xyz="${xyz}" rpy="${rpy}" size="0.025 0.0485 0.0375" />
    </macro>
    <macro name="part_F2" params="xyz rpy">
        <collision_F2 xyz="${xyz}" rpy="${rpy}" />
        <visual_F2 xyz="${xyz}" rpy="${rpy}" />
    </macro>

I then use it in to create a link like so

    <macro name="coxa_bone" params="parent name">
        <link name="${name}_link">
            <inertia_default />
            <part_ax12 xyz="0 0 0" rpy="0 0 ${MPI}" />
            <part_F3 xyz="0 0 -0.0415" rpy="0 ${MPI} 0 "/>
            <part_F2 xyz="0 0 -${L_COXA}" rpy="0 0 ${MPI2} "/>
        </link> 
        <joint_revolute name="${name}" parent="${parent}" xyz="0 0 0" rpy="0 0 0" 
            vel="100" llimit="${MIN_RAD_COXA}" ulimit="${MAX_RAD_COXA}" axis="0 1 0" />   
    </macro>

If I want to provide an offset to the xyz in the collision_F2 macro as it does not align to the stl mesh I'm unable to extract the x y z components again to add an offset. You can get around this by passing in the values separately but that does brake the encapsulation and makes the whole thing pretty verbose again.

what I'd like to be able to do would be something like the following.

    <macro name="collision_F2" params="xyz rpy">
        <collision_box xyz="${xyz[0]+0.03 xyz[1]-0.4 xyz[3]}" rpy="${rpy}" size="0.025 0.0485 0.0375" />
    </macro>

This way I can keep the implementation detail neatly contained.

[xacro indigo] True/False vs. true/false when using conditional blocks with --inorder

When testing the new possibilities that come with using the --inorder argument with xacro under indigo, we found the following behaviour - this possibly is a regression:
When using xacro:properties or macro parameters within a conditional expression e.g using or, the result is not as expected when the values of the properties are set to true/false. The result is correct when using True/False, though.

In xacro the documentation says:

The expression needs to evaluate to "0", "1", "true", or "false", otherwise an error will be thrown.

However, no error is thrown...the block just seems to be skipped.
Documentation also says:

The more powerful evaluation capabilities in ROS Jade allow for much more complex expression. Virtually any python expression that evaluates to a Boolean is feasible:

Which is consistent with our observations as in python it's not true/false but True/False....but this is inconsistent with what is said in the first quote.

A little example:
When running rosrun xacro xacro --inorder on the following snippet:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

  <xacro:property name="cond1" value="false"/>
  <xacro:property name="cond2" value="true"/>

  <xacro:if value="${cond1 or cond2}">
    <link name="test"/>
  </xacro:if>

</robot>

The resulting URDF looks like this:

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from conditional_block.urdf.xacro   | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED                                 | -->
<!-- =================================================================================== -->
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
</robot>

While running the same command on the following snippet:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

  <xacro:property name="cond1" value="False"/>
  <xacro:property name="cond2" value="True"/>

  <xacro:if value="${cond1 or cond2}">
    <link name="test"/>
  </xacro:if>

</robot>

produces the expected result:

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from conditional_block.urdf.xacro   | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED                                 | -->
<!-- =================================================================================== -->
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
  <link name="test"/>
</robot>

Anybody observed this before?

Optional/default block parameters

Is there anyway to specify block parameters as optional? Or specify the default value of block parameters?

Here's an example:

<?xml version="1.0"?>

<a xmlns:xacro="http://www.ros.org/wiki/xacro">
  <xacro:macro name="foo" params="**x">
    <foo_data>
      <xacro:insert_block name="x" />
    </foo_data>
  </xacro:macro>

  <xacro:foo>
    <x>4.5</x>
  </xacro:foo>

  <xacro:foo>
  </xacro:foo>
</a>

If I want to call the macro without specifying x, the only way I've found is to call it with an empty x block (otherwise I get Not enough blocks while evaluating macro exception). I'd prefer to not have the empty tag in the generated file, so thought I'd check if there's an alternative.

expat parsing error

I was trying to execute my urdf.xacro file and I get the following error. can anyone help me in explaining the details of this error.

[ INFO] [1425902453.451149717]: Running 'rosrun xacro xacro.py /home/siva/catkin_ws/src/arm_and_hand_motor_biotac.urdf.xacro'...
Expat parsing error. Check that:

Traceback (most recent call last):
File "/opt/ros/hydro/share/xacro/xacro.py", line 60, in
xacro.main()
File "/opt/ros/hydro/lib/python2.7/dist-packages/xacro/init.py", line 646, in main
doc = parse(f)
File "/usr/lib/python2.7/xml/dom/minidom.py", line 1920, in parse
return expatbuilder.parse(file)
File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 928, in parse
result = builder.parseFile(file)
File "/usr/lib/python2.7/xml/dom/expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: junk after document element: line 28, column 0

Parsing Error for nested evaluations not really helpful

Doing a nested evaluation like ${a/2+${b/2}} is not supported it seems. That's fine with me. However the error message could be more descriptive. Right now I get

rosrun xacro xacro.py workcell.xacro > workcell.urdf 
Traceback (most recent call last):
File "/opt/ros/indigo/share/xacro/xacro.py", line 60, in <module>
xacro.main()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 692, in main    
eval_self_contained(doc)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 627, in eval_self_contained
eval_all(doc.documentElement, macros, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 552, in eval_all
eval_all(body, macros, scoped)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 610, in eval_all
result = eval_text(at[1], symbols)
   File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 482, in eval_text
results.append(handle_expr(lex.next()[1][2:-1]))
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 469, in handle_expr
    return eval_expr(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 450, in eval_expr
    n = eval_term(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 422, in eval_term
    n = eval_factor(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 392, in eval_factor
if lex.peek()[1] == '-':
TypeError: 'NoneType' object has no attribute '__getitem__'

including a macro does not work anymore in Jade

So I see a lot of changes in Jade but I don't see anything that affects the following: you include a file with a macro (and no namespace is provided) and that macro cannot be found.
Should it be used with filename.macro now ? No doc on that on http://wiki.ros.org/xacro#Including_other_xacro_files

To replicate

git clone https://github.com/ros-naoqi/pepper_robot.git
cd pepper_robot/pepper_description/urdf/pepper1.0_generated_urdf/
rosrun xacro xacro pepper_robot.xacro

Error

unknown macro name: xacro:insert_visu_Neck
when processing file: pepper_robot.xacro

While pepper_robot.xacro includes pepper_visual_collisions.xacro which defines that macro.

On Jade and xacro 1.10.4. Thx

Jade sync'd back to Indigo

There have been some fantastic updates to the xacro-Jade branch, but none of these have been backported to Indigo. Seeing how Indigo is an LTS ROS distro, can these changes be sync'd back?

increase speed by replacing xml.minidom with lxml.etree

It appears that we can speed up xacro a lot by moving to lxml.etree instead of using xml.minidom. Obviously this would be a big change.

@mikepurvis , @paulbovbel , @mikeferguson , @wjwwood , and anyone else: any comments or feedback on this proposal?

Related: I'm also interested in adding some more large / complex "full-robot" test cases to xacro, to complement to the PR2 full-robot test case. I think we'd have more confidence when making big changes like this to xacro if we had more large test cases. Anyone have suggestions for which robots to add?

Feature: Second interface so that functionality can be used in own script

I'd so far seen no way to run xacro without using the main()-function that reads sys.argv. I'd however like to convert a urdf.xacro to an urdf within my own python script.

I am missing this functionality when I create the urdf model during the startup-process of my robots.
I store some xacro-arguments in a database so that all robots have the same code-basis but the correct urdf is created. As the xacro/__init__py.main() assumes to be called as it's own program (using sys.argv) it's hard to include the urdf-creation can be included in my own process while I still have access to all Exceptions (e.g. if an argument was not set).

The interface would look something like

# urdf_xacro_filename: absolute path to robot.urdf.xacro
# mappings: a dict of xacro-arguments
def convert_urdf(urdf_xacro_filename, mappings):
     (....)
     return doc.toprettyxml(indent='  ')

Exceptions should be re-raised so that the user of this function could handle them (e.g. just output on rospy.logginfo()).

What do you think about such in interface? I'd be happy to implement it, if there's a good chance that it would be integrated.

Xacro $(find pkg) doesn't work for devel space assets

Roslaunch makes this work by checking for what follows the $(find) invocation, checking the devel space and falling back to the source space. This functionality is marked as being for backward compatibility, and doesn't seem to be present in xacro, although xacro calls into the same substitution_args.resolve_args function.

Looks like the issue is that Xacro treats find/arg/etc as "extensions" of its built-in expression processing capability, meaning that it's not trivial for it to pass the entirety of the attribute string to roslaunch.

This limits the ability to generate at build time a URDF that is pulled into a runtime xacro, for example.

@dirk-thomas Thoughts about whether there's an easy way to fix this?

No way to specify arg defaults

Not sure how important this is, but it would be nice to have the <arg name="foo" default="123" /> syntax from roslaunch.

BC break: expressions and macros inside property-block definition are not expanded

<root version="1.0" xmlns:xacro="http://www.ros.org/wiki/xacro">
        <xacro:macro name="test">
                ahoj
        </xacro:macro>
        <xacro:property name="val" value="2" />
        <xacro:property name="prop">
                <outer attr="${val}">
                testy
                <xacro:test />
                </outer>
        </xacro:property>
        <xacro:macro name="final">
                <xacro:insert_block name="prop" />
        </xacro:macro>
        <xacro:final />
</root>

This snippet generates the following in Indigo:

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from test.xacro
        | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED
        | -->
<!-- =================================================================================== -->
<root version="1.0" xmlns:xacro="http://www.ros.org/wiki/xacro">
  <outer attr="2">

                testy


                ahoj

  </outer>
</root>

And the following in Jade (regardless of --inorder):

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from test.xacro
        | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED
        | -->
<!-- =================================================================================== -->
<root version="1.0" xmlns:xacro="http://www.ros.org/wiki/xacro">
  <outer attr="${val}">

                testy

    <xacro:test/>
  </outer>
</root>

Unable to build package in Kinetic

Attempting to build the package from source in Kinetic encounters an error:

cd ~/ros_catkin_ws/src
git clone https://github.com/ros/xacro.git
cd ..
catkin_make --pkg xarco
Base path: /home/pi/ros_catkin_ws
Source space: /home/pi/ros_catkin_ws/src
Build space: /home/pi/ros_catkin_ws/build
Devel space: /home/pi/ros_catkin_ws/devel
Install space: /home/pi/ros_catkin_ws/install
Packages "xarco" not found in the workspace

I've used this procedure to build many other packages without issue. What is the correct way to build xacro in Kinetic using catkin?

My platform is Raspbian running on a Raspberry Pi 3, where no pre-built packages are available.

Add short command line flags

Currently, the only way to specify the new "in order" file processing is to use the --inorder command line flag. However, the double hyphens cause the XML processing to crash when in a comment. So you should also provide standard one letter command flags. For example -i.

This will cause the XML parser to crash:

<!-- <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find my_description)/robot.urdf'" /> -->

<xacro:if> conditionals do not correctly evaluate numerical values

Numerical values are not correctly evaluated as numbers but as strings in xacro:if conditionals. Consequently, the following examples falsely raise an exception:

<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
  <xacro:if value="${3*0}"/>
  <xacro:if value="0"/>
  <xacro:if value="1"/>
</robot>

Such examples should be also added to the unit test.

$(arg foo) not evaluated in properties

xacro:properties do not try to evaluate $(arg xxx) commands in their value fields.

For example:

<?xml version="1.0"?>
<robot name="myrobot" xmlns:xacro="http://www.ros.org/wiki/xacro">

  <xacro:property name="wheel_width" value="$(arg wheel_width)"/>

  <link name="my_link">
    <origin xyz="0 0 ${wheel_width/2}"/>
  </link>

</robot>

Running rosrun xacro xacro.py test.urdf.xacro wheel_width:=42 will fail with ValueError: could not convert string to float: $(arg test) because the property takes the literal string value "$(arg wheel_width)".

This makes it nearly impossible to do any real math with passed-in arguments. A partial workaround can be found here, but it isn't a real solution in many cases.

Release

Hi, would you be able to do a release to get #42 and #43 into debs?

evaluation of numbers vs strings

@codebot

I noticed a minor issue with python-based evaluation:
If there is leading or trailing whitespace in a property definition of a number, this number will not be evaluated as a number but as a string - which makes sense. If this property is used in some math expressions, one will get probably unexpected results:

<xacro:property name="a" value=" 42 "/>
${2*a}

will evaluate to _42__42_ (spaces replaced by _)

<xacro:property name="a" value=" 42 "/>
${2+a}

will cause TypeError: unsupported operand type(s) for +: 'int' and 'unicode'

My first attempt was to simply strip the whitespace. However, this disables string-based manipulation as above. Probably, one should try to evaluate with and without stripping and compare the type of the result. If it differs, we could issue a warning to remove the whitespace.

Which behavior do you prefer?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.