-
Notifications
You must be signed in to change notification settings - Fork 137
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 ability to define and pass launch arguments to launch files #123
Merged
Merged
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c9fb73f
add self descriptions for substitutions
wjwwood 2bb466e
add tracebacks back to the output by default
wjwwood dc3eaa6
add new actions for declaring launch arguments
wjwwood 1af02d1
new method on LaunchDescription which gets all declared arguments within
wjwwood 6213656
add ability to pass arguments when including a launch description
wjwwood 5cfd710
add description for local variables used in Node action
wjwwood 42bfcb9
fix bug in Node action
wjwwood 4719cb4
cleanup error reporting in Node action
wjwwood 6a9cc14
use launch arguments in examples
wjwwood 6b4927b
add ability to show and pass launch arguments on the command line
wjwwood 2977c5b
fix python 3.5 support
wjwwood 1f5bf87
add accessor for the Condition of an Action
wjwwood c134906
do not automatically push/pop configs when including
wjwwood d27ea82
small refactor to get the launch file location
wjwwood 89eab55
improve ability to detect declared arguments across launch file includes
wjwwood 71a1dfb
add tests for the new DeclareLaunchArgument action
wjwwood 8617c38
test new features of IncludeLaunchDescription
wjwwood c236b57
test new features of LaunchDescription class
wjwwood f5ba658
remove unused imports
wjwwood 6ab4d88
improve output when showing arguments of a launch file
wjwwood 60b72cf
fix the return type of LaunchService.run()
wjwwood 43cb119
fix the checking for the asyncio event loop for the case where it is …
wjwwood 97edc9f
typo
wjwwood b4969f4
restart event loop to allow proper shutdown when there's an unhandled…
wjwwood f077ab6
ExecuteProcess: unregister event handlers if rest of setup fails
wjwwood 4dbd9bb
only put traceback in debug logging
wjwwood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Copyright 2018 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Module for the DeclareLaunchArgument action.""" | ||
|
||
import logging | ||
from typing import List | ||
from typing import Optional | ||
from typing import Text | ||
|
||
from ..action import Action | ||
from ..launch_context import LaunchContext | ||
from ..some_substitutions_type import SomeSubstitutionsType | ||
from ..substitution import Substitution | ||
from ..utilities import normalize_to_list_of_substitutions | ||
from ..utilities import perform_substitutions | ||
|
||
_logger = logging.getLogger('launch.actions.DeclareLaunchArgument') | ||
|
||
|
||
class DeclareLaunchArgument(Action): | ||
""" | ||
Action that declares a new launch argument. | ||
|
||
A launch arguments are stored in a "launch configuration" of the same name. | ||
See :py:class:`launch.actions.SetLaunchConfiguration` and | ||
:py:class:`launch.substitutions.LaunchConfiguration`. | ||
|
||
Any launch arguments declared within a :py:class:`launch.LaunchDescription` | ||
will be exposed as arguments when that launch description is included, e.g. | ||
as additional parameters in the | ||
:py:class:`launch.actions.IncludeLaunchDescription` action or as | ||
command-line arguments when launch with ``ros2 launch ...``. | ||
|
||
In addition to the name, which is also where the argument result is stored, | ||
launch arguments may have a default value and a description. | ||
If a default value is given, then the argument becomes optional and the | ||
default value is placed in the launch configuration instead. | ||
If no default value is given and no value is given when including the | ||
launch description, then an error occurs. | ||
|
||
The default value may use Substitutions, but the name and description can | ||
only be Text, since they need a meaningful value before launching, e.g. | ||
when listing the command-line arguments. | ||
|
||
Note that declaring a launch argument needs to be in a part of the launch | ||
description that is describable without launching. | ||
For example, if you declare a launch argument with this action from within | ||
a condition group or as a callback to an event handler, then it may not be | ||
possible for a tool like ``ros2 launch`` to know about the argument before | ||
launching the launch description. | ||
In such cases, the argument will not be visible on the command line but | ||
may raise an exception if that argument is not satisfied once visited (and | ||
has no default value). | ||
|
||
Put another way, the post-condition of this action being visited is either | ||
that a launch configuration of the same name is set with a value or an | ||
exception is raised because none is set and there is no default value. | ||
However, the pre-condition does not guarantee that the argument was visible | ||
if behind condition or situational inclusions. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
name: Text, | ||
*, | ||
default_value: Optional[SomeSubstitutionsType] = None, | ||
description: Text = 'no description given', | ||
**kwargs | ||
) -> None: | ||
"""Constructor.""" | ||
super().__init__(**kwargs) | ||
self.__name = name | ||
if default_value is None: | ||
self.__default_value = default_value | ||
else: | ||
self.__default_value = normalize_to_list_of_substitutions(default_value) | ||
self.__description = description | ||
|
||
# This is used later to determine if this launch argument will be | ||
# conditionally visited. | ||
# Its value will be read and set at different times and so the value | ||
# may change depending at different times based on the context. | ||
self._conditionally_included = False | ||
|
||
@property | ||
def name(self) -> Text: | ||
"""Getter for self.__name.""" | ||
return self.__name | ||
|
||
@property | ||
def default_value(self) -> Optional[List[Substitution]]: | ||
"""Getter for self.__default_value.""" | ||
return self.__default_value | ||
|
||
@property | ||
def description(self) -> Text: | ||
"""Getter for self.__description.""" | ||
return self.__description | ||
|
||
def execute(self, context: LaunchContext): | ||
"""Execute the action.""" | ||
if self.name not in context.launch_configurations: | ||
if self.default_value is None: | ||
# Argument not already set and no default value given, error. | ||
_logger.error( | ||
"Required launch argument '{}' (description: '{}') was not provided" | ||
.format(self.name, self.description) | ||
) | ||
raise RuntimeError( | ||
"Required launch argument '{}' was not provided.".format(self.name)) | ||
context.launch_configurations[self.name] = \ | ||
perform_substitutions(context, self.default_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
launched