-
Notifications
You must be signed in to change notification settings - Fork 144
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 ForLoop action to repeat entities with an index #802
base: rolling
Are you sure you want to change the base?
Add ForLoop action to repeat entities with an index #802
Conversation
fb823a2
to
769f819
Compare
769f819
to
391f8af
Compare
391f8af
to
b9cd085
Compare
After some quick initial feedback, I changed the implementation to instead take a callback function, similar to |
Are you planning to support xml and yaml syntax as well? |
b9cd085
to
a28eb0c
Compare
Yeah, I think XML and YAML support are very important. I managed to get a working hacky implementation, but it could probably be improved. |
50a7b35
to
65dfa86
Compare
Well, with frontend support, this feels complete enough, so I think this is ready for a real review. |
@Timple feel free to provide feedback and/or just say whether you think this would be useful |
I don't know how this would look like in xml. So an example or test for that would be nice to show that. Having the ability to support N lidar nodes is nice 👍 |
I will work on adding tests, but there are XML and YAML examples in the PR description above. |
Tjeez... I totally overlooked those. That works great! |
593554a
to
6b35a08
Compare
I've now added tests (Python, XML, YAML). |
Signed-off-by: Christophe Bedard <[email protected]>
6b35a08
to
3c84d51
Compare
We discussed this PR at a high level in the November 12th ROS PMC meeting. In short, this is pushing us towards less declarative launch files, which makes writing potential linters/checkers harder. However, it was still possible to do this before using Now the PR just needs to be reviewed. |
Relates #499
Being able to repeat entities (e.g., nodes) N times based on the value of a launch argument is a pretty commonly-requested feature. Example: #499 and https://discourse.ros.org/t/poll-interest-in-ros2-launch-action-to-support-for-loops-e-g-includenlaunchdescriptions/20026. Some current solutions/workarounds include:
OpaqueFunction
: Launch Loop Support? [Feature Request] #499 (comment)While these work, they involve some boilerplate code that has to be repeated in each launch file, and they make launch files more complex.
This PR aims to simplify this by adding a new
ForLoop
action. It takes in something that defines the number of for-loop iterations, which can be a launch argument (LaunchConfiguration
). It also takes in a function that gets called with each for-loop index value (0 to N, exclusive). This function should return a list of entities using the index value to differentiate entities between each for-loop iteration.This is basically a nicer alternative to using an
OpaqueFunction
directly in Python, and supports frontends.Example:
Frontends are also supported. In this case, the callback function is created internally by the parser using the child entities and an
$(index)
substitution referencing the (index) name of the for-loop:If any of these launch files were launched without any launch arguments, they would create 2 pairs of
ping
&pong
nodes, each pair in its own namespace. Withnum_robots:=5
, they would create 5 pairs.Open questions:
launch
? I think so given that this is a common feature request (and undoubtedly a common Google search), but I'm open to other opinions.ForLoop
?Repeat
, maybe?I can add tests once this looks good enough. For now, it's a draft.Also, once it looks good enough, I'd like to post on Discourse to request feedback from users.We could also add support for start/stop like Python's
range()
.Bonus: you can even nest
<for>
loops:Output: