fix: nav2_navigator.py ROS_DOMAIN_ID=1 in script files and all _run_ros2_bash calls
This commit is contained in:
@@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def _run_ros2_bash(cmd: str, timeout: float = 5.0) -> Tuple[int, str, str]:
|
||||
"""执行 ros2 命令(直接运行,不二次包装)"""
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash"
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash && export ROS_DOMAIN_ID=1"
|
||||
full_cmd = f"bash -l -c '{setup} && {cmd}'"
|
||||
try:
|
||||
result = subprocess.run(full_cmd, shell=True, capture_output=True, text=True, timeout=timeout)
|
||||
@@ -100,6 +100,7 @@ class Nav2Navigator:
|
||||
"#!/bin/bash\n"
|
||||
"source /opt/ros/humble/setup.bash 2>/dev/null\n"
|
||||
"source /home/elephant/agv_pro_ros2/install/setup.bash 2>/dev/null\n"
|
||||
"export ROS_DOMAIN_ID=1\n"
|
||||
"ros2 action list 2>&1\n"
|
||||
)
|
||||
script_file = "/tmp/nav2_check.sh"
|
||||
@@ -200,7 +201,7 @@ class Nav2Navigator:
|
||||
|
||||
# 使用 pipe 方式运行导航
|
||||
# 通过 subprocess.Popen + stdin heredoc 避免所有引号转义问题
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash"
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash && export ROS_DOMAIN_ID=1"
|
||||
qz = math.sin(yaw / 2.0)
|
||||
qw = math.cos(yaw / 2.0)
|
||||
|
||||
@@ -449,7 +450,7 @@ class Nav2Navigator:
|
||||
def _nav_thread_func_multi(self, poses: List[Tuple[float, float, float]], timeout_per_pose: float):
|
||||
"""多路径点导航线程"""
|
||||
try:
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash"
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash && export ROS_DOMAIN_ID=1"
|
||||
|
||||
# 构建 poses heredoc
|
||||
poses_lines = []
|
||||
@@ -556,7 +557,7 @@ class Nav2Navigator:
|
||||
"""取消当前导航"""
|
||||
if self.status == Nav2Status.NAVIGATING:
|
||||
self._cancel_event.set()
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash"
|
||||
setup = "source /opt/ros/humble/setup.bash && source /home/elephant/agv_pro_ros2/install/setup.bash && export ROS_DOMAIN_ID=1"
|
||||
cancel_cmd = f'bash -l -c \'{setup} && ros2 action cancel /navigate_to_pose 2>/dev/null || ros2 action cancel /navigate_through_poses 2>/dev/null || true\''
|
||||
subprocess.run(cancel_cmd, shell=True, timeout=3)
|
||||
self.status = Nav2Status.CANCELLED
|
||||
|
||||
Reference in New Issue
Block a user