planner.launch.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/usr/bin/env python3
  2. """
  3. agint_brain.planner.launch - Planner Node 启动文件
  4. 功能:
  5. - 启动 planner_node
  6. - 加载 planner_config.yaml
  7. - 配置 ROS2 参数
  8. - 输出到 screen
  9. 使用方式:
  10. ros2 launch agint_brain planner.launch.py
  11. 可选参数:
  12. planner_config_path: 配置文件路径
  13. input_world_topic: 世界状态 topic
  14. input_user_intent_topic: 用户意图 topic
  15. output_plan_topic: Plan 输出 topic
  16. llm_request_topic: LLM 请求 topic
  17. llm_response_topic: LLM 响应 topic
  18. use_llm: 是否启用 LLM
  19. llm_timeout_sec: LLM 超时时间
  20. debug_log: 是否输出调试日志
  21. """
  22. import os
  23. from pathlib import Path
  24. from ament_index_python.packages import get_package_share_directory
  25. from launch import LaunchDescription
  26. from launch.actions import DeclareLaunchArgument, LogInfo, RegisterEventHandler
  27. from launch.event_handlers import OnProcessExit
  28. from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
  29. from launch_ros.actions import Node
  30. def generate_launch_description() -> LaunchDescription:
  31. """生成 launch description"""
  32. # 获取包共享目录
  33. pkg_share = get_package_share_directory("agint_brain")
  34. # 默认配置文件路径
  35. default_config_path = PathJoinSubstitution([
  36. pkg_share,
  37. "config",
  38. "planner_config.yaml"
  39. ])
  40. # =========================================================================
  41. # Launch Arguments
  42. # =========================================================================
  43. planner_config_path_arg = DeclareLaunchArgument(
  44. "planner_config_path",
  45. default_value=default_config_path,
  46. description="planner_config.yaml 配置文件路径",
  47. )
  48. gate_config_path_arg = DeclareLaunchArgument(
  49. "gate_config_path",
  50. default_value=PathJoinSubstitution([
  51. pkg_share,
  52. "config",
  53. "planner_gate_config.yaml"
  54. ]),
  55. description="planner_gate_config.yaml 配置文件路径(Gate 前置治理配置)",
  56. )
  57. input_world_topic_arg = DeclareLaunchArgument(
  58. "input_world_topic",
  59. default_value="/world/snapshot",
  60. description="World snapshot 输入 topic",
  61. )
  62. input_user_intent_topic_arg = DeclareLaunchArgument(
  63. "input_user_intent_topic",
  64. default_value="/planner/user_intent",
  65. description="用户意图输入 topic(已废弃,使用 input_asr_topic)",
  66. )
  67. input_asr_topic_arg = DeclareLaunchArgument(
  68. "input_asr_topic",
  69. default_value="/asr",
  70. description="ASR 语音识别输入 topic",
  71. )
  72. output_plan_topic_arg = DeclareLaunchArgument(
  73. "output_plan_topic",
  74. default_value="/plan",
  75. description="Plan 输出 topic",
  76. )
  77. llm_request_topic_arg = DeclareLaunchArgument(
  78. "llm_request_topic",
  79. default_value="/planner/llm_request",
  80. description="LLM 请求 topic",
  81. )
  82. llm_response_topic_arg = DeclareLaunchArgument(
  83. "llm_response_topic",
  84. default_value="/planner/llm_response",
  85. description="LLM 响应 topic",
  86. )
  87. use_llm_arg = DeclareLaunchArgument(
  88. "use_llm",
  89. default_value="true",
  90. description="是否启用 LLM",
  91. )
  92. llm_timeout_sec_arg = DeclareLaunchArgument(
  93. "llm_timeout_sec",
  94. default_value="10.0",
  95. description="LLM 请求超时时间(秒)",
  96. )
  97. debug_log_arg = DeclareLaunchArgument(
  98. "debug_log",
  99. default_value="true",
  100. description="是否输出调试日志",
  101. )
  102. default_session_id_arg = DeclareLaunchArgument(
  103. "default_session_id",
  104. default_value="default",
  105. description="默认会话 ID",
  106. )
  107. # =========================================================================
  108. # Planner Node
  109. # =========================================================================
  110. planner_node = Node(
  111. package="agint_brain",
  112. executable="planner_node",
  113. name="planner_node",
  114. output="screen",
  115. emulate_tty=True,
  116. parameters=[
  117. {
  118. "planner_config_path": LaunchConfiguration("planner_config_path"),
  119. "gate_config_path": LaunchConfiguration("gate_config_path"),
  120. "input_world_topic": LaunchConfiguration("input_world_topic"),
  121. "input_asr_topic": LaunchConfiguration("input_asr_topic"),
  122. "output_plan_topic": LaunchConfiguration("output_plan_topic"),
  123. "llm_request_topic": LaunchConfiguration("llm_request_topic"),
  124. "llm_response_topic": LaunchConfiguration("llm_response_topic"),
  125. "use_llm": LaunchConfiguration("use_llm"),
  126. "llm_timeout_sec": LaunchConfiguration("llm_timeout_sec"),
  127. "debug_log": LaunchConfiguration("debug_log"),
  128. "default_session_id": LaunchConfiguration("default_session_id", default="default"),
  129. }
  130. ],
  131. )
  132. # =========================================================================
  133. # Event Handlers
  134. # =========================================================================
  135. exit_event = RegisterEventHandler(
  136. event_handler=OnProcessExit(
  137. target_action=planner_node,
  138. on_exit=[LogInfo(msg="Planner Node 已退出")],
  139. )
  140. )
  141. # =========================================================================
  142. # Launch Description
  143. # =========================================================================
  144. ld = LaunchDescription([
  145. LogInfo(msg="========================================"),
  146. LogInfo(msg="正在启动 Planner Node (含 Gate 前置治理层)..."),
  147. LogInfo(msg="========================================"),
  148. planner_config_path_arg,
  149. gate_config_path_arg,
  150. input_world_topic_arg,
  151. input_asr_topic_arg,
  152. output_plan_topic_arg,
  153. llm_request_topic_arg,
  154. llm_response_topic_arg,
  155. use_llm_arg,
  156. llm_timeout_sec_arg,
  157. debug_log_arg,
  158. default_session_id_arg,
  159. planner_node,
  160. exit_event,
  161. ])
  162. return ld