Ask Your Question
0

xacro if file found

asked 2020-08-20 17:13:12 -0500

James Newton gravatar image

updated 2020-08-21 12:07:20 -0500

Would it not be very very handy to have xacro conditionals that check if a file can be located? Or if a prior attempt to load a file failed?

My use case is a urdf file with meshes loaded from external CAD files. If the CAD files aren't available, a simple geometric shape can substitute.

<kidding>Hm... Perhaps a conditional that checks available processor and RAM resources would be better... </kidding>

The serious idea is that conditionals are good for dealing with errors. If you write a urdf that can use meshes, but the files associated with that were lost or not in the correct location or there aren't resources to load them or whatever, then a conditional could allow you to substitute a simple shape geometry instead. e.g. "load the geometry from this STL file, but if you can't, it's sort of a cylinder with a box on top like this..."

Perhaps there is already a way to do this that I'm missing?

edit retag flag offensive close merge delete

Comments

Hm... Perhaps a conditional that checks available processor and RAM resources would be better...

Is this a serious question?

gvdhoorn gravatar image gvdhoorn  ( 2020-08-21 00:56:32 -0500 )edit

Not really. It's more of an acknowledgement that what goes wrong sometimes has less to do with the files being missing and more to do with the system not being able to manage the files it's been handed. Happy to remove it if it offends you. The main question, the main /point/ is the idea the conditionals are good for dealing with errors. If you write a urdf that can use meshes, but the files associated with that were lost or not in the correct location or whatever, then a conditional could allow you to substitute a simple shape geometry instead. e.g. "load the geometry from this STL file, but if you can't, or if that file is missing, it's sort of a cylinder with a box on top like this..."

James Newton gravatar image James Newton  ( 2020-08-21 12:02:58 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-08-22 10:11:39 -0500

fergs gravatar image

updated 2020-08-22 10:16:52 -0500

I think you might be able to kinda do this already - through a combination of launch and Xacro. You can already pass arguments into Xacro files from the command line or as part of the launch file running xacro and use them in conditional blocks. From roslaunch you can do a "$(find pkg)" on the package that contains your STL files. Or you could use an "$(env ENV_VAR_NAME)" if you wanted to have this be runtime selectable instead.

This ROS Answers has a bunch of detail about xacro and launch interaction.

Now, one complication: the Xacro only gets evaluated once, on startup of the robot launch file (since robot_description is basically a static parameter). This means the check for the package and/or environment variable is dependent only on what's in the robot - not your remote PC that is running RVIZ.

An alternative approach is to use your STL files for visualization geometry, but also add a simple cylinder/box/etc model for your collision geometry. In RVIZ, you can select to view the visualization or collision geometry from checkboxes in the display panel.

edit flag offensive delete link more

Comments

Oh, that point about using the collision geometry is GOLD. I'll just drop the option for simple geometry in the visualization and if people don't have, or don't want, the big STL files, they can just flip that switch. And if they want to do more, e.g. gazebo or whatever, they can just copy that part out in their version of the urdf. Genius! Thanks so much for pointing that out!

James Newton gravatar image James Newton  ( 2020-08-22 12:27:19 -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

2 followers

Stats

Asked: 2020-08-20 17:13:12 -0500

Seen: 120 times

Last updated: Aug 22 '20