12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- from launch import LaunchDescription
15
+ import rclpy
16
+ from launch import LaunchContext , LaunchDescription
16
17
from launch .actions import (
17
18
DeclareLaunchArgument ,
18
19
ExecuteProcess ,
19
20
IncludeLaunchDescription ,
21
+ OpaqueFunction ,
22
+ RegisterEventHandler ,
20
23
)
24
+ from launch .event_handlers import OnExecutionComplete , OnProcessStart
21
25
from launch .launch_description_sources import PythonLaunchDescriptionSource
22
26
from launch .substitutions import LaunchConfiguration
23
- from launch_ros .actions import Node , RosTimer
27
+ from launch_ros .actions import Node
24
28
from launch_ros .substitutions import FindPackageShare
29
+ from rclpy .qos import QoSProfile , ReliabilityPolicy
30
+ from rosgraph_msgs .msg import Clock
25
31
26
32
27
33
def generate_launch_description ():
@@ -32,45 +38,80 @@ def generate_launch_description():
32
38
description = "Path to the game launcher executable" ,
33
39
)
34
40
41
+ launch_game_launcher = ExecuteProcess (
42
+ cmd = [
43
+ LaunchConfiguration ("game_launcher" ),
44
+ "-bg_ConnectToAssetProcessor=0" ,
45
+ ],
46
+ output = "screen" ,
47
+ )
48
+
49
+ def wait_for_clock_message (context : LaunchContext , * args , ** kwargs ):
50
+ rclpy .init ()
51
+ node = rclpy .create_node ("wait_for_game_launcher" )
52
+ node .create_subscription (
53
+ Clock ,
54
+ "/clock" ,
55
+ lambda msg : rclpy .shutdown (),
56
+ QoSProfile (depth = 1 , reliability = ReliabilityPolicy .BEST_EFFORT ),
57
+ )
58
+ rclpy .spin (node )
59
+ return None
60
+
61
+ # Game launcher will start publishing the clock message after loading the simulation
62
+ wait_for_game_launcher = OpaqueFunction (function = wait_for_clock_message )
63
+
64
+ launch_moveit = IncludeLaunchDescription (
65
+ PythonLaunchDescriptionSource (
66
+ [
67
+ "src/examples/rai-manipulation-demo/Project/Examples/panda_moveit_config_demo.launch.py" ,
68
+ ]
69
+ )
70
+ )
71
+
72
+ launch_robotic_manipulation = Node (
73
+ package = "robotic_manipulation" ,
74
+ executable = "robotic_manipulation" ,
75
+ name = "robotic_manipulation_node" ,
76
+ output = "screen" ,
77
+ parameters = [
78
+ {"use_sim_time" : True },
79
+ ],
80
+ )
81
+
82
+ launch_openset = IncludeLaunchDescription (
83
+ PythonLaunchDescriptionSource (
84
+ [
85
+ FindPackageShare ("rai_bringup" ),
86
+ "/launch/openset.launch.py" ,
87
+ ]
88
+ ),
89
+ )
90
+
35
91
return LaunchDescription (
36
92
[
37
93
# Include the game_launcher argument
38
94
game_launcher_arg ,
39
- # Launch the openset nodes
40
- IncludeLaunchDescription (
41
- PythonLaunchDescriptionSource (
42
- [
43
- FindPackageShare ("rai_bringup" ),
44
- "/launch/openset.launch.py" ,
45
- ]
46
- ),
47
- ),
48
- IncludeLaunchDescription (
49
- PythonLaunchDescriptionSource (
50
- [
51
- "src/examples/rai-manipulation-demo/Project/Examples/panda_moveit_config_demo.launch.py" ,
52
- ]
53
- ),
54
- ),
55
- # Launch the robotic_manipulation node after 3 seconds, to ensure the moveit node is ready
56
- RosTimer (
57
- period = 3.0 ,
58
- actions = [
59
- Node (
60
- package = "robotic_manipulation" ,
61
- executable = "robotic_manipulation" ,
62
- name = "robotic_manipulation_node" ,
63
- output = "screen" ,
64
- ),
65
- ],
95
+ # Launch the game launcher and wait for it to load
96
+ launch_game_launcher ,
97
+ RegisterEventHandler (
98
+ event_handler = OnProcessStart (
99
+ target_action = launch_game_launcher ,
100
+ on_start = [
101
+ wait_for_game_launcher ,
102
+ ],
103
+ )
66
104
),
67
- # Launch the game launcher
68
- ExecuteProcess (
69
- cmd = [
70
- LaunchConfiguration ("game_launcher" ),
71
- "-bg_ConnectToAssetProcessor=0" ,
72
- ],
73
- output = "screen" ,
105
+ # Launch the MoveIt node after loading the simulation
106
+ RegisterEventHandler (
107
+ event_handler = OnExecutionComplete (
108
+ target_action = wait_for_game_launcher ,
109
+ on_completion = [
110
+ launch_openset ,
111
+ launch_moveit ,
112
+ launch_robotic_manipulation ,
113
+ ],
114
+ )
74
115
),
75
116
]
76
117
)
0 commit comments