1+ #!/usr/bin/env python3
2+ """
3+ Launch file for Coffee Voice Agent - Complete System Mode
4+
5+ This launch file runs both the LiveKit voice agent script and the ROS2 bridge node
6+ together for a complete production system. The voice agent runs in 'start' mode
7+ (production) and the bridge provides ROS2 integration.
8+
9+ Usage:
10+ ros2 launch coffee_voice_agent voice_agent_system.launch.py
11+
12+ # With custom parameters:
13+ ros2 launch coffee_voice_agent voice_agent_system.launch.py \
14+ voice_agent_mode:=dev \
15+ voice_agent_port:=8080 \
16+ bridge_reconnect_interval:=3.0
17+ """
18+
19+ import os
20+ from launch import LaunchDescription
21+ from launch .actions import ExecuteProcess , DeclareLaunchArgument , TimerAction
22+ from launch .substitutions import LaunchConfiguration
23+ from launch_ros .actions import Node
24+ from launch_ros .substitutions import FindPackageShare
25+
26+
27+ def generate_launch_description ():
28+ """Generate launch description for complete system"""
29+
30+ # Declare launch arguments
31+ voice_agent_mode_arg = DeclareLaunchArgument (
32+ 'voice_agent_mode' ,
33+ default_value = 'start' ,
34+ description = 'Voice agent mode: console, dev, or start (production)'
35+ )
36+
37+ voice_agent_port_arg = DeclareLaunchArgument (
38+ 'voice_agent_port' ,
39+ default_value = '8080' ,
40+ description = 'WebSocket port for voice agent server'
41+ )
42+
43+ bridge_reconnect_interval_arg = DeclareLaunchArgument (
44+ 'bridge_reconnect_interval' ,
45+ default_value = '5.0' ,
46+ description = 'Bridge reconnection interval in seconds'
47+ )
48+
49+ voice_agent_host_arg = DeclareLaunchArgument (
50+ 'voice_agent_host' ,
51+ default_value = 'localhost' ,
52+ description = 'Host address of the voice agent (for bridge connection)'
53+ )
54+
55+ # Get package share directory
56+ package_share = FindPackageShare ('coffee_voice_agent' )
57+
58+ # Path to the voice agent script
59+ script_path = os .path .join (package_share .find ('coffee_voice_agent' ), 'scripts' , 'livekit_voice_agent.py' )
60+
61+ # Create the voice agent process
62+ voice_agent_process = ExecuteProcess (
63+ cmd = [
64+ 'python3' ,
65+ script_path ,
66+ LaunchConfiguration ('voice_agent_mode' )
67+ ],
68+ output = 'screen' ,
69+ name = 'livekit_voice_agent' ,
70+ emulate_tty = True ,
71+ shell = False ,
72+ respawn = True , # Auto-restart in production mode
73+ respawn_delay = 5.0 ,
74+ # Set environment variables for the voice agent
75+ additional_env = {
76+ 'WEBSOCKET_PORT' : LaunchConfiguration ('voice_agent_port' ),
77+ 'WEBSOCKET_HOST' : LaunchConfiguration ('voice_agent_host' ),
78+ }
79+ )
80+
81+ # Create the bridge node (with delay to let voice agent start first)
82+ bridge_node = TimerAction (
83+ period = 3.0 , # Wait 3 seconds for voice agent to start
84+ actions = [
85+ Node (
86+ package = 'coffee_voice_agent' ,
87+ executable = 'voice_agent_bridge' ,
88+ name = 'voice_agent_bridge' ,
89+ output = 'screen' ,
90+ emulate_tty = True ,
91+ parameters = [{
92+ 'voice_agent_host' : LaunchConfiguration ('voice_agent_host' ),
93+ 'voice_agent_port' : LaunchConfiguration ('voice_agent_port' ),
94+ 'reconnect_interval' : LaunchConfiguration ('bridge_reconnect_interval' ),
95+ }],
96+ respawn = True ,
97+ respawn_delay = 2.0
98+ )
99+ ]
100+ )
101+
102+ return LaunchDescription ([
103+ voice_agent_mode_arg ,
104+ voice_agent_port_arg ,
105+ bridge_reconnect_interval_arg ,
106+ voice_agent_host_arg ,
107+ voice_agent_process ,
108+ bridge_node ,
109+ ])
0 commit comments