Skip to content

Commit 9e76d6f

Browse files
SteveMacenskimergify[bot]
authored andcommitted
Fixing lifecycle node autostart issue #445 (#449)
Signed-off-by: Steve Macenski <stevenmacenski@gmail.com> (cherry picked from commit 98952b5) # Conflicts: # launch_ros/launch_ros/actions/lifecycle_node.py # launch_ros/launch_ros/actions/load_composable_nodes.py
1 parent 0cff20a commit 9e76d6f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

launch_ros/launch_ros/actions/lifecycle_node.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def execute(self, context: launch.LaunchContext) -> Optional[List[Action]]:
145145
self._perform_substitutions(context) # ensure self.node_name is expanded
146146
if '<node_name_unspecified>' in self.node_name:
147147
raise RuntimeError('node_name unexpectedly incomplete for lifecycle node')
148+
<<<<<<< HEAD
148149
node = get_ros_node(context)
149150
# Create a subscription to monitor the state changes of the subprocess.
150151
self.__rclpy_subscription = node.create_subscription(
@@ -161,5 +162,22 @@ def execute(self, context: launch.LaunchContext) -> Optional[List[Action]]:
161162
matcher=lambda event: isinstance(event, ChangeState),
162163
entities=[launch.actions.OpaqueFunction(function=self._on_change_state_event)],
163164
))
165+
=======
166+
167+
self.__lifecycle_event_manager = LifecycleEventManager(self)
168+
self.__lifecycle_event_manager.setup_lifecycle_manager(context)
169+
170+
# If autostart is enabled, transition to the 'active' state.
171+
autostart_actions = None
172+
if self.node_autostart:
173+
autostart_actions = [
174+
LifecycleTransition(
175+
lifecycle_node_names=[self.node_name],
176+
transition_ids=[lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
177+
lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE]
178+
),
179+
]
180+
181+
>>>>>>> 98952b5 (Fixing lifecycle node autostart issue #445 (#449))
164182
# Delegate execution to Node and ExecuteProcess.
165183
return super().execute(context)

launch_ros/launch_ros/actions/load_composable_nodes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,24 @@ def execute(
236236
if request is not None:
237237
load_node_requests.append(request)
238238

239+
<<<<<<< HEAD
240+
=======
241+
# If autostart is enabled, transition to the 'active' state.
242+
if hasattr(node_description, 'node_autostart') and node_description.node_autostart:
243+
complete_node_name = request.node_namespace + request.node_name
244+
if not complete_node_name.startswith('/'):
245+
complete_node_name = '/' + complete_node_name
246+
self.__logger.info(
247+
'Autostart enabled for requested lifecycle node {}'.format(complete_node_name))
248+
node_description.init_lifecycle_event_manager(context)
249+
autostart_actions.append(
250+
LifecycleTransition(
251+
lifecycle_node_names=[complete_node_name],
252+
transition_ids=[lifecycle_msgs.msg.Transition.TRANSITION_CONFIGURE,
253+
lifecycle_msgs.msg.Transition.TRANSITION_ACTIVATE]
254+
))
255+
256+
>>>>>>> 98952b5 (Fixing lifecycle node autostart issue #445 (#449))
239257
if load_node_requests:
240258
context.add_completion_future(
241259
context.asyncio_loop.run_in_executor(

0 commit comments

Comments
 (0)