-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,432 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 100 |
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,94 @@ | ||
# 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. | ||
|
||
"""Launch a talker and a listener.""" | ||
|
||
import os | ||
import sys | ||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) # noqa | ||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'launch')) # noqa | ||
|
||
import launch | ||
import launch.actions | ||
import launch.events | ||
|
||
import launch_ros.actions | ||
import launch_ros.events | ||
import launch_ros.events.lifecycle | ||
from launch_ros import get_default_ros_launch_description | ||
|
||
import lifecycle_msgs.msg | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
"""Main.""" | ||
def _on_transition_event(context): | ||
print('got transition_event {}'.format(context.locals.event)) | ||
|
||
ld = launch.LaunchDescription() | ||
|
||
# Launch the talker node. | ||
talker_node = launch_ros.actions.LifecycleNode( | ||
node_name='talker', | ||
package='lifecycle', node_executable='lifecycle_talker', output='screen') | ||
ld.add_action(talker_node) | ||
# When the talker node reaches the PRIMARY_STATE_ACTIVE state, start the listener. | ||
ld.add_action(launch.actions.RegisterEventHandler(launch_ros.event_handlers.OnStateTransition( | ||
target_lifecycle_node=talker_node, goal_state='active', | ||
entities=[ | ||
launch.actions.LogInfo( | ||
msg="lifecycle node 'talker' reached the 'active' state, launching 'listener'."), | ||
launch_ros.actions.LifecycleNode( | ||
node_name='listener', | ||
package='lifecycle', node_executable='lifecycle_listener', output='screen'), | ||
], | ||
))) | ||
|
||
# When the talker reaches 'configured', make it take the 'activate' transition. | ||
ld.add_action(launch.actions.RegisterEventHandler(launch_ros.event_handlers.OnStateTransition( | ||
target_lifecycle_node=talker_node, goal_state='inactive', | ||
entities=[ | ||
launch.actions.LogInfo( | ||
msg="lifecycle node 'talker' reached the 'unconfigured' state, 'activating'."), | ||
launch.actions.EmitEvent(event=launch_ros.events.lifecycle.ChangeState( | ||
lifecycle_node_matcher=launch.events.process.matches_action(talker_node), | ||
transition_id=lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE, | ||
)), | ||
], | ||
))) | ||
|
||
# Make the talker node take the 'configure' transition. | ||
ld.add_action(launch.actions.EmitEvent(event=launch_ros.events.lifecycle.ChangeState( | ||
lifecycle_node_matcher=launch.events.process.matches_action(talker_node), | ||
transition_id=lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE, | ||
))) | ||
|
||
print('Starting introspection of launch description...') | ||
print('') | ||
|
||
print(launch.LaunchIntrospector().format_launch_description(ld)) | ||
|
||
print('') | ||
print('Starting launch of launch description...') | ||
print('') | ||
|
||
# ls = LaunchService(argv=argv, debug=True) | ||
ls = launch.LaunchService(argv=argv) | ||
ls.include_launch_description(get_default_ros_launch_description(prefix_output_with_name=False)) | ||
ls.include_launch_description(ld) | ||
ls.run() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,56 @@ | ||
# 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. | ||
|
||
"""Launch a talker and a listener.""" | ||
|
||
import os | ||
import sys | ||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) # noqa | ||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'launch')) # noqa | ||
|
||
from launch import LaunchDescription | ||
from launch import LaunchIntrospector | ||
from launch import LaunchService | ||
|
||
import launch_ros.actions | ||
from launch_ros import get_default_ros_launch_description | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
"""Main.""" | ||
ld = LaunchDescription([ | ||
launch_ros.actions.Node( | ||
package='demo_nodes_cpp', node_executable='talker', output='screen'), | ||
launch_ros.actions.Node( | ||
package='demo_nodes_cpp', node_executable='listener', output='screen'), | ||
]) | ||
|
||
print('Starting introspection of launch description...') | ||
print('') | ||
|
||
print(LaunchIntrospector().format_launch_description(ld)) | ||
|
||
print('') | ||
print('Starting launch of launch description...') | ||
print('') | ||
|
||
# ls = LaunchService(debug=True) | ||
ls = LaunchService() | ||
ls.include_launch_description(get_default_ros_launch_description(prefix_output_with_name=False)) | ||
ls.include_launch_description(ld) | ||
ls.run() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,29 @@ | ||
# 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. | ||
|
||
"""Main entry point for the `launch_ros` package.""" | ||
|
||
from . import actions | ||
from . import event_handlers | ||
from . import events | ||
from . import substitutions | ||
from .default_launch_description import get_default_ros_launch_description | ||
|
||
__all__ = [ | ||
'actions', | ||
'event_handlers', | ||
'events', | ||
'substitutions', | ||
'get_default_ros_launch_description', | ||
] |
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,23 @@ | ||
# 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. | ||
|
||
"""actions Module.""" | ||
|
||
from .lifecycle_node import LifecycleNode | ||
from .node import Node | ||
|
||
__all__ = [ | ||
'LifecycleNode', | ||
'Node', | ||
] |
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,72 @@ | ||
# 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 ComponentNode action.""" | ||
|
||
import logging | ||
from typing import List | ||
from typing import Optional | ||
|
||
from launch.action import Action | ||
from launch.launch_context import LaunchContext | ||
from launch.some_substitutions_type import SomeSubstitutionsType | ||
from launch.substitutions import LaunchConfiguration | ||
|
||
from .node import Node | ||
from ..substitutions import ExecutableInPackage | ||
|
||
_logger = logging.getLogger(name='launch_ros.component_node') | ||
|
||
|
||
class ComponentNode(Action): | ||
"""Action that wraps a launch_ros.actions.Node and loads it into a node container.""" | ||
|
||
def __init__( | ||
self, *, | ||
node: Node, | ||
node_container_name: SomeSubstitutionsType = LaunchConfiguration(name='node_container'), | ||
) -> None: | ||
""" | ||
Construct an ComponentNode action. | ||
This takes exactly one Node action, and does not visit it, but instead | ||
uses the information within it to instead load it into a node container | ||
by name. | ||
If no container name is given, it will attempt to be loaded from the | ||
launch configurations under the name 'node_container'. | ||
If not found there, a SubstitutionFailure error will occur. | ||
If the given node does not exist, it will fail the same as with the | ||
Node action used normally. | ||
If the given node exists, but is not a component-style node, a | ||
ValueError will occur. | ||
:param: node the Node action from which the component should be loaded | ||
:param: node_container_name the name of the node container to load into | ||
""" | ||
cmd = [ExecutableInPackage(package=package, executable=node_executable)] | ||
cmd += [] if arguments is None else arguments | ||
super().__init__(cmd=cmd, **kwargs) | ||
self.__package = package | ||
self.__node_executable = node_executable | ||
self.__arguments = arguments | ||
|
||
def execute(self, context: LaunchContext) -> Optional[List[Action]]: | ||
""" | ||
Execute the action. | ||
Delegated to :meth:`launch.actions.ExecuteProcess.execute`. | ||
""" | ||
return super().execute(context) |
Oops, something went wrong.