AlexWortega commited on
Commit
3bd2402
·
verified ·
1 Parent(s): 8fe6fb5

Upload tinyvla2/scripts/replay_libero_canon.py with huggingface_hub

Browse files
tinyvla2/scripts/replay_libero_canon.py CHANGED
@@ -26,11 +26,19 @@ def main():
26
  ap.add_argument("--episodes", type=int, default=5)
27
  ap.add_argument("--grip-mode", default="threshold", choices=["threshold", "linear", "gt"])
28
  ap.add_argument("--raw", action="store_true", help="replay raw GT actions instead (control)")
 
 
 
 
 
 
29
  args = ap.parse_args()
30
 
31
  from lerobot.datasets.lerobot_dataset import LeRobotDataset, LeRobotDatasetMetadata
32
  from lerobot.envs.factory import make_env, make_env_config
33
 
 
 
34
  from tinyvla.data.canonical import CanonicalChunkStore
35
 
36
  meta = LeRobotDatasetMetadata("libero_local", root=ROOT)
@@ -78,9 +86,27 @@ def main():
78
  tid, env = env_by_task[task]
79
  obs, _ = env.reset(seed=0)
80
  ep_succ = False
 
81
  for idx in range(s, e - 1):
82
  if args.raw:
83
  act = all_actions[idx]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  else:
85
  # chunk[1] is the motion caused by the action at this frame
86
  act = decode(store.chunk_for(ep, idx - s)[1], all_actions[idx][6])
@@ -96,7 +122,7 @@ def main():
96
  succ += int(ep_succ)
97
  print(f"ep {ep} (task {tid}): {'SUCCESS' if ep_succ else 'fail'} | {task[:55]}", flush=True)
98
 
99
- tag = "RAW GT" if args.raw else f"decoded canonical (grip={args.grip_mode})"
100
  print(f"\n{tag} replay success: {succ}/{replayed}")
101
 
102
 
 
26
  ap.add_argument("--episodes", type=int, default=5)
27
  ap.add_argument("--grip-mode", default="threshold", choices=["threshold", "linear", "gt"])
28
  ap.add_argument("--raw", action="store_true", help="replay raw GT actions instead (control)")
29
+ ap.add_argument("--decode", default="scaled", choices=["scaled", "servo"],
30
+ help="scaled: per-step delta x fitted gain (open loop). "
31
+ "servo: integrate deltas into a desired pose and command the "
32
+ "error against the MEASURED pose (closes the controller lag)")
33
+ ap.add_argument("--kp", type=float, default=120.0)
34
+ ap.add_argument("--kr", type=float, default=12.0)
35
  args = ap.parse_args()
36
 
37
  from lerobot.datasets.lerobot_dataset import LeRobotDataset, LeRobotDatasetMetadata
38
  from lerobot.envs.factory import make_env, make_env_config
39
 
40
+ from scipy.spatial.transform import Rotation
41
+
42
  from tinyvla.data.canonical import CanonicalChunkStore
43
 
44
  meta = LeRobotDatasetMetadata("libero_local", root=ROOT)
 
86
  tid, env = env_by_task[task]
87
  obs, _ = env.reset(seed=0)
88
  ep_succ = False
89
+ des_p, des_R = None, None
90
  for idx in range(s, e - 1):
91
  if args.raw:
92
  act = all_actions[idx]
93
+ elif args.decode == "servo":
94
+ # integrate the canonical deltas into an absolute desired EE pose,
95
+ # then command the error against what the arm actually reached
96
+ d = store.chunk_for(ep, idx - s)[1]
97
+ rs = obs["robot_state"]
98
+ cur_p = np.asarray(rs["eef"]["pos"]).flatten()
99
+ cur_R = Rotation.from_quat(np.asarray(rs["eef"]["quat"]).flatten())
100
+ if des_p is None:
101
+ des_p, des_R = cur_p.copy(), cur_R
102
+ des_p = des_p + d[:3]
103
+ des_R = Rotation.from_rotvec(d[3:6]) * des_R
104
+ act = np.zeros(7, dtype=np.float32)
105
+ act[:3] = args.kp * (des_p - cur_p)
106
+ act[3:6] = args.kr * (des_R * cur_R.inv()).as_rotvec()
107
+ act[6] = (all_actions[idx][6] if args.grip_mode == "gt"
108
+ else (-1.0 if d[6] > fit["grip_threshold"] else 1.0))
109
+ act = np.clip(act, -1, 1)
110
  else:
111
  # chunk[1] is the motion caused by the action at this frame
112
  act = decode(store.chunk_for(ep, idx - s)[1], all_actions[idx][6])
 
122
  succ += int(ep_succ)
123
  print(f"ep {ep} (task {tid}): {'SUCCESS' if ep_succ else 'fail'} | {task[:55]}", flush=True)
124
 
125
+ tag = "RAW GT" if args.raw else f"decoded canonical ({args.decode}, grip={args.grip_mode})"
126
  print(f"\n{tag} replay success: {succ}/{replayed}")
127
 
128