1717from typing import TYPE_CHECKING
1818
1919import numpy as np
20- from pinokin import arrays_equal_n
2120
2221from parol6 .commands ._collision_guard import guard_joint_path
2322from parol6 .commands .base import CommandBase , ExecutionStatusCode
@@ -60,6 +59,7 @@ class SegmentPlayer:
6059 "_inline_activated" ,
6160 "_settling" ,
6261 "_settle_ticks" ,
62+ "_settle_err" ,
6363 "_last_shapes_version" ,
6464 )
6565
@@ -72,6 +72,7 @@ def __init__(self, planner: MotionPlanner) -> None:
7272 self ._inline_activated : bool = False
7373 self ._settling : bool = False
7474 self ._settle_ticks : int = 0
75+ self ._settle_err : int = - 1
7576 self ._last_shapes_version : int = 0
7677
7778 @property
@@ -127,16 +128,36 @@ def tick(self, state: ControllerState) -> bool:
127128 self ._step += 1
128129 self ._settling = False
129130 return True
130- # All waypoints sent — hold MOVE at target until Position_in converges
131+ # All waypoints sent — hold MOVE at target until Position_in
132+ # converges. The tick cap gates on stall, not elapsed time:
133+ # while the firmware is still closing on the target (e.g. it
134+ # fell behind the waypoint stream under CPU starvation) the
135+ # segment stays active, so completion is never reported with
136+ # the robot still in motion.
131137 target = active .trajectory_steps [- 1 ]
132138 if not self ._settling :
133139 self ._settling = True
134140 self ._settle_ticks = 0
141+ self ._settle_err = - 1
142+ err = 0
143+ for i in range (6 ):
144+ d = int (state .Position_in [i ]) - int (target [i ])
145+ if d < 0 :
146+ d = - d
147+ if d > err :
148+ err = d
149+ if self ._settle_err < 0 or err < self ._settle_err :
150+ self ._settle_err = err
151+ self ._settle_ticks = 0
135152 self ._settle_ticks += 1
136- if (
137- arrays_equal_n (state .Position_in [:6 ], target [:6 ])
138- or self ._settle_ticks > SETTLE_MAX_TICKS
139- ):
153+ if err == 0 or self ._settle_ticks > SETTLE_MAX_TICKS :
154+ if err != 0 :
155+ logger .warning (
156+ "Segment completed %d steps short of target "
157+ "(no settle progress for %d ticks)" ,
158+ err ,
159+ SETTLE_MAX_TICKS ,
160+ )
140161 self ._settling = False
141162 self ._complete_segment (active , state )
142163 continue
0 commit comments