|
29 | 29 | from launch.actions import (
|
30 | 30 | DeclareLaunchArgument,
|
31 | 31 | EmitEvent,
|
| 32 | + ExecuteProcess, |
32 | 33 | RegisterEventHandler)
|
33 | 34 | from launch.conditions import IfCondition
|
34 |
| -from launch.event_handlers import OnProcessStart |
| 35 | +from launch.event_handlers import OnProcessStart, OnProcessExit |
35 | 36 | from launch.events import matches_action
|
36 |
| -from launch.substitutions import LaunchConfiguration |
| 37 | +from launch.substitutions import LaunchConfiguration, FindExecutable |
37 | 38 | from launch_ros.actions import LifecycleNode
|
38 | 39 | from launch_ros.event_handlers import OnStateTransition
|
39 | 40 | from launch_ros.events.lifecycle import ChangeState
|
@@ -102,6 +103,20 @@ def generate_launch_description():
|
102 | 103 | remappings=[('from_can_bus', from_can_bus_topic)],
|
103 | 104 | output='screen')
|
104 | 105 |
|
| 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 | + |
105 | 120 | configure_event = RegisterEventHandler(
|
106 | 121 | event_handler=OnProcessStart(
|
107 | 122 | target_action=node,
|
@@ -144,7 +159,8 @@ def generate_launch_description():
|
144 | 159 | ld.add_action(arg_auto_configure)
|
145 | 160 | ld.add_action(arg_auto_activate)
|
146 | 161 | 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) |
148 | 164 | ld.add_action(configure_event)
|
149 | 165 | ld.add_action(activate_event)
|
150 | 166 | return ld
|
0 commit comments