Skip to content

Commit 47e74fe

Browse files
authored
Manipulation demo: Synchronize node launching (#341)
Signed-off-by: Kacper Dąbrowski <[email protected]>
1 parent 5b2469d commit 47e74fe

File tree

1 file changed

+77
-36
lines changed

1 file changed

+77
-36
lines changed

examples/manipulation-demo.launch.py

Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from launch import LaunchDescription
15+
import rclpy
16+
from launch import LaunchContext, LaunchDescription
1617
from launch.actions import (
1718
DeclareLaunchArgument,
1819
ExecuteProcess,
1920
IncludeLaunchDescription,
21+
OpaqueFunction,
22+
RegisterEventHandler,
2023
)
24+
from launch.event_handlers import OnExecutionComplete, OnProcessStart
2125
from launch.launch_description_sources import PythonLaunchDescriptionSource
2226
from launch.substitutions import LaunchConfiguration
23-
from launch_ros.actions import Node, RosTimer
27+
from launch_ros.actions import Node
2428
from launch_ros.substitutions import FindPackageShare
29+
from rclpy.qos import QoSProfile, ReliabilityPolicy
30+
from rosgraph_msgs.msg import Clock
2531

2632

2733
def generate_launch_description():
@@ -32,45 +38,80 @@ def generate_launch_description():
3238
description="Path to the game launcher executable",
3339
)
3440

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+
3591
return LaunchDescription(
3692
[
3793
# Include the game_launcher argument
3894
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+
)
66104
),
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+
)
74115
),
75116
]
76117
)

0 commit comments

Comments
 (0)