"""Follow a person with the base: "follow me" ... "stop" (lumi.py follow_me).
The person is a track of the assistant's Vision; `see()` gives (distance m, angle deg + left, age s) or None once the
track is gone, `people()` [(see, distance, angle, age)] of everyone in view: a track lost is swapped for a fresh one
where the person was last (re-lock). The head turns toward the person (only this task moves the body meanwhile:
head.owners), the base turns after it, so they stay in view when they walk to the side or behind. The base is driven with joy_control (one command lasts 0.5 s: a stuck loop stops the base by itself),
the arm in look and the waist at the front as for every fetch drive. Every command is checked first: where the base
and the arm would be BRAKE_S later must be clear (lidar + map, agv.clearance).
stop() from any thread: the event is set and the base is sent 0 at once
"""
importmath
importre
importthreading
importtime
importtraceback
importnumpyasnp
fromrobotimportagv,head,motion
fromtasksimportfetch
FOLLOW_GAP_M=1.0# m; keep this far from the person (camera distance); nearer: stand still
FOLLOW_MAX_MS=0.15# m/s; forward speed cap (estimate, tune live)
SPEED_GAIN=0.8# m/s per m the person is further than FOLLOW_GAP_M
ACCEL_MS2=0.4# m/s^2; speeding up at most this fast (slowing down at once)
TURN_GAIN=1.0# rad/s per rad the person is off to the side
TURN_MAX_RS=0.5# rad/s; turn speed cap (joy_control takes up to 1.0)
TURN_DEAD_DEG=5.0# deg; the person this near the middle: no turn
TURN_ONLY_DEG=30.0# deg; the person further aside: turn on the spot first, no forward
STALE_S=0.5# s; a sighting older than this: stand still and wait for a new one
LOST_S=2.0# s without a sighting -> "I lost you" (lumi.Vision drops a track after its own LOST_S, 2 s)
BRAKE_S=0.5# s; the base and the arm must be clear where this command would take them by then
ARM_CLEAR_M=fetch.ARM_CLEAR_M# m; arm points kept this far from anything the lidar / map shows
BASE_CLEAR_M=fetch.BASE_HALF_M+fetch.CLEAR_M# m; base centre kept this far, unless it gets further away
TICK_S=0.1# s between commands (joy_control wants > 2 Hz)
JOIN_S=2.0# s a new "follow me" waits for the old loop to end
RELOCK_DEG=25.0# deg; a fresh track this near the lost person's last angle is taken as them (estimate)
RELOCK_M=0.8# m; ... and this near their last distance (estimate)
HEAD_YAW_MAX=90.0# deg; the head turns toward the person up to this far (+ left; body API allows 180)
HEAD_PITCH=10.0# deg; head pitch while following, a little up toward a standing person (as "look at me")
HEAD_STEP_DEG=5.0# deg; a new head move only when the person is this far from where the head was sent
HEAD_VEL=50# speed ratio %; the head is at its full speed from 50 (audio/sing.py, measured)
HEAD_TIMEOUT_S=5# s; one head move (90 deg at ~40 deg/s takes ~2.5 s)
CHARGER=("I'm on the charger, I can't follow you from here.","충전 중이라 따라갈 수 없어요.")