Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $(dirname) to get directory of current launch file. #1103

Merged
merged 4 commits into from
Jul 20, 2017

Conversation

mikepurvis
Copy link
Member

I'm working on adding some test coverage for this, but the basic idea for usage is allowing stuff like:

# test1.launch
<launch>
  <include file="$(dir)/baz/test2.launch" />
</launch>
# baz/test2.launch
<launch>
  <param name="foo" value="$(dir)/foo/bar" />
  <param name="bar" value="$(eval dir() + '/foo/bar')" />
</launch>

Where the output is:

$ cd /tmp
$ roslaunch ~/roslaunch_ws/test1.launch  --dump-params
{/bar: /Users/mikepurvis/roslaunch_ws/baz/foo/bar, /foo: /Users/mikepurvis/roslaunch_ws/baz/foo/bar}

Some possible use-cases for this:

  • When including another launch file from within the same directory, stay DRY and don't repeat the package name everywhere as with $(find)— instead just $(dir)/other.launch.
  • Using eval to make the a launch file do different things depending on where it's installed. For example <node .... if="$(eval dir().startswith('/opt'))" />
  • For launch files which aren't part of packages. We use free-floating launch files as part of a configuration scheme on our robots, and we'd like them to be able to include yamls from their own directory.

FYI @guillaumeautran @Jin-Myung

@IanTheEngineer
Copy link
Contributor

I support this proposal. Well done, Mike!

My only thought is regarding the first bullet point:

When including another launch file from within the same directory, stay DRY and don't repeat the package name everywhere as with $(find)— instead just $(dir)/other.launch

Does this imply that $(find rospkg_name) changes the directory into the package? I always assumed that it functioned the same way as the commandline tool rospack find rospkg_name and returned an absolute path string. Or does it mean that $(find) actually caches the path string for $(dir) to use later? How does the mechanism work?

Either way, this can be solved with a sentence in the docs :)

@dirk-thomas
Copy link
Member

The patch looks good to me. Can you please add some tests (probably to tools/roslaunch/test/unit/test_substitution_args.py) for this new feature.

@mikepurvis
Copy link
Member Author

mikepurvis commented Jul 18, 2017

@IanTheEngineer Nope, $(find PKG) does exactly what you think it does. My comment about avoiding repetition would be for a scenario like this, where you currently have to have:

  <include file="$(find turtlebot_bringup)/launch/includes/robot.launch.xml" />

But might prefer to have something more like:

  <include file="$(dir)/includes/robot.launch.xml" />

@dirk-thomas Yup, tests in progress. I'll add to the unit test, but I'm thinking it would also be worthwhile to add something a bit more end-to-end to the test_roslaunch package, basically an automated version of the demonstration posted in the proposal.

One other bit of bikeshedding to do— the dir name is fine with me and the obvious one to use, but it does conflict with the dir builtin in the eval case. If we care about that, it might be best to pick a different name. If not, $(dir) should stick.

@dirk-thomas
Copy link
Member

One other bit of bikeshedding to do— the dir name is file with me and the obvious one to use, but it does conflict with the dir builtin in the eval case. If we care about that, it might be best to pick a different name. If not, $(dir) should stick.

Very good point. I would rather avoid overriding Python keywords in that case. Maybe dirname instead?

@mikepurvis mikepurvis changed the title Add $(dir) to get directory of current launch file. Add $(dirname) to get directory of current launch file. Jul 18, 2017
@mikepurvis
Copy link
Member Author

Changed to $(dirname), tests added. I think this is good to go now.

@dirk-thomas
Copy link
Member

Great, thank you.

When you have a chance can you please mention this new feature in the wiki and post a link here for future readers to find it.

@dirk-thomas dirk-thomas merged commit fad9104 into lunar-devel Jul 20, 2017
@dirk-thomas dirk-thomas deleted the roslaunch-current-dir branch July 20, 2017 21:09
@mikepurvis
Copy link
Member Author

Done: http://wiki.ros.org/roslaunch/XML#line-77

sputnick1124 pushed a commit to sputnick1124/ros_comm that referenced this pull request Jul 30, 2017
* Add $(dir) to get directory of current launch file.

* Change $(dir) -> $(dirname)

* Add simple tests for $(dirname) substitution.

* Add xmlloader test for $(dirname).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants