Improve charger routing and drive checks near obstacles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 10:02:29 +09:00
co-authored by Claude Opus 5.5
parent 300139949f
commit 161c598e10
5 changed files with 50 additions and 9 deletions
+2 -2
View File
@@ -1498,8 +1498,6 @@ def _supervise():
pass
threading.Thread(target=_supervise, daemon=True).start()
@app.get("/health", tags=["status"])
def health():
return {"ok": True}
@@ -1528,4 +1526,6 @@ if __name__ == "__main__":
camview.ensure_running() # the camera service owns both cameras
threading.Thread(target=start_services, daemon=True).start()
threading.Thread(target=_drive_log, daemon=True).start()
# the supervisor here, not on import: a test importing this module started real lumi.py processes (2026-10-28)
threading.Thread(target=_supervise, daemon=True).start()
uvicorn.run(app, host="0.0.0.0", port=PORT, log_level="warning")
+20 -3
View File
@@ -229,7 +229,8 @@ up when someone says "Hi Lumi"."""
ACTIONS = """
You can also move. Decide if the visitor asks you to do something:
- "go_to": drive to a place. "target" must be one of these marker names: {markers}.
"home", "charger", "charging station" and "go back" mean "home". Map spoken names to the closest marker
"home" and "go back" mean "home"; "charger", "charging station" mean the marker "charge" when it is listed,
else "home". Map spoken names to the closest marker
name (e.g. "point one" or "포인트 원" -> "point1"). If no marker fits, use "none" and say which places you know.
- "look": turn your head. "target" is one of: left, right, center, up, down.
- "wave": wave your hand.
@@ -350,8 +351,8 @@ def _chat(messages, fmt=None, temperature=0.3):
ACTIONS_STREAM = """
You can also move. Decide if the visitor asks you to do something:
- go_to <marker>: drive to a place. Marker names: {markers}. "home", "charger", "charging station" mean
home. Map spoken names to the closest marker name (e.g. "point one" -> p1); the same place said in the other
- go_to <marker>: drive to a place. Marker names: {markers}. "home" means home; "charger", "charging
station" mean the marker "charge" when it is listed, else home. Map spoken names to the closest marker name (e.g. "point one" -> p1); the same place said in the other
language or letters is that marker ("photo zone" -> 포토존, "레지스트레이션" -> Registration, "the meeting room" ->
회의실), but a different name or number is not.
- come: come to the visitor ("come here", "come to me", "come closer", "이리 와", "여기로 와").
@@ -1467,6 +1468,9 @@ def _intent(text, markers=()):
if action == "go_home":
if re.search(r"(^|\s)(나|저|우리|저희)(는|도)?\s", t):
return None # "나 이제 집에 가": the visitor goes home
c = charger(markers)
if c and re.search(_CHARGER_WORD, t):
return ("go_to", c) # "let's go charger" with a charge marker on the map
return ("go_to", "home") if "home" in markers else None
if action == "go_point":
g = m.groups() + (None,) * 5
@@ -1854,6 +1858,13 @@ def _recase(t, text):
# ---------- fetch tasks (docs/16 §4): strict parsing, nothing is guessed ----------
_HERE = r"here|me|여기|이쪽|나한테|저한테|나에게|저에게"
_HOME = r"home|charger|charging station|dock|충전기|충전소"
_CHARGER_WORD = r"\bcharg(?:er|ing)\b|\bgo (?:re)?charge\b|충전|차지하러" # the charger, not home, when the map has one
def charger(markers):
"""The map's charger marker ("charge"), None when there is none and the charger is home."""
return next((m for m in markers if re.fullmatch(r"charg(?:e|er|ing)", m.lower())), None)
_TABLE = r"table|테이블|책상|탁자"
_PLACE_WORD = rf"(?:point|marker|포인트)\s*(\d+)|(?<![a-z])p\s?(\d+)(?!\d)|(\d+)\s*번|(?<![a-z])({_HOME}|{_HERE})(?![a-z0-9_])"
# ^ "dock" alone is home, "dock2" is the marker dock2
@@ -1913,6 +1924,8 @@ def _resolve(m, markers):
word = next((g for g in m.groups()[3:] if g), "")
if re.fullmatch(_HERE, word):
return "here"
if re.fullmatch(_HOME, word) and re.search(_CHARGER_WORD, word) and charger(markers):
return charger(markers)
name = f"p{n}" if n else ("home" if re.fullmatch(_HOME, word) else word)
return wording.marker(name, markers)
@@ -1998,6 +2011,10 @@ def named_place(text, marker, markers):
"""True when the words name this marker ("p1", "point one", "피원", "1번", "home", "the charger", "go back").
A one-letter marker ("a") only after "point" / "marker" or as the last word of "to a": not the article."""
t = _norm(text, markers)
if charger(markers) and re.search(_CHARGER_WORD, t):
if marker == charger(markers):
return True
t = re.sub(_CHARGER_WORD, " ", t) # the charger is not home here
if marker == "home" and re.search(r"\bgo back\b|돌아가|\b(?:home|dock|charger|charging station)\b|집(?:으로|에)|"
r"충전|도크", t):
return True
+15
View File
@@ -86,6 +86,18 @@ def marker_positions():
return xy
def _path_info():
"""The base's planned path as "N points, from (x, y) to (x, y)", or why it can't be read."""
try:
path = agv.request("/api/get_planned_path").get("results", {}).get("path") or []
except (ConnectionError, OSError) as e:
return f"not read ({e})"
if not path:
return "empty"
a, b = path[0], path[-1]
return f"{len(path)} points, from ({a[0]:.2f}, {a[1]:.2f}) to ({b[0]:.2f}, {b[1]:.2f})"
def watch(log=print):
d, down = DriveLog(marker_positions()), False
while True:
@@ -102,6 +114,9 @@ def watch(log=print):
down = False
for line in d.update(st, time.time()):
log(line)
if "seems stuck" in line and not d.drive.get("why"):
d.drive["why"] = True # once per drive: what the base planned and how it runs
log(f" base {st.get('running_status')}, planned path {_path_info()}")
time.sleep(POLL_S)
+9 -4
View File
@@ -2771,16 +2771,21 @@ def instruct(new_steps):
def line_hits(dist):
"""Like turn_hits for a straight drive of `dist` m (+ forward): the map point where the arm would come closer than
ARM_CLEAR_M to something the lidar or the map shows, checked every PROBE_STEP_M; None when clear."""
ARM_CLEAR_M to something the lidar or the map shows, checked every PROBE_STEP_M; None when clear. As in
follow.blocked only coming nearer counts: an arm point already near something may drive away from it."""
if arm_yaw() is None:
return None
pts, (x, y, th) = arm_points(), agv.pose()
R, u = _rot(math.degrees(th)), np.array([math.cos(th), math.sin(th)])
start = [np.array([x, y]) + R @ p for p in pts]
now = [agv.clearance(*w) for w in start]
n = max(1, math.ceil(abs(dist) / PROBE_STEP_M))
for k in range(1, n + 1):
for p in pts:
w = np.array([x, y]) + R @ p + u * dist * k / n
if agv.clearance(*w) < ARM_CLEAR_M:
for w0, c0 in zip(start, now):
w = w0 + u * dist * k / n
near = agv.clearance(*w)
if near < ARM_CLEAR_M and near < c0:
log(f"arm point ({w0[0]:.2f}, {w0[1]:.2f}) {c0:.2f} m clear now, {near:.2f} m after {dist * k / n:+.2f} m")
return w
return None
+4
View File
@@ -607,6 +607,10 @@ assert fetch._turn(30) is False and not any(c[0] == "go_point" for c in calls),
room["clear"] = lambda x, y: 1.0
assert fetch._turn(30) is True and any(c[0] == "go_point" for c in calls)
assert fetch.turn_hits(90) is None
# the arm already near a wall in front (+x): driving back takes it away and is let through, forward is not
room["clear"] = lambda x, y: max(0.0, 0.4 - x)
assert fetch.line_hits(-1.0) is None and fetch.line_hits(1.0) is not None
room["clear"] = lambda x, y: 1.0
# the torso camera sees something where the arm will be (a table top's edge the lidar misses): no turn
real_points, real_extr = skills.surface_points, skills.objects.base_from_camera
skills.objects.base_from_camera = lambda: np.eye(4)