Ask Your Question

Run scripts in

asked 2021-09-23 10:03:14 -0500

drkleppe gravatar image

updated 2021-09-23 10:04:18 -0500


Today (after hours of debugging), I figured out that the "xacro" command outputs the comments in the urdf.

The problem is that when loading an urdf file in a launch file, it will fail if your comment has a ":" in it, since it's read as a yaml string.

The only way around this is to run a script that builds the XML file without comments. This can be done in the launch file, but it would be beneficial to run it during colcon build.

In the, you can define the data files to use, but it would be better to generate data files. So that in the "share" folder, you won't have all the different xacro and urdf files, but instead the one urdf file that defines the robot. It could also help for other configuration files, like combining yaml files for specific configurations, etc.

So, is there a way to run scripts in the file to generate files?

edit retag flag offensive close merge delete


So isn't the real problem here that "urdf file[s] [..] are read as a yaml string"? The title seems to be about something else.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-23 12:00:22 -0500 )edit

Yes and no.

Sorry, I'm not at my computer right now, so the formatting is bad. I'll make a new comment tomorrow.

The original problem was that I ran this code:

urdf= {"robot_description": Command( [
" ",   PathJoinSubstitution([FindPackageShare(package), "urdf", urdf_file])])}

And when I added it as a parameter to a node it gave an error. Something about an yaml parser that failed.

Looking into it, I noticed the error came from a ":" I had in the comment of the urdf file.

<!-- GROUP: etc... -->

And it's because the xacro executable prints a long string including the comments.

I don't know exactly what Command object does, but you can't have ":" in urdf files.

Removing all the ":"s from the urdf comments made everything run smoothly.

The only solution I could think of is to run the urdf through a script to remove ...(more)

drkleppe gravatar image drkleppe  ( 2021-09-23 12:40:26 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-09-24 05:16:07 -0500

drkleppe gravatar image

Looking into this further it seems that this bug is only featured in MoveIt2 when loading an srdf. Running this code in the launch file

robot_description_semantic_file = LaunchConfiguration("robot_description_semantic_file")
    robot_description_semantic = {"robot_description_semantic":Command(
            " ",
            "moveit2", robot_description_semantic_file]),

And this later on;

move_group = Node(

The error becomes

yaml.scanner.ScannerError: mapping values are not allowed here
  in "<unicode string>", line 11, column 13:
      <!--GROUPS: Representation of a set of joi ...

And the problem is fixed when you remove any ":" colon symbols from the file. It seems like it is a bug in MoveIt.

edit flag offensive delete link more


Please don't start using words like bug and fixed without being sure what is going on. It doesn't sound like a solution to me to have to post-process something which should work out-of-the-box. That's also why I asked you what the real problem is (as you're question seems to be about a solution/work-around you've already selected).

I haven't used MoveIt 2 in a while, so this could all make sense, but can you clarify why you are passing an .srdf file through xacro? There are use-cases for it, but if it's not needed, I would just not do it.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-24 06:32:31 -0500 )edit

And please don't post answers unless you are answering your own question.

If this is an answer, then I'd suggest clarifying your post a little. If it's not an answer, please merge the content with your original question text.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-24 06:33:42 -0500 )edit

Sorry for posting the answer. I'm not used to how this works. I'll edit the original question instead. But to clarify:

I'm only running xacro because it's the only way I've found to read a file from declared launch arguments (since they can't be converted to strings).

I haven't tested it, but I suspect the error to happen as long as the srdf contains a ":", using xacro or anything else to read it.

I thought that the error was universal, but found out that this only happens when loading the srdf in Moveit2. And when I thought it was universal I thought a solution would be to pre process files in the file.

Now that this error is only in Moveit2, it's probably something to ask them specifically.

drkleppe gravatar image drkleppe  ( 2021-09-24 07:42:12 -0500 )edit

No need to apologise.

xacro is a very specific tool for a very specific job. It's not a generic "file loader". see the ROS 1 wiki/xacro page.

Now that this error is only in Moveit2, it's probably something to ask them specifically.

I agree it'd be good to open an issue on the MoveIt 2 tracker, but I have a feeling this is a misunderstanding of how to load parameters, not a generic problem with MoveIt.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-24 07:57:41 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-09-23 10:03:14 -0500

Seen: 26 times

Last updated: Sep 24