地图路径规划 HTTP API 服务
服务健康状态检查接口
{
"status": "ok"
}
在地图图像上规划从起点(绿色)到终点(红色)的避障路径,返回路径坐标和可视化图像。
| Header | 值 | 说明 |
|---|---|---|
Content-Type |
application/json |
请求内容类型 |
| 参数名 | 类型 | 字段默认值 | 说明 | 可选值 |
|---|---|---|---|---|
| image_url必填 | string | — | 公开图片 URL | 有效的 HTTP/HTTPS URL |
| path_mode可选 | string | "safe" | 路径规划预设模式。模式会先填充一组参数,随后请求中显式传入的底层参数会覆盖模式预设;旧版调用不传该字段仍可使用。 | legacy, safe, corridor_center, wide_clearance, terminal_wide, s_bend, s_bend_tight |
| passage_mode可选 | string | "auto" | 通过侧偏好预设,可与 path_mode 组合使用;同样可被 passage_preference / passage_bias 显式覆盖。 | auto, prefer_left, prefer_right, prefer_center |
| top_left_x | string | "-16.1" | 地图左上角像素 (0,0) 对应的世界 X 坐标(经度) | 任意浮点数 |
| top_left_y | string | "20.71" | 地图左上角像素 (0,0) 对应的世界 Y 坐标(纬度) | 任意浮点数 |
| bottom_right_x | string | "36.45" | 地图右下角像素 (W-1,H-1) 对应的世界 X 坐标(经度) | 任意浮点数 |
| bottom_right_y | string | "-12.24" | 地图右下角像素 (W-1,H-1) 对应的世界 Y 坐标(纬度) | 任意浮点数 |
| safety | string | "0.09" | 障碍物安全距离(世界单位)。值越小越贴近障碍物 | 正浮点数,推荐 0.01~1.0 |
| segments | string | "10" | S 曲线路径的段数。越多越平滑但计算越慢 | 正整数,推荐 5~50 |
| lateral | string | "0.35" | S 曲线横向偏移量(世界单位),控制曲线摆动幅度 | 正浮点数 |
| planner | string | "auto" | 路径规划算法模式 | auto, grid, zigzag |
| grid_max_dim | string | "320" | 内部规划网格最大尺寸(像素→网格单元)。值越大越精细越慢 | 正整数,32~2048 |
| planning_upscale | string | "1" | NEAREST 放大障碍物 mask 的倍数,使细墙占更多格子 | 正整数,1~16 |
| force_s_bend | string | "false" | 强制逐障碍组 S 弯绕行,绕过一个障碍组后尽量回到主轴。注意:当此参数为 true 时,planner 参数会被强制设为 "zigzag",并保留旧版 S 弯语义,不执行 hard_clearance 强失败拦截 | true/false/1/0 |
| tight_mode | string | "false" | 紧贴模式。为 true 时路径紧贴障碍物边缘(需配合 force_s_bend 使用) | true/false/1/0 |
| simplify_target | string | "auto" | 路径点简化目标数量。默认 auto 自动保留约 8-10 个点,设为 0 或 "all" 则保留所有点不简化 | 整数、"auto" 或 "all" |
| show_waypoints | string | "false" | 是否在叠加图像上显示黄色轨迹点标记(用于调试) | true/false/1/0 |
| hard_clearance | string|null | null | 不可降级的硬安全距离;不满足时安全优先模式会返回失败。默认 path_mode=safe 会预设为 "0.09",显式传入可覆盖。 |
世界坐标单位,例如 "0.09" |
| center_danger_corridors | string | "false" | 是否在狭窄/危险通道中尝试把途径点移到左右障碍中间。默认 path_mode=safe 会预设为 "true"。 |
true/false/1/0 |
| corridor_scan_px | string | "96" | 危险通道居中时向左右扫描障碍的像素距离。默认 path_mode=safe 会预设为 "140"。 |
正数,例如 "140" |
| corridor_max_width_px | string | "128" | 只对宽度不超过该值的通道做居中处理。默认 path_mode=safe 会预设为 "180"。 |
正数,例如 "180" |
| passage_preference | string | "auto" | 软性通过侧偏好。通常建议使用 passage_mode,只有高级调用才直接传该字段。 |
auto, image_left, image_right, left, right, center |
| passage_bias | string | "0" | 通过侧偏好的权重。passage_mode=prefer_left/right/center 会预设为 "4"。 |
非负数,例如 "4" |
| soft_clearance | string | "0" | 软安全距离目标,只影响路径偏好,不作为硬性通行约束。默认 path_mode=safe 会预设为 "0.16"。 |
世界坐标单位,例如 "0.15" |
| soft_clearance_bias | string | "0" | 软安全距离权重,越大越偏向宽裕区域。默认 path_mode=safe 会预设为 "2"。 |
非负数,例如 "2" |
| terminal_soft_clearance | string | "0" | 仅在终段生效的软安全距离,用于让最后一个障碍附近的曲线更大。默认 path_mode=terminal_wide 会预设为 "1.0"。 |
世界坐标单位,例如 "0.2" |
| terminal_soft_clearance_bias | string | "0" | 终段软安全距离权重。默认 path_mode=terminal_wide 会预设为 "40"。 |
非负数,例如 "3" |
| terminal_soft_clearance_start | string | "0.72" | 终段软安全距离从起终点连线的哪个比例开始渐入,避免影响中段点位。默认 path_mode=terminal_wide 会预设为 "0.78"。 |
0 到 0.98 |
| interpretation_json可选 | string | null | 地图解释配置 JSON 字符串,定义 obstacle/start/end 分类规则 | 有效的 JSON 字符串 |
注意:表格中的“字段默认值”是底层字段在没有模式预设时的默认值。实际调用会先应用 path_mode / passage_mode 的模式预设,
再用请求中显式传入的同名字段覆盖。因此在默认 path_mode=safe 下,部分字段的实际生效值会不同,例如
hard_clearance=0.09、center_danger_corridors=true、soft_clearance=0.16。
推荐新调用只传 path_mode / passage_mode 表达意图;一周前的旧调用形式仍然兼容。
服务端执行顺序为:path_mode 预设 → passage_mode 预设 → 请求中显式传入的底层参数覆盖。
因此旧字段如 planner、force_s_bend、hard_clearance、soft_clearance 仍然有效。
| path_mode | 适用场景 | 主要预设 |
|---|---|---|
legacy |
尽量保持旧版默认参数,不主动启用新的安全预设。 | planner=auto,其余底层参数使用原始默认值。 |
safe(默认) |
默认安全优先。适合大多数地图,优先保证硬安全距离和基础避障自然度。 | planner=auto, hard_clearance=0.09, center_danger_corridors=true, soft_clearance=0.16, soft_clearance_bias=2, simplify_target=auto |
corridor_center |
左右障碍夹通道明显,需要更积极地在狭窄通道居中。 | 继承 safe,并使用更大的 corridor_scan_px=160。 |
wide_clearance |
场地较宽,希望路线离障碍更远,但不把软距离作为硬失败条件。 | 继承 safe,并提高 soft_clearance=0.28, soft_clearance_bias=3。 |
terminal_wide |
终点或最后一个障碍附近转向空间不足,需要末段曲线更大。 | 继承 safe,并启用 terminal_soft_clearance=1.0, terminal_soft_clearance_bias=40, terminal_soft_clearance_start=0.78。 |
s_bend |
业务要求强制 S 弯,但不要求紧贴障碍。 | planner=zigzag, force_s_bend=true, tight_mode=false。保留旧版 S 弯语义。 |
s_bend_tight |
业务要求强制 S 弯且贴近障碍通过。 | planner=zigzag, force_s_bend=true, tight_mode=true。不执行 hard_clearance 强失败拦截。 |
| passage_mode | 适用场景 | 主要预设 |
|---|---|---|
auto(默认) | 不指定通过侧,由规划器自动选择。 | 不设置额外偏好。 |
prefer_left | 希望从图像左侧通过。 | passage_preference=image_left, passage_bias=4 |
prefer_right | 希望从图像右侧通过。 | passage_preference=image_right, passage_bias=4 |
prefer_center | 希望尽量居中通过。 | passage_preference=center, passage_bias=4 |
200 成功(业务错误通过响应体 ok=false 表示) 400 请求参数错误 404 Artifact 不存在或已过期
成功时返回完整的路径规划结果 JSON:
{
"ok": true,
"error_message": "",
// --- 模式信息 ---
"mode": "deterministic",
"path_mode": "safe",
"passage_mode": "auto",
"planner": "grid_astar",
"planner_mode_requested": "auto",
"force_s_bend": false,
"tight_mode": false,
"simplify_target": "auto",
"show_waypoints": false,
// --- 图像信息 (Object) ---
"image": {
"width": 800, // 图像宽度(像素)
"height": 600 // 图像高度(像素)
},
// --- 坐标角点 (Object) ---
"corners": {
"top_left": [-16.1, 20.71], // 左上角世界坐标 [X, Y]
"bottom_right": [36.45, -12.24] // 右下角世界坐标 [X, Y]
},
// --- 起点终点坐标 (Object) ---
"start_world": {
"X": ...,
"Y": ...
},
"end_world": {
"X": ...,
"Y": ...
},
// --- 路径轨迹 (Array of Object) ---
"trajectory": [
{ "X": -10.5, "Y": 15.2 },
{ "X": -8.3, "Y": 14.8 },
// ... 更多路径点
],
"waypoints": [...], // 与 trajectory 相同
"original_path": [...], // 原始直线路径(参考用)
"waypoint_count": 25,
// --- 规划参数 ---
"obstacle_extraction": {
"supersample": 2.0,
"dilate": 0
},
"interpretation_applied": null | Object,
"grid_max_dim": 320,
"planning_upscale": 1,
"planning_upscale_applied": 1,
"chord_bias": 0.42,
"slalom_corridor": true,
// --- 文件下载链接 ---
"artifact_id": "abc123xyz",
"overlay_preview_url": "http://host/v1/artifacts/abc123xyz/overlay.png",
"path_csv_url": "http://host/v1/artifacts/abc123xyz/path.csv",
"overlay_image_url": "...", // overlay_preview_url 的别名
"csv_online_url": "...", // path_csv_url 的别名
"visualization_png": "/path/to/overlay.png"
}
{
"ok": false,
"error_message": "download image failed: ..." | "invalid numeric parameter: ...",
"mode": "deterministic",
"planner": "",
"waypoints": [],
"trajectory": []
}
获取路径规划可视化叠加图的 PNG 图像文件。使用 Content-Disposition: inline 可直接在浏览器预览。
| 参数名 | 类型 | 说明 |
|---|---|---|
| artifact_id | string | 规划接口返回的 artifact 标识符 |
| Header | 值 | 说明 |
|---|---|---|
Content-Type |
image/png |
PNG 图像格式 |
Content-Disposition |
inline |
内联显示(浏览器可直接查看) |
Cache-Control |
public, max-age=300 |
缓存 5 分钟 |
200 PNG 图像文件 404 Artifact 不存在或已过期
获取路径坐标的 CSV 文件。每行包含一个路径点的 X, Y 世界坐标。使用 Content-Disposition: attachment 触发下载。
| 参数名 | 类型 | 说明 |
|---|---|---|
| artifact_id | string | 规划接口返回的 artifact 标识符 |
| Header | 值 | 说明 |
|---|---|---|
Content-Type |
text/csv; charset=utf-8 |
CSV 文本格式 |
Content-Disposition |
attachment |
附件下载(浏览器会下载文件) |
X1,Y1
X2,Y2
X3,Y3
...
200 CSV 文件 404 Artifact 不存在或已过期
interpretation_json 用来告诉服务端“哪些像素是障碍物、哪个像素区域是起点、哪个像素区域是终点”。
它是一个 JSON 字符串,不是 JSON 对象;如果不传,服务端使用默认解释规则:黑色/深色为障碍物,绿色为起点,红色为终点。
该配置支持“局部覆盖”:只传其中一段时,其他段会继续使用默认值。例如只想指定起终点像素,可以只传 start 和 end。
像素坐标使用 PIL/图像坐标系:左上角为 (0,0),向右为 X 正方向,向下为 Y 正方向。
{
"version": 1,
"obstacle": {
"mode": "rgb_dark",
"max_channel": 54,
"min_alpha": 16
},
"start": {
"mode": "green_dominant",
"g_min": 80,
"delta": 20
},
"end": {
"mode": "red_dominant",
"r_min": 100,
"delta": 20
}
}
默认分类顺序为:透明像素忽略 → 障碍物 → 起点 → 终点 → 其他。也就是说,如果某个像素同时满足障碍物和起点规则,会先被当作障碍物。
{
"version": 1,
// --- 障碍物配置 ---
"obstacle": {
"mode": "rgb_dark" | "luminance_below" | "luminance_above",
"max_channel": 54, // rgb_dark 模式: R,G,B 都 <= 此值为障碍物
"threshold": 30, // luminance 模式: 亮度阈值
"min_alpha": 16 // 最小透明度,低于此值被忽略
},
// --- 起点配置 ---
"start": {
"mode": "green_dominant" | "pixel",
"g_min": 80, // green_dominant: G >= 此值
"delta": 20, // green_dominant: G > R+delta 且 G > B+delta
"x": 100, // pixel 模式: 像素 X 坐标
"y": 200 // pixel 模式: 像素 Y 坐标
},
// --- 终点配置 ---
"end": {
"mode": "red_dominant" | "pixel",
"r_min": 100, // red_dominant: R >= 此值
"delta": 20, // red_dominant: R > G+delta 且 R > B+delta
"x": 500, // pixel 模式: 像素 X 坐标
"y": 300 // pixel 模式: 像素 Y 坐标
}
}
因为请求体本身已经是 JSON,所以 interpretation_json 的值需要是转义后的字符串。
{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"interpretation_json": "{\"start\":{\"mode\":\"pixel\",\"x\":306,\"y\":268},\"end\":{\"mode\":\"pixel\",\"x\":352,\"y\":420}}"
}
| 场景 | 建议配置 | 说明 |
|---|---|---|
| 图片已有绿色起点、红色终点、黑色障碍 | 不传 interpretation_json |
使用默认规则即可。 |
| 起点/终点颜色不明显或被压缩 | start/end.mode=pixel |
直接指定起终点像素坐标,最稳定。 |
| 障碍不是纯黑,但整体很暗 | obstacle.mode=luminance_below |
通过亮度阈值识别深色障碍。 |
| 透明背景或半透明标记干扰 | 调整 obstacle.min_alpha |
透明度低于该值的像素会被忽略。 |
| 模式 | 说明 |
|---|---|
rgb_dark |
R、G、B 三个通道都 <= max_channel 的像素被识别为障碍物(默认) |
luminance_below |
亮度(0.299*R + 0.587*G + 0.114*B)低于 threshold 的像素为障碍物 |
luminance_above |
亮度高于 threshold 的像素为障碍物 |
{
"version": 1,
"obstacle": {
"mode": "luminance_below",
"threshold": 30,
"min_alpha": 16
},
"start": {
"mode": "green_dominant",
"g_min": 80,
"delta": 20
},
"end": {
"mode": "red_dominant",
"r_min": 100,
"delta": 20
}
}
curl -X POST http://localhost:8788/v1/plan/deterministic \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24"
}'
不传 path_mode 时默认使用 safe,会自动启用硬安全距离、危险通道居中和软安全距离预设。
curl -X POST http://localhost:8788/v1/plan/deterministic \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"path_mode": "terminal_wide",
"passage_mode": "prefer_right"
}'
curl -X POST http://localhost:8788/v1/plan/deterministic \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"path_mode": "s_bend_tight"
}'
curl -X POST http://localhost:8788/v1/plan/deterministic \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"path_mode": "legacy",
"safety": "0.09",
"planner": "auto",
"segments": "10",
"lateral": "0.35"
}'
legacy 不主动启用新的安全预设,适合需要复现旧接口默认行为的调用方。
curl -X POST http://localhost:8788/v1/plan/deterministic \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"planner": "auto",
"force_s_bend": "true",
"tight_mode": "true"
}'
旧字段仍然生效。服务端会识别 force_s_bend=true 并按旧版 S 弯语义处理。
curl -X POST http://localhost:8788/v1/plan/deterministic \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"path_mode": "safe",
"passage_mode": "prefer_right",
"hard_clearance": "0.12",
"soft_clearance": "0.24",
"show_waypoints": "true"
}'
模式先提供预设,显式传入的 hard_clearance、soft_clearance、show_waypoints 会覆盖模式默认值。
curl -X POST http://localhost:8788/v1/plan/deterministic \
-H "Content-Type: application/json" \
-d '{
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"path_mode": "safe",
"interpretation_json": "{\"start\":{\"mode\":\"pixel\",\"x\":306,\"y\":268},\"end\":{\"mode\":\"pixel\",\"x\":352,\"y\":420}}"
}'
import requests
response = requests.post(
"http://localhost:8788/v1/plan/deterministic",
json={
"image_url": "https://example.com/map.png",
"top_left_x": "-16.1",
"top_left_y": "20.71",
"bottom_right_x": "36.45",
"bottom_right_y": "-12.24",
"path_mode": "safe",
"passage_mode": "auto"
}
)
result = response.json()
print(result["overlay_preview_url"]) # 获取可视化图
print(result["path_csv_url"]) # 获取CSV下载链接