Skip to content

Commit b9bbe26

Browse files
committedJan 27, 2025
Wait for interface to be UP before starting node
1 parent b92fdfb commit b9bbe26

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed
 

‎launch/receiver.launch.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
from launch.actions import (
3030
DeclareLaunchArgument,
3131
EmitEvent,
32+
ExecuteProcess,
3233
RegisterEventHandler)
3334
from launch.conditions import IfCondition
34-
from launch.event_handlers import OnProcessStart
35+
from launch.event_handlers import OnProcessStart, OnProcessExit
3536
from launch.events import matches_action
36-
from launch.substitutions import LaunchConfiguration
37+
from launch.substitutions import LaunchConfiguration, FindExecutable
3738
from launch_ros.actions import LifecycleNode
3839
from launch_ros.event_handlers import OnStateTransition
3940
from launch_ros.events.lifecycle import ChangeState
@@ -102,6 +103,20 @@ def generate_launch_description():
102103
remappings=[('from_can_bus', from_can_bus_topic)],
103104
output='screen')
104105

106+
# Wait for interface to be up
107+
wait_for_can_interface_proc = ExecuteProcess(
108+
cmd=[['until ', FindExecutable(name='ip'), ' link show ', interface, ' | ',
109+
FindExecutable(name='grep'), ' \"state UP\"', '; do sleep 1; done']],
110+
shell=True
111+
)
112+
113+
launch_node = RegisterEventHandler(
114+
event_handler=OnProcessExit(
115+
target_action=wait_for_can_interface_proc,
116+
on_exit=node
117+
)
118+
)
119+
105120
configure_event = RegisterEventHandler(
106121
event_handler=OnProcessStart(
107122
target_action=node,
@@ -144,7 +159,8 @@ def generate_launch_description():
144159
ld.add_action(arg_auto_configure)
145160
ld.add_action(arg_auto_activate)
146161
ld.add_action(arg_from_can_bus_topic)
147-
ld.add_action(node)
162+
ld.add_action(wait_for_can_interface_proc)
163+
ld.add_action(launch_node)
148164
ld.add_action(configure_event)
149165
ld.add_action(activate_event)
150166
return ld

‎launch/sender.launch.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
from launch.actions import (
3030
DeclareLaunchArgument,
3131
EmitEvent,
32+
ExecuteProcess,
3233
RegisterEventHandler)
3334
from launch.conditions import IfCondition
34-
from launch.event_handlers import OnProcessStart
35+
from launch.event_handlers import OnProcessStart, OnProcessExit
3536
from launch.events import matches_action
36-
from launch.substitutions import LaunchConfiguration
37+
from launch.substitutions import LaunchConfiguration, FindExecutable
3738
from launch_ros.actions import LifecycleNode
3839
from launch_ros.event_handlers import OnStateTransition
3940
from launch_ros.events.lifecycle import ChangeState
@@ -89,6 +90,20 @@ def generate_launch_description():
8990
}],
9091
remappings=[('to_can_bus', to_can_bus_topic)],
9192
output='screen')
93+
94+
# Wait for interface to be up
95+
wait_for_can_interface_proc = ExecuteProcess(
96+
cmd=[['until ', FindExecutable(name='ip'), ' link show ', interface, ' | ',
97+
FindExecutable(name='grep'), ' \"state UP\"', '; do sleep 1; done']],
98+
shell=True
99+
)
100+
101+
launch_node = RegisterEventHandler(
102+
event_handler=OnProcessExit(
103+
target_action=wait_for_can_interface_proc,
104+
on_exit=node
105+
)
106+
)
92107

93108
configure_event = RegisterEventHandler(
94109
event_handler=OnProcessStart(
@@ -130,7 +145,8 @@ def generate_launch_description():
130145
ld.add_action(arg_auto_configure)
131146
ld.add_action(arg_auto_activate)
132147
ld.add_action(arg_to_can_bus_topic)
133-
ld.add_action(node)
148+
ld.add_action(wait_for_can_interface_proc)
149+
ld.add_action(launch_node)
134150
ld.add_action(configure_event)
135151
ld.add_action(activate_event)
136152
return ld

0 commit comments

Comments
 (0)