初始化位置

This commit is contained in:
ywb
2026-05-18 10:14:05 +08:00
parent a4c8171c42
commit deb97a67c0
3 changed files with 29 additions and 7 deletions
+27 -5
View File
@@ -676,12 +676,34 @@ def api_mission_init_pose():
"""将 AMCL 初始位置设为 (0,0,0),无需 RViz"""
try:
script = "/tmp/ros2_init_pose.sh"
yaml_content = (
"pose:\n"
" header:\n"
" stamp:\n"
" sec: 0\n"
" nanosec: 0\n"
" frame_id: map\n"
" pose:\n"
" position:\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" covariance: [0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n"
" orientation:\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
)
goal_file = "/tmp/nav2_goal_{}.yaml".format(os.getpid())
with open(goal_file, "w") as f:
f.write(yaml_content)
lines = [
"#!/bin/bash",
"export ROS_DOMAIN_ID=0",
"export ROS_DOMAIN_ID=1",
"source /opt/ros/humble/setup.bash",
"source ~/agv_pro_ros2/install/setup.bash",
"python3 /tmp/publish_init_pose.py",
"source /home/elephant/agv_pro_ros2/install/setup.bash",
f'ros2 topic pub --once /initialpose geometry_msgs/PoseWithCovarianceStamped "$(cat {goal_file})"',
]
with open(script, "w") as f:
f.write("\n".join(lines) + "\n")
@@ -689,9 +711,9 @@ def api_mission_init_pose():
result = subprocess.run(
[script],
capture_output=True, text=True, timeout=12,
env={**os.environ, "ROS_DOMAIN_ID": "0"}
env={**os.environ, "ROS_DOMAIN_ID": "1"}
)
logger.info(f"init_pose: rc={result.returncode}")
logger.info(f"init_pose: rc={result.returncode}, stdout={result.stdout[:200]}, stderr={result.stderr[:200]}")
return jsonify({"ok": True, "message": "初始位置已设为 (0,0,0)"})
except Exception as e:
logger.error(f"初始化位置失败: {e}")
+1 -1
View File
@@ -25,7 +25,7 @@ ARM_CONFIG = {
# ========== 地图 ==========
MAP_CONFIG = {
"map_dir": "/home/elephant/agv_pro_ros2/src/agv_pro_navigation2/map/",
"map_dir": "/home/elephant/agv_pro_ros2/install/agv_pro_navigation2/share/agv_pro_navigation2/map/",
"map_file": "map.yaml",
}
+1 -1
View File
@@ -11,7 +11,7 @@ createApp({
sequence: [],
poseForm: { name: '', photo_type: 'front', description: '' },
// 地图
mapForm: { map_dir: '/home/elephant/agv_pro_ros2/src/agv_pro_navigation2/map/', map_file: 'map.yaml' },
mapForm: { map_dir: '/home/elephant/agv_pro_ros2/install/agv_pro_navigation2/share/agv_pro_navigation2/map/', map_file: 'map.yaml' },
mapMsg: '',
mapLoaded: false,
mapImageUrl: '',