Skip to content

Commit 41f09fa

Browse files
authored
fix(converter): skip identity and ik failure steps (#305)
1 parent 99c03ec commit 41f09fa

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

python/rcs/lerobot_joint_converter.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import warnings
34
from dataclasses import dataclass
45
from pathlib import Path
56
from typing import Any, Iterable
@@ -269,7 +270,7 @@ def _build_observation_state(self, row: pd.Series) -> np.ndarray:
269270

270271
return np.concatenate(vectors).astype(np.float32)
271272

272-
def _convert_action_to_joint_space(self, row: pd.Series) -> np.ndarray:
273+
def _convert_action_to_joint_space(self, row: pd.Series) -> np.ndarray | None:
273274
actions = []
274275
for robot_key in self.robot_keys:
275276
observation_joints = row[f"observation_joints_{robot_key}"]
@@ -309,8 +310,9 @@ def _convert_action_to_joint_space(self, row: pd.Series) -> np.ndarray:
309310
target_pose, observation_joints_vec, tcp_offset=self.tcp_offset
310311
)
311312
if ik_joints is None:
312-
msg = f"IK failed for robot '{robot_key}' at step {row['step']}"
313-
raise ValueError(msg)
313+
msg = f"IK failed for robot '{robot_key}' at step {row['step']}, ignoring step"
314+
warnings.warn(msg, stacklevel=1)
315+
return None
314316
arm_action_vec = np.asarray(ik_joints, dtype=np.float32)
315317

316318
actions.append(np.concatenate([arm_action_vec, action_gripper_vec]).astype(np.float32))
@@ -329,11 +331,13 @@ def _prepare_transition_table(self, table: pd.DataFrame) -> pd.DataFrame:
329331
df["observation_state"] = df.apply(self._build_observation_state, axis=1)
330332
df["action_vector"] = df.apply(self._convert_action_to_joint_space, axis=1)
331333

334+
df = df[df["action_vector"].notna()] # noqa: PD901
335+
332336
prev_action: np.ndarray | None = None
333337
keep_mask = []
334338
for action_vec in df["action_vector"]:
335339
assert isinstance(action_vec, np.ndarray)
336-
keep_mask.append(prev_action is None or not np.array_equal(action_vec, prev_action))
340+
keep_mask.append(prev_action is None or not np.allclose(action_vec, prev_action, atol=1e-4, rtol=0))
337341
prev_action = action_vec
338342

339343
return df.loc[keep_mask].reset_index(drop=True)

0 commit comments

Comments
 (0)