55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from launch import LaunchDescription
|
||
from launch_ros.actions import Node
|
||
from launch.actions import SetEnvironmentVariable, RegisterEventHandler
|
||
from launch.event_handlers import OnProcessExit
|
||
from launch.actions import EmitEvent
|
||
from launch.events import Shutdown
|
||
import os
|
||
|
||
|
||
def generate_launch_description():
|
||
"""启动声纹注册节点(需要ASR服务)"""
|
||
# 获取interfaces包的install路径
|
||
interfaces_install_path = os.path.expanduser('~/ros_learn/hivecore_robot_interfaces/install')
|
||
|
||
# 设置AMENT_PREFIX_PATH,确保能找到interfaces包的消息类型
|
||
ament_prefix_path = os.environ.get('AMENT_PREFIX_PATH', '')
|
||
if interfaces_install_path not in ament_prefix_path:
|
||
if ament_prefix_path:
|
||
ament_prefix_path = f'{ament_prefix_path}:{interfaces_install_path}'
|
||
else:
|
||
ament_prefix_path = interfaces_install_path
|
||
|
||
# ASR + 音频输入设备节点(提供ASR和AudioData服务)
|
||
asr_audio_node = Node(
|
||
package='robot_speaker',
|
||
executable='asr_audio_node',
|
||
name='asr_audio_node',
|
||
output='screen'
|
||
)
|
||
|
||
# 声纹注册节点
|
||
register_speaker_node = Node(
|
||
package='robot_speaker',
|
||
executable='register_speaker_node',
|
||
name='register_speaker_node',
|
||
output='screen'
|
||
)
|
||
|
||
# 当注册节点退出时,关闭整个 launch
|
||
register_exit_handler = RegisterEventHandler(
|
||
OnProcessExit(
|
||
target_action=register_speaker_node,
|
||
on_exit=[
|
||
EmitEvent(event=Shutdown(reason='注册完成,关闭所有节点'))
|
||
]
|
||
)
|
||
)
|
||
|
||
return LaunchDescription([
|
||
SetEnvironmentVariable('AMENT_PREFIX_PATH', ament_prefix_path),
|
||
asr_audio_node,
|
||
register_speaker_node,
|
||
register_exit_handler,
|
||
])
|