Skip to content

Commit be8d1c0

Browse files
committed
fixed wait for completeion to match new return format
1 parent e3b91c9 commit be8d1c0

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

dimos/manipulation/control/coordinator_client.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -325,26 +325,32 @@ def preview_trajectory(trajectory: JointTrajectory, joint_names: list[str]) -> N
325325

326326

327327
def wait_for_completion(client: CoordinatorClient, task_name: str, timeout: float = 60.0) -> bool:
328-
"""Wait for trajectory to complete with progress display."""
328+
"""Wait for trajectory to complete by polling task state.
329+
330+
TrajectoryState is an IntEnum: IDLE=0, EXECUTING=1, COMPLETED=2, ABORTED=3, FAULT=4.
331+
"""
329332
start = time.time()
330-
last_progress = -1.0
333+
_STATE_NAMES = {0: "IDLE", 1: "EXECUTING", 2: "COMPLETED", 3: "ABORTED", 4: "FAULT"}
331334

332335
while time.time() - start < timeout:
333336
status = client.get_trajectory_status(task_name)
334-
if not status.get("active", False):
335-
state: str = status.get("state", "UNKNOWN")
336-
print(f"\nTrajectory finished: {state}")
337-
return state == "COMPLETED"
337+
if not status:
338+
print("\nCould not get trajectory status")
339+
return False
338340

339-
progress = status.get("progress", 0.0)
340-
if progress != last_progress:
341-
bar_len = 30
342-
filled = int(bar_len * progress)
343-
bar = "=" * filled + "-" * (bar_len - filled)
344-
print(f"\r[{bar}] {progress * 100:.1f}%", end="", flush=True)
345-
last_progress = progress
341+
state_val = status.get("state")
342+
state_name = _STATE_NAMES.get(state_val, f"UNKNOWN({state_val})") # type: ignore[arg-type]
346343

347-
time.sleep(0.05)
344+
if state_val in (0, 2): # IDLE or COMPLETED
345+
print(f"\nTrajectory finished: {state_name}")
346+
return True
347+
if state_val in (3, 4): # ABORTED or FAULT
348+
print(f"\nTrajectory failed: {state_name}")
349+
return False
350+
# state_val == 1 means EXECUTING, keep polling
351+
elapsed = time.time() - start
352+
print(f"\r Executing... ({elapsed:.1f}s)", end="", flush=True)
353+
time.sleep(0.1)
348354

349355
print("\nTimeout waiting for trajectory")
350356
return False
@@ -476,12 +482,12 @@ def run(self) -> None:
476482

477483
def status(self) -> None:
478484
"""Show task status."""
485+
_STATE_NAMES = {0: "IDLE", 1: "EXECUTING", 2: "COMPLETED", 3: "ABORTED", 4: "FAULT"}
479486
status = self._client.get_trajectory_status(self._current_task)
487+
state_val = status.get("state")
488+
state_name = _STATE_NAMES.get(state_val, f"UNKNOWN({state_val})") # type: ignore[arg-type]
480489
print(f"\nTask: {self._current_task}")
481-
print(f" Active: {status.get('active', False)}")
482-
print(f" State: {status.get('state', 'UNKNOWN')}")
483-
if "progress" in status:
484-
print(f" Progress: {status['progress'] * 100:.1f}%")
490+
print(f" State: {state_name} ({state_val})")
485491

486492
def cancel(self) -> None:
487493
"""Cancel active trajectory."""

dimos/manipulation/manipulation_blueprints.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def _make_xarm6_config(
175175
max_acceleration=2.0,
176176
joint_name_mapping=joint_mapping,
177177
coordinator_task_name=coordinator_task,
178+
home_joints=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
178179
)
179180

180181

@@ -273,6 +274,7 @@ def _make_piper_config(
273274
max_acceleration=2.0,
274275
joint_name_mapping=joint_mapping,
275276
coordinator_task_name=coordinator_task,
277+
home_joints=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
276278
)
277279

278280

0 commit comments

Comments
 (0)