-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeriesMoveToAction.py
More file actions
87 lines (69 loc) · 2.62 KB
/
Copy pathSeriesMoveToAction.py
File metadata and controls
87 lines (69 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
SeriesMoveToAction — 多目标点自主导航移动
功能:机器人依次经过多个目标坐标点,支持避障
注意:字段名为 targets(不是 target_points)
"""
import time
import requests
# ── 配置 ──────────────────────────────────────────────
ROBOT_IP = "10.160.129.252"
PORT = 1448
BASE_URL = f"http://{ROBOT_IP}:{PORT}/api/core/motion/v1/actions"
# 绕过系统代理(避免 127.0.0.1:7890 超时)
SESSION = __import__("requests").Session()
SESSION.trust_env = False
# 目标点列表(按顺序经过)
TARGET_POINTS = [
{"x": 14.8, "y": -4.2, "z": 0},
{"x": 12.8, "y": -5.6, "z": 0},
{"x": 9.5, "y": -4.2, "z": 0},
]
SPEED_RATIO = 0.8
FAIL_RETRY = 2
POLL_INTERVAL_S = 1.0
# ──────────────────────────────────────────────────────
def build_payload():
return {
"action_name": "agent.actions.SeriesMoveToAction",
"options": {
"targets": TARGET_POINTS,
"move_options": {
"mode": 0,
"flags": [],
"speed_ratio": SPEED_RATIO,
"fail_retry_count": FAIL_RETRY,
},
},
}
def poll_until_done(action_id):
url = f"{BASE_URL}/{action_id}"
while True:
resp = SESSION.get(url, timeout=5)
data = resp.json()
status = data["state"]["status"]
result = data["state"]["result"]
reason = data["state"].get("reason", "")
if status == 4:
if result == 0:
print(f"[完成] action_id={action_id} 已经过全部 {len(TARGET_POINTS)} 个目标点")
else:
print(f"[失败] action_id={action_id} result={result} reason={reason}")
return result == 0
status_desc = {0: "初始化", 1: "运行中"}.get(status, str(status))
print(f"[{status_desc}] action_id={action_id} ...")
time.sleep(POLL_INTERVAL_S)
def main():
payload = build_payload()
print(f"[SeriesMoveToAction] 共 {len(TARGET_POINTS)} 个目标点")
for i, p in enumerate(TARGET_POINTS):
print(f" {i+1}. ({p['x']}, {p['y']})")
resp = SESSION.post(BASE_URL, json=payload, timeout=5)
if resp.status_code != 200:
print(f"[错误] HTTP {resp.status_code}: {resp.text}")
return
data = resp.json()
action_id = data["action_id"]
print(f"[已创建] action_id={action_id}")
poll_until_done(action_id)
if __name__ == "__main__":
main()