Add the final programs of 7 coding agents on all 20 tasks (420 sessions) (part 2)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- policies/drawer_top_open/kimi31pro-s1/episodes.csv +101 -0
- policies/drawer_top_open/kimi31pro-s1/policy.py +143 -0
- policies/drawer_top_open/kimi31pro-s2/episodes.csv +101 -0
- policies/drawer_top_open/kimi31pro-s2/policy.py +178 -0
- policies/drawer_top_open/kimi31pro-s3/episodes.csv +101 -0
- policies/drawer_top_open/kimi31pro-s3/policy.py +67 -0
- policies/drawer_top_open/opus-s1/episodes.csv +101 -0
- policies/drawer_top_open/opus-s1/policy.py +280 -0
- policies/drawer_top_open/opus-s2/episodes.csv +101 -0
- policies/drawer_top_open/opus-s2/g1kin.py +93 -0
- policies/drawer_top_open/opus-s2/handles.py +34 -0
- policies/drawer_top_open/opus-s2/policy.py +281 -0
- policies/drawer_top_open/opus-s3/episodes.csv +101 -0
- policies/drawer_top_open/opus-s3/headcam.py +33 -0
- policies/drawer_top_open/opus-s3/kin.py +79 -0
- policies/drawer_top_open/opus-s3/policy.py +377 -0
- policies/flip_cup/astra-s1/episodes.csv +101 -0
- policies/flip_cup/astra-s1/policy.py +143 -0
- policies/flip_cup/astra-s2/episodes.csv +101 -0
- policies/flip_cup/astra-s2/policy.py +226 -0
- policies/flip_cup/astra-s3/episodes.csv +101 -0
- policies/flip_cup/astra-s3/policy.py +176 -0
- policies/flip_cup/deepseek1017-s1/episodes.csv +101 -0
- policies/flip_cup/deepseek1017-s1/policy.py +220 -0
- policies/flip_cup/deepseek1017-s2/episodes.csv +101 -0
- policies/flip_cup/deepseek1017-s2/policy.py +289 -0
- policies/flip_cup/deepseek1017-s3/episodes.csv +101 -0
- policies/flip_cup/deepseek1017-s3/policy.py +364 -0
- policies/flip_cup/gpt61sol-s1/episodes.csv +101 -0
- policies/flip_cup/gpt61sol-s1/policy.py +137 -0
- policies/flip_cup/gpt61sol-s2/episodes.csv +101 -0
- policies/flip_cup/gpt61sol-s2/policy.py +100 -0
- policies/flip_cup/gpt61sol-s3/episodes.csv +101 -0
- policies/flip_cup/gpt61sol-s3/policy.py +70 -0
- policies/flip_cup/gpt61terra-s1/episodes.csv +101 -0
- policies/flip_cup/gpt61terra-s1/policy.py +61 -0
- policies/flip_cup/gpt61terra-s2/episodes.csv +101 -0
- policies/flip_cup/gpt61terra-s2/policy.py +65 -0
- policies/flip_cup/gpt61terra-s3/episodes.csv +101 -0
- policies/flip_cup/gpt61terra-s3/policy.py +62 -0
- policies/flip_cup/gpt6sol-s1/episodes.csv +101 -0
- policies/flip_cup/gpt6sol-s1/policy.py +131 -0
- policies/flip_cup/gpt6sol-s2/episodes.csv +101 -0
- policies/flip_cup/gpt6sol-s2/policy.py +109 -0
- policies/flip_cup/gpt6sol-s3/episodes.csv +101 -0
- policies/flip_cup/gpt6sol-s3/policy.py +34 -0
- policies/flip_cup/kimi31pro-s1/episodes.csv +101 -0
- policies/flip_cup/kimi31pro-s1/policy.py +251 -0
- policies/flip_cup/kimi31pro-s2/episodes.csv +101 -0
- policies/flip_cup/kimi31pro-s2/policy.py +119 -0
policies/drawer_top_open/kimi31pro-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1350,timeout,0
|
| 3 |
+
620001,0,1350,timeout,0
|
| 4 |
+
620002,0,1350,timeout,0
|
| 5 |
+
620003,0,1350,timeout,0
|
| 6 |
+
620004,0,1350,timeout,0
|
| 7 |
+
620005,0,1350,timeout,0
|
| 8 |
+
620006,0,1350,timeout,0
|
| 9 |
+
620007,0,1350,timeout,0
|
| 10 |
+
620008,0,1350,timeout,0
|
| 11 |
+
620009,0,1350,timeout,0
|
| 12 |
+
620010,0,1350,timeout,0
|
| 13 |
+
620011,0,1350,timeout,0
|
| 14 |
+
620012,0,1350,timeout,0
|
| 15 |
+
620013,0,1350,timeout,0
|
| 16 |
+
620014,0,1350,timeout,0
|
| 17 |
+
620015,0,1350,timeout,0
|
| 18 |
+
620016,0,1350,timeout,0
|
| 19 |
+
620017,0,1350,timeout,0
|
| 20 |
+
620018,0,1350,timeout,0
|
| 21 |
+
620019,0,1350,timeout,0
|
| 22 |
+
620020,0,1350,timeout,0
|
| 23 |
+
620021,0,1350,timeout,0
|
| 24 |
+
620022,0,1350,timeout,0
|
| 25 |
+
620023,0,1350,timeout,0
|
| 26 |
+
620024,0,1350,timeout,0
|
| 27 |
+
620025,0,1350,timeout,0
|
| 28 |
+
620026,0,1350,timeout,0
|
| 29 |
+
620027,0,1350,timeout,0
|
| 30 |
+
620028,0,1350,timeout,0
|
| 31 |
+
620029,0,1350,timeout,0
|
| 32 |
+
620030,0,1350,timeout,0
|
| 33 |
+
620031,0,1350,timeout,0
|
| 34 |
+
620032,0,1350,timeout,0
|
| 35 |
+
620033,0,1350,timeout,0
|
| 36 |
+
620034,0,1350,timeout,0
|
| 37 |
+
620035,0,1350,timeout,0
|
| 38 |
+
620036,0,1350,timeout,0
|
| 39 |
+
620037,0,1350,timeout,0
|
| 40 |
+
620038,0,1350,timeout,0
|
| 41 |
+
620039,0,1350,timeout,0
|
| 42 |
+
620040,0,1350,timeout,0
|
| 43 |
+
620041,0,1350,timeout,0
|
| 44 |
+
620042,0,1350,timeout,0
|
| 45 |
+
620043,0,1350,timeout,0
|
| 46 |
+
620044,0,1350,timeout,0
|
| 47 |
+
620045,0,1350,timeout,0
|
| 48 |
+
620046,0,1350,timeout,0
|
| 49 |
+
620047,0,1350,timeout,0
|
| 50 |
+
620048,0,1350,timeout,0
|
| 51 |
+
620049,0,1350,timeout,0
|
| 52 |
+
620050,0,1350,timeout,0
|
| 53 |
+
620051,0,1350,timeout,0
|
| 54 |
+
620052,0,1350,timeout,0
|
| 55 |
+
620053,0,1350,timeout,0
|
| 56 |
+
620054,0,1350,timeout,0
|
| 57 |
+
620055,0,1350,timeout,0
|
| 58 |
+
620056,0,1350,timeout,0
|
| 59 |
+
620057,0,1350,timeout,0
|
| 60 |
+
620058,0,1350,timeout,0
|
| 61 |
+
620059,0,1350,timeout,0
|
| 62 |
+
620060,0,1350,timeout,0
|
| 63 |
+
620061,0,1350,timeout,0
|
| 64 |
+
620062,0,1350,timeout,0
|
| 65 |
+
620063,0,1350,timeout,0
|
| 66 |
+
620064,0,1350,timeout,0
|
| 67 |
+
620065,0,1350,timeout,0
|
| 68 |
+
620066,0,1350,timeout,0
|
| 69 |
+
620067,0,1350,timeout,0
|
| 70 |
+
620068,0,1350,timeout,0
|
| 71 |
+
620069,0,1350,timeout,0
|
| 72 |
+
620070,0,1350,timeout,0
|
| 73 |
+
620071,0,1350,timeout,0
|
| 74 |
+
620072,0,1350,timeout,0
|
| 75 |
+
620073,0,1350,timeout,0
|
| 76 |
+
620074,0,1350,timeout,0
|
| 77 |
+
620075,0,1350,timeout,0
|
| 78 |
+
620076,0,1350,timeout,0
|
| 79 |
+
620077,0,1350,timeout,0
|
| 80 |
+
620078,0,1350,timeout,0
|
| 81 |
+
620079,0,1350,timeout,0
|
| 82 |
+
620080,0,1350,timeout,0
|
| 83 |
+
620081,0,1350,timeout,0
|
| 84 |
+
620082,0,1350,timeout,0
|
| 85 |
+
620083,0,1350,timeout,0
|
| 86 |
+
620084,0,1350,timeout,0
|
| 87 |
+
620085,0,1350,timeout,0
|
| 88 |
+
620086,0,1350,timeout,0
|
| 89 |
+
620087,0,1350,timeout,0
|
| 90 |
+
620088,0,1350,timeout,0
|
| 91 |
+
620089,0,1350,timeout,0
|
| 92 |
+
620090,0,1350,timeout,0
|
| 93 |
+
620091,0,1350,timeout,0
|
| 94 |
+
620092,0,1350,timeout,0
|
| 95 |
+
620093,0,1350,timeout,0
|
| 96 |
+
620094,0,1350,timeout,0
|
| 97 |
+
620095,0,1350,timeout,0
|
| 98 |
+
620096,0,1350,timeout,0
|
| 99 |
+
620097,0,1350,timeout,0
|
| 100 |
+
620098,0,1350,timeout,0
|
| 101 |
+
620099,0,1350,timeout,0
|
policies/drawer_top_open/kimi31pro-s1/policy.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hand-written visual control for opening the cabinet's top drawer."""
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Policy:
|
| 7 |
+
"""Approach, align to the top drawer handle, close, and pull."""
|
| 8 |
+
|
| 9 |
+
def reset(self, obs, tools):
|
| 10 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 11 |
+
state = np.asarray(obs["low_dim_obs"], dtype=np.float32)
|
| 12 |
+
self.origin = state[18:22].copy()
|
| 13 |
+
self.t = 0
|
| 14 |
+
self.pre = np.array([-1.2, 0.0, 0.0, 1.5, 1.57, -0.7, 0.0], dtype=np.float32)
|
| 15 |
+
self.forward = 0.08
|
| 16 |
+
self.right = -0.05
|
| 17 |
+
self.arm_yaw = 0.0
|
| 18 |
+
self.track = None
|
| 19 |
+
self.missed = 0
|
| 20 |
+
self.stable = 0
|
| 21 |
+
self.close_t = None
|
| 22 |
+
self.last_detection = None
|
| 23 |
+
|
| 24 |
+
def base_to(self, state, forward, right):
|
| 25 |
+
"""Request a base displacement in the initial body frame."""
|
| 26 |
+
ox, oy, _, yaw0 = self.origin
|
| 27 |
+
dx = ox + forward * np.cos(yaw0) + right * np.sin(yaw0) - state[18]
|
| 28 |
+
dy = oy + forward * np.sin(yaw0) - right * np.cos(yaw0) - state[19]
|
| 29 |
+
yaw = state[21]
|
| 30 |
+
ex = np.cos(yaw) * dx + np.sin(yaw) * dy
|
| 31 |
+
ey = -np.sin(yaw) * dx + np.cos(yaw) * dy
|
| 32 |
+
vx = np.clip(3.0 * ex, -0.14, 0.14)
|
| 33 |
+
vy = np.clip(3.0 * ey, -0.14, 0.14)
|
| 34 |
+
if 0.001 < abs(vx) < 0.065:
|
| 35 |
+
vx = np.sign(vx) * 0.065
|
| 36 |
+
if 0.001 < abs(vy) < 0.065:
|
| 37 |
+
vy = np.sign(vy) * 0.065
|
| 38 |
+
if abs(ex) < 0.007:
|
| 39 |
+
vx = 0.0
|
| 40 |
+
if abs(ey) < 0.007:
|
| 41 |
+
vy = 0.0
|
| 42 |
+
yaw_error = (yaw0 - yaw + np.pi) % (2 * np.pi) - np.pi
|
| 43 |
+
return vx, vy, np.clip(1.5 * yaw_error, -0.22, 0.22)
|
| 44 |
+
|
| 45 |
+
@staticmethod
|
| 46 |
+
def handles(image):
|
| 47 |
+
"""Find dark handle bars surrounded by the white cabinet panels."""
|
| 48 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 49 |
+
spread = (np.max(image, axis=2).astype(np.int16)
|
| 50 |
+
- np.min(image, axis=2).astype(np.int16))
|
| 51 |
+
dark = np.uint8((gray < 140) & (spread < 35))
|
| 52 |
+
dark[:, :5] = 0
|
| 53 |
+
dark[:, 80:] = 0
|
| 54 |
+
dark[80:, :] = 0
|
| 55 |
+
distance = cv2.distanceTransform(dark, cv2.DIST_L2, 3)
|
| 56 |
+
core = np.uint8(distance >= 1.2)
|
| 57 |
+
count, labels, stats, centroids = cv2.connectedComponentsWithStats(core, 8)
|
| 58 |
+
candidates = []
|
| 59 |
+
for i in range(1, count):
|
| 60 |
+
x, y, w, h, area = [int(v) for v in stats[i]]
|
| 61 |
+
if area < 8 or w < 7 or w > 40 or h < 15 or h > 75:
|
| 62 |
+
continue
|
| 63 |
+
if y + h > 82 or h < 1.05 * w:
|
| 64 |
+
continue
|
| 65 |
+
x0, x1 = max(0, x - 3), min(84, x + w + 3)
|
| 66 |
+
y0, y1 = max(0, y - 3), min(84, y + h + 3)
|
| 67 |
+
background = ((gray[y0:y1, x0:x1] > 165)
|
| 68 |
+
& (spread[y0:y1, x0:x1] < 35))
|
| 69 |
+
if float(np.mean(background)) < 0.35:
|
| 70 |
+
continue
|
| 71 |
+
cx, cy = centroids[i]
|
| 72 |
+
candidates.append((area, float(cx), float(cy), h, (x, y, w, h)))
|
| 73 |
+
return candidates
|
| 74 |
+
|
| 75 |
+
def acquire(self, detections):
|
| 76 |
+
"""Track the rightmost full handle, which is the top drawer here."""
|
| 77 |
+
if self.track is None:
|
| 78 |
+
return max(detections, key=lambda item: item[1]) if detections else None
|
| 79 |
+
farther_right = [item for item in detections if item[1] > self.track[1] + 8]
|
| 80 |
+
if farther_right:
|
| 81 |
+
return max(farther_right, key=lambda item: item[1])
|
| 82 |
+
near = [item for item in detections
|
| 83 |
+
if abs(item[1] - self.track[1]) < 20 and abs(item[2] - self.track[2]) < 30]
|
| 84 |
+
if near:
|
| 85 |
+
return min(near, key=lambda item: (item[1] - self.track[1]) ** 2
|
| 86 |
+
+ 0.25 * (item[2] - self.track[2]) ** 2)
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
def act(self, obs, tools):
|
| 90 |
+
state = np.asarray(obs["low_dim_obs"], dtype=np.float32)
|
| 91 |
+
raw = self.hold.copy()
|
| 92 |
+
raw[:4] = [0.0, 0.0, 0.74, 0.0]
|
| 93 |
+
alpha = 0.0 if self.t < 100 else min(1.0, (self.t - 99) / 110.0)
|
| 94 |
+
alpha = alpha * alpha * (3.0 - 2.0 * alpha)
|
| 95 |
+
raw[4:11] = alpha * self.pre
|
| 96 |
+
if self.t >= 230:
|
| 97 |
+
raw[6] = self.arm_yaw
|
| 98 |
+
raw[10] = self.arm_yaw
|
| 99 |
+
raw[18:20] = 0.0
|
| 100 |
+
|
| 101 |
+
if self.t < 230:
|
| 102 |
+
raw[0], raw[1], raw[3] = self.base_to(state, self.forward, self.right)
|
| 103 |
+
|
| 104 |
+
if self.t >= 230 and self.close_t is None:
|
| 105 |
+
found = self.acquire(self.handles(tools.image("left_wrist")))
|
| 106 |
+
if found is not None:
|
| 107 |
+
self.track = found
|
| 108 |
+
self.missed = 0
|
| 109 |
+
else:
|
| 110 |
+
self.missed += 1
|
| 111 |
+
self.last_detection = found
|
| 112 |
+
guidance = found if found is not None else self.track
|
| 113 |
+
if guidance is not None:
|
| 114 |
+
_, cx, cy, height, _ = guidance
|
| 115 |
+
if self.t % 2 == 0:
|
| 116 |
+
gain = 0.00025 if found is not None else 0.0001
|
| 117 |
+
self.arm_yaw += float(np.clip(-gain * (cx - 42.0), -0.002, 0.002))
|
| 118 |
+
self.arm_yaw = float(np.clip(self.arm_yaw, -0.65, 0.3))
|
| 119 |
+
aligned = (found is not None and abs(cx - 42) < 6
|
| 120 |
+
and 0 <= cy <= 72 and height >= 15)
|
| 121 |
+
self.stable = self.stable + 1 if aligned else 0
|
| 122 |
+
else:
|
| 123 |
+
self.stable = 0
|
| 124 |
+
if self.t % 2 == 0:
|
| 125 |
+
self.arm_yaw = float(np.clip(self.arm_yaw - 0.001, -0.65, 0.3))
|
| 126 |
+
|
| 127 |
+
raw[0] = 0.0
|
| 128 |
+
raw[1] = 0.0
|
| 129 |
+
yaw_error = (self.origin[3] - state[21] + np.pi) % (2 * np.pi) - np.pi
|
| 130 |
+
raw[3] = np.clip(2.0 * yaw_error, -0.25, 0.25)
|
| 131 |
+
if self.stable >= 12 or (self.t >= 800 and found is not None):
|
| 132 |
+
self.close_t = self.t
|
| 133 |
+
|
| 134 |
+
if self.close_t is not None:
|
| 135 |
+
elapsed = self.t - self.close_t
|
| 136 |
+
raw[18] = 0.7 * min(1.0, (elapsed + 1) / 45.0)
|
| 137 |
+
if 70 <= elapsed < 290:
|
| 138 |
+
raw[0] = -0.18
|
| 139 |
+
yaw_error = (self.origin[3] - state[21] + np.pi) % (2 * np.pi) - np.pi
|
| 140 |
+
raw[3] = np.clip(1.5 * yaw_error, -0.22, 0.22)
|
| 141 |
+
|
| 142 |
+
self.t += 1
|
| 143 |
+
return raw
|
policies/drawer_top_open/kimi31pro-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,1,474,success,0
|
| 3 |
+
620001,1,520,success,0
|
| 4 |
+
620002,1,475,success,0
|
| 5 |
+
620003,1,475,success,0
|
| 6 |
+
620004,1,748,success,0
|
| 7 |
+
620005,0,1350,timeout,0
|
| 8 |
+
620006,1,1169,success,0
|
| 9 |
+
620007,1,478,success,0
|
| 10 |
+
620008,1,464,success,0
|
| 11 |
+
620009,1,867,success,0
|
| 12 |
+
620010,1,458,success,0
|
| 13 |
+
620011,1,471,success,0
|
| 14 |
+
620012,0,1350,timeout,0
|
| 15 |
+
620013,1,897,success,0
|
| 16 |
+
620014,1,473,success,0
|
| 17 |
+
620015,1,476,success,0
|
| 18 |
+
620016,1,462,success,0
|
| 19 |
+
620017,1,1186,success,0
|
| 20 |
+
620018,1,477,success,0
|
| 21 |
+
620019,1,477,success,0
|
| 22 |
+
620020,1,535,success,0
|
| 23 |
+
620021,1,476,success,0
|
| 24 |
+
620022,1,477,success,0
|
| 25 |
+
620023,1,471,success,0
|
| 26 |
+
620024,0,1350,timeout,0
|
| 27 |
+
620025,1,467,success,0
|
| 28 |
+
620026,1,554,success,0
|
| 29 |
+
620027,1,473,success,0
|
| 30 |
+
620028,1,1346,success,0
|
| 31 |
+
620029,1,942,success,0
|
| 32 |
+
620030,1,472,success,0
|
| 33 |
+
620031,1,468,success,0
|
| 34 |
+
620032,0,1350,timeout,0
|
| 35 |
+
620033,0,1350,timeout,0
|
| 36 |
+
620034,1,475,success,0
|
| 37 |
+
620035,1,829,success,0
|
| 38 |
+
620036,1,493,success,0
|
| 39 |
+
620037,1,745,success,0
|
| 40 |
+
620038,1,475,success,0
|
| 41 |
+
620039,1,462,success,0
|
| 42 |
+
620040,1,1017,success,0
|
| 43 |
+
620041,1,531,success,0
|
| 44 |
+
620042,1,535,success,0
|
| 45 |
+
620043,1,564,success,0
|
| 46 |
+
620044,1,476,success,0
|
| 47 |
+
620045,1,990,success,0
|
| 48 |
+
620046,1,559,success,0
|
| 49 |
+
620047,0,1350,timeout,0
|
| 50 |
+
620048,1,461,success,0
|
| 51 |
+
620049,1,474,success,0
|
| 52 |
+
620050,1,458,success,0
|
| 53 |
+
620051,1,473,success,0
|
| 54 |
+
620052,1,852,success,0
|
| 55 |
+
620053,1,474,success,0
|
| 56 |
+
620054,1,472,success,0
|
| 57 |
+
620055,1,688,success,0
|
| 58 |
+
620056,1,533,success,0
|
| 59 |
+
620057,1,1163,success,0
|
| 60 |
+
620058,1,466,success,0
|
| 61 |
+
620059,1,534,success,0
|
| 62 |
+
620060,1,731,success,0
|
| 63 |
+
620061,0,1350,timeout,0
|
| 64 |
+
620062,1,1160,success,0
|
| 65 |
+
620063,0,1350,timeout,0
|
| 66 |
+
620064,1,473,success,0
|
| 67 |
+
620065,1,464,success,0
|
| 68 |
+
620066,1,1049,success,0
|
| 69 |
+
620067,1,850,success,0
|
| 70 |
+
620068,1,1111,success,0
|
| 71 |
+
620069,1,480,success,0
|
| 72 |
+
620070,1,1054,success,0
|
| 73 |
+
620071,1,872,success,0
|
| 74 |
+
620072,0,1350,timeout,0
|
| 75 |
+
620073,0,1350,timeout,0
|
| 76 |
+
620074,1,910,success,0
|
| 77 |
+
620075,1,475,success,0
|
| 78 |
+
620076,0,1350,timeout,0
|
| 79 |
+
620077,1,471,success,0
|
| 80 |
+
620078,1,461,success,0
|
| 81 |
+
620079,1,1053,success,0
|
| 82 |
+
620080,1,1045,success,0
|
| 83 |
+
620081,0,1350,timeout,0
|
| 84 |
+
620082,0,1350,timeout,0
|
| 85 |
+
620083,1,474,success,0
|
| 86 |
+
620084,1,475,success,0
|
| 87 |
+
620085,1,531,success,0
|
| 88 |
+
620086,0,1350,timeout,0
|
| 89 |
+
620087,1,475,success,0
|
| 90 |
+
620088,0,1350,timeout,0
|
| 91 |
+
620089,1,459,success,0
|
| 92 |
+
620090,1,467,success,0
|
| 93 |
+
620091,1,1348,success,0
|
| 94 |
+
620092,1,602,success,0
|
| 95 |
+
620093,1,534,success,0
|
| 96 |
+
620094,1,1078,success,0
|
| 97 |
+
620095,1,855,success,0
|
| 98 |
+
620096,1,469,success,0
|
| 99 |
+
620097,0,1350,timeout,0
|
| 100 |
+
620098,1,476,success,0
|
| 101 |
+
620099,1,1197,success,0
|
policies/drawer_top_open/kimi31pro-s2/policy.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hand-written reach, grasp, and pull controller for the top cabinet drawer."""
|
| 2 |
+
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Policy:
|
| 8 |
+
"""Deterministic joint-space controller with closed-loop base guidance."""
|
| 9 |
+
|
| 10 |
+
def reset(self, obs, tools):
|
| 11 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 12 |
+
self.cabinet_pose = np.array([0.30, 0.01, 0.74, 0.0], dtype=np.float32)
|
| 13 |
+
self.grasp_pose = np.array(
|
| 14 |
+
[-0.58, 0.0, -0.65, 0.80, 1.0, 0.0, 0.0], dtype=np.float32
|
| 15 |
+
)
|
| 16 |
+
self.phase = "initial"
|
| 17 |
+
self.pull_start = 240
|
| 18 |
+
self.open_time = 0
|
| 19 |
+
self.good_count = 0
|
| 20 |
+
self.empty_count = 0
|
| 21 |
+
self.aggressive_pull = False
|
| 22 |
+
|
| 23 |
+
@staticmethod
|
| 24 |
+
def _angle_error(target, value):
|
| 25 |
+
return (target - value + np.pi) % (2.0 * np.pi) - np.pi
|
| 26 |
+
|
| 27 |
+
@staticmethod
|
| 28 |
+
def _empty_grip(q):
|
| 29 |
+
# Fully closed fingers with no handle between them reach -0.02 rad.
|
| 30 |
+
return q[7] < -0.018 and q[8] < -0.018
|
| 31 |
+
|
| 32 |
+
@staticmethod
|
| 33 |
+
def _top_handle(image):
|
| 34 |
+
"""Return the center of the large bar, excluding trim and lower handles."""
|
| 35 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 36 |
+
neutral = (
|
| 37 |
+
np.max(image, axis=2).astype(np.int16)
|
| 38 |
+
- np.min(image, axis=2).astype(np.int16)
|
| 39 |
+
) < 35
|
| 40 |
+
mask = ((gray < 145) & neutral).astype(np.uint8)
|
| 41 |
+
mask[:, :8] = 0
|
| 42 |
+
mask[:, 76:] = 0
|
| 43 |
+
count, _, stats, centers = cv2.connectedComponentsWithStats(mask, 8)
|
| 44 |
+
candidates = []
|
| 45 |
+
for i in range(1, count):
|
| 46 |
+
x, y, w, h, area = stats[i]
|
| 47 |
+
density = area / float(w * h)
|
| 48 |
+
if (
|
| 49 |
+
45 <= h <= 82
|
| 50 |
+
and 5 <= w <= 25
|
| 51 |
+
and area >= 200
|
| 52 |
+
and density > 0.50
|
| 53 |
+
and centers[i, 0] > 18.0
|
| 54 |
+
):
|
| 55 |
+
candidates.append((area, centers[i]))
|
| 56 |
+
if not candidates:
|
| 57 |
+
return None
|
| 58 |
+
return max(candidates, key=lambda item: item[0])[1]
|
| 59 |
+
|
| 60 |
+
def _approach_base(self, raw, q):
|
| 61 |
+
yaw = q[21]
|
| 62 |
+
raw[3] = np.clip(
|
| 63 |
+
2.0 * self._angle_error(self.cabinet_pose[3], yaw), -0.35, 0.35
|
| 64 |
+
)
|
| 65 |
+
ex = self.cabinet_pose[0] - q[18]
|
| 66 |
+
ey = self.cabinet_pose[1] - q[19]
|
| 67 |
+
c, s = np.cos(yaw), np.sin(yaw)
|
| 68 |
+
vx = np.clip(2.0 * (c * ex + s * ey), -0.15, 0.15)
|
| 69 |
+
vy = np.clip(2.0 * (-s * ex + c * ey), -0.15, 0.15)
|
| 70 |
+
if abs(vx) > 0.02:
|
| 71 |
+
raw[0] = np.copysign(max(0.06, abs(vx)), vx)
|
| 72 |
+
if abs(vy) > 0.02:
|
| 73 |
+
raw[1] = np.copysign(max(0.06, abs(vy)), vy)
|
| 74 |
+
|
| 75 |
+
def _guide_base(self, raw, q, pulling):
|
| 76 |
+
yaw = q[21]
|
| 77 |
+
raw[3] = np.clip(
|
| 78 |
+
3.0 * self._angle_error(self.cabinet_pose[3], yaw), -0.5, 0.5
|
| 79 |
+
)
|
| 80 |
+
if pulling:
|
| 81 |
+
raw[0] = -0.08
|
| 82 |
+
lateral_error = np.cos(yaw) * (self.cabinet_pose[1] - q[19])
|
| 83 |
+
if abs(lateral_error) > 0.015:
|
| 84 |
+
raw[1] = np.clip(1.5 * lateral_error, -0.10, 0.10)
|
| 85 |
+
if abs(raw[1]) < 0.06:
|
| 86 |
+
raw[1] = np.copysign(0.06, raw[1])
|
| 87 |
+
|
| 88 |
+
def _pull_action(self, raw, q, pull_step):
|
| 89 |
+
self._guide_base(raw, q, pulling=pull_step < 300)
|
| 90 |
+
if self.aggressive_pull:
|
| 91 |
+
if pull_step < 300:
|
| 92 |
+
raw[0] = -0.10
|
| 93 |
+
fraction = min(1.0, (pull_step + 1.0) / 180.0)
|
| 94 |
+
pitch_delta, wrist_delta = 0.30, -0.80
|
| 95 |
+
else:
|
| 96 |
+
fraction = min(1.0, (pull_step + 1.0) / 240.0)
|
| 97 |
+
pitch_delta, wrist_delta = 0.15, -0.65
|
| 98 |
+
pose = self.grasp_pose.copy()
|
| 99 |
+
pose[0] += pitch_delta * fraction
|
| 100 |
+
pose[3] += 0.50 * fraction
|
| 101 |
+
pose[5] += wrist_delta * fraction
|
| 102 |
+
raw[4:11] = pose
|
| 103 |
+
raw[18] = 1.0
|
| 104 |
+
|
| 105 |
+
def act(self, obs, tools):
|
| 106 |
+
q = np.asarray(obs["low_dim_obs"], dtype=np.float32)
|
| 107 |
+
t = int(obs["t"])
|
| 108 |
+
|
| 109 |
+
# Keep the successful baseline untouched. Only an actually empty close
|
| 110 |
+
# enters the camera-timed retry path.
|
| 111 |
+
if t == 200 and self.phase == "initial":
|
| 112 |
+
if self._empty_grip(q):
|
| 113 |
+
self.phase = "open"
|
| 114 |
+
self.open_time = t
|
| 115 |
+
self.good_count = 0
|
| 116 |
+
self.aggressive_pull = True
|
| 117 |
+
else:
|
| 118 |
+
self.phase = "initial_ok"
|
| 119 |
+
if t >= 240 and self.phase == "initial_ok":
|
| 120 |
+
self.phase = "pull"
|
| 121 |
+
if self.phase == "retry_close" and t >= self.pull_start:
|
| 122 |
+
self.phase = "pull"
|
| 123 |
+
if self.phase == "pull":
|
| 124 |
+
pull_step = t - self.pull_start
|
| 125 |
+
if 150 <= pull_step < 300 and self._empty_grip(q):
|
| 126 |
+
self.empty_count += 1
|
| 127 |
+
else:
|
| 128 |
+
self.empty_count = 0
|
| 129 |
+
if self.empty_count >= 10:
|
| 130 |
+
self.phase = "open"
|
| 131 |
+
self.open_time = t
|
| 132 |
+
self.good_count = 0
|
| 133 |
+
self.empty_count = 0
|
| 134 |
+
|
| 135 |
+
raw = np.zeros(20, dtype=np.float32)
|
| 136 |
+
raw[2] = 0.74
|
| 137 |
+
raw[19] = 0.6
|
| 138 |
+
|
| 139 |
+
if self.phase in ("initial", "initial_ok"):
|
| 140 |
+
if t < 160:
|
| 141 |
+
self._approach_base(raw, q)
|
| 142 |
+
raw[18] = 0.0
|
| 143 |
+
raw[4:11] = self.grasp_pose
|
| 144 |
+
else:
|
| 145 |
+
self._guide_base(raw, q, pulling=False)
|
| 146 |
+
raw[18] = 1.0
|
| 147 |
+
raw[4:11] = self.grasp_pose
|
| 148 |
+
elif self.phase == "open":
|
| 149 |
+
self._approach_base(raw, q)
|
| 150 |
+
raw[18] = 0.0
|
| 151 |
+
raw[4:11] = self.grasp_pose
|
| 152 |
+
if t - self.open_time >= 20 and t % 2 == 0:
|
| 153 |
+
center = self._top_handle(tools.image("left_wrist"))
|
| 154 |
+
if (
|
| 155 |
+
center is not None
|
| 156 |
+
and 36.0 <= center[0] <= 49.0
|
| 157 |
+
and 28.0 <= center[1] <= 48.0
|
| 158 |
+
):
|
| 159 |
+
self.good_count += 1
|
| 160 |
+
else:
|
| 161 |
+
self.good_count = 0
|
| 162 |
+
if self.good_count >= 2:
|
| 163 |
+
self.phase = "retry_close"
|
| 164 |
+
self.pull_start = t + 70
|
| 165 |
+
self.close_start = t
|
| 166 |
+
elif self.phase == "retry_close":
|
| 167 |
+
self._guide_base(raw, q, pulling=False)
|
| 168 |
+
if t - self.close_start < 30:
|
| 169 |
+
raw[0] = 0.06
|
| 170 |
+
raw[18] = 1.0
|
| 171 |
+
raw[4:11] = self.grasp_pose
|
| 172 |
+
if t == self.close_start + 50 and self._empty_grip(q):
|
| 173 |
+
self.phase = "open"
|
| 174 |
+
self.open_time = t
|
| 175 |
+
self.good_count = 0
|
| 176 |
+
else:
|
| 177 |
+
self._pull_action(raw, q, t - self.pull_start)
|
| 178 |
+
return raw
|
policies/drawer_top_open/kimi31pro-s3/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,1,439,success,0
|
| 3 |
+
620001,0,1350,timeout,0
|
| 4 |
+
620002,0,1350,timeout,0
|
| 5 |
+
620003,0,1350,timeout,0
|
| 6 |
+
620004,0,1350,timeout,0
|
| 7 |
+
620005,0,1350,timeout,0
|
| 8 |
+
620006,0,1350,timeout,0
|
| 9 |
+
620007,0,1350,timeout,0
|
| 10 |
+
620008,0,1350,timeout,0
|
| 11 |
+
620009,0,1350,timeout,0
|
| 12 |
+
620010,0,1350,timeout,0
|
| 13 |
+
620011,0,1350,timeout,0
|
| 14 |
+
620012,0,1350,timeout,0
|
| 15 |
+
620013,0,1350,timeout,0
|
| 16 |
+
620014,1,436,success,0
|
| 17 |
+
620015,0,1350,timeout,0
|
| 18 |
+
620016,1,440,success,0
|
| 19 |
+
620017,0,1350,timeout,0
|
| 20 |
+
620018,1,445,success,0
|
| 21 |
+
620019,0,1350,timeout,0
|
| 22 |
+
620020,0,1350,timeout,0
|
| 23 |
+
620021,0,1350,timeout,0
|
| 24 |
+
620022,0,1350,timeout,0
|
| 25 |
+
620023,1,444,success,0
|
| 26 |
+
620024,1,449,success,0
|
| 27 |
+
620025,0,1350,timeout,0
|
| 28 |
+
620026,0,1350,timeout,0
|
| 29 |
+
620027,0,1350,timeout,0
|
| 30 |
+
620028,0,1350,timeout,0
|
| 31 |
+
620029,0,1350,timeout,0
|
| 32 |
+
620030,1,434,success,0
|
| 33 |
+
620031,1,444,success,0
|
| 34 |
+
620032,1,463,success,0
|
| 35 |
+
620033,0,1350,timeout,0
|
| 36 |
+
620034,0,1350,timeout,0
|
| 37 |
+
620035,0,1350,timeout,0
|
| 38 |
+
620036,0,1350,timeout,0
|
| 39 |
+
620037,1,446,success,0
|
| 40 |
+
620038,0,1350,timeout,0
|
| 41 |
+
620039,0,1350,timeout,0
|
| 42 |
+
620040,0,1350,timeout,0
|
| 43 |
+
620041,0,1350,timeout,0
|
| 44 |
+
620042,0,1350,timeout,0
|
| 45 |
+
620043,0,1350,timeout,0
|
| 46 |
+
620044,0,1350,timeout,0
|
| 47 |
+
620045,0,1350,timeout,0
|
| 48 |
+
620046,0,1350,timeout,0
|
| 49 |
+
620047,0,1350,timeout,0
|
| 50 |
+
620048,0,1350,timeout,0
|
| 51 |
+
620049,0,1350,timeout,0
|
| 52 |
+
620050,1,442,success,0
|
| 53 |
+
620051,0,1350,timeout,0
|
| 54 |
+
620052,1,448,success,0
|
| 55 |
+
620053,0,1350,timeout,0
|
| 56 |
+
620054,1,441,success,0
|
| 57 |
+
620055,0,1350,timeout,0
|
| 58 |
+
620056,0,1350,timeout,0
|
| 59 |
+
620057,0,1350,timeout,0
|
| 60 |
+
620058,1,447,success,0
|
| 61 |
+
620059,0,1350,timeout,0
|
| 62 |
+
620060,0,1350,timeout,0
|
| 63 |
+
620061,0,1350,timeout,0
|
| 64 |
+
620062,0,1350,timeout,0
|
| 65 |
+
620063,0,1350,timeout,0
|
| 66 |
+
620064,0,1350,timeout,0
|
| 67 |
+
620065,0,1350,timeout,0
|
| 68 |
+
620066,0,1350,timeout,0
|
| 69 |
+
620067,0,1350,timeout,0
|
| 70 |
+
620068,0,1350,timeout,0
|
| 71 |
+
620069,0,1350,timeout,0
|
| 72 |
+
620070,0,1350,timeout,0
|
| 73 |
+
620071,0,1350,timeout,0
|
| 74 |
+
620072,0,1350,timeout,0
|
| 75 |
+
620073,0,1350,timeout,0
|
| 76 |
+
620074,0,1350,timeout,0
|
| 77 |
+
620075,0,1350,timeout,0
|
| 78 |
+
620076,0,1350,timeout,0
|
| 79 |
+
620077,0,1350,timeout,0
|
| 80 |
+
620078,0,1350,timeout,0
|
| 81 |
+
620079,0,1350,timeout,0
|
| 82 |
+
620080,0,1350,timeout,0
|
| 83 |
+
620081,0,1350,timeout,0
|
| 84 |
+
620082,0,1350,timeout,0
|
| 85 |
+
620083,0,1350,timeout,0
|
| 86 |
+
620084,1,440,success,0
|
| 87 |
+
620085,0,1350,timeout,0
|
| 88 |
+
620086,0,1350,timeout,0
|
| 89 |
+
620087,0,1350,timeout,0
|
| 90 |
+
620088,1,446,success,0
|
| 91 |
+
620089,0,1350,timeout,0
|
| 92 |
+
620090,0,1350,timeout,0
|
| 93 |
+
620091,0,1350,timeout,0
|
| 94 |
+
620092,0,1350,timeout,0
|
| 95 |
+
620093,0,1350,timeout,0
|
| 96 |
+
620094,0,1350,timeout,0
|
| 97 |
+
620095,0,1350,timeout,0
|
| 98 |
+
620096,0,1350,timeout,0
|
| 99 |
+
620097,0,1350,timeout,0
|
| 100 |
+
620098,0,1350,timeout,0
|
| 101 |
+
620099,0,1350,timeout,0
|
policies/drawer_top_open/kimi31pro-s3/policy.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic hand-written controller for the top cabinet drawer.
|
| 2 |
+
|
| 3 |
+
The arm is raised before it is adducted (adduction while hanging collides with
|
| 4 |
+
the thigh). A short forward walk brings the left hand to the drawer handle.
|
| 5 |
+
The pull uses the opposite wrist orientation and a reduced gripper command;
|
| 6 |
+
both details keep the handle between the finger pads during the slow retreat.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Policy:
|
| 13 |
+
def reset(self, obs, tools):
|
| 14 |
+
self.k = 0
|
| 15 |
+
self.start = np.asarray(tools.hold_action(), dtype=np.float32).copy()
|
| 16 |
+
self.goal = self.start.copy()
|
| 17 |
+
self.goal[18] = 0.4
|
| 18 |
+
# Left arm: raised shoulder, adduction, and the grasp wrist orientation.
|
| 19 |
+
self.goal[4:11] = [-0.6, -0.3, 0.0, 1.0, 1.55, 0.0, 0.0]
|
| 20 |
+
p = np.asarray(obs["low_dim_obs"], dtype=np.float32)[18:22]
|
| 21 |
+
self.y0 = float(p[1])
|
| 22 |
+
self.yaw0 = float(p[3])
|
| 23 |
+
|
| 24 |
+
def _base(self, raw, obs, vx_world, vy_world, yaw_gain):
|
| 25 |
+
p = np.asarray(obs["low_dim_obs"], dtype=np.float32)[18:22]
|
| 26 |
+
yaw = float(p[3])
|
| 27 |
+
c, s = np.cos(yaw), np.sin(yaw)
|
| 28 |
+
raw[0] = c * vx_world + s * vy_world
|
| 29 |
+
raw[1] = -s * vx_world + c * vy_world
|
| 30 |
+
yaw_error = (self.yaw0 - yaw + np.pi) % (2.0 * np.pi) - np.pi
|
| 31 |
+
raw[3] = float(np.clip(yaw_gain * yaw_error, -0.5, 0.5))
|
| 32 |
+
return raw
|
| 33 |
+
|
| 34 |
+
def act(self, obs, tools):
|
| 35 |
+
k = self.k
|
| 36 |
+
self.k += 1
|
| 37 |
+
start, goal = self.start, self.goal
|
| 38 |
+
|
| 39 |
+
if k < 61:
|
| 40 |
+
# Raise pitch/elbow first, then adduct and rotate the wrist.
|
| 41 |
+
raw = start + (goal - start) * min(1.0, k / 50.0)
|
| 42 |
+
u = min(1.0, k / 25.0)
|
| 43 |
+
raw[4] = start[4] + (goal[4] - start[4]) * u
|
| 44 |
+
raw[7] = start[7] + (goal[7] - start[7]) * u
|
| 45 |
+
return np.asarray(raw, dtype=np.float32)
|
| 46 |
+
|
| 47 |
+
if k < 117:
|
| 48 |
+
j = k - 61
|
| 49 |
+
raw = goal.copy()
|
| 50 |
+
vx = 0.25 if j < 45 else 0.0
|
| 51 |
+
p = np.asarray(obs["low_dim_obs"], dtype=np.float32)[18:22]
|
| 52 |
+
vy = float(np.clip(1.0 * (self.y0 - float(p[1])), -0.1, 0.1))
|
| 53 |
+
return self._base(raw, obs, vx, vy, 2.0)
|
| 54 |
+
|
| 55 |
+
if k < 158:
|
| 56 |
+
j = k - 117
|
| 57 |
+
raw = goal.copy()
|
| 58 |
+
raw[18] = 0.4 + 0.4 * min(1.0, j / 15.0)
|
| 59 |
+
return raw
|
| 60 |
+
|
| 61 |
+
j = k - 158
|
| 62 |
+
raw = goal.copy()
|
| 63 |
+
raw[18] = 0.8
|
| 64 |
+
vx = -0.08 if j < 250 else 0.0
|
| 65 |
+
p = np.asarray(obs["low_dim_obs"], dtype=np.float32)[18:22]
|
| 66 |
+
vy = float(np.clip(2.0 * (self.y0 - float(p[1])), -0.1, 0.1))
|
| 67 |
+
return self._base(raw, obs, vx, vy, 5.0)
|
policies/drawer_top_open/opus-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,1,550,success,0
|
| 3 |
+
620001,1,576,success,0
|
| 4 |
+
620002,1,508,success,0
|
| 5 |
+
620003,1,785,success,0
|
| 6 |
+
620004,1,465,success,0
|
| 7 |
+
620005,1,559,success,0
|
| 8 |
+
620006,1,595,success,0
|
| 9 |
+
620007,1,950,success,0
|
| 10 |
+
620008,1,598,success,0
|
| 11 |
+
620009,1,508,success,0
|
| 12 |
+
620010,1,551,success,0
|
| 13 |
+
620011,1,705,success,0
|
| 14 |
+
620012,1,444,success,0
|
| 15 |
+
620013,1,812,success,0
|
| 16 |
+
620014,1,564,success,0
|
| 17 |
+
620015,1,509,success,0
|
| 18 |
+
620016,1,568,success,0
|
| 19 |
+
620017,1,756,success,0
|
| 20 |
+
620018,1,567,success,0
|
| 21 |
+
620019,1,527,success,0
|
| 22 |
+
620020,1,739,success,0
|
| 23 |
+
620021,1,311,success,0
|
| 24 |
+
620022,1,467,success,0
|
| 25 |
+
620023,1,608,success,0
|
| 26 |
+
620024,1,578,success,0
|
| 27 |
+
620025,1,821,success,0
|
| 28 |
+
620026,1,643,success,0
|
| 29 |
+
620027,1,508,success,0
|
| 30 |
+
620028,1,462,success,0
|
| 31 |
+
620029,1,711,success,0
|
| 32 |
+
620030,1,559,success,0
|
| 33 |
+
620031,1,681,success,0
|
| 34 |
+
620032,1,638,success,0
|
| 35 |
+
620033,1,701,success,0
|
| 36 |
+
620034,1,533,success,0
|
| 37 |
+
620035,1,594,success,0
|
| 38 |
+
620036,1,449,success,0
|
| 39 |
+
620037,1,816,success,0
|
| 40 |
+
620038,1,573,success,0
|
| 41 |
+
620039,1,481,success,0
|
| 42 |
+
620040,1,447,success,0
|
| 43 |
+
620041,1,712,success,0
|
| 44 |
+
620042,1,465,success,0
|
| 45 |
+
620043,1,434,success,0
|
| 46 |
+
620044,1,701,success,0
|
| 47 |
+
620045,1,514,success,0
|
| 48 |
+
620046,1,513,success,0
|
| 49 |
+
620047,1,452,success,0
|
| 50 |
+
620048,1,778,success,0
|
| 51 |
+
620049,1,437,success,0
|
| 52 |
+
620050,1,567,success,0
|
| 53 |
+
620051,1,677,success,0
|
| 54 |
+
620052,1,655,success,0
|
| 55 |
+
620053,1,571,success,0
|
| 56 |
+
620054,1,629,success,0
|
| 57 |
+
620055,1,467,success,0
|
| 58 |
+
620056,1,536,success,0
|
| 59 |
+
620057,1,465,success,0
|
| 60 |
+
620058,1,563,success,0
|
| 61 |
+
620059,1,465,success,0
|
| 62 |
+
620060,1,477,success,0
|
| 63 |
+
620061,1,760,success,0
|
| 64 |
+
620062,1,465,success,0
|
| 65 |
+
620063,1,434,success,0
|
| 66 |
+
620064,0,1350,timeout,0
|
| 67 |
+
620065,1,765,success,0
|
| 68 |
+
620066,1,511,success,0
|
| 69 |
+
620067,1,505,success,0
|
| 70 |
+
620068,1,513,success,0
|
| 71 |
+
620069,1,679,success,0
|
| 72 |
+
620070,1,589,success,0
|
| 73 |
+
620071,1,507,success,0
|
| 74 |
+
620072,1,449,success,0
|
| 75 |
+
620073,1,514,success,0
|
| 76 |
+
620074,1,562,success,0
|
| 77 |
+
620075,1,537,success,0
|
| 78 |
+
620076,1,648,success,0
|
| 79 |
+
620077,1,562,success,0
|
| 80 |
+
620078,1,598,success,0
|
| 81 |
+
620079,1,479,success,0
|
| 82 |
+
620080,1,463,success,0
|
| 83 |
+
620081,1,432,success,0
|
| 84 |
+
620082,1,465,success,0
|
| 85 |
+
620083,1,521,success,0
|
| 86 |
+
620084,1,567,success,0
|
| 87 |
+
620085,1,559,success,0
|
| 88 |
+
620086,1,928,success,0
|
| 89 |
+
620087,1,605,success,0
|
| 90 |
+
620088,1,645,success,0
|
| 91 |
+
620089,1,900,success,0
|
| 92 |
+
620090,1,587,success,0
|
| 93 |
+
620091,1,929,success,0
|
| 94 |
+
620092,1,466,success,0
|
| 95 |
+
620093,1,717,success,0
|
| 96 |
+
620094,1,465,success,0
|
| 97 |
+
620095,1,466,success,0
|
| 98 |
+
620096,1,585,success,0
|
| 99 |
+
620097,1,465,success,0
|
| 100 |
+
620098,1,515,success,0
|
| 101 |
+
620099,1,673,success,0
|
policies/drawer_top_open/opus-s1/policy.py
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Open the top drawer: walk up to the cabinet, grasp the top handle with the left
|
| 2 |
+
hand, then walk backwards holding it.
|
| 3 |
+
|
| 4 |
+
The cabinet sits at a fixed place in the odometry (world) frame; only the robot's
|
| 5 |
+
start pose varies between seeds. The robot walks to a fixed stand pose in front
|
| 6 |
+
of the handle and reaches for it with the gripper's fingers opening vertically.
|
| 7 |
+
Before closing, the left wrist camera checks where the handle bar ends inside
|
| 8 |
+
the open gripper and shifts the grasp sideways until the bar spans the fingers.
|
| 9 |
+
A missed grasp (gripper closes fully) is retried at other heights; a handle lost
|
| 10 |
+
while pulling is grasped again where the hand last held it.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import numpy as np
|
| 14 |
+
from scipy.optimize import least_squares
|
| 15 |
+
|
| 16 |
+
# ----------------------------------------------------------------------------
|
| 17 |
+
# Kinematics (approximate G1 arm chain, pelvis frame, waist assumed rigid)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _rx(a):
|
| 21 |
+
c, s = np.cos(a), np.sin(a)
|
| 22 |
+
return np.array([[1, 0, 0], [0, c, -s], [0, s, c]])
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _ry(a):
|
| 26 |
+
c, s = np.cos(a), np.sin(a)
|
| 27 |
+
return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]])
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _rz(a):
|
| 31 |
+
c, s = np.cos(a), np.sin(a)
|
| 32 |
+
return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def fk_left(q, tool):
|
| 36 |
+
p = np.array([-0.0039635, 0, 0.054])
|
| 37 |
+
R = np.eye(3)
|
| 38 |
+
p = p + R @ np.array([0.0039563, 0.10022, 0.23778]); R = R @ _rx(0.27931)
|
| 39 |
+
R = R @ _ry(q[0])
|
| 40 |
+
p = p + R @ np.array([0, 0.038, -0.013831]); R = R @ _rx(-0.27925) @ _rx(q[1])
|
| 41 |
+
p = p + R @ np.array([0, 0.00624, -0.1032]); R = R @ _rz(q[2])
|
| 42 |
+
p = p + R @ np.array([0.015783, 0, -0.080518]); R = R @ _ry(q[3])
|
| 43 |
+
p = p + R @ np.array([0.100, 0.00188791, -0.010]); R = R @ _rx(q[4])
|
| 44 |
+
p = p + R @ np.array([0.038, 0, 0]); R = R @ _ry(q[5])
|
| 45 |
+
p = p + R @ np.array([0.046, 0, 0]); R = R @ _rz(q[6])
|
| 46 |
+
return p + R @ np.array([tool, 0, 0]), R
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Q_LO = np.array([-3.0892, -0.05, -2.618, -1.0472, -1.97222, -1.61443, -1.61443])
|
| 50 |
+
Q_HI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443])
|
| 51 |
+
TOOL = 0.19
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def ik_left(target, q0, maxdown=0.3):
|
| 55 |
+
"""Fingers' centre at target, opening axis in the world x-z plane (to pinch a
|
| 56 |
+
horizontal bar running along y), gripper pointing roughly forward."""
|
| 57 |
+
q0 = np.clip(np.asarray(q0, float), Q_LO + 1e-3, Q_HI - 1e-3)
|
| 58 |
+
pref = np.array([1.0, 0, 0])
|
| 59 |
+
|
| 60 |
+
def res(q):
|
| 61 |
+
p, R = fk_left(q, TOOL)
|
| 62 |
+
return np.concatenate([
|
| 63 |
+
3 * (p - target),
|
| 64 |
+
[1.0 * R[1, 1]],
|
| 65 |
+
0.05 * (R[:, 0] - pref),
|
| 66 |
+
[0.5 * max(0.0, -R[2, 0] - np.sin(maxdown))],
|
| 67 |
+
[0.5 * max(0.0, abs(R[1, 0]) - 0.5)],
|
| 68 |
+
[0.3 * max(0.0, -R[2, 1])],
|
| 69 |
+
0.01 * (q - q0),
|
| 70 |
+
])
|
| 71 |
+
return least_squares(res, q0, bounds=(Q_LO, Q_HI)).x
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
# ----------------------------------------------------------------------------
|
| 75 |
+
# Vision
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def handle_band(w):
|
| 79 |
+
"""Rows spanned by the handle bar in the (open-gripper) left wrist image.
|
| 80 |
+
|
| 81 |
+
The bar shows as a near-vertical mid-grey band left of the image centre;
|
| 82 |
+
image-up is the robot's right. Returns (first_row, last_row) or None."""
|
| 83 |
+
im = w.astype(float)
|
| 84 |
+
g = im.mean(2)
|
| 85 |
+
sat = im.max(2) - im.min(2)
|
| 86 |
+
m = (g > 70) & (g < 125) & (sat < 25)
|
| 87 |
+
m[:, :6] = False
|
| 88 |
+
m[:, 60:] = False
|
| 89 |
+
rows = np.nonzero(m.sum(1) >= 4)[0]
|
| 90 |
+
if len(rows) < 6:
|
| 91 |
+
return None
|
| 92 |
+
xs = np.nonzero(m[30:70])[1]
|
| 93 |
+
xc = float(xs.mean()) if len(xs) >= 20 else None
|
| 94 |
+
return int(rows.min()), int(rows.max()), xc
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
# ----------------------------------------------------------------------------
|
| 98 |
+
# Grasp point on the closed top-drawer handle, odometry (world) frame: measured by
|
| 99 |
+
# grasping on the demonstration seed; the same on every development seed.
|
| 100 |
+
REF_GRASP = np.array([0.618, -0.02, 0.740])
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def wrap(a):
|
| 104 |
+
return (a + np.pi) % (2 * np.pi) - np.pi
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class Policy:
|
| 108 |
+
"""The control policy that is scored on the hidden seeds."""
|
| 109 |
+
|
| 110 |
+
P = dict(STAND_X=0.43, STAND_DY=0.03, XPRE=0.12, XIN=0.02, VB=-0.3,
|
| 111 |
+
RETRACT=0.15, TRET=40, MAXREGRASP=4, RAMP=1, YAWTOL=0.02,
|
| 112 |
+
BAND_MIN_END=58, BAND_GOAL_END=70, BAND_PX_PER_M=700.0)
|
| 113 |
+
|
| 114 |
+
def reset(self, obs, tools):
|
| 115 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 116 |
+
self.phase = 'look'
|
| 117 |
+
self.t0 = 0
|
| 118 |
+
self.q = self.hold[4:11].astype(float).copy()
|
| 119 |
+
self.grasp = REF_GRASP.copy()
|
| 120 |
+
self.attempt = 0
|
| 121 |
+
self.zoff = [0.0, -0.02, 0.02, -0.035, 0.035]
|
| 122 |
+
self.traj = None
|
| 123 |
+
self.hold_pose = None
|
| 124 |
+
self.settle = 0
|
| 125 |
+
self.traj_pull = None
|
| 126 |
+
self.regrasps = 0
|
| 127 |
+
self.ycorr = 0
|
| 128 |
+
self.same_z = False
|
| 129 |
+
self.hand_world = self.grasp[:2].copy()
|
| 130 |
+
|
| 131 |
+
# -- helpers
|
| 132 |
+
def go(self, p, t):
|
| 133 |
+
self.phase, self.t0 = p, t
|
| 134 |
+
|
| 135 |
+
def rel(self, lo, pw):
|
| 136 |
+
x, y, yaw = lo[18], lo[19], lo[21]
|
| 137 |
+
d = pw[:2] - np.array([x, y])
|
| 138 |
+
c, s = np.cos(yaw), np.sin(yaw)
|
| 139 |
+
return np.array([c * d[0] + s * d[1], -s * d[0] + c * d[1], pw[2] - lo[20]])
|
| 140 |
+
|
| 141 |
+
def base_goto(self, raw, lo, target, tol=0.012, ytol=0.03):
|
| 142 |
+
x, y, yaw = lo[18], lo[19], lo[21]
|
| 143 |
+
ex, ey = target[0] - x, target[1] - y
|
| 144 |
+
c, s = np.cos(yaw), np.sin(yaw)
|
| 145 |
+
bx, by = c * ex + s * ey, -s * ex + c * ey
|
| 146 |
+
eyaw = wrap(target[2] - yaw)
|
| 147 |
+
vx = np.clip(1.2 * bx, -0.15, 0.15)
|
| 148 |
+
vy = np.clip(1.2 * by, -0.12, 0.12)
|
| 149 |
+
wz = np.clip(1.5 * eyaw, -0.3, 0.3)
|
| 150 |
+
done_xy = np.hypot(bx, by) < tol
|
| 151 |
+
sp = np.hypot(vx, vy)
|
| 152 |
+
if done_xy:
|
| 153 |
+
vx = vy = 0.0
|
| 154 |
+
elif sp < 0.065:
|
| 155 |
+
vx, vy = vx / sp * 0.065, vy / sp * 0.065
|
| 156 |
+
if abs(eyaw) < ytol:
|
| 157 |
+
wz = 0.0
|
| 158 |
+
elif abs(wz) < 0.12:
|
| 159 |
+
wz = np.sign(wz) * 0.12
|
| 160 |
+
raw[0], raw[1], raw[3] = vx, vy, wz
|
| 161 |
+
return done_xy and abs(eyaw) < ytol
|
| 162 |
+
|
| 163 |
+
def arm_target(self, lo, dx):
|
| 164 |
+
r = self.rel(lo, self.grasp + np.array([0, 0, self.zoff[self.attempt]]))
|
| 165 |
+
return r + np.array([dx, 0, 0])
|
| 166 |
+
|
| 167 |
+
# -- main
|
| 168 |
+
def act(self, obs, tools):
|
| 169 |
+
lo = np.asarray(obs['low_dim_obs'], dtype=float)
|
| 170 |
+
t = int(obs['t'])
|
| 171 |
+
raw = self.hold.copy()
|
| 172 |
+
raw[4:11] = self.q
|
| 173 |
+
raw[18] = 0.0
|
| 174 |
+
tt = t - self.t0
|
| 175 |
+
ph = self.phase
|
| 176 |
+
P = self.P
|
| 177 |
+
|
| 178 |
+
if ph == 'look':
|
| 179 |
+
if tt >= 3:
|
| 180 |
+
g = self.grasp
|
| 181 |
+
self.stand = np.array([g[0] - P['STAND_X'], g[1] + P['STAND_DY'], 0.0])
|
| 182 |
+
self.go('walk', t)
|
| 183 |
+
elif ph == 'walk':
|
| 184 |
+
done = self.base_goto(raw, lo, self.stand, tol=0.02, ytol=0.04)
|
| 185 |
+
self.settle = self.settle + 1 if done else 0
|
| 186 |
+
if self.settle > 5 or tt > 150:
|
| 187 |
+
self.go('pre', t)
|
| 188 |
+
self.qs = self.q.copy()
|
| 189 |
+
elif ph == 'pre':
|
| 190 |
+
if self.traj is None:
|
| 191 |
+
tgt_pre = self.arm_target(lo, -P['XPRE'])
|
| 192 |
+
q1 = ik_left(tgt_pre, self.q if self.attempt else np.array([-0.3, 0, -1.0, 0.5, 1.0, 0.8, 0.4]))
|
| 193 |
+
n = 6
|
| 194 |
+
self.traj = [ik_left(self.arm_target(lo, -P['XPRE'] + (P['XPRE'] + P['XIN']) * i / n), q1) for i in range(n + 1)]
|
| 195 |
+
self.traj_q1 = q1
|
| 196 |
+
a = min(1.0, tt / 35)
|
| 197 |
+
raw[4:11] = self.qs + a * (self.traj_q1 - self.qs)
|
| 198 |
+
if tt >= 40:
|
| 199 |
+
self.q = self.traj_q1.copy()
|
| 200 |
+
self.go('in', t)
|
| 201 |
+
elif ph == 'in':
|
| 202 |
+
f = min(1.0, tt / 40) * (len(self.traj) - 1)
|
| 203 |
+
i = min(int(f), len(self.traj) - 2)
|
| 204 |
+
a = f - i
|
| 205 |
+
raw[4:11] = (1 - a) * self.traj[i] + a * self.traj[i + 1]
|
| 206 |
+
if tt >= 48:
|
| 207 |
+
self.q = self.traj[-1].copy()
|
| 208 |
+
band = handle_band(tools.image('left_wrist'))
|
| 209 |
+
dy = 0.0
|
| 210 |
+
if band is not None:
|
| 211 |
+
if band[1] < P['BAND_MIN_END']:
|
| 212 |
+
dy = -(P['BAND_GOAL_END'] - band[1]) / P['BAND_PX_PER_M']
|
| 213 |
+
elif band[0] > 15:
|
| 214 |
+
dy = (band[0] - 5) / P['BAND_PX_PER_M']
|
| 215 |
+
if dy != 0.0 and self.ycorr < 3:
|
| 216 |
+
self.ycorr += 1
|
| 217 |
+
self.grasp[1] += float(np.clip(dy, -0.08, 0.08))
|
| 218 |
+
self.same_z = True
|
| 219 |
+
self.go('retreat', t)
|
| 220 |
+
else:
|
| 221 |
+
self.go('close', t)
|
| 222 |
+
elif ph == 'close':
|
| 223 |
+
raw[18] = 1.0
|
| 224 |
+
if tt >= 25:
|
| 225 |
+
if lo[44] < 0.95:
|
| 226 |
+
self.hold_pose = lo[18:22].copy()
|
| 227 |
+
self.go('pull', t)
|
| 228 |
+
else:
|
| 229 |
+
self.go('retreat', t)
|
| 230 |
+
elif ph == 'retreat':
|
| 231 |
+
raw[18] = 0.0
|
| 232 |
+
f = min(1.0, tt / 30) * (len(self.traj) - 1)
|
| 233 |
+
i = min(int(f), len(self.traj) - 2)
|
| 234 |
+
a = f - i
|
| 235 |
+
rev = self.traj[::-1]
|
| 236 |
+
raw[4:11] = (1 - a) * rev[i] + a * rev[i + 1]
|
| 237 |
+
if tt >= 35:
|
| 238 |
+
self.q = self.traj[0].copy()
|
| 239 |
+
self.qs = self.q.copy()
|
| 240 |
+
if not self.same_z:
|
| 241 |
+
self.attempt = (self.attempt + 1) % len(self.zoff)
|
| 242 |
+
self.same_z = False
|
| 243 |
+
self.traj = None
|
| 244 |
+
self.go('pre', t)
|
| 245 |
+
elif ph == 'pull':
|
| 246 |
+
raw[18] = 1.0
|
| 247 |
+
if self.traj_pull is None:
|
| 248 |
+
tgt = self.arm_target(lo, P['XIN'])
|
| 249 |
+
self.traj_pull = [ik_left(tgt - np.array([P['RETRACT'] * i / 4, 0, 0]), self.q) for i in range(5)]
|
| 250 |
+
f = min(1.0, tt / P['TRET']) * 4
|
| 251 |
+
i = min(int(f), 3)
|
| 252 |
+
a = f - i
|
| 253 |
+
raw[4:11] = (1 - a) * self.traj_pull[i] + a * self.traj_pull[i + 1]
|
| 254 |
+
raw[0] = P['VB'] * min(1.0, (tt + 1) / P['RAMP']) if tt < 150 else 0.0
|
| 255 |
+
if lo[44] < 0.9:
|
| 256 |
+
p, _ = fk_left(lo[0:7], TOOL)
|
| 257 |
+
c, s = np.cos(lo[21]), np.sin(lo[21])
|
| 258 |
+
self.hand_world = np.array([lo[18] + c * p[0] - s * p[1], lo[19] + s * p[0] + c * p[1]])
|
| 259 |
+
elif lo[44] > 0.97 and tt > 10 and self.regrasps < P['MAXREGRASP']:
|
| 260 |
+
# lost the handle: go back for it where the hand last held it
|
| 261 |
+
self.regrasps += 1
|
| 262 |
+
self.grasp[0] = self.hand_world[0]
|
| 263 |
+
g = self.grasp
|
| 264 |
+
self.stand = np.array([g[0] - P['STAND_X'], g[1] + P['STAND_DY'], 0.0])
|
| 265 |
+
self.q = raw[4:11].copy()
|
| 266 |
+
self.traj = None
|
| 267 |
+
self.traj_pull = None
|
| 268 |
+
self.attempt = 0
|
| 269 |
+
self.ycorr = 0
|
| 270 |
+
self.settle = 0
|
| 271 |
+
self.go('walk', t)
|
| 272 |
+
return raw
|
| 273 |
+
eyaw = wrap(self.hold_pose[3] - lo[21])
|
| 274 |
+
raw[3] = np.clip(2.0 * eyaw, -0.3, 0.3) if abs(eyaw) > P['YAWTOL'] else 0.0
|
| 275 |
+
c, s = np.cos(lo[21]), np.sin(lo[21])
|
| 276 |
+
ey = -s * (self.hold_pose[0] - lo[18]) + c * (self.hold_pose[1] - lo[19])
|
| 277 |
+
raw[1] = np.clip(1.5 * ey, -0.1, 0.1) if abs(ey) > 0.02 else 0.0
|
| 278 |
+
if tt > 200:
|
| 279 |
+
raw[18] = 0.0
|
| 280 |
+
return raw
|
policies/drawer_top_open/opus-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,1,680,success,0
|
| 3 |
+
620001,1,575,success,0
|
| 4 |
+
620002,1,542,success,0
|
| 5 |
+
620003,1,570,success,0
|
| 6 |
+
620004,1,545,success,0
|
| 7 |
+
620005,1,549,success,0
|
| 8 |
+
620006,1,536,success,0
|
| 9 |
+
620007,1,624,success,0
|
| 10 |
+
620008,1,549,success,0
|
| 11 |
+
620009,1,573,success,0
|
| 12 |
+
620010,1,572,success,0
|
| 13 |
+
620011,1,531,success,0
|
| 14 |
+
620012,1,570,success,0
|
| 15 |
+
620013,1,528,success,0
|
| 16 |
+
620014,1,536,success,0
|
| 17 |
+
620015,1,548,success,0
|
| 18 |
+
620016,1,527,success,0
|
| 19 |
+
620017,1,549,success,0
|
| 20 |
+
620018,1,526,success,0
|
| 21 |
+
620019,1,540,success,0
|
| 22 |
+
620020,1,570,success,0
|
| 23 |
+
620021,1,524,success,0
|
| 24 |
+
620022,1,523,success,0
|
| 25 |
+
620023,1,537,success,0
|
| 26 |
+
620024,1,527,success,0
|
| 27 |
+
620025,1,677,success,0
|
| 28 |
+
620026,1,541,success,0
|
| 29 |
+
620027,1,539,success,0
|
| 30 |
+
620028,1,523,success,0
|
| 31 |
+
620029,1,539,success,0
|
| 32 |
+
620030,1,530,success,0
|
| 33 |
+
620031,1,577,success,0
|
| 34 |
+
620032,1,573,success,0
|
| 35 |
+
620033,1,596,success,0
|
| 36 |
+
620034,1,533,success,0
|
| 37 |
+
620035,1,534,success,0
|
| 38 |
+
620036,1,556,success,0
|
| 39 |
+
620037,1,573,success,0
|
| 40 |
+
620038,1,562,success,0
|
| 41 |
+
620039,1,534,success,0
|
| 42 |
+
620040,1,544,success,0
|
| 43 |
+
620041,1,545,success,0
|
| 44 |
+
620042,1,568,success,0
|
| 45 |
+
620043,1,539,success,0
|
| 46 |
+
620044,1,540,success,0
|
| 47 |
+
620045,1,548,success,0
|
| 48 |
+
620046,1,534,success,0
|
| 49 |
+
620047,1,574,success,0
|
| 50 |
+
620048,1,533,success,0
|
| 51 |
+
620049,1,534,success,0
|
| 52 |
+
620050,1,595,success,0
|
| 53 |
+
620051,1,541,success,0
|
| 54 |
+
620052,1,556,success,0
|
| 55 |
+
620053,1,570,success,0
|
| 56 |
+
620054,1,591,success,0
|
| 57 |
+
620055,1,536,success,0
|
| 58 |
+
620056,1,535,success,0
|
| 59 |
+
620057,1,541,success,0
|
| 60 |
+
620058,1,679,success,0
|
| 61 |
+
620059,1,542,success,0
|
| 62 |
+
620060,1,534,success,0
|
| 63 |
+
620061,1,572,success,0
|
| 64 |
+
620062,1,554,success,0
|
| 65 |
+
620063,1,532,success,0
|
| 66 |
+
620064,1,555,success,0
|
| 67 |
+
620065,1,620,success,0
|
| 68 |
+
620066,1,533,success,0
|
| 69 |
+
620067,1,570,success,0
|
| 70 |
+
620068,1,533,success,0
|
| 71 |
+
620069,1,547,success,0
|
| 72 |
+
620070,1,596,success,0
|
| 73 |
+
620071,1,540,success,0
|
| 74 |
+
620072,1,536,success,0
|
| 75 |
+
620073,1,541,success,0
|
| 76 |
+
620074,1,552,success,0
|
| 77 |
+
620075,1,538,success,0
|
| 78 |
+
620076,1,651,success,0
|
| 79 |
+
620077,1,546,success,0
|
| 80 |
+
620078,1,547,success,0
|
| 81 |
+
620079,1,590,success,0
|
| 82 |
+
620080,1,534,success,0
|
| 83 |
+
620081,1,569,success,0
|
| 84 |
+
620082,1,552,success,0
|
| 85 |
+
620083,1,539,success,0
|
| 86 |
+
620084,1,528,success,0
|
| 87 |
+
620085,1,534,success,0
|
| 88 |
+
620086,0,1350,timeout,0
|
| 89 |
+
620087,1,734,success,0
|
| 90 |
+
620088,1,545,success,0
|
| 91 |
+
620089,1,535,success,0
|
| 92 |
+
620090,1,538,success,0
|
| 93 |
+
620091,1,535,success,0
|
| 94 |
+
620092,1,532,success,0
|
| 95 |
+
620093,1,533,success,0
|
| 96 |
+
620094,1,572,success,0
|
| 97 |
+
620095,1,570,success,0
|
| 98 |
+
620096,0,1350,timeout,0
|
| 99 |
+
620097,1,536,success,0
|
| 100 |
+
620098,1,524,success,0
|
| 101 |
+
620099,1,651,success,0
|
policies/drawer_top_open/opus-s2/g1kin.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Approximate G1 arm forward kinematics (from the public g1_29dof URDF), pelvis frame."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def rotx(a):
|
| 6 |
+
c, s = np.cos(a), np.sin(a)
|
| 7 |
+
return np.array([[1, 0, 0], [0, c, -s], [0, s, c]])
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def roty(a):
|
| 11 |
+
c, s = np.cos(a), np.sin(a)
|
| 12 |
+
return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]])
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def rotz(a):
|
| 16 |
+
c, s = np.cos(a), np.sin(a)
|
| 17 |
+
return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def rpy(r, p, y):
|
| 21 |
+
return rotz(y) @ roty(p) @ rotx(r)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
TORSO = np.array([-0.0039635, 0.0, 0.054])
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def arm_chain(side):
|
| 28 |
+
s = 1.0 if side == 'L' else -1.0
|
| 29 |
+
return [
|
| 30 |
+
# (xyz, rpy, axis)
|
| 31 |
+
(np.array([0.0039563, s * 0.10022, 0.23778]), (s * 0.27931, 0, 0), 'y'),
|
| 32 |
+
(np.array([0.0, s * 0.038, -0.013831]), (-s * 0.27925, 0, 0), 'x'),
|
| 33 |
+
(np.array([0.0, s * 0.00624, -0.1032]), (0, 0, 0), 'z'),
|
| 34 |
+
(np.array([0.015783, 0.0, -0.080518]), (0, 0, 0), 'y'),
|
| 35 |
+
(np.array([0.100, s * 0.00188791, -0.010]), (0, 0, 0), 'x'),
|
| 36 |
+
(np.array([0.038, 0.0, 0.0]), (0, 0, 0), 'y'),
|
| 37 |
+
(np.array([0.046, 0.0, 0.0]), (0, 0, 0), 'z'),
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
AX = {'x': rotx, 'y': roty, 'z': rotz}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def fk(q, side='L', tool=np.array([0.12, 0.0, 0.0])):
|
| 45 |
+
"""Return (tool position, rotation) in pelvis frame, and the joint frames."""
|
| 46 |
+
R = np.eye(3)
|
| 47 |
+
p = TORSO.copy()
|
| 48 |
+
frames = []
|
| 49 |
+
for (xyz, r, ax), qi in zip(arm_chain(side), q):
|
| 50 |
+
p = p + R @ xyz
|
| 51 |
+
R = R @ rpy(*r) @ AX[ax](qi)
|
| 52 |
+
frames.append((p.copy(), R.copy()))
|
| 53 |
+
return p + R @ tool, R, frames
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
LO = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443])
|
| 57 |
+
HI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443])
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def limits(side):
|
| 61 |
+
return LO, HI
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def rot_err(R, Rd):
|
| 65 |
+
E = Rd @ R.T
|
| 66 |
+
w = np.array([E[2, 1] - E[1, 2], E[0, 2] - E[2, 0], E[1, 0] - E[0, 1]]) / 2
|
| 67 |
+
return w
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def ik(p_des, R_des, q0, side='L', tool=np.array([0.12, 0.0, 0.0]), w_rot=0.3, iters=300,
|
| 71 |
+
q_rest=None, w_rest=1e-4):
|
| 72 |
+
q = np.array(q0, dtype=float)
|
| 73 |
+
lo, hi = limits(side)
|
| 74 |
+
if q_rest is None:
|
| 75 |
+
q_rest = np.zeros(7)
|
| 76 |
+
for _ in range(iters):
|
| 77 |
+
p, R, _ = fk(q, side, tool)
|
| 78 |
+
e = np.concatenate([p_des - p, w_rot * rot_err(R, R_des)])
|
| 79 |
+
if np.linalg.norm(e) < 1e-5:
|
| 80 |
+
break
|
| 81 |
+
J = np.zeros((6, 7))
|
| 82 |
+
h = 1e-5
|
| 83 |
+
for j in range(7):
|
| 84 |
+
dq = q.copy(); dq[j] += h
|
| 85 |
+
p2, R2, _ = fk(dq, side, tool)
|
| 86 |
+
J[:3, j] = (p2 - p) / h
|
| 87 |
+
J[3:, j] = w_rot * rot_err(R, R2) / h
|
| 88 |
+
lam = 1e-3
|
| 89 |
+
A = J.T @ J + lam * np.eye(7) + w_rest * np.eye(7)
|
| 90 |
+
dq = np.linalg.solve(A, J.T @ e + w_rest * (q_rest - q))
|
| 91 |
+
q = np.clip(q + dq, lo + 0.02, hi - 0.02)
|
| 92 |
+
p, R, _ = fk(q, side, tool)
|
| 93 |
+
return q, np.linalg.norm(p_des - p), np.linalg.norm(rot_err(R, R_des))
|
policies/drawer_top_open/opus-s2/handles.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy import ndimage
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def find_handles(img, vmin=55, vmax=110, min_area=12):
|
| 6 |
+
a = img.astype(np.int16)
|
| 7 |
+
v = a.max(axis=2)
|
| 8 |
+
sp = v - a.min(axis=2)
|
| 9 |
+
m = (sp < 14) & (v > vmin) & (v < vmax)
|
| 10 |
+
lab, n = ndimage.label(m)
|
| 11 |
+
out = []
|
| 12 |
+
for k in range(1, n + 1):
|
| 13 |
+
ys, xs = np.nonzero(lab == k)
|
| 14 |
+
if len(xs) < min_area:
|
| 15 |
+
continue
|
| 16 |
+
cu, cv = xs.mean(), ys.mean()
|
| 17 |
+
X = np.stack([xs - cu, ys - cv]).astype(float)
|
| 18 |
+
ev, evec = np.linalg.eigh(X @ X.T / len(xs))
|
| 19 |
+
d = evec[:, 1]
|
| 20 |
+
if d[0] < 0:
|
| 21 |
+
d = -d
|
| 22 |
+
proj = (xs - cu) * d[0] + (ys - cv) * d[1]
|
| 23 |
+
length = proj.max() - proj.min() + 1
|
| 24 |
+
width = len(xs) / length
|
| 25 |
+
angle = float(np.degrees(np.arctan2(d[1], d[0])))
|
| 26 |
+
if width < 1.5 or length < 6:
|
| 27 |
+
continue
|
| 28 |
+
# endpoints: mean of pixels within 1.5px of each extreme along axis
|
| 29 |
+
e1 = np.array([xs[proj <= proj.min() + 1.5].mean(), ys[proj <= proj.min() + 1.5].mean()])
|
| 30 |
+
e2 = np.array([xs[proj >= proj.max() - 1.5].mean(), ys[proj >= proj.max() - 1.5].mean()])
|
| 31 |
+
trunc = xs.min() <= 0 or xs.max() >= img.shape[1] - 1 or ys.min() <= 0 or ys.max() >= img.shape[0] - 1
|
| 32 |
+
out.append(dict(c=(cu, cv), e1=e1, e2=e2, length=length, width=width, angle=angle,
|
| 33 |
+
area=len(xs), trunc=bool(trunc)))
|
| 34 |
+
return out
|
policies/drawer_top_open/opus-s2/policy.py
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Open the top drawer of the kitchen cabinet.
|
| 2 |
+
|
| 3 |
+
Pipeline: look at the drawer front with the left wrist camera, localise the top
|
| 4 |
+
handle in 3D (calibrated wrist camera + arm forward kinematics + known handle
|
| 5 |
+
height), walk to a standing spot, re-localise from close by, grasp the handle
|
| 6 |
+
with the left gripper rolled 90 degrees (fingers above/below the bar) and pull.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
from scipy.spatial.transform import Rotation
|
| 11 |
+
|
| 12 |
+
from g1kin import fk, ik, rotx, roty, rotz
|
| 13 |
+
from handles import find_handles
|
| 14 |
+
|
| 15 |
+
# Left wrist camera, in the wrist_yaw link frame: offset, rotation (rotvec), focal (px).
|
| 16 |
+
CAM_OFF = np.array([0.136654, 0.007828, 0.035661])
|
| 17 |
+
CAM_R = Rotation.from_rotvec([-1.72328, 1.756228, -0.776116]).as_matrix()
|
| 18 |
+
CAM_F = 68.061685
|
| 19 |
+
HZ = (0.7365, 0.6008, 0.4956) # world heights of the three stacked handle bars
|
| 20 |
+
HHALF = (0.0403, 0.0516, 0.0495) # their half lengths
|
| 21 |
+
Z_TOP = HZ[0]
|
| 22 |
+
|
| 23 |
+
TOOL = np.array([0.16, 0.0, 0.0]) # grasp point between the fingertips, wrist_yaw frame
|
| 24 |
+
QR_SAFE = np.array([0.3, -0.2, 0.0, 1.2, 0.0, 0.0, 0.0])
|
| 25 |
+
|
| 26 |
+
STAND = np.array([0.30, 0.12]) # handle position in the pelvis frame when grasping
|
| 27 |
+
ROLL = np.pi / 2
|
| 28 |
+
GRASP_DX = 0.02 # final grasp point beyond the bar (handle frame, m): bar deep between the fingers
|
| 29 |
+
GRASP_DY = -0.02 # lateral correction so the fingers close near the middle of the bar
|
| 30 |
+
V_STAR = 30.0 # bar row (rotated wrist image) seen just before good grasps
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def cam_world(q, pel):
|
| 34 |
+
_, _, fr = fk(q, "L")
|
| 35 |
+
p, R = fr[6]
|
| 36 |
+
Ry = rotz(pel[3])
|
| 37 |
+
C = np.array([pel[0], pel[1], pel[2]]) + Ry @ (p + R @ CAM_OFF)
|
| 38 |
+
return C, Ry @ R @ CAM_R
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def ray_plane(C, R, uv, z):
|
| 42 |
+
d = R @ np.array([(uv[0] - 41.5) / CAM_F, (uv[1] - 41.5) / CAM_F, 1.0])
|
| 43 |
+
if d[2] > -1e-3:
|
| 44 |
+
return None
|
| 45 |
+
return C + (z - C[2]) / d[2] * d
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _bar_center(C, R, h, z, half):
|
| 49 |
+
"""Centre (x, y) and yaw of a bar of known height and half length, or None."""
|
| 50 |
+
p1 = ray_plane(C, R, h["e1"], z)
|
| 51 |
+
p2 = ray_plane(C, R, h["e2"], z)
|
| 52 |
+
if p1 is None or p2 is None:
|
| 53 |
+
return None
|
| 54 |
+
L = np.linalg.norm(p1 - p2)
|
| 55 |
+
if h["trunc"]:
|
| 56 |
+
if not (0.015 < L < 2 * half + 0.02):
|
| 57 |
+
return None
|
| 58 |
+
e1_in = 1.5 < h["e1"][0] < 81.5 and 1.5 < h["e1"][1] < 81.5
|
| 59 |
+
d = (p2 - p1) / (L + 1e-9)
|
| 60 |
+
if e1_in:
|
| 61 |
+
p2 = p1 + d * 2 * half
|
| 62 |
+
else:
|
| 63 |
+
p1 = p2 - d * 2 * half
|
| 64 |
+
elif abs(L - 2 * half) > 0.025:
|
| 65 |
+
return None
|
| 66 |
+
d = p1 - p2
|
| 67 |
+
yaw = np.arctan2(-d[0], d[1])
|
| 68 |
+
return np.array([(p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2]), float(yaw), bool(h["trunc"])
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def localize_top(img, q, pel, prior=None):
|
| 72 |
+
"""World position (x, y) and yaw of the top handle, or None.
|
| 73 |
+
|
| 74 |
+
Every bar seen is tried as each of the three stacked handles (known heights);
|
| 75 |
+
the labelling under which the bars agree on one position wins.
|
| 76 |
+
"""
|
| 77 |
+
C, R = cam_world(q, pel)
|
| 78 |
+
hs = [h for h in find_handles(img) if abs(h["angle"]) < 40 and h["length"] > 8 and h["width"] > 1.6]
|
| 79 |
+
hs.sort(key=lambda h: h["c"][1])
|
| 80 |
+
hyp = [] # (det index, k, centre, yaw, trunc)
|
| 81 |
+
for i, h in enumerate(hs):
|
| 82 |
+
for k in range(3):
|
| 83 |
+
r = _bar_center(C, R, h, HZ[k], HHALF[k])
|
| 84 |
+
if r is not None:
|
| 85 |
+
hyp.append((i, k, r[0], r[1], r[2]))
|
| 86 |
+
if not hyp:
|
| 87 |
+
return None
|
| 88 |
+
best, best_score = None, -1e9
|
| 89 |
+
for a in hyp:
|
| 90 |
+
members = [a]
|
| 91 |
+
for b in hyp:
|
| 92 |
+
if b[0] == a[0]:
|
| 93 |
+
continue
|
| 94 |
+
if (b[0] < a[0]) != (b[1] < a[1]) or b[1] == a[1]:
|
| 95 |
+
continue
|
| 96 |
+
if np.linalg.norm(b[2] - a[2]) < 0.03 and all(m[0] != b[0] for m in members):
|
| 97 |
+
members.append(b)
|
| 98 |
+
score = len(members) - 0.3 * sum(m[4] for m in members)
|
| 99 |
+
if prior is not None:
|
| 100 |
+
score -= 3.0 * np.linalg.norm(a[2] - prior)
|
| 101 |
+
if score > best_score:
|
| 102 |
+
best, best_score = members, score
|
| 103 |
+
w = np.array([0.3 if m[4] else 1.0 for m in best])
|
| 104 |
+
c = sum(wi * m[2] for wi, m in zip(w, best)) / w.sum()
|
| 105 |
+
yaws = [m[3] for m in best if not m[4]] or [m[3] for m in best]
|
| 106 |
+
return c, float(np.median(yaws)), len(best)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def bar_row_rotated(img):
|
| 110 |
+
"""Row at which the handle bar crosses the finger axis, in the wrist image rotated so
|
| 111 |
+
that world-up is image-up (gripper rolled 90 degrees). Returns (row, width) or None."""
|
| 112 |
+
rot = np.ascontiguousarray(np.rot90(img, k=-1))
|
| 113 |
+
best = None
|
| 114 |
+
for h in find_handles(rot):
|
| 115 |
+
if abs(h["angle"]) > 30 or h["width"] < 3.5 or h["length"] < 12:
|
| 116 |
+
continue
|
| 117 |
+
cu, cv = h["c"]
|
| 118 |
+
e1, e2 = h["e1"], h["e2"]
|
| 119 |
+
slope = (e2[1] - e1[1]) / (e2[0] - e1[0] + 1e-9)
|
| 120 |
+
row = cv + slope * (43 - cu)
|
| 121 |
+
if best is None or h["area"] > best[2]:
|
| 122 |
+
best = (row, h["width"], h["area"])
|
| 123 |
+
return None if best is None else best[:2]
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
class Policy:
|
| 127 |
+
def reset(self, obs, tools):
|
| 128 |
+
o = np.asarray(obs["low_dim_obs"], float)
|
| 129 |
+
self.x0, self.y0, self.yaw0 = o[18], o[19], o[21]
|
| 130 |
+
self.t = 0
|
| 131 |
+
self.phase = "look0"
|
| 132 |
+
self.pt = 0
|
| 133 |
+
self.base_goal = None
|
| 134 |
+
self.yaw_goal = self.yaw0
|
| 135 |
+
self.ql = np.zeros(7)
|
| 136 |
+
self.qr = np.zeros(7)
|
| 137 |
+
self.grip = 0.0
|
| 138 |
+
self.handle = None
|
| 139 |
+
self.hyaw = 0.0
|
| 140 |
+
self.dz = 0.0
|
| 141 |
+
self.dbg = None
|
| 142 |
+
self.debug = getattr(self, "debug", False)
|
| 143 |
+
|
| 144 |
+
# ---------------------------------------------------------------- base
|
| 145 |
+
def base_cmd(self, o):
|
| 146 |
+
if self.base_goal is None:
|
| 147 |
+
return 0.0, 0.0, 0.0, 0.0
|
| 148 |
+
ex, ey = self.base_goal[0] - o[18], self.base_goal[1] - o[19]
|
| 149 |
+
c, s = np.cos(o[21]), np.sin(o[21])
|
| 150 |
+
bx, by = c * ex + s * ey, -s * ex + c * ey
|
| 151 |
+
vx, vy = np.clip(1.5 * bx, -0.2, 0.2), np.clip(1.5 * by, -0.2, 0.2)
|
| 152 |
+
sp = np.hypot(vx, vy)
|
| 153 |
+
dist = np.hypot(bx, by)
|
| 154 |
+
if sp < 0.06:
|
| 155 |
+
if dist > 0.02:
|
| 156 |
+
vx, vy = vx / (sp + 1e-9) * 0.06, vy / (sp + 1e-9) * 0.06
|
| 157 |
+
else:
|
| 158 |
+
vx = vy = 0.0
|
| 159 |
+
eyaw = (self.yaw_goal - o[21] + np.pi) % (2 * np.pi) - np.pi
|
| 160 |
+
wz = np.clip(2.0 * eyaw, -0.4, 0.4)
|
| 161 |
+
if abs(wz) < 0.03:
|
| 162 |
+
wz = 0.0
|
| 163 |
+
return vx, vy, wz, dist
|
| 164 |
+
|
| 165 |
+
def handle_rel(self, o):
|
| 166 |
+
"""Top handle in the current pelvis frame (x, y, z) and relative yaw."""
|
| 167 |
+
d = self.handle - o[18:20]
|
| 168 |
+
c, s = np.cos(o[21]), np.sin(o[21])
|
| 169 |
+
return np.array([c * d[0] + s * d[1], -s * d[0] + c * d[1], Z_TOP - o[20]]), self.hyaw - o[21]
|
| 170 |
+
|
| 171 |
+
def grasp_R(self, ryaw):
|
| 172 |
+
return rotz(ryaw) @ rotx(ROLL)
|
| 173 |
+
|
| 174 |
+
def set_stand_goal(self):
|
| 175 |
+
c, s = np.cos(self.hyaw), np.sin(self.hyaw)
|
| 176 |
+
off = np.array([c * STAND[0] - s * STAND[1], s * STAND[0] + c * STAND[1]])
|
| 177 |
+
self.base_goal = self.handle - off
|
| 178 |
+
self.yaw_goal = self.hyaw
|
| 179 |
+
|
| 180 |
+
def look(self, o, tools):
|
| 181 |
+
img = tools.image("left_wrist")
|
| 182 |
+
r = localize_top(img, o[0:7], o[18:22], prior=self.handle)
|
| 183 |
+
if r is None:
|
| 184 |
+
self.dbg = dict(look="fail")
|
| 185 |
+
return False
|
| 186 |
+
self.handle, self.hyaw = r[0], float(np.clip(r[1], -0.15, 0.15))
|
| 187 |
+
self.dbg = dict(h=np.round(self.handle, 3).tolist(), yaw=round(self.hyaw, 3), n=r[2])
|
| 188 |
+
return True
|
| 189 |
+
|
| 190 |
+
# ---------------------------------------------------------------- act
|
| 191 |
+
def act(self, obs, tools):
|
| 192 |
+
o = np.asarray(obs["low_dim_obs"], float)
|
| 193 |
+
self.t += 1
|
| 194 |
+
self.pt += 1
|
| 195 |
+
qcur = o[0:7]
|
| 196 |
+
|
| 197 |
+
if self.phase == "look0":
|
| 198 |
+
self.ql = np.zeros(7)
|
| 199 |
+
self.qr = np.zeros(7)
|
| 200 |
+
self.grip = 0.0
|
| 201 |
+
if self.pt >= 25:
|
| 202 |
+
ok = self.look(o, tools)
|
| 203 |
+
if not ok:
|
| 204 |
+
self.handle = np.array([self.x0 + 0.54, self.y0])
|
| 205 |
+
self.hyaw = 0.0
|
| 206 |
+
self.set_stand_goal()
|
| 207 |
+
self.phase, self.pt = "walk", 0
|
| 208 |
+
# arm pose for walking / second look: camera above and behind the handle
|
| 209 |
+
self.q_look, _, _ = ik(np.array([0.22, 0.12, 0.12]), roty(0.25), np.zeros(7), tool=TOOL)
|
| 210 |
+
elif self.phase == "walk":
|
| 211 |
+
s = min(1.0, self.pt / 30)
|
| 212 |
+
self.ql = s * self.q_look
|
| 213 |
+
self.qr = s * QR_SAFE
|
| 214 |
+
_, _, _, dist = self.base_cmd(o)
|
| 215 |
+
eyaw = abs(self.yaw_goal - o[21])
|
| 216 |
+
if (dist < 0.02 and eyaw < 0.05 and self.pt > 40) or self.pt > 250:
|
| 217 |
+
self.phase, self.pt = "settle", 0
|
| 218 |
+
elif self.phase == "settle":
|
| 219 |
+
if self.pt >= 20:
|
| 220 |
+
self.look(o, tools)
|
| 221 |
+
self.set_stand_goal()
|
| 222 |
+
hr, ryaw = self.handle_rel(o)
|
| 223 |
+
self.q_from = qcur.copy()
|
| 224 |
+
self.q_pre, _, _ = ik(hr + rotz(ryaw) @ np.array([-0.12, GRASP_DY, 0]), self.grasp_R(ryaw),
|
| 225 |
+
self.ql, tool=TOOL)
|
| 226 |
+
self.phase, self.pt = "pre", 0
|
| 227 |
+
elif self.phase == "pre":
|
| 228 |
+
s = min(1.0, self.pt / 40)
|
| 229 |
+
self.ql = self.q_from + s * (self.q_pre - self.q_from)
|
| 230 |
+
if self.pt >= 55:
|
| 231 |
+
self.phase, self.pt = "approach", 0
|
| 232 |
+
elif self.phase == "approach":
|
| 233 |
+
# -0.12 -> -0.05 (steps 0-40), dwell (40-70), -> GRASP_DX (70-100)
|
| 234 |
+
if self.pt < 40:
|
| 235 |
+
dx = -0.12 + 0.07 * self.pt / 40
|
| 236 |
+
elif self.pt < 70:
|
| 237 |
+
dx = -0.05
|
| 238 |
+
else:
|
| 239 |
+
dx = -0.05 + (0.05 + GRASP_DX) * min(1.0, (self.pt - 70) / 30)
|
| 240 |
+
if self.pt % 5 == 1:
|
| 241 |
+
if self.pt < 95:
|
| 242 |
+
r = bar_row_rotated(tools.image("left_wrist"))
|
| 243 |
+
if r is not None:
|
| 244 |
+
depth = max(0.03, -dx + 0.03)
|
| 245 |
+
err = r[0] - V_STAR
|
| 246 |
+
self.dz = float(np.clip(self.dz - 0.5 * err * depth / CAM_F, -0.05, 0.05))
|
| 247 |
+
self.dbg = dict(bar=None if r is None else [round(float(r[0]), 1), round(float(r[1]), 1)],
|
| 248 |
+
dz=round(self.dz, 4))
|
| 249 |
+
hr, ryaw = self.handle_rel(o)
|
| 250 |
+
self.ql, _, _ = ik(hr + rotz(ryaw) @ np.array([dx, GRASP_DY, 0]) + np.array([0, 0, self.dz]),
|
| 251 |
+
self.grasp_R(ryaw), self.ql, tool=TOOL, iters=40)
|
| 252 |
+
if self.pt >= 110:
|
| 253 |
+
self.phase, self.pt = "grasp", 0
|
| 254 |
+
elif self.phase == "grasp":
|
| 255 |
+
self.grip = min(1.0, self.pt / 15)
|
| 256 |
+
if self.pt >= 40:
|
| 257 |
+
self.phase, self.pt = "pull", 0
|
| 258 |
+
hr, ryaw = self.handle_rel(o)
|
| 259 |
+
self.pull_from = hr + rotz(ryaw) @ np.array([GRASP_DX, GRASP_DY, 0]) + np.array([0, 0, self.dz])
|
| 260 |
+
self.pull_ryaw = ryaw
|
| 261 |
+
c, s_ = np.cos(self.hyaw), np.sin(self.hyaw)
|
| 262 |
+
self.base_goal = self.base_goal - 0.35 * np.array([c, s_])
|
| 263 |
+
self.base_hold = True
|
| 264 |
+
elif self.phase == "pull":
|
| 265 |
+
s = min(1.0, self.pt / 80)
|
| 266 |
+
if self.pt % 4 == 1:
|
| 267 |
+
tgt = self.pull_from + rotz(self.pull_ryaw) @ np.array([-0.18 * s, 0, 0])
|
| 268 |
+
self.ql, _, _ = ik(tgt, self.grasp_R(self.pull_ryaw), self.ql, tool=TOOL, iters=40)
|
| 269 |
+
|
| 270 |
+
raw = np.zeros(20)
|
| 271 |
+
raw[2] = 0.74
|
| 272 |
+
if self.phase in ("look0", "settle", "pre", "approach", "grasp") or (self.phase == "pull" and self.pt < 60):
|
| 273 |
+
vx = vy = wz = 0.0
|
| 274 |
+
else:
|
| 275 |
+
vx, vy, wz, _ = self.base_cmd(o)
|
| 276 |
+
raw[0], raw[1], raw[3] = vx, vy, wz
|
| 277 |
+
raw[4:11] = self.ql
|
| 278 |
+
raw[11:18] = self.qr
|
| 279 |
+
raw[18] = self.grip
|
| 280 |
+
raw[19] = 0.0
|
| 281 |
+
return raw
|
policies/drawer_top_open/opus-s3/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,1,650,success,0
|
| 3 |
+
620001,1,612,success,0
|
| 4 |
+
620002,1,619,success,0
|
| 5 |
+
620003,1,582,success,0
|
| 6 |
+
620004,1,610,success,0
|
| 7 |
+
620005,1,676,success,0
|
| 8 |
+
620006,1,595,success,0
|
| 9 |
+
620007,1,560,success,0
|
| 10 |
+
620008,1,592,success,0
|
| 11 |
+
620009,1,632,success,0
|
| 12 |
+
620010,1,622,success,0
|
| 13 |
+
620011,1,689,success,0
|
| 14 |
+
620012,1,709,success,0
|
| 15 |
+
620013,1,727,success,0
|
| 16 |
+
620014,1,593,success,0
|
| 17 |
+
620015,1,603,success,0
|
| 18 |
+
620016,1,644,success,0
|
| 19 |
+
620017,1,644,success,0
|
| 20 |
+
620018,1,632,success,0
|
| 21 |
+
620019,1,546,success,0
|
| 22 |
+
620020,1,610,success,0
|
| 23 |
+
620021,1,651,success,0
|
| 24 |
+
620022,1,635,success,0
|
| 25 |
+
620023,1,629,success,0
|
| 26 |
+
620024,1,640,success,0
|
| 27 |
+
620025,1,624,success,0
|
| 28 |
+
620026,1,599,success,0
|
| 29 |
+
620027,1,597,success,0
|
| 30 |
+
620028,1,677,success,0
|
| 31 |
+
620029,1,664,success,0
|
| 32 |
+
620030,1,714,success,0
|
| 33 |
+
620031,1,616,success,0
|
| 34 |
+
620032,1,632,success,0
|
| 35 |
+
620033,1,601,success,0
|
| 36 |
+
620034,1,665,success,0
|
| 37 |
+
620035,1,586,success,0
|
| 38 |
+
620036,1,603,success,0
|
| 39 |
+
620037,1,612,success,0
|
| 40 |
+
620038,1,583,success,0
|
| 41 |
+
620039,1,624,success,0
|
| 42 |
+
620040,1,585,success,0
|
| 43 |
+
620041,1,683,success,0
|
| 44 |
+
620042,1,747,success,0
|
| 45 |
+
620043,1,630,success,0
|
| 46 |
+
620044,1,648,success,0
|
| 47 |
+
620045,1,632,success,0
|
| 48 |
+
620046,1,593,success,0
|
| 49 |
+
620047,1,646,success,0
|
| 50 |
+
620048,1,706,success,0
|
| 51 |
+
620049,1,585,success,0
|
| 52 |
+
620050,1,685,success,0
|
| 53 |
+
620051,1,627,success,0
|
| 54 |
+
620052,1,598,success,0
|
| 55 |
+
620053,1,586,success,0
|
| 56 |
+
620054,1,604,success,0
|
| 57 |
+
620055,1,628,success,0
|
| 58 |
+
620056,1,592,success,0
|
| 59 |
+
620057,1,587,success,0
|
| 60 |
+
620058,1,609,success,0
|
| 61 |
+
620059,1,671,success,0
|
| 62 |
+
620060,1,607,success,0
|
| 63 |
+
620061,1,681,success,0
|
| 64 |
+
620062,1,623,success,0
|
| 65 |
+
620063,1,603,success,0
|
| 66 |
+
620064,1,573,success,0
|
| 67 |
+
620065,1,605,success,0
|
| 68 |
+
620066,1,587,success,0
|
| 69 |
+
620067,1,590,success,0
|
| 70 |
+
620068,1,600,success,0
|
| 71 |
+
620069,1,596,success,0
|
| 72 |
+
620070,1,586,success,0
|
| 73 |
+
620071,1,589,success,0
|
| 74 |
+
620072,1,825,success,0
|
| 75 |
+
620073,1,751,success,0
|
| 76 |
+
620074,1,550,success,0
|
| 77 |
+
620075,1,654,success,0
|
| 78 |
+
620076,1,588,success,0
|
| 79 |
+
620077,1,601,success,0
|
| 80 |
+
620078,1,604,success,0
|
| 81 |
+
620079,1,613,success,0
|
| 82 |
+
620080,1,716,success,0
|
| 83 |
+
620081,1,595,success,0
|
| 84 |
+
620082,1,761,success,0
|
| 85 |
+
620083,1,598,success,0
|
| 86 |
+
620084,1,643,success,0
|
| 87 |
+
620085,1,582,success,0
|
| 88 |
+
620086,1,620,success,0
|
| 89 |
+
620087,1,623,success,0
|
| 90 |
+
620088,1,630,success,0
|
| 91 |
+
620089,1,661,success,0
|
| 92 |
+
620090,1,585,success,0
|
| 93 |
+
620091,1,658,success,0
|
| 94 |
+
620092,1,683,success,0
|
| 95 |
+
620093,1,572,success,0
|
| 96 |
+
620094,1,669,success,0
|
| 97 |
+
620095,1,613,success,0
|
| 98 |
+
620096,1,584,success,0
|
| 99 |
+
620097,1,617,success,0
|
| 100 |
+
620098,1,629,success,0
|
| 101 |
+
620099,1,575,success,0
|
policies/drawer_top_open/opus-s3/headcam.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Head camera model (pelvis frame), calibrated from the left gripper seen at known arm poses."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
# camera centre (pelvis frame), camera axes as columns (x right, y down, z optical), focal px
|
| 5 |
+
CAM_C = np.array([0.1379, 0.0027, 0.3873])
|
| 6 |
+
CAM_R = np.array([[0.0242, -0.9044, 0.426],
|
| 7 |
+
[-0.9997, -0.0215, 0.0113],
|
| 8 |
+
[-0.001, -0.4261, -0.9047]])
|
| 9 |
+
CAM_F = 70.59
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def ray(u, v):
|
| 13 |
+
"""Unit ray (pelvis frame) through pixel (u, v) of the 84x84 head image."""
|
| 14 |
+
d = CAM_R @ np.array([(u - 42.0) / CAM_F, (v - 42.0) / CAM_F, 1.0])
|
| 15 |
+
return d / np.linalg.norm(d)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def project(p):
|
| 19 |
+
pc = CAM_R.T @ (np.asarray(p) - CAM_C)
|
| 20 |
+
return np.array([42 + CAM_F * pc[0] / pc[2], 42 + CAM_F * pc[1] / pc[2]])
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def on_plane_z(u, v, z):
|
| 24 |
+
"""Point on the ray through (u,v) at pelvis-frame height z."""
|
| 25 |
+
d = ray(u, v)
|
| 26 |
+
t = (z - CAM_C[2]) / d[2]
|
| 27 |
+
return CAM_C + t * d
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def on_plane_x(u, v, x):
|
| 31 |
+
d = ray(u, v)
|
| 32 |
+
t = (x - CAM_C[0]) / d[0]
|
| 33 |
+
return CAM_C + t * d
|
policies/drawer_top_open/opus-s3/kin.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Approximate G1 arm kinematics (pelvis frame: x forward, y left, z up)."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
from scipy.optimize import least_squares
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def _rx(a):
|
| 7 |
+
c, s = np.cos(a), np.sin(a)
|
| 8 |
+
return np.array([[1, 0, 0], [0, c, -s], [0, s, c]])
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def _ry(a):
|
| 12 |
+
c, s = np.cos(a), np.sin(a)
|
| 13 |
+
return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _rz(a):
|
| 17 |
+
c, s = np.cos(a), np.sin(a)
|
| 18 |
+
return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _rpy(r, p, y):
|
| 22 |
+
return _rz(y) @ _ry(p) @ _rx(r)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
LO = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443])
|
| 26 |
+
HI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443])
|
| 27 |
+
TORSO = np.array([-0.0039635, 0.0, 0.054])
|
| 28 |
+
HAND = 0.12 # wrist-yaw joint to grasp centre (guess)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def fk(q, side="left", hand=HAND):
|
| 32 |
+
"""Return (position, rotation) of the grasp point in the pelvis frame."""
|
| 33 |
+
s = 1.0 if side == "left" else -1.0
|
| 34 |
+
lo, hi = (LO, HI) if side == "left" else (np.array([LO[0], -HI[1], LO[2], LO[3], LO[4], LO[5], LO[6]]), None)
|
| 35 |
+
p = TORSO.copy()
|
| 36 |
+
R = np.eye(3)
|
| 37 |
+
|
| 38 |
+
def step(t, Rj):
|
| 39 |
+
nonlocal p, R
|
| 40 |
+
p = p + R @ np.asarray(t)
|
| 41 |
+
R = R @ Rj
|
| 42 |
+
|
| 43 |
+
step([0.0039563, s * 0.10022, 0.23778], _rpy(s * 0.27931, 5.4949e-05, -s * 0.00019159) @ _ry(q[0]))
|
| 44 |
+
step([0, s * 0.038, -0.013831], _rx(-s * 0.27925) @ _rx(q[1]))
|
| 45 |
+
step([0, s * 0.00624, -0.1032], _rz(q[2]))
|
| 46 |
+
step([0.015783, 0, -0.080518], _ry(q[3]))
|
| 47 |
+
step([0.100, s * 0.00188791, -0.010], _rx(q[4]))
|
| 48 |
+
step([0.038, 0, 0], _ry(q[5]))
|
| 49 |
+
step([0.046, 0, 0], _rz(q[6]))
|
| 50 |
+
return p + R @ np.array([hand, 0, 0]), R
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def limits(side):
|
| 54 |
+
# shoulder roll limited so the upper arm does not hit the torso
|
| 55 |
+
if side == "left":
|
| 56 |
+
lo = LO.copy()
|
| 57 |
+
lo[1] = 0.02
|
| 58 |
+
return lo, HI
|
| 59 |
+
# right arm: roll/yaw limits mirrored
|
| 60 |
+
lo = np.array([-3.0892, -2.2515, -2.618, -1.0472, -1.97222, -1.61443, -1.61443])
|
| 61 |
+
hi = np.array([2.6704, -0.02, 2.618, 2.0944, 1.97222, 1.61443, 1.61443])
|
| 62 |
+
return lo, hi
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def ik(target_p, target_R=None, side="left", q0=None, hand=HAND, w_rot=0.3, reg=0.01, q_ref=None):
|
| 66 |
+
lo, hi = limits(side)
|
| 67 |
+
q0 = np.zeros(7) if q0 is None else np.asarray(q0, float)
|
| 68 |
+
q_ref = q0 if q_ref is None else q_ref
|
| 69 |
+
|
| 70 |
+
def res(q):
|
| 71 |
+
p, R = fk(q, side, hand)
|
| 72 |
+
r = [p - target_p]
|
| 73 |
+
if target_R is not None:
|
| 74 |
+
r.append(w_rot * (R - target_R).ravel())
|
| 75 |
+
r.append(reg * (q - q_ref))
|
| 76 |
+
return np.concatenate(r)
|
| 77 |
+
|
| 78 |
+
sol = least_squares(res, np.clip(q0, lo + 1e-3, hi - 1e-3), bounds=(lo, hi))
|
| 79 |
+
return sol.x, sol
|
policies/drawer_top_open/opus-s3/policy.py
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Open the top drawer: walk to a fixed pose relative to the handle seen by the
|
| 2 |
+
head camera, grasp the handle with the left gripper (fingers vertical), pull."""
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
from scipy import ndimage
|
| 6 |
+
|
| 7 |
+
from headcam import on_plane_z, project
|
| 8 |
+
from kin import fk, ik
|
| 9 |
+
|
| 10 |
+
TUCK_L = np.array([0.2, 0.25, 0.0, 1.3, 0.0, 0.0, 0.0]) # arms down, out of the head view
|
| 11 |
+
TUCK_R = np.array([0.2, -0.25, 0.0, 1.3, 0.0, 0.0, 0.0])
|
| 12 |
+
RT = np.array([[1.0, 0, 0], [0, 0, -1.0], [0, 1.0, 0]]) # gripper forward, fingers vertical
|
| 13 |
+
|
| 14 |
+
P = dict(
|
| 15 |
+
ZH=-0.02, # handle height in the pelvis frame
|
| 16 |
+
HX=0.31, # desired handle position in the pelvis frame after walking
|
| 17 |
+
HY=0.13,
|
| 18 |
+
PRE=0.06,
|
| 19 |
+
WALK_TOL=0.04,
|
| 20 |
+
KI=0.05, # pre-grasp stand-off
|
| 21 |
+
PULL_T=150.0,
|
| 22 |
+
HOOK=0.4,
|
| 23 |
+
PULL_D=0.12,
|
| 24 |
+
BACK_T=500,
|
| 25 |
+
BACK_D=0.30,
|
| 26 |
+
VBACK=-0.1,
|
| 27 |
+
EMPTY=-0.017,
|
| 28 |
+
RETRIES=2,
|
| 29 |
+
RETRY_D=0.18,
|
| 30 |
+
DX=0.10, # max grasp depth offset past the detected handle
|
| 31 |
+
DZ=0.005,
|
| 32 |
+
DY=-0.06,
|
| 33 |
+
ADV=0.0015, # approach speed per step
|
| 34 |
+
LAG=0.015, # contact: commanded minus measured hand x
|
| 35 |
+
BACKOFF=0.01,
|
| 36 |
+
KZ=0.2 / 537.0,
|
| 37 |
+
CT=43.0,
|
| 38 |
+
KY=0.0002,
|
| 39 |
+
BOT=75,
|
| 40 |
+
TOP=8,
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def wood_edge(im):
|
| 45 |
+
"""Bottom edge of the wooden counter front: v = m*u + b, or None."""
|
| 46 |
+
g = im.astype(float)
|
| 47 |
+
wood = (g[..., 0] - g[..., 2]) > 30
|
| 48 |
+
us, vs = [], []
|
| 49 |
+
for u in range(8, 76):
|
| 50 |
+
rows = np.nonzero(wood[0:40, u])[0]
|
| 51 |
+
if len(rows):
|
| 52 |
+
r = rows[0]
|
| 53 |
+
while r + 1 < 40 and wood[r + 1, u]:
|
| 54 |
+
r += 1
|
| 55 |
+
us.append(u)
|
| 56 |
+
vs.append(r + 0.5)
|
| 57 |
+
if len(us) < 20:
|
| 58 |
+
return None
|
| 59 |
+
us = np.array(us, float)
|
| 60 |
+
vs = np.array(vs)
|
| 61 |
+
A = np.stack([us, np.ones_like(us)], 1)
|
| 62 |
+
m, b = np.linalg.lstsq(A, vs, rcond=None)[0]
|
| 63 |
+
for _ in range(2):
|
| 64 |
+
keep = np.abs(vs - (m * us + b)) < 1.2
|
| 65 |
+
if keep.sum() < 10:
|
| 66 |
+
break
|
| 67 |
+
m, b = np.linalg.lstsq(A[keep], vs[keep], rcond=None)[0]
|
| 68 |
+
return m, b
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def detect_handle(im, pred=None):
|
| 72 |
+
"""Top drawer handle in the head image: topmost dark horizontal bar below the counter."""
|
| 73 |
+
g = im.astype(float).mean(axis=2)
|
| 74 |
+
# thin dark horizontal line: darker than the pixels a few rows above and below
|
| 75 |
+
d = np.zeros_like(g)
|
| 76 |
+
for k in (1, 2, 3):
|
| 77 |
+
up = np.full_like(g, 0.0)
|
| 78 |
+
dn = np.full_like(g, 0.0)
|
| 79 |
+
up[k:] = g[:-k]
|
| 80 |
+
dn[:-k] = g[k:]
|
| 81 |
+
d = np.maximum(d, np.minimum(up, dn) - g)
|
| 82 |
+
dark = (d > 25) & (g < 112)
|
| 83 |
+
loose = (d > 12) & (g < 132)
|
| 84 |
+
edge = wood_edge(im)
|
| 85 |
+
vv = np.arange(84)[:, None]
|
| 86 |
+
uu = np.arange(84)[None, :]
|
| 87 |
+
if edge is not None:
|
| 88 |
+
dark &= vv > edge[0] * uu + edge[1] + 3
|
| 89 |
+
else:
|
| 90 |
+
dark[:8] = False
|
| 91 |
+
dark[60:] = False
|
| 92 |
+
dark[:, :10] = False
|
| 93 |
+
dark[:, 74:] = False
|
| 94 |
+
# horizontal runs of dark-line pixels, 6..30 px long, containing a dark core
|
| 95 |
+
runs = []
|
| 96 |
+
for r in range(84):
|
| 97 |
+
row = dark[r]
|
| 98 |
+
u = 0
|
| 99 |
+
while u < 84:
|
| 100 |
+
if row[u]:
|
| 101 |
+
s = u
|
| 102 |
+
while u < 84 and row[u]:
|
| 103 |
+
u += 1
|
| 104 |
+
if 5 <= u - s <= 30:
|
| 105 |
+
# extend over the lighter ends of the bar
|
| 106 |
+
s0, u0 = s, u
|
| 107 |
+
while s > 0 and loose[r, s - 1] and s0 - s < 5:
|
| 108 |
+
s -= 1
|
| 109 |
+
while u < 84 and loose[r, u] and u - u0 < 5:
|
| 110 |
+
u += 1
|
| 111 |
+
runs.append((r, s, u))
|
| 112 |
+
else:
|
| 113 |
+
u += 1
|
| 114 |
+
best = None
|
| 115 |
+
for r, s, e in runs:
|
| 116 |
+
if True:
|
| 117 |
+
c = ((s + e - 1) / 2.0, float(r), e - s)
|
| 118 |
+
if pred is not None:
|
| 119 |
+
d = np.hypot(c[0] - pred[0], c[1] - pred[1])
|
| 120 |
+
if d > 8:
|
| 121 |
+
continue
|
| 122 |
+
key = d
|
| 123 |
+
else:
|
| 124 |
+
key = c[1]
|
| 125 |
+
if best is None or key < best[0]:
|
| 126 |
+
best = (key, c)
|
| 127 |
+
return None if best is None else best[1]
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def detect_bar(im):
|
| 131 |
+
"""Handle bar in the left wrist image (gripper rolled 90 deg: the bar is a
|
| 132 |
+
vertical uniform-grey band). Returns (column centre, width, top row, bottom row)."""
|
| 133 |
+
g = im.astype(float).mean(axis=2)
|
| 134 |
+
mask = (g >= 86) & (g <= 106)
|
| 135 |
+
mask = ndimage.binary_opening(mask, np.ones((1, 3)))
|
| 136 |
+
lab, n = ndimage.label(mask)
|
| 137 |
+
best = None
|
| 138 |
+
for i in range(1, n + 1):
|
| 139 |
+
ys, xs = np.nonzero(lab == i)
|
| 140 |
+
if ys.max() - ys.min() < 12 or len(ys) < 60:
|
| 141 |
+
continue
|
| 142 |
+
if best is None or len(ys) > best[0]:
|
| 143 |
+
best = (len(ys), ys, xs)
|
| 144 |
+
if best is None:
|
| 145 |
+
return None
|
| 146 |
+
_, ys, xs = best
|
| 147 |
+
near = np.abs(ys - 42) <= 10
|
| 148 |
+
c = xs[near].mean() if near.sum() >= 10 else xs.mean()
|
| 149 |
+
rows, counts = np.unique(ys, return_counts=True)
|
| 150 |
+
w = float(np.median(counts))
|
| 151 |
+
return float(c), w, int(ys.min()), int(ys.max())
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def to_world(p, pel):
|
| 155 |
+
x, y, yaw = pel
|
| 156 |
+
c, s = np.cos(yaw), np.sin(yaw)
|
| 157 |
+
return np.array([x + c * p[0] - s * p[1], y + s * p[0] + c * p[1], p[2]])
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def to_body(pw, pel):
|
| 161 |
+
x, y, yaw = pel
|
| 162 |
+
c, s = np.cos(yaw), np.sin(yaw)
|
| 163 |
+
dx, dy = pw[0] - x, pw[1] - y
|
| 164 |
+
return np.array([c * dx + s * dy, -s * dx + c * dy, pw[2]])
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
class Policy:
|
| 168 |
+
def reset(self, obs, tools):
|
| 169 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 170 |
+
self.phase = "settle"
|
| 171 |
+
self.t_phase = 0
|
| 172 |
+
self.meas = []
|
| 173 |
+
self.handle_w = None
|
| 174 |
+
self.q_left = np.zeros(7)
|
| 175 |
+
self.grip = 0.6
|
| 176 |
+
self.dbg = ""
|
| 177 |
+
self.n_walk = 0
|
| 178 |
+
self.hist = []
|
| 179 |
+
self.qi = np.zeros(7)
|
| 180 |
+
self.bar = None
|
| 181 |
+
self.off = np.zeros(3)
|
| 182 |
+
self.n_lag = 0
|
| 183 |
+
self.n_empty = 0
|
| 184 |
+
self.retries = 0
|
| 185 |
+
|
| 186 |
+
def pel(self, obs):
|
| 187 |
+
lo = obs["low_dim_obs"]
|
| 188 |
+
return np.array([lo[18], lo[19], lo[21]])
|
| 189 |
+
|
| 190 |
+
def measure(self, obs, tools):
|
| 191 |
+
pred = None
|
| 192 |
+
if self.handle_w is not None:
|
| 193 |
+
pred = project(to_body(self.handle_w, self.pel(obs)))
|
| 194 |
+
det = detect_handle(tools.image("head"), pred)
|
| 195 |
+
if det is None:
|
| 196 |
+
return None
|
| 197 |
+
u, v, w = det
|
| 198 |
+
pb = on_plane_z(u, v, P["ZH"])
|
| 199 |
+
return to_world(pb, self.pel(obs))
|
| 200 |
+
|
| 201 |
+
def walk_err(self, pel):
|
| 202 |
+
"""Body-frame error to the stance with yaw 0 and the handle at (HX, HY)."""
|
| 203 |
+
goal = self.handle_w[:2] - np.array([P["HX"], P["HY"]])
|
| 204 |
+
ew = goal - pel[:2]
|
| 205 |
+
c, s = np.cos(pel[2]), np.sin(pel[2])
|
| 206 |
+
eb = np.array([c * ew[0] + s * ew[1], -s * ew[0] + c * ew[1]])
|
| 207 |
+
return eb, np.linalg.norm(eb)
|
| 208 |
+
|
| 209 |
+
def servo(self, tools):
|
| 210 |
+
"""Centre the handle bar between the fingers using the left wrist camera."""
|
| 211 |
+
self.bar = detect_bar(tools.image("left_wrist"))
|
| 212 |
+
if self.bar is None:
|
| 213 |
+
return
|
| 214 |
+
c, w, top, bot = self.bar
|
| 215 |
+
if w > 22 or bot - top < 15:
|
| 216 |
+
self.bar = None
|
| 217 |
+
return
|
| 218 |
+
self.off[2] -= np.clip(P["KZ"] * (c - P["CT"]), -0.0015, 0.0015)
|
| 219 |
+
# image up = world right (-y): centre the visible part of the bar vertically
|
| 220 |
+
mid = (min(bot, 80) + max(top, 3)) / 2.0
|
| 221 |
+
self.off[1] -= np.clip(P["KY"] * (41.5 - mid), -0.0015, 0.0015)
|
| 222 |
+
self.off[1:] = np.clip(self.off[1:], [-0.12, -0.08], [0.08, 0.08])
|
| 223 |
+
|
| 224 |
+
def empty(self, obs):
|
| 225 |
+
"""Fingers closed on nothing (they stop near -0.012 on the handle)."""
|
| 226 |
+
return float(np.mean(obs["low_dim_obs"][7:9])) < P["EMPTY"]
|
| 227 |
+
|
| 228 |
+
def hand_now(self):
|
| 229 |
+
p, _ = fk(self.q_left, "left")
|
| 230 |
+
return p
|
| 231 |
+
|
| 232 |
+
def goto(self, name):
|
| 233 |
+
self.phase = name
|
| 234 |
+
self.t_phase = 0
|
| 235 |
+
|
| 236 |
+
def arm(self, target, q0=None, pitch=0.0):
|
| 237 |
+
c, s = np.cos(pitch), np.sin(pitch)
|
| 238 |
+
Ry = np.array([[c, 0, s], [0, 1.0, 0], [-s, 0, c]])
|
| 239 |
+
q, _ = ik(np.asarray(target, float), Ry @ RT, "left", q0=self.q_left if q0 is None else q0)
|
| 240 |
+
self.q_left = q
|
| 241 |
+
return q
|
| 242 |
+
|
| 243 |
+
def act(self, obs, tools):
|
| 244 |
+
a = self.hold.copy()
|
| 245 |
+
pel = self.pel(obs)
|
| 246 |
+
self.t_phase += 1
|
| 247 |
+
tp = self.t_phase
|
| 248 |
+
|
| 249 |
+
if self.phase in ("settle", "walk", "measure"):
|
| 250 |
+
a[4:11] = TUCK_L
|
| 251 |
+
a[11:18] = TUCK_R
|
| 252 |
+
if self.phase == "settle":
|
| 253 |
+
if tp > 30:
|
| 254 |
+
m = self.measure(obs, tools)
|
| 255 |
+
if m is not None:
|
| 256 |
+
self.meas.append(m)
|
| 257 |
+
if tp >= 40:
|
| 258 |
+
if not self.meas:
|
| 259 |
+
self.dbg = "no handle"
|
| 260 |
+
return a
|
| 261 |
+
self.handle_w = np.median(np.array(self.meas), axis=0)
|
| 262 |
+
self.meas = []
|
| 263 |
+
self.goto("walk")
|
| 264 |
+
elif self.phase == "walk":
|
| 265 |
+
eb, dist = self.walk_err(pel)
|
| 266 |
+
a[3] = np.clip(-1.5 * pel[2], -0.3, 0.3)
|
| 267 |
+
if dist > 0.012:
|
| 268 |
+
v = eb * np.clip(1.5 * dist, 0.07, 0.2) / dist
|
| 269 |
+
a[0], a[1] = v
|
| 270 |
+
self.dbg = f"eb={np.round(eb,3)}"
|
| 271 |
+
if (dist < 0.012 and abs(pel[2]) < 0.02) or tp > 300:
|
| 272 |
+
self.goto("measure")
|
| 273 |
+
elif self.phase == "measure":
|
| 274 |
+
if tp > 25:
|
| 275 |
+
m = self.measure(obs, tools)
|
| 276 |
+
if m is not None:
|
| 277 |
+
self.meas.append(m)
|
| 278 |
+
if tp >= 40:
|
| 279 |
+
if self.meas:
|
| 280 |
+
self.handle_w = np.median(np.array(self.meas), axis=0)
|
| 281 |
+
self.meas = []
|
| 282 |
+
self.n_walk += 1
|
| 283 |
+
eb, dist = self.walk_err(pel)
|
| 284 |
+
self.hist.append(np.round(eb, 3).tolist())
|
| 285 |
+
if dist > P["WALK_TOL"] and self.n_walk < 3:
|
| 286 |
+
self.goto("walk")
|
| 287 |
+
else:
|
| 288 |
+
self.q_left = np.zeros(7)
|
| 289 |
+
self.goto("pregrasp")
|
| 290 |
+
else:
|
| 291 |
+
hb = to_body(self.handle_w, pel)
|
| 292 |
+
self.dbg = f"hb={np.round(hb,3)}"
|
| 293 |
+
if self.phase == "pregrasp":
|
| 294 |
+
if tp == 1:
|
| 295 |
+
self.off = np.array([-P["PRE"], P["DY"], P["DZ"]])
|
| 296 |
+
self.grip = 0.0
|
| 297 |
+
if tp > 35:
|
| 298 |
+
self.servo(tools)
|
| 299 |
+
self.arm(hb + self.off)
|
| 300 |
+
if tp >= 60:
|
| 301 |
+
self.goto("approach")
|
| 302 |
+
elif self.phase == "approach":
|
| 303 |
+
self.servo(tools)
|
| 304 |
+
self.off[0] += P["ADV"]
|
| 305 |
+
self.arm(hb + self.off)
|
| 306 |
+
pm, _ = fk(obs["low_dim_obs"][0:7], "left")
|
| 307 |
+
pc, _ = fk(self.q_left, "left")
|
| 308 |
+
lag = pc[0] - pm[0]
|
| 309 |
+
if tp == 1:
|
| 310 |
+
self.pel_app = pel.copy()
|
| 311 |
+
retreat = to_body(np.r_[self.pel_app[:2], 0.0], pel)[0]
|
| 312 |
+
lag = max(lag, retreat)
|
| 313 |
+
self.dbg = f"off={np.round(self.off,3)} lag={lag:.3f} bar={self.bar}"
|
| 314 |
+
self.n_lag = self.n_lag + 1 if (tp > 20 and lag > P["LAG"]) else 0
|
| 315 |
+
if self.n_lag >= 5 or self.off[0] > P["DX"]:
|
| 316 |
+
self.off[0] -= P["BACKOFF"]
|
| 317 |
+
self.tgt_fix = hb + self.off
|
| 318 |
+
self.grasp_w = to_world(self.tgt_fix, pel)
|
| 319 |
+
self.hist.append(("grasp", np.round(self.off, 3).tolist(), round(float(lag), 3)))
|
| 320 |
+
self.goto("close")
|
| 321 |
+
elif self.phase == "close":
|
| 322 |
+
self.arm(self.tgt_fix)
|
| 323 |
+
self.grip = 1.0
|
| 324 |
+
if tp >= 30:
|
| 325 |
+
self.back0 = pel.copy()
|
| 326 |
+
if self.empty(obs) and self.retries < P["RETRIES"]:
|
| 327 |
+
self.goto("lost")
|
| 328 |
+
else:
|
| 329 |
+
self.goto("pull")
|
| 330 |
+
elif self.phase == "lost":
|
| 331 |
+
# missed or dropped the handle: open, back the hand off, start over
|
| 332 |
+
self.grip = 0.0
|
| 333 |
+
self.arm(self.tgt_fix - np.array([0.10 * min(1.0, tp / 30.0), 0, 0]))
|
| 334 |
+
if tp >= 40:
|
| 335 |
+
self.retries += 1
|
| 336 |
+
self.hist.append(("retry", int(obs["t"])))
|
| 337 |
+
self.handle_w = None
|
| 338 |
+
self.meas = []
|
| 339 |
+
self.n_walk = 0
|
| 340 |
+
self.qi = np.zeros(7)
|
| 341 |
+
self.n_empty = 0
|
| 342 |
+
self.goto("settle")
|
| 343 |
+
elif self.phase == "pull":
|
| 344 |
+
# retract the arm while stepping backwards
|
| 345 |
+
fp = min(1.0, tp / 20.0)
|
| 346 |
+
f = min(1.0, max(0.0, tp - 20) / P["PULL_T"])
|
| 347 |
+
# keep the hand's lateral world position on the bar while the body drifts
|
| 348 |
+
tb = to_body(self.grasp_w, pel)
|
| 349 |
+
tgt = np.array([self.tgt_fix[0] - P["PULL_D"] * f, tb[1], self.tgt_fix[2]])
|
| 350 |
+
self.arm(tgt, pitch=P["HOOK"] * fp)
|
| 351 |
+
self.grip = 1.0
|
| 352 |
+
moved = np.hypot(*(pel[:2] - self.back0[:2]))
|
| 353 |
+
self.dbg = f"moved={moved:.3f}"
|
| 354 |
+
if tp > 20 and tp < P["BACK_T"] and moved < P["BACK_D"]:
|
| 355 |
+
a[0] = P["VBACK"]
|
| 356 |
+
ey = to_body(np.r_[self.back0[:2], 0.0], pel)[1]
|
| 357 |
+
if abs(ey) > 0.01:
|
| 358 |
+
a[1] = np.clip(1.5 * ey, -0.1, 0.1)
|
| 359 |
+
a[3] = np.clip(-1.0 * pel[2], -0.2, 0.2)
|
| 360 |
+
self.n_empty = self.n_empty + 1 if self.empty(obs) else 0
|
| 361 |
+
if self.n_empty >= 10:
|
| 362 |
+
if moved < P["RETRY_D"] and self.retries < P["RETRIES"]:
|
| 363 |
+
self.tgt_fix = self.hand_now()
|
| 364 |
+
self.goto("lost")
|
| 365 |
+
else:
|
| 366 |
+
# drawer pulled out to its stop: stand still
|
| 367 |
+
self.goto("done")
|
| 368 |
+
elif self.phase == "done":
|
| 369 |
+
self.grip = 0.0
|
| 370 |
+
if self.phase in ("pregrasp", "approach"):
|
| 371 |
+
# integral action against gravity sag of the position-controlled arm
|
| 372 |
+
qm = obs["low_dim_obs"][0:7]
|
| 373 |
+
self.qi = np.clip(self.qi + P["KI"] * (self.q_left - qm), -0.1, 0.1)
|
| 374 |
+
a[4:11] = self.q_left + self.qi
|
| 375 |
+
a[11:18] = TUCK_R
|
| 376 |
+
a[18] = self.grip
|
| 377 |
+
return a
|
policies/flip_cup/astra-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,1,1167,success,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,1,1141,success,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,1,1064,success,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,1,1071,success,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,1,931,success,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,1,1212,success,0
|
| 24 |
+
620022,1,1150,success,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,1,1183,success,0
|
| 27 |
+
620025,1,1044,success,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,1,1121,success,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,1,1010,success,0
|
| 33 |
+
620031,1,1293,success,0
|
| 34 |
+
620032,1,1120,success,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,1,1083,success,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,1,1351,success,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,1,1634,success,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,1,1081,success,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,1,988,success,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,1,1385,success,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,1,1059,success,0
|
| 67 |
+
620065,1,979,success,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,1,1202,success,0
|
| 81 |
+
620079,1,1067,success,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,1,1241,success,0
|
| 86 |
+
620084,1,1408,success,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,1,1065,success,0
|
| 90 |
+
620088,1,1119,success,0
|
| 91 |
+
620089,1,1055,success,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,1,1060,success,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/astra-s1/policy.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic camera-guided cup turnover.
|
| 2 |
+
|
| 3 |
+
The head view selects the nearer hand. Pelvis feedback controls short base
|
| 4 |
+
adjustments; color segmentation in the wrist view guides the reach. Once the
|
| 5 |
+
cup is close, reach depth is latched while alignment settles. The hand then
|
| 6 |
+
retracts, pre-rotates, grasps, lifts, turns, lowers, releases, and withdraws.
|
| 7 |
+
All parameters are hand-written controller constants; no fitted components
|
| 8 |
+
or demonstration files are used at runtime.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
import cv2
|
| 13 |
+
|
| 14 |
+
class Policy:
|
| 15 |
+
|
| 16 |
+
def cup(self, im):
|
| 17 |
+
f = im.astype(float)
|
| 18 |
+
m = (np.ptp(f, axis=2) < 27) & (f.mean(2) > 65) & (f.mean(2) < 238)
|
| 19 |
+
n, l, st, c = cv2.connectedComponentsWithStats(m.astype('uint8'))
|
| 20 |
+
ids = [i for i in range(1, n) if st[i, 4] > 40 and st[i, 1] < 76 and (not (st[i, 2] > 78 and st[i, 3] < 60 and (st[i, 1] > 24)))]
|
| 21 |
+
if not ids:
|
| 22 |
+
return None
|
| 23 |
+
i = max(ids, key=lambda i: st[i, 4])
|
| 24 |
+
x, y, w, h, ar = st[i]
|
| 25 |
+
return np.array([c[i, 0], c[i, 1], w, h, ar])
|
| 26 |
+
|
| 27 |
+
def reset(self, obs, tools):
|
| 28 |
+
self.a = np.array(tools.hold_action())
|
| 29 |
+
self.a[19:] = 0
|
| 30 |
+
im = tools.image('head').astype(float)
|
| 31 |
+
r, g, b = im.transpose(2, 0, 1)
|
| 32 |
+
m = (np.ptp(im, 2) < 30) & (im.mean(2) < 205) & (im.mean(2) > 50)
|
| 33 |
+
m[14:] = False
|
| 34 |
+
y, x = np.where(m)
|
| 35 |
+
if len(x) < 5:
|
| 36 |
+
m = (r > 110) & (g > 70) & (b < g * 0.8) & (g < r * 0.92)
|
| 37 |
+
m[15:] = False
|
| 38 |
+
y, x = np.where(m)
|
| 39 |
+
cx = float(np.mean(x)) if len(x) else 25
|
| 40 |
+
self.side = 1 if cx < 42 else -1
|
| 41 |
+
self.idx = 5 if self.side == 1 else 12
|
| 42 |
+
self.grip = 19 if self.side == 1 else 20
|
| 43 |
+
self.forward_checked = False
|
| 44 |
+
self.depth_ready = False
|
| 45 |
+
self.ready_t = 0
|
| 46 |
+
self.cam = 'left_wrist' if self.side == 1 else 'right_wrist'
|
| 47 |
+
dist = cx if self.side == 1 else 83 - cx
|
| 48 |
+
self.sr = 0.27
|
| 49 |
+
self.sp = -0.6
|
| 50 |
+
self.el = 0.2
|
| 51 |
+
self.start = self.a.copy()
|
| 52 |
+
self.stage = -1
|
| 53 |
+
self.t0 = 0
|
| 54 |
+
self.grasp = None
|
| 55 |
+
self.base_y = float(obs['low_dim_obs'][22]) + (13 - dist) * 0.006 * self.side
|
| 56 |
+
|
| 57 |
+
def arm(self, sp, sr, el, wr=0, g=0):
|
| 58 |
+
a = self.a.copy()
|
| 59 |
+
a[self.idx:self.idx + 7] = [sp, self.side * sr, 0, el, self.side * wr, 0, 0]
|
| 60 |
+
a[self.grip] = g
|
| 61 |
+
return a
|
| 62 |
+
|
| 63 |
+
def act(self, obs, tools):
|
| 64 |
+
t = obs['t']
|
| 65 |
+
u = t - self.t0
|
| 66 |
+
if self.stage == -2:
|
| 67 |
+
dx = self.forward_x - obs['low_dim_obs'][21]
|
| 68 |
+
self.a[0] = max(0.08, min(0.18, 2 * dx)) if dx > 0.012 else 0
|
| 69 |
+
self.a[3] = np.clip(-3 * obs['low_dim_obs'][24], -0.35, 0.35)
|
| 70 |
+
if dx < 0.012 or u > 120:
|
| 71 |
+
self.a[0] = 0
|
| 72 |
+
self.a[3] = 0
|
| 73 |
+
self.stage = 1
|
| 74 |
+
self.t0 = t + 40
|
| 75 |
+
elif self.stage == -1:
|
| 76 |
+
dy = self.base_y - obs['low_dim_obs'][22]
|
| 77 |
+
self.a[1] = np.sign(dy) * max(0.065, min(0.25, 2 * abs(dy))) if abs(dy) > 0.012 else 0
|
| 78 |
+
self.a[3] = np.clip(-3 * obs['low_dim_obs'][24], -0.3, 0.3)
|
| 79 |
+
if abs(dy) < 0.012 and t > 40 or t > 220:
|
| 80 |
+
self.a[1] = 0
|
| 81 |
+
self.a[3] = 0
|
| 82 |
+
self.stage = 0
|
| 83 |
+
self.t0 = t
|
| 84 |
+
self.start = self.a.copy()
|
| 85 |
+
elif self.stage == 0:
|
| 86 |
+
target = self.arm(self.sp, self.sr, self.el)
|
| 87 |
+
self.a = self.start + (target - self.start) * min(1, (u + 1) / 60)
|
| 88 |
+
if u >= 80:
|
| 89 |
+
self.stage = 1
|
| 90 |
+
self.t0 = t
|
| 91 |
+
elif self.stage == 1:
|
| 92 |
+
if u >= 0 and u % 10 == 0:
|
| 93 |
+
c = self.cup(tools.image(self.cam))
|
| 94 |
+
self.last_c = c
|
| 95 |
+
if c is not None:
|
| 96 |
+
x, y, w, h, area = c
|
| 97 |
+
if not self.forward_checked:
|
| 98 |
+
self.forward_checked = True
|
| 99 |
+
if w < 51:
|
| 100 |
+
self.forward_x = min(0.265, float(obs['low_dim_obs'][21]) + 0.08)
|
| 101 |
+
self.stage = -2
|
| 102 |
+
self.t0 = t
|
| 103 |
+
return self.a
|
| 104 |
+
self.sr += self.side * 0.0009 * (42 - x)
|
| 105 |
+
self.el += np.clip((y - 43) * 0.002, -0.06, 0.06)
|
| 106 |
+
if w >= 73 and h >= 72 and (not self.depth_ready):
|
| 107 |
+
self.depth_ready = True
|
| 108 |
+
self.ready_t = t
|
| 109 |
+
if not self.depth_ready:
|
| 110 |
+
if abs(x - 42) < 7 and abs(y - 43) < 7:
|
| 111 |
+
if self.sp + self.a[4] > -1.15:
|
| 112 |
+
self.sp -= 0.018
|
| 113 |
+
self.el += 0.027
|
| 114 |
+
elif self.a[4] < 0.55:
|
| 115 |
+
self.a[4] += 0.015
|
| 116 |
+
self.sp -= 0.015
|
| 117 |
+
elif u > 50 and (abs(x - 42) < 3 and abs(y - 43) < 3 or t - self.ready_t > 100):
|
| 118 |
+
self.stage = 2
|
| 119 |
+
self.t0 = t
|
| 120 |
+
self.start = self.a.copy()
|
| 121 |
+
self.grasp = (self.sp - 0.2, self.sr, self.el + 0.28)
|
| 122 |
+
else:
|
| 123 |
+
self.el += 0.015
|
| 124 |
+
self.sr = float(np.clip(self.sr, -0.6, 0.6))
|
| 125 |
+
self.sp = max(-2.2, self.sp)
|
| 126 |
+
self.el = float(np.clip(self.el, -0.5, 1.7))
|
| 127 |
+
self.a = self.arm(self.sp, self.sr, self.el)
|
| 128 |
+
if u > 700:
|
| 129 |
+
self.stage = 2
|
| 130 |
+
self.t0 = t
|
| 131 |
+
self.start = self.a.copy()
|
| 132 |
+
self.grasp = (self.sp - 0.2, self.sr, self.el + 0.28)
|
| 133 |
+
else:
|
| 134 |
+
sp, sr, el = self.grasp
|
| 135 |
+
poses = [(sp + 0.35, sr, el - 0.48, -1.1, 0), (sp, sr, el, -1.1, 0), (sp, sr, el, -1.1, 1), (sp - 0.25, sr, el, -1.1, 1), (sp - 0.25, sr, el, 1.97, 1), (sp, sr, el, 1.97, 1), (sp, sr, el, 1.97, 0), (-0.35, sr, 0, 0, 0)]
|
| 136 |
+
j = min(self.stage - 2, len(poses) - 1)
|
| 137 |
+
target = self.arm(*poses[j])
|
| 138 |
+
self.a = self.start + (target - self.start) * min(1, (u + 1) / 65)
|
| 139 |
+
if u >= 99 and self.stage < 9:
|
| 140 |
+
self.stage += 1
|
| 141 |
+
self.t0 = t + 1
|
| 142 |
+
self.start = self.a.copy()
|
| 143 |
+
return self.a
|
policies/flip_cup/astra-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,1,1482,success,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,1,1433,success,0
|
| 7 |
+
620005,1,1447,success,0
|
| 8 |
+
620006,1,1499,success,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,1,1403,success,0
|
| 11 |
+
620009,1,1344,success,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,1,1378,success,0
|
| 15 |
+
620013,1,1439,success,0
|
| 16 |
+
620014,1,1668,success,0
|
| 17 |
+
620015,1,1401,success,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,1,1428,success,0
|
| 20 |
+
620018,1,1474,success,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,1,1488,success,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,1,1462,success,0
|
| 25 |
+
620023,1,1526,success,0
|
| 26 |
+
620024,1,1417,success,0
|
| 27 |
+
620025,1,1477,success,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,1,1535,success,0
|
| 30 |
+
620028,1,1467,success,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,1,1762,success,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,1,1366,success,0
|
| 36 |
+
620034,1,1482,success,0
|
| 37 |
+
620035,1,1484,success,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,1,1496,success,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,1,1589,success,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,1,1373,success,0
|
| 48 |
+
620046,1,1499,success,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,1,1461,success,0
|
| 51 |
+
620049,1,1383,success,0
|
| 52 |
+
620050,1,1519,success,0
|
| 53 |
+
620051,1,1477,success,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,1,1477,success,0
|
| 57 |
+
620055,1,1475,success,0
|
| 58 |
+
620056,1,1388,success,0
|
| 59 |
+
620057,1,1460,success,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,1,1412,success,0
|
| 62 |
+
620060,1,1493,success,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,1,1429,success,0
|
| 66 |
+
620064,1,1495,success,0
|
| 67 |
+
620065,1,1366,success,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,1,1365,success,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,1,1475,success,0
|
| 73 |
+
620071,1,1380,success,0
|
| 74 |
+
620072,1,1457,success,0
|
| 75 |
+
620073,1,1537,success,0
|
| 76 |
+
620074,1,1442,success,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,1,1401,success,0
|
| 80 |
+
620078,1,1517,success,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,1,1451,success,0
|
| 84 |
+
620082,1,1479,success,0
|
| 85 |
+
620083,1,1675,success,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,1,1445,success,0
|
| 90 |
+
620088,1,1433,success,0
|
| 91 |
+
620089,1,1541,success,0
|
| 92 |
+
620090,1,1406,success,0
|
| 93 |
+
620091,1,1426,success,0
|
| 94 |
+
620092,1,1483,success,0
|
| 95 |
+
620093,1,1423,success,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,1,1589,success,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/astra-s2/policy.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic cup-turning controller using camera segmentation, visual feedback, and joint-axis inverse kinematics. Runtime inputs are exclusively the robot cameras and proprioception."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
from scipy.spatial.transform import Rotation
|
| 5 |
+
from scipy.optimize import least_squares
|
| 6 |
+
|
| 7 |
+
class Policy:
|
| 8 |
+
|
| 9 |
+
def reset(self, obs, tools):
|
| 10 |
+
"""Initialize the approach and estimate lateral alignment from the head camera."""
|
| 11 |
+
self.a = np.array(tools.hold_action(), float)
|
| 12 |
+
self.a[19:] = 0
|
| 13 |
+
self.a[5:12] = [-0.4, 0.15, 0, -0.8, 0, 0.9, 0]
|
| 14 |
+
self.a[12:19] = [-0.4, -0.15, 0, -0.8, 0, 0.9, 0]
|
| 15 |
+
self.phase = 'walk'
|
| 16 |
+
self.age = 0
|
| 17 |
+
self.q = -0.4
|
| 18 |
+
self.roll = 0.15
|
| 19 |
+
self.height = 0.74
|
| 20 |
+
self.pitch = 0.0
|
| 21 |
+
self.box = None
|
| 22 |
+
self.missing = 0
|
| 23 |
+
self.searchdir = 1
|
| 24 |
+
self.angle = -0.3
|
| 25 |
+
im = tools.image('head').astype(float)
|
| 26 |
+
r, g, b = im.transpose(2, 0, 1)
|
| 27 |
+
m = ((abs(r - b) < 20) & (abs(g - b) < 20) & (r > 70) & (r < 230)).astype('uint8')
|
| 28 |
+
m[16:] = 0
|
| 29 |
+
n, l, st, cc = cv2.connectedComponentsWithStats(m)
|
| 30 |
+
candidates = [i for i in range(1, n) if st[i, 4] > 15 and st[i, 3] > 2]
|
| 31 |
+
self.basex = 0.3
|
| 32 |
+
self.basey = 0.0
|
| 33 |
+
if candidates:
|
| 34 |
+
k = max(candidates, key=lambda i: st[i, 4])
|
| 35 |
+
x, y, w, h, _ = st[k]
|
| 36 |
+
self.basex = float(np.clip(0.3 - (y + h) * 0.008, 0.17, 0.3))
|
| 37 |
+
self.basey = float(np.clip(-(cc[k, 0] - 17) * 0.008, -0.22, 0.15))
|
| 38 |
+
|
| 39 |
+
def detect(self, im):
|
| 40 |
+
"""Find the neutral-colored cup and its bright, elongated handle in the wrist image."""
|
| 41 |
+
a = im.astype(float)
|
| 42 |
+
r, g, b = a.transpose(2, 0, 1)
|
| 43 |
+
m = ((b > r - 7) & (b > g - 7) & (b < r + 25) & (r > 85) & (r < 239)).astype('uint8')
|
| 44 |
+
m[72:] = 0
|
| 45 |
+
m[:, :3] = 0
|
| 46 |
+
m[:, 81:] = 0
|
| 47 |
+
n, l, st, cen = cv2.connectedComponentsWithStats(m)
|
| 48 |
+
choices = [i for i in range(1, n) if st[i, 4] > 50 and st[i, 3] > 8 and (st[i, 2] > 8) and (st[i, 2] <= 78)]
|
| 49 |
+
if not choices:
|
| 50 |
+
return None
|
| 51 |
+
i = max(choices, key=lambda i: st[i, 4])
|
| 52 |
+
x, y, w, h, area = st[i]
|
| 53 |
+
bright = ((r > 210) & (g > 210) & (b > 210) & (b > g - 9)).astype('uint8')
|
| 54 |
+
bright[:max(0, y + 3)] = 0
|
| 55 |
+
bright[min(84, y + h):] = 0
|
| 56 |
+
bright[:, :max(0, x - 3)] = 0
|
| 57 |
+
bright[:, min(84, x + w + 3):] = 0
|
| 58 |
+
nn, ll, ss, cc = cv2.connectedComponentsWithStats(bright)
|
| 59 |
+
candidates = [j for j in range(1, nn) if ss[j, 4] >= 6 and ss[j, 3] >= 6 and (ss[j, 3] > ss[j, 2] * 1.2)]
|
| 60 |
+
if candidates:
|
| 61 |
+
j = max(candidates, key=lambda j: ss[j, 4])
|
| 62 |
+
cx = cc[j, 0]
|
| 63 |
+
required = 46.0 if abs(cx - cen[i, 0]) > 6 else 38.0
|
| 64 |
+
w = ss[j, 3] * 60.0 / required
|
| 65 |
+
y = ss[j, 1]
|
| 66 |
+
h = ss[j, 3]
|
| 67 |
+
else:
|
| 68 |
+
cx = cen[i, 0]
|
| 69 |
+
return np.array([cx, y + h, w, h, area])
|
| 70 |
+
|
| 71 |
+
def rotation(self, q):
|
| 72 |
+
"""Compose the seven arm joint rotations in their physical axis order."""
|
| 73 |
+
r = np.eye(3)
|
| 74 |
+
for ax, ang in zip('yxzyxyz', q):
|
| 75 |
+
r = r @ Rotation.from_euler(ax, ang).as_matrix()
|
| 76 |
+
return r
|
| 77 |
+
|
| 78 |
+
def flip_target(self):
|
| 79 |
+
"""Solve bounded wrist inverse kinematics for a half-turn while keeping the cup clear of the arm."""
|
| 80 |
+
q = self.norm.copy()
|
| 81 |
+
target = Rotation.from_euler('x', np.pi).as_matrix() @ self.rotation(q)
|
| 82 |
+
q[0] -= 0.6
|
| 83 |
+
q[2] = -2.6
|
| 84 |
+
|
| 85 |
+
def residual(v):
|
| 86 |
+
q[4:] = v
|
| 87 |
+
return Rotation.from_matrix(self.rotation(q).T @ target).as_rotvec()
|
| 88 |
+
sol = least_squares(residual, [0.8, 0.5, -0.4], bounds=([-1.97, -1.61, -1.61], [1.97, 1.61, 1.61]))
|
| 89 |
+
q[4:] = sol.x
|
| 90 |
+
return q.copy()
|
| 91 |
+
|
| 92 |
+
def act(self, obs, tools):
|
| 93 |
+
"""Advance the deterministic state machine by one control step."""
|
| 94 |
+
a = self.a
|
| 95 |
+
self.age += 1
|
| 96 |
+
t = obs['t']
|
| 97 |
+
s = obs['low_dim_obs']
|
| 98 |
+
if self.phase == 'walk':
|
| 99 |
+
x, y, z, yaw = s[21:25]
|
| 100 |
+
err = np.array([self.basex - x, self.basey - y])
|
| 101 |
+
v = err * 2
|
| 102 |
+
if np.linalg.norm(v) > 0.017:
|
| 103 |
+
v *= max(0.065, np.linalg.norm(v)) / np.linalg.norm(v)
|
| 104 |
+
else:
|
| 105 |
+
v *= 0
|
| 106 |
+
a[:2] = [np.cos(yaw) * v[0] + np.sin(yaw) * v[1], -np.sin(yaw) * v[0] + np.cos(yaw) * v[1]]
|
| 107 |
+
a[3] = -3 * yaw
|
| 108 |
+
if self.age >= 180:
|
| 109 |
+
self.phase = 'reach'
|
| 110 |
+
self.age = 0
|
| 111 |
+
a[:2] = 0
|
| 112 |
+
a[3] = 0
|
| 113 |
+
elif self.phase == 'reach':
|
| 114 |
+
if self.age % 5 == 0:
|
| 115 |
+
b = self.detect(tools.image('left_wrist'))
|
| 116 |
+
self.box = b
|
| 117 |
+
if b is not None:
|
| 118 |
+
cx, bot, w, h, area = b
|
| 119 |
+
self.missing = 0
|
| 120 |
+
if self.roll < -0.5 and cx > 55 and (self.q > -0.6):
|
| 121 |
+
self.phase = 'sidestep'
|
| 122 |
+
self.age = 0
|
| 123 |
+
self.sidegoal = s[22] - 0.16
|
| 124 |
+
self.roll = np.clip(self.roll + (42 - cx) * 0.0008, -0.55, 0.75)
|
| 125 |
+
if abs(cx - 42) < 20:
|
| 126 |
+
self.height = np.clip(self.height + (55 - bot) * 0.0008, 0.45, 0.77)
|
| 127 |
+
if w >= 60 and abs(cx - 42) < 2.5 and (abs(bot - 55) < 8):
|
| 128 |
+
self.phase = 'close'
|
| 129 |
+
self.age = 0
|
| 130 |
+
self.graspheight = self.height
|
| 131 |
+
elif w < 60 and abs(cx - 42) < 6 and (abs(bot - 55) < 7):
|
| 132 |
+
if self.q > -1.5:
|
| 133 |
+
self.q -= 0.018
|
| 134 |
+
else:
|
| 135 |
+
self.pitch = min(0.65, self.pitch + 0.008)
|
| 136 |
+
else:
|
| 137 |
+
self.missing += 1
|
| 138 |
+
self.height = min(0.77, self.height + 0.001)
|
| 139 |
+
if self.missing > 8:
|
| 140 |
+
self.angle = -0.55
|
| 141 |
+
self.roll += self.searchdir * 0.012
|
| 142 |
+
if self.roll < -0.5:
|
| 143 |
+
self.searchdir = 1
|
| 144 |
+
if self.roll > 0.65:
|
| 145 |
+
self.searchdir = -1
|
| 146 |
+
e = -0.8 + (self.q + 0.4) * (-0.8 / 1.1)
|
| 147 |
+
a[2] = self.height
|
| 148 |
+
a[4] = self.pitch
|
| 149 |
+
a[5:12] = [self.q, self.roll, 0, e, 0, self.angle - self.q - e - self.pitch, 0]
|
| 150 |
+
elif self.phase == 'sidestep':
|
| 151 |
+
a[2] = 0.74
|
| 152 |
+
yaw = s[24]
|
| 153 |
+
dy = self.sidegoal - s[22]
|
| 154 |
+
v = np.sign(dy) * max(0.065, min(0.15, abs(dy) * 2)) if abs(dy) > 0.008 else 0.0
|
| 155 |
+
a[0] = np.sin(yaw) * v
|
| 156 |
+
a[1] = np.cos(yaw) * v
|
| 157 |
+
a[3] = -3 * yaw
|
| 158 |
+
if self.age > 130:
|
| 159 |
+
a[:2] = 0
|
| 160 |
+
a[3] = 0
|
| 161 |
+
self.phase = 'reach'
|
| 162 |
+
self.age = 0
|
| 163 |
+
self.roll = 0.15
|
| 164 |
+
self.height = 0.74
|
| 165 |
+
elif self.phase == 'close':
|
| 166 |
+
a[19] = 1.0
|
| 167 |
+
if self.age > 70:
|
| 168 |
+
self.phase = 'lift'
|
| 169 |
+
self.age = 0
|
| 170 |
+
self.ga = a.copy()
|
| 171 |
+
self.late = obs['t'] > 850
|
| 172 |
+
target = Rotation.from_euler('y', a[4]).as_matrix() @ self.rotation(a[5:12])
|
| 173 |
+
q = np.array([-1.46, 0.29, 0, -0.03, 0, 1.19, 0.0])
|
| 174 |
+
|
| 175 |
+
def residual(v):
|
| 176 |
+
q[4:] = v
|
| 177 |
+
return Rotation.from_matrix(self.rotation(q).T @ target).as_rotvec()
|
| 178 |
+
sol = least_squares(residual, [0, 1.19, 0], bounds=([-1.97, -1.61, -1.61], [1.97, 1.61, 1.61]))
|
| 179 |
+
q[4:] = sol.x
|
| 180 |
+
self.norm = q.copy()
|
| 181 |
+
self.ft = self.flip_target()
|
| 182 |
+
elif self.phase == 'lift':
|
| 183 |
+
a[2] = min(0.76, a[2] + 0.002)
|
| 184 |
+
f = np.clip((self.age - 60) / 100.0, 0, 1)
|
| 185 |
+
a[5:12] = self.ga[5:12] + (self.norm - self.ga[5:12]) * f
|
| 186 |
+
a[4] = self.ga[4] * (1 - f)
|
| 187 |
+
if self.age > 170:
|
| 188 |
+
self.phase = 'move'
|
| 189 |
+
self.age = 0
|
| 190 |
+
elif self.phase == 'move':
|
| 191 |
+
x, y, z, yaw = s[21:25]
|
| 192 |
+
v = np.array([0.43 - x, -y]) * 2
|
| 193 |
+
if np.linalg.norm(v) > 0.018:
|
| 194 |
+
v *= max(0.065, np.linalg.norm(v)) / np.linalg.norm(v)
|
| 195 |
+
else:
|
| 196 |
+
v *= 0
|
| 197 |
+
a[:2] = [np.cos(yaw) * v[0] + np.sin(yaw) * v[1], -np.sin(yaw) * v[0] + np.cos(yaw) * v[1]]
|
| 198 |
+
a[3] = -3 * yaw
|
| 199 |
+
if self.age > 130:
|
| 200 |
+
self.phase = 'flip'
|
| 201 |
+
self.age = 0
|
| 202 |
+
a[:2] = 0
|
| 203 |
+
a[3] = 0
|
| 204 |
+
elif self.phase == 'flip':
|
| 205 |
+
f = min(1.0, self.age / 220.0)
|
| 206 |
+
a[5:12] = self.norm + (self.ft - self.norm) * f
|
| 207 |
+
a[2] = 0.82
|
| 208 |
+
if self.age > (240 if self.late else 270):
|
| 209 |
+
self.phase = 'lower'
|
| 210 |
+
self.age = 0
|
| 211 |
+
elif self.phase == 'lower':
|
| 212 |
+
a[2] = max(0.76, a[2] - 0.001)
|
| 213 |
+
if self.age > (80 if self.late else 200):
|
| 214 |
+
self.phase = 'release'
|
| 215 |
+
self.age = 0
|
| 216 |
+
elif self.phase == 'release':
|
| 217 |
+
a[19] = 0
|
| 218 |
+
if self.age > 60:
|
| 219 |
+
self.phase = 'retreat'
|
| 220 |
+
self.age = 0
|
| 221 |
+
elif self.phase == 'retreat':
|
| 222 |
+
a[2] = min(0.74, a[2] + 0.002)
|
| 223 |
+
a[4] = max(0.0, a[4] - 0.01)
|
| 224 |
+
target = np.array([-0.4, 0.15, 0, -0.8, 0, 0.9, 0])
|
| 225 |
+
a[5:12] += np.clip(target - a[5:12], -0.02, 0.02)
|
| 226 |
+
return a.copy()
|
policies/flip_cup/astra-s3/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,1,1458,success,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,1,1472,success,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,1,1483,success,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,1,1313,success,0
|
| 16 |
+
620014,1,1557,success,0
|
| 17 |
+
620015,1,1306,success,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,1,1271,success,0
|
| 27 |
+
620025,1,1277,success,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,1,1492,success,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,1,1562,success,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,1,1562,success,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,1,1262,success,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,1,1486,success,0
|
| 54 |
+
620052,1,1462,success,0
|
| 55 |
+
620053,1,1594,success,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,1,1408,success,0
|
| 58 |
+
620056,1,1562,success,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,1,1562,success,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,1,1390,success,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,1,1052,success,0
|
| 68 |
+
620066,1,1622,success,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,1,1422,success,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,1,1271,success,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,1,1275,success,0
|
| 87 |
+
620085,1,1563,success,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,1,1410,success,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,1,1275,success,0
|
policies/flip_cup/astra-s3/policy.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic image-guided cup manipulation with analytic arm control."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
from scipy.spatial.transform import Rotation
|
| 5 |
+
from scipy.optimize import least_squares
|
| 6 |
+
|
| 7 |
+
def rot(axis,a):
|
| 8 |
+
v=np.zeros(3);v[axis]=a
|
| 9 |
+
return Rotation.from_rotvec(v).as_matrix()
|
| 10 |
+
def fk(q):
|
| 11 |
+
sp,sr,sy,el,wr,wp,wy=q
|
| 12 |
+
m=rot(1,sp)@rot(0,sr)@rot(2,sy)
|
| 13 |
+
p=m@np.array([0,0,-.18]);m=m@rot(1,el);p+=m@np.array([0,0,-.18])
|
| 14 |
+
m=m@rot(0,wr)@rot(1,wp)@rot(2,wy)
|
| 15 |
+
return p,m
|
| 16 |
+
LO=np.array([-3,-1.5,-2.6,-1.,-1.95,-1.6,-1.6])
|
| 17 |
+
HI=np.array([2.6,2.2,2.6,2.05,1.95,1.6,1.6])
|
| 18 |
+
def solve(p,m,q):
|
| 19 |
+
def residual(x):
|
| 20 |
+
a,b=fk(x)
|
| 21 |
+
return np.r_[(a-p)*10,Rotation.from_matrix(b.T@m).as_rotvec(),(x-q)*.002]
|
| 22 |
+
return least_squares(residual,np.clip(q,LO,HI),bounds=(LO,HI),max_nfev=100).x
|
| 23 |
+
|
| 24 |
+
def detect(im,full=False):
|
| 25 |
+
hsv=cv2.cvtColor(im,cv2.COLOR_RGB2HSV)
|
| 26 |
+
mask=((hsv[:,:,1]<45)&(hsv[:,:,2]>55)&(hsv[:,:,2]<235)).astype('uint8')
|
| 27 |
+
mask[79:]=0;mask[:,:3]=0;mask[:,81:]=0
|
| 28 |
+
n,l,st,cent=cv2.connectedComponentsWithStats(mask)
|
| 29 |
+
cand=[]
|
| 30 |
+
for i in range(1,n):
|
| 31 |
+
x,y,w,h,area=st[i]
|
| 32 |
+
if area>25 and y<(79 if full else 60) and h>5 and w>3 and (area<2000 or full):
|
| 33 |
+
cand.append((area,i))
|
| 34 |
+
if not cand:return None
|
| 35 |
+
_,i=max(cand)
|
| 36 |
+
return np.r_[cent[i],st[i,4]] if full else cent[i]
|
| 37 |
+
|
| 38 |
+
class Controller:
|
| 39 |
+
def reset(self,obs,tools):
|
| 40 |
+
self.a=np.asarray(tools.hold_action(),dtype=float)
|
| 41 |
+
self.a[19:21]=0
|
| 42 |
+
self.q0=None
|
| 43 |
+
self.start=None
|
| 44 |
+
self.align_t=0
|
| 45 |
+
self.good=0
|
| 46 |
+
self.command=np.zeros(2)
|
| 47 |
+
self.last_feature=None
|
| 48 |
+
self.final_t=0
|
| 49 |
+
self.final_good=0
|
| 50 |
+
self.adjust_done=False
|
| 51 |
+
self.goal=None
|
| 52 |
+
self.settle_until=80
|
| 53 |
+
self.move_until=80
|
| 54 |
+
def act(self,obs,tools):
|
| 55 |
+
t=obs['t'];a=self.a
|
| 56 |
+
if self.start is None:
|
| 57 |
+
a[5:12]=[-.7,.32,0,-.5,0,.95,0]
|
| 58 |
+
pos=obs['low_dim_obs'][21:23];yaw=obs['low_dim_obs'][24]
|
| 59 |
+
a[3]=np.clip(-3*(yaw-.01),-.25,.25) if t>=80 else 0
|
| 60 |
+
a[0:2]=0
|
| 61 |
+
if self.goal is not None:
|
| 62 |
+
delta=self.goal-pos
|
| 63 |
+
if np.linalg.norm(delta)<.012 or t>=self.move_until:
|
| 64 |
+
self.goal=None;self.settle_until=t+65
|
| 65 |
+
else:
|
| 66 |
+
v=delta*3
|
| 67 |
+
speed=np.linalg.norm(v)
|
| 68 |
+
v*=np.clip(speed,.11,.2)/max(speed,1e-6)
|
| 69 |
+
c,sn=np.cos(yaw),np.sin(yaw)
|
| 70 |
+
a[0:2]=[c*v[0]+sn*v[1],-sn*v[0]+c*v[1]]
|
| 71 |
+
elif t>=self.settle_until:
|
| 72 |
+
f=detect(tools.image('left_wrist'));self.last_feature=f
|
| 73 |
+
if f is None:delta=np.array([0,-.12])
|
| 74 |
+
else:
|
| 75 |
+
err=f-np.array([46.4,53.])
|
| 76 |
+
delta=np.array([0,-err[0]*.0025])
|
| 77 |
+
if abs(err[0])<8:
|
| 78 |
+
self.start=t;a[3]=0;return a.copy()
|
| 79 |
+
if abs(err[0])<4:delta[1]=0
|
| 80 |
+
if abs(err[1])<5:delta[0]=0
|
| 81 |
+
delta=np.clip(delta,-.12,.12)
|
| 82 |
+
self.goal=pos+delta
|
| 83 |
+
self.goal[0]=.164
|
| 84 |
+
self.goal[0]=np.clip(self.goal[0],.09,.25)
|
| 85 |
+
self.goal[1]=np.clip(self.goal[1],-.65,.25)
|
| 86 |
+
self.move_until=t+100
|
| 87 |
+
if t>=380:
|
| 88 |
+
self.start=t;a[0:2]=0;a[3]=0
|
| 89 |
+
return a.copy()
|
| 90 |
+
t=t-self.start
|
| 91 |
+
if not hasattr(self,'pre_sr'):
|
| 92 |
+
ex=0 if self.last_feature is None else self.last_feature[0]-46.4
|
| 93 |
+
self.pre_sr=.32-(np.clip(ex*.005,-.08,.08) if abs(ex)>8 else 0)
|
| 94 |
+
a[0:2]=0;a[3]=0
|
| 95 |
+
if t>=320 and not self.adjust_done:
|
| 96 |
+
if self.final_t%20==0:
|
| 97 |
+
f=detect(tools.image('left_wrist'),True)
|
| 98 |
+
if f is not None:
|
| 99 |
+
ex,ey=f[:2]-[54.7,43.9]
|
| 100 |
+
a[6]-=np.clip(ex*.0007,-.015,.015)
|
| 101 |
+
a[10]+=np.clip(ey*.0018,-.035,.035)
|
| 102 |
+
if abs(ex)<8 and abs(ey)<8:
|
| 103 |
+
a[4]+=np.clip((1000-f[2])*.00003,-.012,.012)
|
| 104 |
+
a[6]=np.clip(a[6],-.3,.9);a[10]=np.clip(a[10],.4,1.35);a[4]=np.clip(a[4],.1,.55)
|
| 105 |
+
if abs(ex)<5 and abs(ey)<5 and abs(f[2]-1000)<250:self.final_good+=1
|
| 106 |
+
else:self.final_good=0
|
| 107 |
+
else:
|
| 108 |
+
a[10]=min(1.35,a[10]+.025)
|
| 109 |
+
if self.final_good>=2 or self.final_t>=260:
|
| 110 |
+
self.adjust_done=True
|
| 111 |
+
self.final_t+=1
|
| 112 |
+
return a.copy()
|
| 113 |
+
if t>=320:t-=self.final_t
|
| 114 |
+
if t<90:a[5:12]=[-.7,self.pre_sr,0,-.5,0,1.2,0]
|
| 115 |
+
elif t<250:
|
| 116 |
+
k=(t-90)//40+1
|
| 117 |
+
a[5:12]=[-.7-.15*k,self.pre_sr,0,-.5+.25*k,0,1.2-.1*k,0]
|
| 118 |
+
elif t<320:
|
| 119 |
+
cy=55 if self.last_feature is None else self.last_feature[1]
|
| 120 |
+
correction=np.clip(max(0,44-cy)*.02-max(0,cy-59)*.012,-.13,.13)
|
| 121 |
+
a[4]=.35+correction;a[10]=.9-correction
|
| 122 |
+
elif t<380:a[19]=1
|
| 123 |
+
else:
|
| 124 |
+
if self.q0 is None:
|
| 125 |
+
self.q0=a[5:12].copy();self.p0,self.r0=fk(self.q0);self.q=self.q0.copy();self.grasp_pitch=a[4];self.place_extra=np.clip((.17-obs["low_dim_obs"][21])*1.5,0,.12)
|
| 126 |
+
if t<460:
|
| 127 |
+
p=self.p0+np.array([0,0,.12])*min(1,(t-379)/60)
|
| 128 |
+
self.q=solve(p,self.r0,self.q);a[5:12]=self.q
|
| 129 |
+
elif t<760:
|
| 130 |
+
angle=(t-459)*np.pi/300
|
| 131 |
+
self.q=solve(self.p0+[0,0,.12],self.r0@rot(0,angle),self.q);a[5:12]=self.q
|
| 132 |
+
elif t<860:
|
| 133 |
+
u=(t-759)/100
|
| 134 |
+
p=self.p0+np.array([.01*u*self.place_extra/.12,0,.12*(1-u)+.02*u*self.place_extra/.12])
|
| 135 |
+
a[4]=self.grasp_pitch+self.place_extra*u
|
| 136 |
+
self.q=solve(p,self.r0@rot(0,np.pi),self.q);a[5:12]=self.q
|
| 137 |
+
else:
|
| 138 |
+
a[19]=0
|
| 139 |
+
if t>940:
|
| 140 |
+
u=min(1,(t-940)/80)
|
| 141 |
+
p=self.p0+np.array([-.08*u,0,.03*u])
|
| 142 |
+
self.q=solve(p,self.r0@rot(0,np.pi),self.q);a[5:12]=self.q
|
| 143 |
+
return a.copy()
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
SIGNS=np.array([1,-1,-1,1,-1,1,-1])
|
| 147 |
+
def mirror_action(a):
|
| 148 |
+
b=np.asarray(a,dtype=float).copy()
|
| 149 |
+
b[1]*=-1;b[3]*=-1
|
| 150 |
+
b[5:12]=np.asarray(a[12:19])*SIGNS
|
| 151 |
+
b[12:19]=np.asarray(a[5:12])*SIGNS
|
| 152 |
+
b[19]=a[20];b[20]=a[19]
|
| 153 |
+
return b
|
| 154 |
+
class MirrorTools:
|
| 155 |
+
def __init__(self,tools):self.tools=tools
|
| 156 |
+
def hold_action(self):return mirror_action(self.tools.hold_action())
|
| 157 |
+
def image(self,camera):
|
| 158 |
+
camera={'left_wrist':'right_wrist','right_wrist':'left_wrist'}.get(camera,camera)
|
| 159 |
+
return self.tools.image(camera)[:,::-1].copy()
|
| 160 |
+
class Policy:
|
| 161 |
+
def reset(self,obs,tools):
|
| 162 |
+
h=cv2.cvtColor(tools.image('head'),cv2.COLOR_RGB2HSV)
|
| 163 |
+
mask=((h[:,:,1]<45)&(h[:,:,2]>30)&(h[:,:,2]<220)).astype('uint8');mask[12:]=0
|
| 164 |
+
n,l,st,cent=cv2.connectedComponentsWithStats(mask)
|
| 165 |
+
self.mirror=False
|
| 166 |
+
if n>1:
|
| 167 |
+
i=1+np.argmax(st[1:,4]);self.mirror=cent[i,0]>42
|
| 168 |
+
self.core=Controller();self.core.reset(self.observation(obs),self.tool(tools))
|
| 169 |
+
def observation(self,obs):
|
| 170 |
+
if not self.mirror:return obs
|
| 171 |
+
o=obs.copy();v=obs['low_dim_obs'].copy();v[22]*=-1;v[24]*=-1;o['low_dim_obs']=v
|
| 172 |
+
return o
|
| 173 |
+
def tool(self,tools):return MirrorTools(tools) if self.mirror else tools
|
| 174 |
+
def act(self,obs,tools):
|
| 175 |
+
a=self.core.act(self.observation(obs),self.tool(tools))
|
| 176 |
+
return mirror_action(a) if self.mirror else a
|
policies/flip_cup/deepseek1017-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/deepseek1017-s1/policy.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Control policy for the "flip cup" task on the simulated Unitree G1.
|
| 2 |
+
|
| 3 |
+
The robot starts in front of a counter. The target cup is upside down on the
|
| 4 |
+
counter top in front of the robot and is visible in the wrist cameras. The
|
| 5 |
+
policy is a deterministic scripted motion:
|
| 6 |
+
|
| 7 |
+
1. step forward to the counter,
|
| 8 |
+
2. stand tall and raise the left arm so that the wrist camera looks down at
|
| 9 |
+
the cup,
|
| 10 |
+
3. reach over the cup, close the gripper and lift it,
|
| 11 |
+
4. rotate the wrist/elbow so that the cup is turned right way up,
|
| 12 |
+
5. lower the arm again, open the gripper and back away.
|
| 13 |
+
|
| 14 |
+
The arm targets are absolute joint angles; the policy only writes the joints it
|
| 15 |
+
needs and leaves the rest at the values reported by tools.hold_action().
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
import numpy as np
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _lerp(a, b, t):
|
| 22 |
+
"""Linear interpolation between two scalars with t clamped to [0, 1]."""
|
| 23 |
+
t = min(1.0, max(0.0, t))
|
| 24 |
+
return a + (b - a) * t
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _ramp(t, t0, t1):
|
| 28 |
+
"""Return a 0..1 interpolation parameter over the interval [t0, t1]."""
|
| 29 |
+
if t1 <= t0:
|
| 30 |
+
return 1.0
|
| 31 |
+
return min(1.0, max(0.0, (t - t0) / float(t1 - t0)))
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class Policy:
|
| 35 |
+
"""Scripted pick, flip and place behaviour for the upside-down cup."""
|
| 36 |
+
|
| 37 |
+
# ── phase boundaries (control steps, 50 Hz) ────────────────────────────
|
| 38 |
+
T_WALK_END = 40
|
| 39 |
+
T_RPREP_END = 66
|
| 40 |
+
T_LPREP_END = 92
|
| 41 |
+
T_REACH_END = 116
|
| 42 |
+
T_STRAFE_END = 136
|
| 43 |
+
T_CLOSE_END = 178
|
| 44 |
+
T_LIFT_END = 226
|
| 45 |
+
T_FLIP_END = 276
|
| 46 |
+
T_LOWER_END = 316
|
| 47 |
+
T_OPEN_END = 348
|
| 48 |
+
T_RETREAT_END = 420
|
| 49 |
+
|
| 50 |
+
# ── joint targets ──────────────────────────────────────────────────────
|
| 51 |
+
SP_TALL = 0.20
|
| 52 |
+
EL_TALL = 0.00
|
| 53 |
+
WP_TALL = -1.20
|
| 54 |
+
SP_REACH = 0.40
|
| 55 |
+
EL_REACH = 0.35
|
| 56 |
+
SP_LIFT = 0.80
|
| 57 |
+
EL_LIFT = 0.60
|
| 58 |
+
WP_FLIP = 1.54 # wrist pitch after the 180 degree turn
|
| 59 |
+
SP_LOWER = 0.20
|
| 60 |
+
EL_LOWER = 0.90
|
| 61 |
+
|
| 62 |
+
def reset(self, obs, tools):
|
| 63 |
+
"""Prepare for one episode."""
|
| 64 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32).copy()
|
| 65 |
+
|
| 66 |
+
def act(self, obs, tools):
|
| 67 |
+
"""Return the 21-float action for the current control step."""
|
| 68 |
+
t = int(obs.get("t", 0))
|
| 69 |
+
h = np.asarray(tools.hold_action(), dtype=np.float32).copy()
|
| 70 |
+
|
| 71 |
+
# Start from the current targets but never let the base drift.
|
| 72 |
+
a = h
|
| 73 |
+
a[0] = 0.0
|
| 74 |
+
a[1] = 0.0
|
| 75 |
+
a[3] = 0.0
|
| 76 |
+
|
| 77 |
+
# The left arm is the manipulating arm; keep the right arm neutral.
|
| 78 |
+
a[12:19] = self.hold[12:19] if hasattr(self, "hold") else a[12:19]
|
| 79 |
+
a[20] = 0.0
|
| 80 |
+
|
| 81 |
+
if t < self.T_WALK_END:
|
| 82 |
+
# Walk up to the counter. The base controller stops on contact.
|
| 83 |
+
a[0] = 0.30
|
| 84 |
+
a[2] = 0.75
|
| 85 |
+
a[4] = 0.0
|
| 86 |
+
a[5:12] = self.hold[5:12]
|
| 87 |
+
a[19] = 0.0
|
| 88 |
+
return a
|
| 89 |
+
|
| 90 |
+
# From here on stand tall: this lifts the shoulders and puts the
|
| 91 |
+
# wrist cameras above the counter top.
|
| 92 |
+
a[2] = 1.0
|
| 93 |
+
a[4] = 0.0
|
| 94 |
+
a[19] = 0.0
|
| 95 |
+
|
| 96 |
+
if t < self.T_RPREP_END:
|
| 97 |
+
# Give the whole-body controller time to settle in the tall pose.
|
| 98 |
+
a[5] = self.SP_TALL
|
| 99 |
+
a[6] = 0.0
|
| 100 |
+
a[7] = 0.0
|
| 101 |
+
a[8] = self.EL_TALL
|
| 102 |
+
a[9] = 0.0
|
| 103 |
+
a[10] = self.WP_TALL
|
| 104 |
+
a[11] = 0.0
|
| 105 |
+
return a
|
| 106 |
+
|
| 107 |
+
if t < self.T_LPREP_END:
|
| 108 |
+
# Raise the left arm to the observation pose over the counter.
|
| 109 |
+
a[5] = self.SP_TALL
|
| 110 |
+
a[6] = 0.0
|
| 111 |
+
a[7] = 0.0
|
| 112 |
+
a[8] = self.EL_TALL
|
| 113 |
+
a[9] = 0.0
|
| 114 |
+
a[10] = self.WP_TALL
|
| 115 |
+
a[11] = 0.0
|
| 116 |
+
return a
|
| 117 |
+
|
| 118 |
+
if t < self.T_REACH_END:
|
| 119 |
+
# Reach forward over the counter until the cup is between the
|
| 120 |
+
# fingers (the wrist camera shows the cup centred here).
|
| 121 |
+
u = _ramp(t, self.T_LPREP_END, self.T_REACH_END)
|
| 122 |
+
a[5] = _lerp(self.SP_TALL, self.SP_REACH, u)
|
| 123 |
+
a[6] = 0.0
|
| 124 |
+
a[7] = 0.0
|
| 125 |
+
a[8] = _lerp(self.EL_TALL, self.EL_REACH, u)
|
| 126 |
+
a[9] = 0.0
|
| 127 |
+
a[10] = self.WP_TALL
|
| 128 |
+
a[11] = 0.0
|
| 129 |
+
return a
|
| 130 |
+
|
| 131 |
+
if t < self.T_STRAFE_END:
|
| 132 |
+
# Small sideways step that slides the cup deeper into the gripper.
|
| 133 |
+
a[5] = self.SP_REACH
|
| 134 |
+
a[6] = 0.0
|
| 135 |
+
a[7] = 0.0
|
| 136 |
+
a[8] = self.EL_REACH
|
| 137 |
+
a[9] = 0.0
|
| 138 |
+
a[10] = self.WP_TALL
|
| 139 |
+
a[11] = 0.0
|
| 140 |
+
a[1] = 0.30
|
| 141 |
+
return a
|
| 142 |
+
|
| 143 |
+
if t < self.T_CLOSE_END:
|
| 144 |
+
# Close the gripper on the cup.
|
| 145 |
+
a[5] = self.SP_REACH
|
| 146 |
+
a[6] = 0.0
|
| 147 |
+
a[7] = 0.0
|
| 148 |
+
a[8] = self.EL_REACH
|
| 149 |
+
a[9] = 0.0
|
| 150 |
+
a[10] = self.WP_TALL
|
| 151 |
+
a[11] = 0.0
|
| 152 |
+
a[19] = 1.0
|
| 153 |
+
return a
|
| 154 |
+
|
| 155 |
+
if t < self.T_LIFT_END:
|
| 156 |
+
# Lift the cup clear of the counter.
|
| 157 |
+
u = _ramp(t, self.T_CLOSE_END, self.T_LIFT_END)
|
| 158 |
+
a[5] = _lerp(self.SP_REACH, self.SP_LIFT, u)
|
| 159 |
+
a[6] = 0.0
|
| 160 |
+
a[7] = 0.0
|
| 161 |
+
a[8] = _lerp(self.EL_REACH, self.EL_LIFT, u)
|
| 162 |
+
a[9] = 0.0
|
| 163 |
+
a[10] = self.WP_TALL
|
| 164 |
+
a[11] = 0.0
|
| 165 |
+
a[19] = 1.0
|
| 166 |
+
return a
|
| 167 |
+
|
| 168 |
+
if t < self.T_FLIP_END:
|
| 169 |
+
# Rotate the cup 180 degrees about the (horizontal) wrist pitch
|
| 170 |
+
# axis. The sum shoulder_pitch + elbow + wrist_pitch changes by
|
| 171 |
+
# ~pi, which turns the upside-down cup right way up.
|
| 172 |
+
u = _ramp(t, self.T_LIFT_END, self.T_FLIP_END)
|
| 173 |
+
a[5] = self.SP_LIFT
|
| 174 |
+
a[6] = 0.0
|
| 175 |
+
a[7] = 0.0
|
| 176 |
+
a[8] = _lerp(self.EL_LIFT, self.EL_REACH, u)
|
| 177 |
+
a[9] = 0.0
|
| 178 |
+
a[10] = _lerp(self.WP_TALL, self.WP_FLIP, u)
|
| 179 |
+
a[11] = 0.0
|
| 180 |
+
a[19] = 1.0
|
| 181 |
+
return a
|
| 182 |
+
|
| 183 |
+
if t < self.T_LOWER_END:
|
| 184 |
+
# Lower the flipped cup towards the counter while keeping the
|
| 185 |
+
# joint-angle sum constant (so the cup stays upright).
|
| 186 |
+
u = _ramp(t, self.T_FLIP_END, self.T_LOWER_END)
|
| 187 |
+
a[5] = _lerp(self.SP_LIFT, self.SP_LOWER, u)
|
| 188 |
+
a[6] = 0.0
|
| 189 |
+
a[7] = 0.0
|
| 190 |
+
a[8] = _lerp(self.EL_REACH, self.EL_LOWER, u)
|
| 191 |
+
a[9] = 0.0
|
| 192 |
+
a[10] = self.WP_FLIP
|
| 193 |
+
a[11] = 0.0
|
| 194 |
+
a[19] = 1.0
|
| 195 |
+
return a
|
| 196 |
+
|
| 197 |
+
if t < self.T_OPEN_END:
|
| 198 |
+
# Gently release the cup.
|
| 199 |
+
u = _ramp(t, self.T_LOWER_END, self.T_OPEN_END)
|
| 200 |
+
a[5] = self.SP_LOWER
|
| 201 |
+
a[6] = 0.0
|
| 202 |
+
a[7] = 0.0
|
| 203 |
+
a[8] = self.EL_LOWER
|
| 204 |
+
a[9] = 0.0
|
| 205 |
+
a[10] = self.WP_FLIP
|
| 206 |
+
a[11] = 0.0
|
| 207 |
+
a[19] = _lerp(1.0, 0.0, u)
|
| 208 |
+
return a
|
| 209 |
+
|
| 210 |
+
# Retreat from the cup and settle so that the task condition can hold.
|
| 211 |
+
u = _ramp(t, self.T_OPEN_END, self.T_RETREAT_END)
|
| 212 |
+
a[5] = _lerp(self.SP_LOWER, 0.20, u)
|
| 213 |
+
a[6] = 0.0
|
| 214 |
+
a[7] = 0.0
|
| 215 |
+
a[8] = _lerp(self.EL_LOWER, 0.20, u)
|
| 216 |
+
a[9] = 0.0
|
| 217 |
+
a[10] = _lerp(self.WP_FLIP, -0.50, u)
|
| 218 |
+
a[11] = 0.0
|
| 219 |
+
a[19] = 0.0
|
| 220 |
+
return a
|
policies/flip_cup/deepseek1017-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/deepseek1017-s2/policy.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hand-written control policy for turning an upside-down cup right way up.
|
| 2 |
+
|
| 3 |
+
Observation model
|
| 4 |
+
-----------------
|
| 5 |
+
The robot's own head camera is the only view of the scene. The cup is the
|
| 6 |
+
dark, colour-neutral blob standing on the brightly lit work surface in the
|
| 7 |
+
upper part of the head view (it sits right at the boundary between the lit
|
| 8 |
+
surface and the checkered cloth). Its image position tells which arm is on
|
| 9 |
+
the cup's side.
|
| 10 |
+
|
| 11 |
+
Control
|
| 12 |
+
-------
|
| 13 |
+
1. find the cup in the head image and choose the arm on its side,
|
| 14 |
+
2. yaw the base so the cup lines up with that arm,
|
| 15 |
+
3. walk a fixed list of grasp postures with that arm; each attempt is
|
| 16 |
+
raise clear of the surface -> lean/settle -> close -> lift -> roll the
|
| 17 |
+
wrist over -> set down -> release,
|
| 18 |
+
4. re-aim the base to a second lateral offset and repeat the list,
|
| 19 |
+
5. finish in a compact stance.
|
| 20 |
+
|
| 21 |
+
The whole thing is deterministic (no clocks, no random numbers) and never
|
| 22 |
+
commands anything outside the documented joint/velocity ranges.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
import numpy as np
|
| 26 |
+
|
| 27 |
+
# ---------------------------------------------------------------- cup finder
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _detect_cup(rgb):
|
| 31 |
+
"""Locate the cup in a head-camera image (never raises)."""
|
| 32 |
+
try:
|
| 33 |
+
return _detect_cup_inner(rgb)
|
| 34 |
+
except Exception:
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _detect_cup_inner(rgb):
|
| 39 |
+
"""Locate the cup in a head-camera image.
|
| 40 |
+
|
| 41 |
+
Returns (cx, cy, w, h) of the largest dark neutral blob in the upper part
|
| 42 |
+
of the image, or None.
|
| 43 |
+
"""
|
| 44 |
+
im = np.asarray(rgb).astype(np.float32)
|
| 45 |
+
h, w, _ = im.shape
|
| 46 |
+
r, g, b = im[:, :, 0], im[:, :, 1], im[:, :, 2]
|
| 47 |
+
rb = np.abs(r - b)
|
| 48 |
+
val = im.mean(2)
|
| 49 |
+
neutral = (rb < 24) & (val < 205) & (val > 40)
|
| 50 |
+
mask = np.zeros((h, w), np.uint8)
|
| 51 |
+
ylim = int(h * 0.62)
|
| 52 |
+
mask[:ylim] = neutral[:ylim]
|
| 53 |
+
# 4-neighbour erosion to drop single-pixel speckle
|
| 54 |
+
m = mask.astype(np.float32)
|
| 55 |
+
m2 = m.copy()
|
| 56 |
+
m2[1:, :] *= m[:-1, :]
|
| 57 |
+
m2[:-1, :] *= m[1:, :]
|
| 58 |
+
m2[:, 1:] *= m[:, :-1]
|
| 59 |
+
m2[:, :-1] *= m[:, 1:]
|
| 60 |
+
mask = (m2 > 0.5).astype(np.uint8)
|
| 61 |
+
best = None
|
| 62 |
+
seen = np.zeros_like(mask)
|
| 63 |
+
ys, xs = np.where(mask > 0)
|
| 64 |
+
for y0, x0 in zip(ys, xs):
|
| 65 |
+
if seen[y0, x0]:
|
| 66 |
+
continue
|
| 67 |
+
stack = [(y0, x0)]
|
| 68 |
+
seen[y0, x0] = 1
|
| 69 |
+
pts = []
|
| 70 |
+
while stack:
|
| 71 |
+
y, x = stack.pop()
|
| 72 |
+
pts.append((y, x))
|
| 73 |
+
for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
| 74 |
+
yy, xx = y + dy, x + dx
|
| 75 |
+
if 0 <= yy < h and 0 <= xx < w and mask[yy, xx] and not seen[yy, xx]:
|
| 76 |
+
seen[yy, xx] = 1
|
| 77 |
+
stack.append((yy, xx))
|
| 78 |
+
n = len(pts)
|
| 79 |
+
if n < 16:
|
| 80 |
+
continue
|
| 81 |
+
py = np.array([p[0] for p in pts])
|
| 82 |
+
px = np.array([p[1] for p in pts])
|
| 83 |
+
bw = px.max() - px.min() + 1
|
| 84 |
+
bh = py.max() - py.min() + 1
|
| 85 |
+
if bw > 42 or bh > 42:
|
| 86 |
+
continue
|
| 87 |
+
if best is None or n > best[0]:
|
| 88 |
+
best = (n, float(px.mean()), float(py.mean()), int(bw), int(bh))
|
| 89 |
+
if best is None:
|
| 90 |
+
return None
|
| 91 |
+
return best[1:]
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
# Grasp postures: (torso_pitch, shoulder_pitch, shoulder_roll, elbow,
|
| 95 |
+
# wrist_pitch, wrist_roll)
|
| 96 |
+
# The first group reaches for a cup that is close to the chest (the arm is
|
| 97 |
+
# folded, which is where the wrist camera actually sees the surface holding
|
| 98 |
+
# the cup); the later ones sweep progressively farther and higher.
|
| 99 |
+
_ATTEMPTS = [
|
| 100 |
+
(0.00, 0.60, 0.00, 1.90, -1.20, 0.00),
|
| 101 |
+
(0.00, 0.72, 0.00, 1.95, -1.20, 1.50),
|
| 102 |
+
(0.00, 0.60, 0.00, 1.90, -1.20, -1.50),
|
| 103 |
+
(0.00, 0.70, 0.00, 1.70, -0.80, 0.00),
|
| 104 |
+
(0.00, 0.52, 0.00, 1.60, -0.90, 0.00),
|
| 105 |
+
(0.30, 1.30, -0.20, 0.10, 0.00, 0.00),
|
| 106 |
+
(0.65, 0.35, -0.30, 1.10, -1.00, 0.00),
|
| 107 |
+
(0.00, 1.10, 0.00, 0.20, 0.00, 0.00),
|
| 108 |
+
]
|
| 109 |
+
|
| 110 |
+
# lateral base offsets (cup image column targets) tried in turn
|
| 111 |
+
_AIM_TARGETS_R = [30.0, 48.0]
|
| 112 |
+
_AIM_TARGETS_L = [54.0, 36.0]
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class Policy:
|
| 116 |
+
"""Deterministic scripted cup-flipping policy."""
|
| 117 |
+
|
| 118 |
+
def reset(self, obs, tools):
|
| 119 |
+
self.hold = np.asarray(tools.hold_action(), np.float32)
|
| 120 |
+
self.height = float(self.hold[2])
|
| 121 |
+
self.pitch = float(self.hold[4])
|
| 122 |
+
self.left = np.array(self.hold[5:12], np.float32)
|
| 123 |
+
self.right = np.array(self.hold[12:19], np.float32)
|
| 124 |
+
self.grip_l = float(self.hold[19])
|
| 125 |
+
self.grip_r = float(self.hold[20])
|
| 126 |
+
self.cup = None
|
| 127 |
+
self.arm = "R"
|
| 128 |
+
self.pass_i = 0
|
| 129 |
+
self.targets = _AIM_TARGETS_R
|
| 130 |
+
self.target_cx = self.targets[0]
|
| 131 |
+
self.phase = "settle"
|
| 132 |
+
self.phase_t = 0
|
| 133 |
+
self.att = 0
|
| 134 |
+
self.sub = 0
|
| 135 |
+
|
| 136 |
+
# -- helpers -----------------------------------------------------
|
| 137 |
+
def _action(self, vx=0.0, vy=0.0, wz=0.0):
|
| 138 |
+
raw = self.hold.copy()
|
| 139 |
+
raw[0] = vx
|
| 140 |
+
raw[1] = vy
|
| 141 |
+
raw[2] = self.height
|
| 142 |
+
raw[3] = wz
|
| 143 |
+
raw[4] = self.pitch
|
| 144 |
+
raw[5:12] = self.left
|
| 145 |
+
raw[12:19] = self.right
|
| 146 |
+
raw[19] = self.grip_l
|
| 147 |
+
raw[20] = self.grip_r
|
| 148 |
+
return raw
|
| 149 |
+
|
| 150 |
+
def _set_arm(self, sp, roll, el, wp, wr):
|
| 151 |
+
tgt = np.array([sp, roll, 0.0, el, wr, wp, 0.0], np.float32)
|
| 152 |
+
if self.arm == "R":
|
| 153 |
+
self.right = tgt
|
| 154 |
+
else:
|
| 155 |
+
self.left = tgt
|
| 156 |
+
|
| 157 |
+
def _grip(self, closed):
|
| 158 |
+
v = 1.0 if closed else 0.0
|
| 159 |
+
if self.arm == "R":
|
| 160 |
+
self.grip_r = v
|
| 161 |
+
else:
|
| 162 |
+
self.grip_l = v
|
| 163 |
+
|
| 164 |
+
def _next_sub(self):
|
| 165 |
+
self.sub += 1
|
| 166 |
+
self.phase_t = 0
|
| 167 |
+
|
| 168 |
+
# -- main loop ---------------------------------------------------
|
| 169 |
+
def act(self, obs, tools):
|
| 170 |
+
self.phase_t += 1
|
| 171 |
+
|
| 172 |
+
if self.phase == "settle":
|
| 173 |
+
if self.phase_t == 1:
|
| 174 |
+
self.cup = _detect_cup(tools.image("head"))
|
| 175 |
+
cx = self.cup[0] if self.cup is not None else 14.0
|
| 176 |
+
if cx > 44.0:
|
| 177 |
+
self.arm = "L"
|
| 178 |
+
self.targets = _AIM_TARGETS_L
|
| 179 |
+
else:
|
| 180 |
+
self.arm = "R"
|
| 181 |
+
self.targets = _AIM_TARGETS_R
|
| 182 |
+
self.target_cx = self.targets[0]
|
| 183 |
+
if self.phase_t >= 5:
|
| 184 |
+
self.phase = "aim"
|
| 185 |
+
self.phase_t = 0
|
| 186 |
+
return self._action()
|
| 187 |
+
|
| 188 |
+
if self.phase == "aim":
|
| 189 |
+
if self.phase_t % 2 == 1:
|
| 190 |
+
self.cup = _detect_cup(tools.image("head"))
|
| 191 |
+
wz = 0.0
|
| 192 |
+
if self.cup is not None:
|
| 193 |
+
err = self.cup[0] - self.target_cx
|
| 194 |
+
if abs(err) > 5.0 and self.phase_t < 26:
|
| 195 |
+
wz = float(np.clip(-0.035 * err, -0.45, 0.45))
|
| 196 |
+
else:
|
| 197 |
+
self.phase = "grasp"
|
| 198 |
+
self.phase_t = 0
|
| 199 |
+
self.sub = 0
|
| 200 |
+
else:
|
| 201 |
+
wz = -0.18 if self.arm == "R" else 0.18
|
| 202 |
+
if self.phase_t >= 26:
|
| 203 |
+
self.phase = "grasp"
|
| 204 |
+
self.phase_t = 0
|
| 205 |
+
self.sub = 0
|
| 206 |
+
return self._action(wz=wz)
|
| 207 |
+
|
| 208 |
+
if self.phase == "grasp":
|
| 209 |
+
return self._grasp()
|
| 210 |
+
|
| 211 |
+
return self._action()
|
| 212 |
+
|
| 213 |
+
def _grasp(self):
|
| 214 |
+
pitch, sp, roll, el, wp, wr = _ATTEMPTS[self.att % len(_ATTEMPTS)]
|
| 215 |
+
# alternate the roll sign between passes over the list
|
| 216 |
+
if (self.att // len(_ATTEMPTS)) % 2 == 1:
|
| 217 |
+
roll = -roll
|
| 218 |
+
wp = wp - 0.25
|
| 219 |
+
rp = roll
|
| 220 |
+
|
| 221 |
+
if self.sub == 0: # raise the arm clear of the work surface
|
| 222 |
+
self.pitch = 0.0
|
| 223 |
+
self._set_arm(sp, rp, el, wp, wr)
|
| 224 |
+
self._grip(False)
|
| 225 |
+
if self.phase_t >= 9:
|
| 226 |
+
self._next_sub()
|
| 227 |
+
return self._action()
|
| 228 |
+
|
| 229 |
+
if self.sub == 1: # lean in / settle on the target posture
|
| 230 |
+
self.pitch = pitch
|
| 231 |
+
if self.phase_t >= 11:
|
| 232 |
+
self._next_sub()
|
| 233 |
+
return self._action()
|
| 234 |
+
|
| 235 |
+
if self.sub == 2: # settle
|
| 236 |
+
if self.phase_t >= 4:
|
| 237 |
+
self._next_sub()
|
| 238 |
+
return self._action()
|
| 239 |
+
|
| 240 |
+
if self.sub == 3: # close the gripper
|
| 241 |
+
self._grip(True)
|
| 242 |
+
if self.phase_t >= 11:
|
| 243 |
+
self._next_sub()
|
| 244 |
+
return self._action()
|
| 245 |
+
|
| 246 |
+
if self.sub == 4: # lift
|
| 247 |
+
self.pitch = max(pitch - 0.20, 0.0)
|
| 248 |
+
self._set_arm(min(sp + 0.40, 2.5), rp * 0.7,
|
| 249 |
+
max(el - 0.55, 0.0), wp * 0.4, wr)
|
| 250 |
+
if self.phase_t >= 12:
|
| 251 |
+
self._next_sub()
|
| 252 |
+
return self._action()
|
| 253 |
+
|
| 254 |
+
if self.sub == 5: # roll the wrist over to turn the cup upright
|
| 255 |
+
wrist = 1.6 if (self.att % 2 == 0) else -1.6
|
| 256 |
+
self._set_arm(min(sp + 0.40, 2.5), rp * 0.7,
|
| 257 |
+
max(el - 0.55, 0.0), wrist, wr)
|
| 258 |
+
if self.phase_t >= 14:
|
| 259 |
+
self._next_sub()
|
| 260 |
+
return self._action()
|
| 261 |
+
|
| 262 |
+
if self.sub == 6: # set it back down
|
| 263 |
+
self.pitch = pitch
|
| 264 |
+
self._set_arm(sp, rp, el, 1.6 if (self.att % 2 == 0) else -1.6, wr)
|
| 265 |
+
if self.phase_t >= 12:
|
| 266 |
+
self._next_sub()
|
| 267 |
+
return self._action()
|
| 268 |
+
|
| 269 |
+
if self.sub == 7: # release, straighten up
|
| 270 |
+
self._grip(False)
|
| 271 |
+
if self.phase_t >= 8:
|
| 272 |
+
self.pitch = 0.0
|
| 273 |
+
if self.phase_t >= 14:
|
| 274 |
+
self.att += 1
|
| 275 |
+
self.sub = 0
|
| 276 |
+
self.phase_t = 0
|
| 277 |
+
if self.att >= len(_ATTEMPTS):
|
| 278 |
+
self.att = 0
|
| 279 |
+
self.pass_i += 1
|
| 280 |
+
if self.pass_i >= len(self.targets):
|
| 281 |
+
self.phase = "done"
|
| 282 |
+
else:
|
| 283 |
+
self.target_cx = self.targets[self.pass_i]
|
| 284 |
+
self.phase = "aim"
|
| 285 |
+
self.phase_t = 0
|
| 286 |
+
return self._action()
|
| 287 |
+
|
| 288 |
+
self.phase = "done"
|
| 289 |
+
return self._action()
|
policies/flip_cup/deepseek1017-s3/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/deepseek1017-s3/policy.py
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Control policy for the ``flip_cup`` task.
|
| 2 |
+
|
| 3 |
+
The policy is pure hand-written control logic (no learned components). It
|
| 4 |
+
uses the robot's own head camera to find the mug (a neutral-grey body sitting
|
| 5 |
+
on a bright yellow coaster), walks to the side of the counter where the mug
|
| 6 |
+
sits, and then runs a short sequence of arm/gripper poses that reach for the
|
| 7 |
+
mug, close the gripper, lift, rotate the wrist to turn the mug over and set it
|
| 8 |
+
back down.
|
| 9 |
+
|
| 10 |
+
Everything is deterministic. No wall-clock time and no unseeded randomness
|
| 11 |
+
are used.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import cv2
|
| 15 |
+
import numpy as np
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# ---------------------------------------------------------------------------
|
| 19 |
+
# small image utilities
|
| 20 |
+
# ---------------------------------------------------------------------------
|
| 21 |
+
|
| 22 |
+
def _cup_blobs(image):
|
| 23 |
+
"""Return candidate mug blobs in a head image, largest first.
|
| 24 |
+
|
| 25 |
+
The mug is a light neutral-grey object. The cream counter and the blue
|
| 26 |
+
floor are strongly coloured, so a low-saturation bright blob near the top
|
| 27 |
+
of the image is a good mug candidate. Each entry is ``(area, x, y, w, h)``.
|
| 28 |
+
"""
|
| 29 |
+
rgb = image.astype(np.int16)
|
| 30 |
+
hi = rgb.max(axis=2)
|
| 31 |
+
lo = rgb.min(axis=2)
|
| 32 |
+
neutral = ((hi - lo) < 26) & (rgb[:, :, 1] > 105) & (rgb[:, :, 1] < 246)
|
| 33 |
+
mask = cv2.morphologyEx(
|
| 34 |
+
neutral.astype(np.uint8), cv2.MORPH_OPEN, np.ones((2, 2), np.uint8)
|
| 35 |
+
)
|
| 36 |
+
# The mug lives on the counter edge, i.e. near the top of the head view.
|
| 37 |
+
mask[34:, :] = 0
|
| 38 |
+
n, _labels, stats, _cent = cv2.connectedComponentsWithStats(mask, 8)
|
| 39 |
+
out = []
|
| 40 |
+
for i in range(1, n):
|
| 41 |
+
x, y, w, h, area = stats[i]
|
| 42 |
+
if area >= 9:
|
| 43 |
+
out.append((int(area), int(x), int(y), int(w), int(h)))
|
| 44 |
+
out.sort(reverse=True)
|
| 45 |
+
return out
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _coaster_centroid(image):
|
| 49 |
+
"""Centroid of the bright-yellow coaster under the mug, or ``None``."""
|
| 50 |
+
r = image[:, :, 0].astype(np.int16)
|
| 51 |
+
g = image[:, :, 1].astype(np.int16)
|
| 52 |
+
b = image[:, :, 2].astype(np.int16)
|
| 53 |
+
mask = (
|
| 54 |
+
(r > 190) & (g > 160) & (b < 215) & ((r - b) > 35) & ((g - b) > 20)
|
| 55 |
+
).astype(np.uint8)
|
| 56 |
+
mask[32:, :] = 0
|
| 57 |
+
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, np.ones((2, 2), np.uint8))
|
| 58 |
+
ys, xs = np.where(mask > 0)
|
| 59 |
+
if len(xs) < 6:
|
| 60 |
+
return None
|
| 61 |
+
return float(xs.mean()), float(ys.mean()), int(len(xs))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _find_mug(image):
|
| 65 |
+
"""Best guess of the mug position in a head image or ``None``."""
|
| 66 |
+
blobs = _cup_blobs(image)
|
| 67 |
+
if blobs:
|
| 68 |
+
area, x, y, w, h = blobs[0]
|
| 69 |
+
if area <= 420 and w <= 30 and h <= 30:
|
| 70 |
+
return float(x + w * 0.5), float(y + h * 0.5), float(area), "blob"
|
| 71 |
+
coaster = _coaster_centroid(image)
|
| 72 |
+
if coaster is not None:
|
| 73 |
+
cx, cy, area = coaster
|
| 74 |
+
return cx, max(0.0, cy - 4.0), float(area), "coaster"
|
| 75 |
+
return None
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# ---------------------------------------------------------------------------
|
| 79 |
+
# policy
|
| 80 |
+
# ---------------------------------------------------------------------------
|
| 81 |
+
|
| 82 |
+
class Policy:
|
| 83 |
+
"""Deterministic scripted policy for turning the mug the right way up."""
|
| 84 |
+
|
| 85 |
+
def reset(self, obs, tools):
|
| 86 |
+
"""Prepare a new episode."""
|
| 87 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 88 |
+
self.t = 0
|
| 89 |
+
self.phase = "settle"
|
| 90 |
+
self.phase_t = 0
|
| 91 |
+
self.side = "L" # side of the head image the mug starts on
|
| 92 |
+
self.arm = "A" # "A": action slice 5..11, "B": slice 12..18
|
| 93 |
+
self.start_mug = None
|
| 94 |
+
self._poses = []
|
| 95 |
+
self._attempt = 0
|
| 96 |
+
self._grasped = False
|
| 97 |
+
self._mug_before = None
|
| 98 |
+
self._sr0 = -0.6
|
| 99 |
+
self._sy0 = 0.2
|
| 100 |
+
|
| 101 |
+
# -- helpers ----------------------------------------------------------
|
| 102 |
+
def _look_action(self):
|
| 103 |
+
action = self.hold.copy()
|
| 104 |
+
action[4] = -0.2 # lean back a little: the mug is high
|
| 105 |
+
action[2] = 0.80
|
| 106 |
+
return action
|
| 107 |
+
|
| 108 |
+
def _set_arm(self, action, arm, sp, el, sr, sy, wp=0.0, wr=0.0, grip=None):
|
| 109 |
+
"""Write an arm pose (and optionally a gripper command) into action."""
|
| 110 |
+
base = 5 if arm == "A" else 12
|
| 111 |
+
grip_idx = 19 if arm == "A" else 20
|
| 112 |
+
action[base + 0] = sp
|
| 113 |
+
action[base + 1] = sr
|
| 114 |
+
action[base + 2] = sy
|
| 115 |
+
action[base + 3] = el
|
| 116 |
+
action[base + 4] = wr
|
| 117 |
+
action[base + 5] = wp
|
| 118 |
+
action[base + 6] = 0.0
|
| 119 |
+
if grip is not None:
|
| 120 |
+
action[grip_idx] = grip
|
| 121 |
+
|
| 122 |
+
def _mug_visible(self, image):
|
| 123 |
+
return _find_mug(image)
|
| 124 |
+
|
| 125 |
+
# -- main control loop -------------------------------------------------
|
| 126 |
+
def act(self, obs, tools):
|
| 127 |
+
"""Return the 21-float physical action for the current step."""
|
| 128 |
+
self.t += 1
|
| 129 |
+
self.phase_t += 1
|
| 130 |
+
|
| 131 |
+
if obs.get("fell", False):
|
| 132 |
+
return self.hold.astype(np.float32)
|
| 133 |
+
|
| 134 |
+
# ---- settle and locate the mug ---------------------------------
|
| 135 |
+
if self.phase == "settle":
|
| 136 |
+
action = self._look_action()
|
| 137 |
+
if self.phase_t >= 12:
|
| 138 |
+
mug = self._mug_visible(np.asarray(tools.image("head")))
|
| 139 |
+
if mug is not None:
|
| 140 |
+
self.start_mug = mug
|
| 141 |
+
self.side = "L" if mug[0] < 42.0 else "R"
|
| 142 |
+
# After strafing towards the mug it crosses the image, so
|
| 143 |
+
# the arm that ends up next to it is the opposite one.
|
| 144 |
+
self.arm = "A" if self.side == "L" else "B"
|
| 145 |
+
self.phase = "strafe"
|
| 146 |
+
self.phase_t = 0
|
| 147 |
+
return action.astype(np.float32)
|
| 148 |
+
|
| 149 |
+
# ---- strafe to the mug's side of the counter --------------------
|
| 150 |
+
if self.phase == "strafe":
|
| 151 |
+
action = self._look_action()
|
| 152 |
+
direction = 1.0 if self.side == "L" else -1.0
|
| 153 |
+
target = 72.0 if self.side == "L" else 12.0
|
| 154 |
+
if self.phase_t % 4 == 0:
|
| 155 |
+
mug = self._mug_visible(np.asarray(tools.image("head")))
|
| 156 |
+
if mug is not None:
|
| 157 |
+
self.start_mug = mug
|
| 158 |
+
err = target - mug[0]
|
| 159 |
+
if abs(err) <= 5.0:
|
| 160 |
+
self.phase = "walk"
|
| 161 |
+
self.phase_t = 0
|
| 162 |
+
return action.astype(np.float32)
|
| 163 |
+
action[1] = direction * (0.30 if abs(err) > 8.0 else 0.12)
|
| 164 |
+
else:
|
| 165 |
+
action[1] = direction * 0.22
|
| 166 |
+
else:
|
| 167 |
+
action[1] = direction * 0.22
|
| 168 |
+
if self.phase_t > 150:
|
| 169 |
+
self.phase = "walk"
|
| 170 |
+
self.phase_t = 0
|
| 171 |
+
return action.astype(np.float32)
|
| 172 |
+
|
| 173 |
+
# ---- walk up to the counter -------------------------------------
|
| 174 |
+
if self.phase == "walk":
|
| 175 |
+
action = self.hold.copy()
|
| 176 |
+
action[0] = 0.35
|
| 177 |
+
action[2] = 1.0
|
| 178 |
+
action[4] = 0.55
|
| 179 |
+
if self.phase_t >= 55:
|
| 180 |
+
self.phase = "look_again"
|
| 181 |
+
self.phase_t = 0
|
| 182 |
+
return action.astype(np.float32)
|
| 183 |
+
|
| 184 |
+
if self.phase == "look_again":
|
| 185 |
+
action = self._look_action()
|
| 186 |
+
if self.phase_t >= 16:
|
| 187 |
+
self._poses = self._grasp_poses()
|
| 188 |
+
self._attempt = 0
|
| 189 |
+
self.phase = "reach"
|
| 190 |
+
self.phase_t = 0
|
| 191 |
+
return action.astype(np.float32)
|
| 192 |
+
|
| 193 |
+
# ---- reach / close / lift, several poses --------------------------
|
| 194 |
+
if self.phase == "reach":
|
| 195 |
+
if self.phase_t == 1:
|
| 196 |
+
self._mug_before = self._mug_visible(
|
| 197 |
+
np.asarray(tools.image("head"))
|
| 198 |
+
)
|
| 199 |
+
sp, el, sr, sy, wp = self._poses[self._attempt]
|
| 200 |
+
action = self._look_action()
|
| 201 |
+
self._set_arm(action, self.arm, sp, el, sr, sy, wp=wp, grip=0.0)
|
| 202 |
+
if self.phase_t >= 22:
|
| 203 |
+
self.phase = "close"
|
| 204 |
+
self.phase_t = 0
|
| 205 |
+
return action.astype(np.float32)
|
| 206 |
+
|
| 207 |
+
if self.phase == "close":
|
| 208 |
+
sp, el, sr, sy, wp = self._poses[self._attempt]
|
| 209 |
+
action = self._look_action()
|
| 210 |
+
self._set_arm(action, self.arm, sp, el, sr, sy, wp=wp, grip=1.0)
|
| 211 |
+
if self.phase_t >= 22:
|
| 212 |
+
self.phase = "lift"
|
| 213 |
+
self.phase_t = 0
|
| 214 |
+
return action.astype(np.float32)
|
| 215 |
+
|
| 216 |
+
if self.phase == "lift":
|
| 217 |
+
sp, el, sr, sy, wp = self._poses[self._attempt]
|
| 218 |
+
action = self._look_action()
|
| 219 |
+
self._set_arm(
|
| 220 |
+
action,
|
| 221 |
+
self.arm,
|
| 222 |
+
min(2.4, sp + 0.45),
|
| 223 |
+
min(1.8, el + 0.25),
|
| 224 |
+
sr,
|
| 225 |
+
sy,
|
| 226 |
+
wp=wp,
|
| 227 |
+
grip=1.0,
|
| 228 |
+
)
|
| 229 |
+
if self.phase_t >= 26:
|
| 230 |
+
after = self._mug_visible(np.asarray(tools.image("head")))
|
| 231 |
+
if self._mug_before is not None and after is None:
|
| 232 |
+
self._grasped = True
|
| 233 |
+
self.phase = "flip_ready"
|
| 234 |
+
self.phase_t = 0
|
| 235 |
+
else:
|
| 236 |
+
self.phase = "release"
|
| 237 |
+
self.phase_t = 0
|
| 238 |
+
return action.astype(np.float32)
|
| 239 |
+
|
| 240 |
+
if self.phase == "release":
|
| 241 |
+
sp, el, sr, sy, wp = self._poses[self._attempt]
|
| 242 |
+
action = self._look_action()
|
| 243 |
+
self._set_arm(action, self.arm, sp, el, sr, sy, wp=wp, grip=0.0)
|
| 244 |
+
if self.phase_t >= 18:
|
| 245 |
+
self.phase = "back_off"
|
| 246 |
+
self.phase_t = 0
|
| 247 |
+
return action.astype(np.float32)
|
| 248 |
+
|
| 249 |
+
if self.phase == "back_off":
|
| 250 |
+
action = self._look_action()
|
| 251 |
+
if self.phase_t >= 16:
|
| 252 |
+
self._attempt += 1
|
| 253 |
+
if self._attempt >= len(self._poses):
|
| 254 |
+
self.phase = "shove"
|
| 255 |
+
self.phase_t = 0
|
| 256 |
+
else:
|
| 257 |
+
self.phase = "reach"
|
| 258 |
+
self.phase_t = 0
|
| 259 |
+
return action.astype(np.float32)
|
| 260 |
+
|
| 261 |
+
# ---- last resort: a broad sweep can tip the mug over ---------------
|
| 262 |
+
if self.phase == "shove":
|
| 263 |
+
t = min(1.0, self.phase_t / 60.0)
|
| 264 |
+
if self.arm == "A":
|
| 265 |
+
sp, el, sy, wp, wr = 1.9, 0.9, -0.2, 1.5, 0.0
|
| 266 |
+
sp1, sy1, wr1 = 2.5, -1.5, 1.5
|
| 267 |
+
else:
|
| 268 |
+
sp, el, sy, wp, wr = 1.9, 0.9, 0.2, -1.5, 0.0
|
| 269 |
+
sp1, sy1, wr1 = 2.5, 1.5, -1.5
|
| 270 |
+
action = self._look_action()
|
| 271 |
+
self._set_arm(
|
| 272 |
+
action, self.arm,
|
| 273 |
+
sp + (sp1 - sp) * t,
|
| 274 |
+
el,
|
| 275 |
+
self._sr0,
|
| 276 |
+
sy + (sy1 - sy) * t,
|
| 277 |
+
wp=wp, wr=wr + (wr1 - wr) * t,
|
| 278 |
+
)
|
| 279 |
+
if self.phase_t >= 60:
|
| 280 |
+
self.phase = "shove_hold"
|
| 281 |
+
self.phase_t = 0
|
| 282 |
+
return action.astype(np.float32)
|
| 283 |
+
|
| 284 |
+
if self.phase == "shove_hold":
|
| 285 |
+
action = self._look_action()
|
| 286 |
+
if self.arm == "A":
|
| 287 |
+
self._set_arm(action, self.arm, 2.6, 1.5, self._sr0, -1.5,
|
| 288 |
+
wp=1.5, wr=1.5)
|
| 289 |
+
else:
|
| 290 |
+
self._set_arm(action, self.arm, 2.6, 1.5, self._sr0, 1.5,
|
| 291 |
+
wp=-1.5, wr=-1.5)
|
| 292 |
+
if self.phase_t >= 160:
|
| 293 |
+
self.phase = "done"
|
| 294 |
+
self.phase_t = 0
|
| 295 |
+
return action.astype(np.float32)
|
| 296 |
+
|
| 297 |
+
# ---- the mug is held: flip it and set it down ---------------------
|
| 298 |
+
if self.phase == "flip_ready":
|
| 299 |
+
action = self._look_action()
|
| 300 |
+
self._set_arm(
|
| 301 |
+
action, self.arm, 1.2, 0.8, self._sr0, self._sy0,
|
| 302 |
+
wp=0.0, grip=1.0,
|
| 303 |
+
)
|
| 304 |
+
if self.phase_t >= 22:
|
| 305 |
+
self.phase = "flip"
|
| 306 |
+
self.phase_t = 0
|
| 307 |
+
return action.astype(np.float32)
|
| 308 |
+
|
| 309 |
+
if self.phase == "flip":
|
| 310 |
+
action = self._look_action()
|
| 311 |
+
self._set_arm(
|
| 312 |
+
action, self.arm, 1.2, 0.8, self._sr0, self._sy0,
|
| 313 |
+
wp=1.5, grip=1.0,
|
| 314 |
+
)
|
| 315 |
+
if self.phase_t >= 30:
|
| 316 |
+
self.phase = "place"
|
| 317 |
+
self.phase_t = 0
|
| 318 |
+
return action.astype(np.float32)
|
| 319 |
+
|
| 320 |
+
if self.phase == "place":
|
| 321 |
+
action = self._look_action()
|
| 322 |
+
self._set_arm(
|
| 323 |
+
action, self.arm, 0.35, 0.2, self._sr0, self._sy0,
|
| 324 |
+
wp=1.5, grip=1.0,
|
| 325 |
+
)
|
| 326 |
+
if self.phase_t >= 28:
|
| 327 |
+
self.phase = "open"
|
| 328 |
+
self.phase_t = 0
|
| 329 |
+
return action.astype(np.float32)
|
| 330 |
+
|
| 331 |
+
if self.phase == "open":
|
| 332 |
+
action = self._look_action()
|
| 333 |
+
self._set_arm(
|
| 334 |
+
action, self.arm, 0.35, 0.2, self._sr0, self._sy0,
|
| 335 |
+
wp=1.5, grip=0.0,
|
| 336 |
+
)
|
| 337 |
+
if self.phase_t >= 18:
|
| 338 |
+
self.phase = "final"
|
| 339 |
+
self.phase_t = 0
|
| 340 |
+
return action.astype(np.float32)
|
| 341 |
+
|
| 342 |
+
# ---- stand still --------------------------------------------------
|
| 343 |
+
return self._look_action().astype(np.float32)
|
| 344 |
+
|
| 345 |
+
# -- pose library ------------------------------------------------------
|
| 346 |
+
def _grasp_poses(self):
|
| 347 |
+
"""Reach poses for the arm that ends up next to the mug.
|
| 348 |
+
|
| 349 |
+
Each pose is ``(shoulder_pitch, elbow, shoulder_roll, shoulder_yaw,
|
| 350 |
+
wrist_pitch)``. The arm reaches up over the counter edge where the
|
| 351 |
+
mug sits; the wrist pitch aims the palm at the mug.
|
| 352 |
+
"""
|
| 353 |
+
if self.arm == "A":
|
| 354 |
+
self._sr0, self._sy0 = 0.6, -0.2
|
| 355 |
+
sign = 1.0
|
| 356 |
+
else:
|
| 357 |
+
self._sr0, self._sy0 = -0.6, 0.2
|
| 358 |
+
sign = -1.0
|
| 359 |
+
return [
|
| 360 |
+
(1.4, 0.5, self._sr0, self._sy0, sign * 0.4),
|
| 361 |
+
(1.7, 0.6, self._sr0, self._sy0, sign * 0.6),
|
| 362 |
+
(2.0, 0.7, self._sr0, self._sy0, sign * 0.8),
|
| 363 |
+
(2.3, 0.8, self._sr0, self._sy0, sign * 1.0),
|
| 364 |
+
]
|
policies/flip_cup/gpt61sol-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,1,1814,success,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,1,1815,success,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,1,1721,success,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,1,1349,success,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,1,1694,success,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,1,1485,success,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,1,1727,success,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,1,1704,success,0
|
| 26 |
+
620024,1,1210,success,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,1,1491,success,0
|
| 37 |
+
620035,1,1712,success,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,1,1625,success,0
|
| 46 |
+
620044,1,1450,success,0
|
| 47 |
+
620045,1,1664,success,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,1,1668,success,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,1,1373,success,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,1,1719,success,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,1,1792,success,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,1,1546,success,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,1,1712,success,0
|
| 96 |
+
620094,1,1802,success,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,1,1350,success,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,1,1433,success,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt61sol-s1/policy.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hand-written visual alignment and a smooth cup-flipping sequence."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
|
| 5 |
+
class Policy:
|
| 6 |
+
"""Visual feedback for approach, followed by smooth deterministic motions."""
|
| 7 |
+
|
| 8 |
+
def reset(self, obs, tools):
|
| 9 |
+
self.a = np.asarray(tools.hold_action(), dtype=float)
|
| 10 |
+
self.a[19:21] = 0
|
| 11 |
+
self.initial = self.a.copy()
|
| 12 |
+
self.phase = 'raise'
|
| 13 |
+
self.tick = 0
|
| 14 |
+
self.align_tick = 0
|
| 15 |
+
self.goal = None
|
| 16 |
+
self.wait = 0
|
| 17 |
+
self.stage = 0
|
| 18 |
+
self.start = self.a.copy()
|
| 19 |
+
self.stages = [
|
| 20 |
+
([-0.5, 0.25, 0, 0, -0.8, 0, 0], 0, 80, 60),
|
| 21 |
+
([-0.8, 0.25, 0, 0.6, -0.8, 0, 0], 0, 100, 60),
|
| 22 |
+
([-0.8, 0.25, 0, 0.6, -0.8, 0, 0], 1, 80, 60),
|
| 23 |
+
([-1.05, 0.25, 0, 0.35, -0.8, 0, 0], 1, 100, 60),
|
| 24 |
+
([-1.05, 0.65, 0, 0.35, 1.95, 0, 0], 1, 180, 120),
|
| 25 |
+
([-0.8, 0.65, 0, 0.6, 1.95, 0, 0], 1, 100, 60),
|
| 26 |
+
([-0.8, 0.65, 0, 0.8, 1.95, 0, 0], 1, 100, 60),
|
| 27 |
+
([-0.8, 0.65, 0, 0.8, 1.95, 0, 0], 0, 100, 60),
|
| 28 |
+
([-1.05, 0.65, 0, 0.35, 1.95, 0, 0], 0, 100, 60),
|
| 29 |
+
([-0.5, 0.25, 0, 0, 0, 0, 0], 0, 200, 60),
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
def cup(self, im, head=False):
|
| 33 |
+
im = im.astype(np.int16)
|
| 34 |
+
v = im.max(2)
|
| 35 |
+
mi = im.min(2)
|
| 36 |
+
mask = ((v - mi < 30) & (v > 75) & (v < 225) & (mi > 60)).astype(np.uint8)
|
| 37 |
+
if head:
|
| 38 |
+
mask[20:] = 0
|
| 39 |
+
mask[:, :14] = 0
|
| 40 |
+
mask[:, 77:] = 0
|
| 41 |
+
else:
|
| 42 |
+
mask[78:] = 0
|
| 43 |
+
n, l, stats, cen = cv2.connectedComponentsWithStats(mask)
|
| 44 |
+
valid = [i for i in range(1, n) if stats[i, 4] > (8 if head else 100)]
|
| 45 |
+
if not valid:
|
| 46 |
+
return None
|
| 47 |
+
i = max(valid, key=lambda j: stats[j, 4])
|
| 48 |
+
return np.r_[stats[i, :4], cen[i]]
|
| 49 |
+
|
| 50 |
+
def act(self, obs, tools):
|
| 51 |
+
ld = obs['low_dim_obs']
|
| 52 |
+
self.tick += 1
|
| 53 |
+
if self.phase == 'raise':
|
| 54 |
+
end = self.initial.copy()
|
| 55 |
+
end[5:12] = [-0.5, 0.25, 0, 0, 0, 0, 0]
|
| 56 |
+
self.a = self.initial + (end - self.initial) * min(1, self.tick / 60)
|
| 57 |
+
if self.tick >= 100:
|
| 58 |
+
self.phase = 'align'
|
| 59 |
+
self.tick = 0
|
| 60 |
+
self.wait = 0
|
| 61 |
+
return self.a
|
| 62 |
+
if self.phase == 'align':
|
| 63 |
+
self.a[0:2] = 0
|
| 64 |
+
self.a[3] = 0
|
| 65 |
+
self.align_tick += 1
|
| 66 |
+
if self.goal is not None:
|
| 67 |
+
delta = self.goal - ld[21:23]
|
| 68 |
+
yaw = ld[24]
|
| 69 |
+
local = np.array([[np.cos(yaw), np.sin(yaw)], [-np.sin(yaw), np.cos(yaw)]]) @ delta
|
| 70 |
+
if np.linalg.norm(delta) < 0.004 or self.tick > 120:
|
| 71 |
+
self.goal = None
|
| 72 |
+
self.wait = 60
|
| 73 |
+
self.tick = 0
|
| 74 |
+
else:
|
| 75 |
+
self.a[0:2] = local / max(np.linalg.norm(local), 1e-06) * 0.09
|
| 76 |
+
elif self.wait > 0:
|
| 77 |
+
self.wait -= 1
|
| 78 |
+
else:
|
| 79 |
+
box = self.cup(tools.image('left_wrist'))
|
| 80 |
+
if box is not None and box[2] < 80:
|
| 81 |
+
x, y, w, h, cx, cy = box
|
| 82 |
+
dx = float(np.clip(0.004 * (59 - cy), -0.06, 0.06))
|
| 83 |
+
dy = float(np.clip((40.4 - cx) * 0.003, -0.09, 0.09))
|
| 84 |
+
if abs(dx) < 0.008 and abs(dy) < 0.008:
|
| 85 |
+
self.phase = 'motion'
|
| 86 |
+
self.tick = 0
|
| 87 |
+
self.start = self.a.copy()
|
| 88 |
+
return self.a
|
| 89 |
+
else:
|
| 90 |
+
head = self.cup(tools.image('head'), True)
|
| 91 |
+
dx = 0
|
| 92 |
+
dy = 0.06 if head is None else float(np.clip((31.0 - head[4]) * 0.007, -0.12, 0.12))
|
| 93 |
+
yaw = ld[24]
|
| 94 |
+
world = np.array([[np.cos(yaw), -np.sin(yaw)], [np.sin(yaw), np.cos(yaw)]]) @ np.array([dx, dy])
|
| 95 |
+
self.goal = ld[21:23].copy() + world
|
| 96 |
+
self.tick = 0
|
| 97 |
+
if self.align_tick > 600:
|
| 98 |
+
self.phase = 'motion'
|
| 99 |
+
self.tick = 0
|
| 100 |
+
self.a[0:2] = 0
|
| 101 |
+
self.start = self.a.copy()
|
| 102 |
+
return self.a
|
| 103 |
+
if self.phase == 'carry':
|
| 104 |
+
self.a[0:2] = 0
|
| 105 |
+
self.a[3] = float(np.clip(-ld[24], -0.15, 0.15))
|
| 106 |
+
delta = self.transport_goal - ld[21:23]
|
| 107 |
+
predicted = delta - ld[46:48] * 0.35
|
| 108 |
+
if self.tick < 145 and np.linalg.norm(predicted) > 0.014:
|
| 109 |
+
yaw = ld[24]
|
| 110 |
+
local = np.array([[np.cos(yaw), np.sin(yaw)], [-np.sin(yaw), np.cos(yaw)]]) @ predicted
|
| 111 |
+
self.a[0:2] = local / np.linalg.norm(local) * 0.075
|
| 112 |
+
if self.tick >= 205:
|
| 113 |
+
self.phase = 'motion'
|
| 114 |
+
self.tick = 0
|
| 115 |
+
self.a[0:2] = 0
|
| 116 |
+
self.a[3] = 0
|
| 117 |
+
self.start = self.a.copy()
|
| 118 |
+
return self.a
|
| 119 |
+
if self.stage >= len(self.stages):
|
| 120 |
+
return self.a
|
| 121 |
+
p, g, n, ramp = self.stages[self.stage]
|
| 122 |
+
end = self.start.copy()
|
| 123 |
+
end[0:2] = 0
|
| 124 |
+
end[3] = 0
|
| 125 |
+
end[5:12] = p
|
| 126 |
+
end[19] = g
|
| 127 |
+
end[2] = 0.7 if 5 <= self.stage <= 7 else 0.74
|
| 128 |
+
f = min(1, self.tick / ramp)
|
| 129 |
+
self.a = self.start + (end - self.start) * f
|
| 130 |
+
if self.tick >= n:
|
| 131 |
+
self.stage += 1
|
| 132 |
+
self.tick = 0
|
| 133 |
+
self.start = self.a.copy()
|
| 134 |
+
if self.stage == 4:
|
| 135 |
+
self.phase = 'carry'
|
| 136 |
+
self.transport_goal = np.array([0.24, float(ld[22])])
|
| 137 |
+
return self.a
|
policies/flip_cup/gpt61sol-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,1,1385,success,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,1,1231,success,0
|
| 6 |
+
620004,1,1494,success,0
|
| 7 |
+
620005,1,1255,success,0
|
| 8 |
+
620006,1,1386,success,0
|
| 9 |
+
620007,1,1193,success,0
|
| 10 |
+
620008,1,1269,success,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,1,1403,success,0
|
| 14 |
+
620012,1,1350,success,0
|
| 15 |
+
620013,1,1236,success,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,1,1267,success,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,1,1682,success,0
|
| 24 |
+
620022,1,1276,success,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,1,1248,success,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,1,1378,success,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,1,1224,success,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,1,1183,success,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,1,1447,success,0
|
| 38 |
+
620036,1,1203,success,0
|
| 39 |
+
620037,1,1436,success,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,1,1261,success,0
|
| 46 |
+
620044,1,1393,success,0
|
| 47 |
+
620045,1,1430,success,0
|
| 48 |
+
620046,1,1203,success,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,1,1250,success,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,1,1191,success,0
|
| 53 |
+
620051,1,1246,success,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,1,1360,success,0
|
| 56 |
+
620054,1,1294,success,0
|
| 57 |
+
620055,1,1244,success,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,1,1421,success,0
|
| 62 |
+
620060,1,1471,success,0
|
| 63 |
+
620061,1,1414,success,0
|
| 64 |
+
620062,1,1334,success,0
|
| 65 |
+
620063,1,1303,success,0
|
| 66 |
+
620064,1,1295,success,0
|
| 67 |
+
620065,1,1215,success,0
|
| 68 |
+
620066,1,1198,success,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,1,1388,success,0
|
| 73 |
+
620071,1,1253,success,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,1,1231,success,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,1,1389,success,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,1,1518,success,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,1,1387,success,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,1,1326,success,0
|
| 90 |
+
620088,1,1239,success,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,1,1537,success,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,1,1206,success,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,1,1259,success,0
|
| 98 |
+
620096,1,1370,success,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,1,1260,success,0
|
policies/flip_cup/gpt61sol-s2/policy.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic colour servo and phased cup manipulation."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
|
| 5 |
+
class Policy:
|
| 6 |
+
def reset(self,obs,tools):
|
| 7 |
+
self.a=np.asarray(tools.hold_action(),dtype=float)
|
| 8 |
+
self.a[19]=0
|
| 9 |
+
self.a[5:12]=[-.85,.28,0,0,0,.85,0]
|
| 10 |
+
self.phase='settle';self.start=0;self.retries=0
|
| 11 |
+
# Choose the arm from the cup's visible silhouette on the table.
|
| 12 |
+
im=tools.image('head').astype(np.int16)
|
| 13 |
+
m=((im.max(2)-im.min(2)<35)&(im.mean(2)>25)&(im.mean(2)<225)).astype(np.uint8)
|
| 14 |
+
m[10:]=0
|
| 15 |
+
n,l,st,cs=cv2.connectedComponentsWithStats(m)
|
| 16 |
+
ids=[i for i in range(1,n) if st[i,4]>=2 and st[i,2]<22]
|
| 17 |
+
self.right=bool(ids and cs[max(ids,key=lambda i:st[i,4]),0]>42)
|
| 18 |
+
def detect(self,im):
|
| 19 |
+
f=im.astype(np.int16)
|
| 20 |
+
mask=((f.max(2)-f.min(2)<30)&(f.mean(2)>65)&(f.mean(2)<245)).astype(np.uint8)
|
| 21 |
+
mask[70:]=0
|
| 22 |
+
n,l,st,cs=cv2.connectedComponentsWithStats(mask)
|
| 23 |
+
ids=[i for i in range(1,n) if st[i,4]>60 and cs[i,1]<60]
|
| 24 |
+
if not ids:return None
|
| 25 |
+
i=max(ids,key=lambda i:st[i,4]);return cs[i],st[i]
|
| 26 |
+
def enter(self,p,t):self.phase=p;self.start=t
|
| 27 |
+
def act(self,obs,tools):
|
| 28 |
+
t=obs['t'];q=obs['low_dim_obs'];a=self.a
|
| 29 |
+
age=t-self.start
|
| 30 |
+
if self.phase=='settle' and age>=80:self.enter('approach',t)
|
| 31 |
+
elif self.phase=='approach':
|
| 32 |
+
if age>150:a[4]=min(.4,a[4]+.002)
|
| 33 |
+
if t%10==0:
|
| 34 |
+
im=tools.image('right_wrist' if self.right else 'left_wrist')
|
| 35 |
+
if self.right:im=im[:,::-1]
|
| 36 |
+
z=self.detect(im)
|
| 37 |
+
if z:
|
| 38 |
+
c,b=z
|
| 39 |
+
a[6]+=np.clip((42-c[0])*.002,-.035,.035)
|
| 40 |
+
a[5]+=np.clip((c[1]-25)*.002,-.035,.035)
|
| 41 |
+
a[5]=np.clip(a[5],-1.2,-.35);a[6]=np.clip(a[6],-.12,.65)
|
| 42 |
+
a[10]=-a[5]
|
| 43 |
+
a[0]=.08 if b[4]<(1800+min(900,300*self.retries)) else 0
|
| 44 |
+
a[3]=np.clip(-q[24]*2,-.3,.3)
|
| 45 |
+
if b[4]>(1800+min(900,300*self.retries)) and abs(c[0]-42)<8 and abs(c[1]-25)<10:
|
| 46 |
+
a[0]=a[3]=0;a[19]=1;self.enter('grasp',t)
|
| 47 |
+
else:a[0]=0
|
| 48 |
+
elif self.phase=='grasp':
|
| 49 |
+
if age>=60:
|
| 50 |
+
if np.mean(q[19:21] if self.right else q[10:12])>-.018:
|
| 51 |
+
self.enter('lift',t)
|
| 52 |
+
else:
|
| 53 |
+
a[19]=0;self.retries+=1;a[4]=min(.4,a[4]+.08);self.enter('retry',t)
|
| 54 |
+
elif self.phase=='retry':
|
| 55 |
+
if age>=35:self.enter('approach',t)
|
| 56 |
+
elif self.phase=='lift':
|
| 57 |
+
a[4]=max(0,a[4]-.002)
|
| 58 |
+
a[2]=min(.78,a[2]+.001)
|
| 59 |
+
a[5]=max(-1.75,a[5]-.006)
|
| 60 |
+
a[10]=min(1.57,-a[5])
|
| 61 |
+
if age>=250:self.enter('prepare',t)
|
| 62 |
+
elif self.phase=='prepare':
|
| 63 |
+
# Redistribute wrist rotation before turning around the extended arm.
|
| 64 |
+
if age<130:
|
| 65 |
+
a[9]=max(-1.57,a[9]-.013)
|
| 66 |
+
a[11]=-a[9]
|
| 67 |
+
else:
|
| 68 |
+
a[7]=max(-.55,a[7]-.010)
|
| 69 |
+
a[10]=1.57+a[7]
|
| 70 |
+
if age>=220:self.enter('flip',t)
|
| 71 |
+
elif self.phase=='flip':
|
| 72 |
+
a[7]=min(2.59,a[7]+.010)
|
| 73 |
+
if age>=340:
|
| 74 |
+
self.wref=(q[16:19]*[-1,1,-1] if self.right else q[7:10]).copy()
|
| 75 |
+
self.enter('lower',t)
|
| 76 |
+
elif self.phase=='lower':
|
| 77 |
+
# Wrist tracking error marks contact; stop descending and release.
|
| 78 |
+
a[5]=min(-1.57,a[5]+.004)
|
| 79 |
+
if age>50:a[2]=max(.50,a[2]-.001)
|
| 80 |
+
wrists=q[16:19]*[-1,1,-1] if self.right else q[7:10]
|
| 81 |
+
contact=(np.linalg.norm(wrists-self.wref)>.07 or np.linalg.norm(wrists-a[9:12])>.10)
|
| 82 |
+
if (age>50 and contact) or age>=270:
|
| 83 |
+
a[19]=0;self.enter('release',t)
|
| 84 |
+
elif self.phase=='release':
|
| 85 |
+
if age>=110:self.enter('withdraw',t)
|
| 86 |
+
elif self.phase=='withdraw':
|
| 87 |
+
if age<140:
|
| 88 |
+
a[2]=max(.4,a[2]-.001)
|
| 89 |
+
elif age<240:
|
| 90 |
+
a[6]=min(.7,a[6]+.004)
|
| 91 |
+
else:
|
| 92 |
+
a[2]=min(.74,a[2]+.0015)
|
| 93 |
+
out=a.copy()
|
| 94 |
+
out[5]-=a[4]
|
| 95 |
+
if self.right:
|
| 96 |
+
# Reflect the same controller for the right arm.
|
| 97 |
+
out[12:19]=out[5:12]*np.array([1,-1,-1,1,-1,1,-1])
|
| 98 |
+
out[5:12]=0
|
| 99 |
+
out[20]=out[19];out[19]=.6
|
| 100 |
+
return out
|
policies/flip_cup/gpt61sol-s3/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1459,fell,1
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1459,fell,1
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1450,fell,1
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt61sol-s3/policy.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic visual cup manipulation controller."""
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
|
| 5 |
+
class Policy:
|
| 6 |
+
place_yaw=.4
|
| 7 |
+
place_roll=0.
|
| 8 |
+
place_pitch=-1.57
|
| 9 |
+
place_height=.74
|
| 10 |
+
def reset(self,obs,tools):
|
| 11 |
+
self.a=np.asarray(tools.hold_action(),dtype=float)
|
| 12 |
+
self.a[19:]=0
|
| 13 |
+
self.phase='raise';self.tick=0;self.start=self.a.copy()
|
| 14 |
+
self.base_target=float(obs['low_dim_obs'][21])+.14
|
| 15 |
+
self.target=self.a.copy();self.target[5:12]=[-.9,0,0,-.5,0,0,0];self.target[12:19]=self.target[5:12]
|
| 16 |
+
self.duration=80
|
| 17 |
+
def transition(self,name,target,duration):
|
| 18 |
+
self.phase=name;self.tick=0;self.start=self.a.copy();self.target=target.copy();self.duration=duration
|
| 19 |
+
@staticmethod
|
| 20 |
+
def cup(im):
|
| 21 |
+
a=im.astype(float)
|
| 22 |
+
m=((a.max(2)-a.min(2)<24)&(a.mean(2)>55)&(a.mean(2)<248)).astype(np.uint8)
|
| 23 |
+
m[:3]=0;m[:,:5]=0;m[:,-5:]=0
|
| 24 |
+
n,lab,st,c=cv2.connectedComponentsWithStats(m)
|
| 25 |
+
ids=[i for i in range(1,n) if st[i,4]>12 and st[i,2]>3 and st[i,3]>8 and st[i,2]<1.7*st[i,3]]
|
| 26 |
+
if not ids:return None
|
| 27 |
+
i=max(ids,key=lambda i:st[i,4]);return c[i],st[i]
|
| 28 |
+
def act(self,obs,tools):
|
| 29 |
+
q=obs['low_dim_obs'];self.tick+=1
|
| 30 |
+
if self.phase=='walk':
|
| 31 |
+
err=self.base_target-q[21]
|
| 32 |
+
self.a[0]=.12 if err>.012 else (-.07 if err<-.025 else 0)
|
| 33 |
+
if self.tick>=150:
|
| 34 |
+
self.a[0]=0;b=self.a.copy();b[5:12]=[-.3,0,.25,-1.,0,1.05,0];self.transition('prepare',b,80)
|
| 35 |
+
elif self.phase=='servo':
|
| 36 |
+
if self.tick%5==0:
|
| 37 |
+
f=self.cup(tools.image('left_wrist'))
|
| 38 |
+
if f:
|
| 39 |
+
xy,st=f
|
| 40 |
+
self.a[7]=np.clip(self.a[7]+(42-xy[0])*.002,-1,1)
|
| 41 |
+
self.a[10]=np.clip(self.a[10]+(xy[1]-42)*.002,0,1.6)
|
| 42 |
+
if abs(xy[0]-42)<7 and abs(xy[1]-42)<7:
|
| 43 |
+
self.a[5]=max(-1.3,self.a[5]-.007);self.a[8]=-1.3-self.a[5]
|
| 44 |
+
if st[4]>2100:
|
| 45 |
+
b=self.a.copy();b[19]=1;self.transition('grip',b,100)
|
| 46 |
+
if self.phase=='servo' and self.tick>470:
|
| 47 |
+
b=self.a.copy();b[19]=1;self.transition('grip',b,100)
|
| 48 |
+
elif self.phase=='hold':pass
|
| 49 |
+
else:
|
| 50 |
+
f=min(1,self.tick/(self.duration*.8));self.a=self.start+(self.target-self.start)*f
|
| 51 |
+
if self.phase=="reach":self.a[0]=.1 if q[21]<self.base_target+.12 else 0
|
| 52 |
+
else:self.a[0]=0
|
| 53 |
+
if self.tick>=self.duration:
|
| 54 |
+
b=self.a.copy()
|
| 55 |
+
if self.phase=='raise':self.transition('walk',b,150)
|
| 56 |
+
elif self.phase=='prepare':self.transition('servo',b,470)
|
| 57 |
+
elif self.phase=='grip':
|
| 58 |
+
b[5]-=.65;b[8]+=.65;self.transition('lift',b,160)
|
| 59 |
+
elif self.phase=='lift':
|
| 60 |
+
b[10]=-1.6;self.transition('flip',b,240)
|
| 61 |
+
elif self.phase=='flip':
|
| 62 |
+
b[4]=.6;b[5:12]=[-1.1,0,self.place_yaw,-1.,self.place_roll,self.place_pitch,0];self.transition('reach',b,180)
|
| 63 |
+
elif self.phase=='reach':
|
| 64 |
+
b[2]=self.place_height;self.transition('lower',b,180)
|
| 65 |
+
elif self.phase=='lower':
|
| 66 |
+
b[19]=0;self.transition('release',b,80)
|
| 67 |
+
elif self.phase=='release':
|
| 68 |
+
b[2]=.74;b[4]=0;b[5:12]=[-.9,0,0,-.5,0,0,0];self.transition('retreat',b,100)
|
| 69 |
+
elif self.phase=='retreat':self.transition('hold',b,1)
|
| 70 |
+
return self.a.copy()
|
policies/flip_cup/gpt61terra-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt61terra-s1/policy.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
class Policy:
|
| 5 |
+
def reset(self, obs, tools):
|
| 6 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 7 |
+
self.roll = .15
|
| 8 |
+
self.reach = .7
|
| 9 |
+
|
| 10 |
+
def act(self, obs, tools):
|
| 11 |
+
t = int(obs['t'])
|
| 12 |
+
a = self.hold.copy()
|
| 13 |
+
a[:2] = 0
|
| 14 |
+
a[2] = .9
|
| 15 |
+
a[3:5] = 0
|
| 16 |
+
a[19] = 0
|
| 17 |
+
if t == 220:
|
| 18 |
+
im = tools.image('left_wrist')
|
| 19 |
+
high = im.max(axis=2).astype(np.int16)
|
| 20 |
+
low = im.min(axis=2).astype(np.int16)
|
| 21 |
+
mask = ((high-low < 24) & (low > 85) & (high < 250)).astype(np.uint8)
|
| 22 |
+
mask[:8,:] = 0
|
| 23 |
+
mask[:,75:] = 0
|
| 24 |
+
n, labels, stats, centers = cv2.connectedComponentsWithStats(mask)
|
| 25 |
+
candidates = [i for i in range(1,n) if stats[i,4] > 200 and stats[i,1] < 42 and stats[i,3] > 10 and stats[i,1]+stats[i,3] < 82]
|
| 26 |
+
if candidates:
|
| 27 |
+
i = max(candidates, key=lambda j: stats[j,4])
|
| 28 |
+
cx, cy = centers[i]
|
| 29 |
+
# Small departures from the nominal view reflect placement.
|
| 30 |
+
if abs(cx-34.5) > 3:
|
| 31 |
+
self.roll = float(np.clip(.15-.003*(cx-34.5), -.25, .35))
|
| 32 |
+
if cy < 40:
|
| 33 |
+
self.reach = float(np.clip(.7-.003*(43.4-cy), .65, .7))
|
| 34 |
+
if t >= 100:
|
| 35 |
+
f = min(1., (t-100)/100.)
|
| 36 |
+
a[5:12] = [-.7*f, .15*f, 0, .7*f, 0, -.3*f, 0]
|
| 37 |
+
if t >= 220:
|
| 38 |
+
f = min(1., (t-220)/30.)
|
| 39 |
+
a[5] = -.7+( .7-self.reach)*f
|
| 40 |
+
a[6] = .15+(self.roll-.15)*f
|
| 41 |
+
a[8] = .7+(self.reach-.7)*f
|
| 42 |
+
if t >= 250:
|
| 43 |
+
a[19] = 1
|
| 44 |
+
if t >= 350:
|
| 45 |
+
f = min(1., (t-350)/150.)
|
| 46 |
+
a[5] = -self.reach+(-1.2+self.reach)*f
|
| 47 |
+
if t >= 520:
|
| 48 |
+
f = min(1., (t-520)/200.)
|
| 49 |
+
a[5] = -1.2-.6*f
|
| 50 |
+
a[8] = self.reach*(1-f)
|
| 51 |
+
a[10] = -.3-1.3*f
|
| 52 |
+
if t >= 750:
|
| 53 |
+
f = min(1., (t-750)/150.)
|
| 54 |
+
a[5] = -1.8+.3*f
|
| 55 |
+
a[2] = .9-.43*f
|
| 56 |
+
if t >= 930:
|
| 57 |
+
a[19] = 0
|
| 58 |
+
if t >= 1000:
|
| 59 |
+
f = min(1., (t-1000)/100.)
|
| 60 |
+
a[6] = self.roll+.5*f
|
| 61 |
+
return a
|
policies/flip_cup/gpt61terra-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt61terra-s2/policy.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
class Policy:
|
| 5 |
+
def reset(self, obs, tools):
|
| 6 |
+
self.base = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 7 |
+
self.roll = 0.25
|
| 8 |
+
self.last_seen = None
|
| 9 |
+
|
| 10 |
+
def cup(self, im):
|
| 11 |
+
# The porcelain is grey and nearly achromatic; the tabletop is cream
|
| 12 |
+
# and the background is blue. Ignore the dark edges of the gripper.
|
| 13 |
+
hsv = cv2.cvtColor(im, cv2.COLOR_RGB2HSV)
|
| 14 |
+
m = ((hsv[:,:,1] < 55) & (hsv[:,:,2] > 75) & (hsv[:,:,2] < 225)).astype(np.uint8)
|
| 15 |
+
m[:4,:] = 0; m[:, :3] = 0; m[:, 81:] = 0
|
| 16 |
+
n, labels, stats, centers = cv2.connectedComponentsWithStats(m, 8)
|
| 17 |
+
candidates = []
|
| 18 |
+
for i in range(1,n):
|
| 19 |
+
x,y,w,h,area = stats[i]
|
| 20 |
+
if area >= 25 and h >= 8 and w >= 5 and y < 75:
|
| 21 |
+
candidates.append((area, centers[i][0], centers[i][1]))
|
| 22 |
+
if not candidates: return None
|
| 23 |
+
return max(candidates)
|
| 24 |
+
|
| 25 |
+
def act(self, obs, tools):
|
| 26 |
+
t = obs['t']
|
| 27 |
+
a = self.base.copy()
|
| 28 |
+
a[0:5] = [0,0,.74,0,0]
|
| 29 |
+
a[19] = 0
|
| 30 |
+
a[5:12] = [-.45,self.roll,0,0,0,0,0]
|
| 31 |
+
if 90 <= t < 200 and t % 5 == 0:
|
| 32 |
+
c = self.cup(tools.image('left_wrist'))
|
| 33 |
+
if c is not None:
|
| 34 |
+
self.last_seen = c
|
| 35 |
+
self.roll = float(np.clip(self.roll + np.clip((42-c[1])*.0009, -.012, .012), -.25, .65))
|
| 36 |
+
if t >= 200:
|
| 37 |
+
# Move the hand towards the side of the cup with a gentle torso lean.
|
| 38 |
+
f = min(1., (t-200)/100.)
|
| 39 |
+
a[5] = -.45 - .10*f
|
| 40 |
+
a[8] = .13*f
|
| 41 |
+
a[4] = .15*f
|
| 42 |
+
a[10] = -.17*f
|
| 43 |
+
if t >= 310:
|
| 44 |
+
a[19] = 1
|
| 45 |
+
if t >= 390:
|
| 46 |
+
f = min(1., (t-390)/90.)
|
| 47 |
+
a[5] -= .25*f
|
| 48 |
+
a[8] += .25*f
|
| 49 |
+
a[4] *= 1-f
|
| 50 |
+
if t >= 500:
|
| 51 |
+
f = min(1., (t-500)/150.)
|
| 52 |
+
a[9] = 1.9*f
|
| 53 |
+
a[7] = .95*f
|
| 54 |
+
if t >= 690:
|
| 55 |
+
f = min(1., (t-690)/120.)
|
| 56 |
+
a[5] += .25*f
|
| 57 |
+
a[8] -= .25*f
|
| 58 |
+
a[4] = .15*f
|
| 59 |
+
if t >= 830:
|
| 60 |
+
a[19] = 0
|
| 61 |
+
if t >= 900:
|
| 62 |
+
a[5] = -.8
|
| 63 |
+
a[8] = .4
|
| 64 |
+
a[4] = 0
|
| 65 |
+
return a
|
policies/flip_cup/gpt61terra-s3/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,1,1181,success,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,1,1192,success,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,1,1199,success,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,1,1178,success,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,1,1206,success,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,1,1209,success,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,1,1185,success,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,1,1178,success,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,1,1197,success,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,1,1179,success,0
|
| 94 |
+
620092,1,1207,success,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt61terra-s3/policy.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import cv2
|
| 3 |
+
|
| 4 |
+
class Policy:
|
| 5 |
+
def reset(self, obs, tools):
|
| 6 |
+
self.a = np.asarray(tools.hold_action(), dtype=np.float32).copy()
|
| 7 |
+
self.a[19] = 0
|
| 8 |
+
self.pitch = -1.15
|
| 9 |
+
self.roll = .3
|
| 10 |
+
self.target_x = 42.0
|
| 11 |
+
|
| 12 |
+
def act(self, obs, tools):
|
| 13 |
+
t = int(obs['t']); a = self.a
|
| 14 |
+
a[0] = 0
|
| 15 |
+
if t < 55:
|
| 16 |
+
a[0] = -.3
|
| 17 |
+
elif t < 115:
|
| 18 |
+
a[5:12] = [-.5,.1,0,2,0,0,0]
|
| 19 |
+
elif t < 175:
|
| 20 |
+
a[5:12] = [-1.5,.1,0,2,0,0,0]
|
| 21 |
+
elif t < 255:
|
| 22 |
+
a[5:12] = [-1.3,.3,0,1,0,0,0]
|
| 23 |
+
elif t < 355:
|
| 24 |
+
a[0] = .15
|
| 25 |
+
elif t < 435:
|
| 26 |
+
a[5:12] = [-1.15,.3,0,1,0,0,0]
|
| 27 |
+
elif t < 610:
|
| 28 |
+
if (t-435)%5 == 0:
|
| 29 |
+
im = tools.image('left_wrist').astype(np.int16)
|
| 30 |
+
r,g,b = im[:,:,0], im[:,:,1], im[:,:,2]
|
| 31 |
+
mask = (abs(r-g)<12)&(abs(g-b)<12)&(r>75)&(r<220)
|
| 32 |
+
n,labels,stats,centers=cv2.connectedComponentsWithStats(mask.astype(np.uint8))
|
| 33 |
+
valid=[k for k in range(1,n) if stats[k,4]>60]
|
| 34 |
+
if valid:
|
| 35 |
+
k=max(valid,key=lambda k:stats[k,4]); x,y,w,h,area=stats[k]; cx=centers[k,0]
|
| 36 |
+
if t == 435 and x == 0 and y+h >= 65:
|
| 37 |
+
white=(abs(r-g)<14)&(abs(g-b)<14)&(r>195)
|
| 38 |
+
white[:4]=0
|
| 39 |
+
wn,wl,ws,wc=cv2.connectedComponentsWithStats(white.astype(np.uint8))
|
| 40 |
+
options=[q for q in range(1,wn) if ws[q,4]>30 and 7<=ws[q,2]<=25 and ws[q,3]>=9 and wc[q,1]>14 and wc[q,1]<y+h+4 and x-16<wc[q,0]<x+w+12]
|
| 41 |
+
if options:
|
| 42 |
+
q=max(options,key=lambda q:ws[q,4])
|
| 43 |
+
self.target_x=float(np.clip(42+cx-wc[q,0],28,62))
|
| 44 |
+
self.roll = float(np.clip(self.roll+(self.target_x-cx)*.0017,0,.7))
|
| 45 |
+
self.pitch = float(np.clip(self.pitch+(y+h-48)*.0009,-1.4,-.95))
|
| 46 |
+
self.drive = .09 if w<62 else 0
|
| 47 |
+
else: self.drive=0
|
| 48 |
+
a[0]=self.drive
|
| 49 |
+
a[5]=self.pitch; a[6]=self.roll
|
| 50 |
+
elif t < 690:
|
| 51 |
+
a[9]=-1.3
|
| 52 |
+
elif t < 770:
|
| 53 |
+
a[19]=1
|
| 54 |
+
elif t < 870:
|
| 55 |
+
a[5]=self.pitch-.3
|
| 56 |
+
elif t < 1020:
|
| 57 |
+
a[9]=1.9
|
| 58 |
+
elif t < 1120:
|
| 59 |
+
a[5]=self.pitch
|
| 60 |
+
else:
|
| 61 |
+
a[19]=0
|
| 62 |
+
return a.copy()
|
policies/flip_cup/gpt6sol-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt6sol-s1/policy.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hand-written cup turning controller for the G1 task."""
|
| 2 |
+
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def _cup_blob(image, head=False):
|
| 8 |
+
p = image.astype(np.int16)
|
| 9 |
+
hi = p.max(axis=2)
|
| 10 |
+
lo = p.min(axis=2)
|
| 11 |
+
grey = (hi - lo < 17) & (lo > 88) & (hi < 245)
|
| 12 |
+
grey[:, :4] = False
|
| 13 |
+
grey[:, 80:] = False
|
| 14 |
+
if head:
|
| 15 |
+
grey[31:] = False
|
| 16 |
+
else:
|
| 17 |
+
grey[:3] = False
|
| 18 |
+
grey[78:] = False
|
| 19 |
+
n, labels, stats, cents = cv2.connectedComponentsWithStats(grey.astype(np.uint8), 8)
|
| 20 |
+
best = None
|
| 21 |
+
best_score = -1
|
| 22 |
+
for i in range(1, n):
|
| 23 |
+
x, y, w, h, area = [int(v) for v in stats[i]]
|
| 24 |
+
if head:
|
| 25 |
+
if area < 10 or w < 4 or h < 3 or y > 20:
|
| 26 |
+
continue
|
| 27 |
+
score = area - 1.5*y
|
| 28 |
+
else:
|
| 29 |
+
if area < 35 or w < 6 or h < 6 or y > 65 or x > 68:
|
| 30 |
+
continue
|
| 31 |
+
score = area - 2*max(0, y-30)
|
| 32 |
+
if score > best_score:
|
| 33 |
+
best = (float(cents[i, 0]), float(cents[i, 1]), w, h)
|
| 34 |
+
best_score = score
|
| 35 |
+
return best
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class Policy:
|
| 39 |
+
def reset(self, obs, tools):
|
| 40 |
+
self.home = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 41 |
+
self.start = np.asarray(obs['low_dim_obs'][21:25], dtype=np.float32)
|
| 42 |
+
blob = _cup_blob(tools.image('head'), head=True)
|
| 43 |
+
self.side = 1 if blob is None or blob[0] < 43 else -1
|
| 44 |
+
self.roll = 0.0
|
| 45 |
+
self.wp = 0.35
|
| 46 |
+
self.last_image_step = -100
|
| 47 |
+
self.last_seen = None
|
| 48 |
+
|
| 49 |
+
def _nav(self, obs, action):
|
| 50 |
+
x, y, _, yaw = obs['low_dim_obs'][21:25]
|
| 51 |
+
target_x = self.start[0] + 0.43
|
| 52 |
+
target_y = self.start[1] + self.side*0.49
|
| 53 |
+
target_yaw = -self.side*1.57
|
| 54 |
+
dx, dy = target_x-x, target_y-y
|
| 55 |
+
f = np.cos(yaw)*dx + np.sin(yaw)*dy
|
| 56 |
+
l = -np.sin(yaw)*dx + np.cos(yaw)*dy
|
| 57 |
+
action[0] = np.clip(1.5*f, -.17, .17) if abs(f) > .035 else 0
|
| 58 |
+
action[1] = np.clip(1.5*l, -.17, .17) if abs(l) > .035 else 0
|
| 59 |
+
err = (target_yaw-yaw+np.pi) % (2*np.pi)-np.pi
|
| 60 |
+
action[3] = np.clip(1.5*err, -.5, .5) if abs(err) > .06 else 0
|
| 61 |
+
|
| 62 |
+
def _servo(self, obs, tools):
|
| 63 |
+
if obs['t'] - self.last_image_step < 10:
|
| 64 |
+
return
|
| 65 |
+
self.last_image_step = obs['t']
|
| 66 |
+
camera = 'left_wrist' if self.side == 1 else 'right_wrist'
|
| 67 |
+
blob = _cup_blob(tools.image(camera))
|
| 68 |
+
if blob is None:
|
| 69 |
+
return
|
| 70 |
+
self.last_seen = blob
|
| 71 |
+
cx, cy, _, _ = blob
|
| 72 |
+
self.roll = float(np.clip(self.roll + self.side*.005*(42-cx), -.4, .45))
|
| 73 |
+
self.wp = float(np.clip(self.wp + .004*(cy-24), -.3, 1.45))
|
| 74 |
+
|
| 75 |
+
def act(self, obs, tools):
|
| 76 |
+
t = int(obs['t'])
|
| 77 |
+
a = self.home.copy()
|
| 78 |
+
a[0:2] = 0
|
| 79 |
+
a[3] = 0
|
| 80 |
+
a[19:21] = .6
|
| 81 |
+
if t < 220:
|
| 82 |
+
a[1] = self.side*.20
|
| 83 |
+
return a
|
| 84 |
+
if t < 340:
|
| 85 |
+
a[0] = .20
|
| 86 |
+
return a
|
| 87 |
+
if t < 580:
|
| 88 |
+
a[3] = -self.side*.5
|
| 89 |
+
return a
|
| 90 |
+
if t < 740:
|
| 91 |
+
self._nav(obs, a)
|
| 92 |
+
return a
|
| 93 |
+
|
| 94 |
+
a[2] = .85
|
| 95 |
+
a[4] = -.1
|
| 96 |
+
start = 5 if self.side == 1 else 12
|
| 97 |
+
grip = 19 if self.side == 1 else 20
|
| 98 |
+
a[grip] = 0
|
| 99 |
+
if t < 850:
|
| 100 |
+
self._servo(obs, tools)
|
| 101 |
+
a[start:start+7] = [-.2, self.roll, 0, -.3, 0, self.wp, 0]
|
| 102 |
+
if self.side == -1:
|
| 103 |
+
a[start+1] *= -1
|
| 104 |
+
return a
|
| 105 |
+
if t < 1000:
|
| 106 |
+
self._servo(obs, tools)
|
| 107 |
+
u = (t-850)/150
|
| 108 |
+
a[start:start+7] = [-.2-.34*u, self.roll, 0, -.3, 0, self.wp, 0]
|
| 109 |
+
if self.side == -1:
|
| 110 |
+
a[start+1] *= -1
|
| 111 |
+
return a
|
| 112 |
+
a[grip] = 1
|
| 113 |
+
grasp_wp = min(self.wp, 1.05)
|
| 114 |
+
if t < 1090:
|
| 115 |
+
a[start:start+7] = [-.54, self.roll, 0, -.3, 0, grasp_wp, 0]
|
| 116 |
+
elif t < 1200:
|
| 117 |
+
a[start:start+7] = [-.72, self.roll, 0, -.65, 0, grasp_wp, 0]
|
| 118 |
+
elif t < 1300:
|
| 119 |
+
u = (t-1200)/100
|
| 120 |
+
a[start:start+7] = [-.72, self.roll, 0, -.65, 1.6*u, grasp_wp-.7*u, 0]
|
| 121 |
+
elif t < 1410:
|
| 122 |
+
a[2] = .7
|
| 123 |
+
a[start:start+7] = [-.35, self.roll, 0, -.35, 1.6, grasp_wp-.7, 0]
|
| 124 |
+
else:
|
| 125 |
+
a[2] = .74
|
| 126 |
+
a[grip] = 0
|
| 127 |
+
a[start:start+7] = [-.25, 0, 0, -.3, 0, .2, 0]
|
| 128 |
+
if self.side == -1:
|
| 129 |
+
a[start+1] *= -1
|
| 130 |
+
a[start+4] *= -1
|
| 131 |
+
return a
|
policies/flip_cup/gpt6sol-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,1,605,success,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt6sol-s2/policy.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hand-written visual servo and arm sequence for the inverted cup."""
|
| 2 |
+
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Policy:
|
| 8 |
+
def reset(self, obs, tools):
|
| 9 |
+
self.home = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 10 |
+
self.home[0] = self.home[1] = self.home[3] = 0.0
|
| 11 |
+
self.home[2] = 0.74
|
| 12 |
+
self.home[4] = 0.0
|
| 13 |
+
self.home[19:21] = 0.0
|
| 14 |
+
self.state = "align"
|
| 15 |
+
self.state_t = 0
|
| 16 |
+
self.cup_x = None
|
| 17 |
+
self.good_align = 0
|
| 18 |
+
self.search_direction = 1.0
|
| 19 |
+
self.last_image_step = -100
|
| 20 |
+
self.origin_x = float(obs["low_dim_obs"][21])
|
| 21 |
+
self.stage_index = 0
|
| 22 |
+
self.stages = [
|
| 23 |
+
("settle", 45, 0.0, -0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.74),
|
| 24 |
+
("approach", 85, 0.0, -1.0, 0.35, 0.0, 0.0, 0.7, 0.0, 0.0, 0.74),
|
| 25 |
+
("lean", 65, 0.4, -1.0, 0.35, 0.0, 0.0, 0.7, 0.0, 0.0, 0.74),
|
| 26 |
+
("tip", 45, 0.4, -1.2, 0.35, 0.0, 0.0, 0.7, 0.0, 0.0, 0.74),
|
| 27 |
+
("handle", 55, 0.4, -1.3, 0.53, 0.3, 0.0, 0.7, 0.0, 0.0, 0.74),
|
| 28 |
+
("close", 70, 0.4, -1.3, 0.53, 0.3, 0.0, 0.7, 1.0, 0.0, 0.74),
|
| 29 |
+
("first_turn", 80, 0.4, -1.3, 0.53, 0.3, 0.0, -1.5, 1.0, 0.0, 0.74),
|
| 30 |
+
("first_release", 60, 0.4, -1.3, 0.53, 0.3, 0.0, -1.5, 0.0, 0.0, 0.74),
|
| 31 |
+
("side_approach", 90, 0.0, -0.95, 0.55, 0.0, 0.0, 0.7, 0.0, 0.0, 0.74),
|
| 32 |
+
("side_grasp", 80, 0.0, -0.95, 0.55, 0.0, 0.0, 0.7, 1.0, 0.0, 0.74),
|
| 33 |
+
("side_lift", 70, 0.0, -1.4, 0.55, 0.0, 0.0, 0.7, 1.0, 0.0, 0.74),
|
| 34 |
+
("move_over_table", 70, 0.8, -1.4, -1.0, 0.0, 0.0, 0.7, 1.0, 0.18, 0.74),
|
| 35 |
+
("second_turn", 80, 0.8, -1.4, -1.0, 0.0, 0.0, -1.5, 1.0, 0.0, 0.74),
|
| 36 |
+
("lower", 80, 0.8, -1.1, -1.0, 0.0, 0.0, -1.5, 1.0, 0.0, 0.74),
|
| 37 |
+
("second_release", 35, 0.8, -1.1, -1.0, 0.0, 0.0, -1.5, 0.0, 0.0, 0.74),
|
| 38 |
+
("withdraw", 120, 0.0, -0.65, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.74),
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
@staticmethod
|
| 42 |
+
def _cup_in_head(image):
|
| 43 |
+
hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
|
| 44 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 45 |
+
mask = ((hsv[:, :, 1] < 55) & (gray > 45) & (gray < 210)).astype(np.uint8)
|
| 46 |
+
mask[25:, :] = 0
|
| 47 |
+
mask[:, :3] = 0
|
| 48 |
+
n, _, stats, centers = cv2.connectedComponentsWithStats(mask, 8)
|
| 49 |
+
best_area = 34
|
| 50 |
+
best_x = None
|
| 51 |
+
for i in range(1, n):
|
| 52 |
+
area = int(stats[i, cv2.CC_STAT_AREA])
|
| 53 |
+
if area > best_area:
|
| 54 |
+
best_area = area
|
| 55 |
+
best_x = float(centers[i, 0])
|
| 56 |
+
return best_x
|
| 57 |
+
|
| 58 |
+
def _advance(self):
|
| 59 |
+
self.stage_index += 1
|
| 60 |
+
self.state_t = 0
|
| 61 |
+
|
| 62 |
+
def act(self, obs, tools):
|
| 63 |
+
raw = self.home.copy()
|
| 64 |
+
body = obs["low_dim_obs"]
|
| 65 |
+
yaw = float(body[24])
|
| 66 |
+
if self.state == "align":
|
| 67 |
+
raw[4] = -0.2
|
| 68 |
+
raw[3] = float(np.clip(-1.8 * yaw, -0.3, 0.3))
|
| 69 |
+
if obs["t"] - self.last_image_step >= 5:
|
| 70 |
+
self.cup_x = self._cup_in_head(tools.image("head"))
|
| 71 |
+
self.last_image_step = obs["t"]
|
| 72 |
+
if self.state_t >= 35:
|
| 73 |
+
if self.cup_x is not None:
|
| 74 |
+
error = self.cup_x - 22.0
|
| 75 |
+
if abs(error) > 2.5:
|
| 76 |
+
raw[1] = -float(np.clip(abs(error) * 0.009, 0.08, 0.25)) * np.sign(error)
|
| 77 |
+
self.good_align = 0
|
| 78 |
+
elif abs(yaw) < 0.08:
|
| 79 |
+
self.good_align += 1
|
| 80 |
+
if self.good_align > 18:
|
| 81 |
+
self.state = "sequence"
|
| 82 |
+
self.state_t = 0
|
| 83 |
+
else:
|
| 84 |
+
# Traverse the table if the cup is outside the head view.
|
| 85 |
+
y = float(body[22])
|
| 86 |
+
if y > 0.30:
|
| 87 |
+
self.search_direction = -1.0
|
| 88 |
+
if y < -0.45:
|
| 89 |
+
self.search_direction = 1.0
|
| 90 |
+
raw[1] = 0.16 * self.search_direction
|
| 91 |
+
if self.state_t > 340:
|
| 92 |
+
self.state = "sequence"
|
| 93 |
+
self.state_t = 0
|
| 94 |
+
else:
|
| 95 |
+
self.state_t += 1
|
| 96 |
+
return raw
|
| 97 |
+
if self.stage_index >= len(self.stages):
|
| 98 |
+
raw[5] = -0.65
|
| 99 |
+
return raw
|
| 100 |
+
_, duration, pitch, sp, sy, elbow, wr, wp, grip, vx, height = self.stages[self.stage_index]
|
| 101 |
+
raw[0] = vx
|
| 102 |
+
raw[2] = height
|
| 103 |
+
raw[4] = pitch
|
| 104 |
+
raw[5:12] = (sp, 0.0, sy, elbow, wr, wp, 0.0)
|
| 105 |
+
raw[19] = grip
|
| 106 |
+
self.state_t += 1
|
| 107 |
+
if self.state_t >= duration:
|
| 108 |
+
self._advance()
|
| 109 |
+
return raw
|
policies/flip_cup/gpt6sol-s3/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,1,1088,success,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/gpt6sol-s3/policy.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic cup-turning controller for the G1."""
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Policy:
|
| 7 |
+
def reset(self, obs, tools):
|
| 8 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 9 |
+
|
| 10 |
+
def act(self, obs, tools):
|
| 11 |
+
t = int(obs['t'])
|
| 12 |
+
a = self.hold.copy()
|
| 13 |
+
a[10] = 0.9
|
| 14 |
+
if t < 500:
|
| 15 |
+
# Reach the cup from the left, tip it, then roll it onto its base.
|
| 16 |
+
a[0] = 0.3 if 50 <= t < 85 else 0.0
|
| 17 |
+
a[2] = 0.63 if 85 <= t < 345 else 0.74
|
| 18 |
+
a[5] = -1.2 if t >= 345 else -0.8
|
| 19 |
+
a[6] = -0.2 if t >= 235 else (0.6 if t >= 85 else 0.4)
|
| 20 |
+
a[19] = 1.0 if 165 <= t < 345 else 0.0
|
| 21 |
+
elif t < 950:
|
| 22 |
+
# Sweep again if the first turn did not settle upright.
|
| 23 |
+
u = t - 500
|
| 24 |
+
a[2] = 0.63 if 50 <= u < 310 else 0.74
|
| 25 |
+
a[5] = -1.2 if u >= 310 else -0.8
|
| 26 |
+
a[6] = -0.2 if u >= 200 else (0.7 if u >= 50 else 0.2)
|
| 27 |
+
a[19] = 1.0 if 130 <= u < 310 else 0.0
|
| 28 |
+
else:
|
| 29 |
+
u = t - 950
|
| 30 |
+
a[2] = 0.58 if 50 <= u < 310 else 0.74
|
| 31 |
+
a[5] = -1.2 if u >= 310 else -0.8
|
| 32 |
+
a[6] = -0.2 if u >= 200 else (0.8 if u >= 50 else 0.5)
|
| 33 |
+
a[19] = 1.0 if 130 <= u < 310 else 0.0
|
| 34 |
+
return a
|
policies/flip_cup/kimi31pro-s1/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,1,1038,success,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,1,1027,success,0
|
| 7 |
+
620005,1,1026,success,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,1,1027,success,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,1,1363,success,0
|
| 15 |
+
620013,1,1607,success,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,1,1033,success,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,1,1027,success,0
|
| 27 |
+
620025,1,1028,success,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,1,1045,success,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,1,1240,success,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,1,1028,success,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,1,1026,success,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,1,1026,success,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,1,1026,success,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,1,1026,success,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/kimi31pro-s1/policy.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic visual-servo policy for turning the cup upright."""
|
| 2 |
+
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Policy:
|
| 8 |
+
"""Hand-written joint-space control with a wrist-camera grasp servo."""
|
| 9 |
+
|
| 10 |
+
def reset(self, obs, tools):
|
| 11 |
+
self.raw = np.asarray(tools.hold_action(), dtype=np.float32).copy()
|
| 12 |
+
self.raw[2] = 0.74
|
| 13 |
+
self.raw[20] = 0.6
|
| 14 |
+
head_x = self._head_cup_x(tools.image("head"))
|
| 15 |
+
if head_x is None:
|
| 16 |
+
head_x = 13.5
|
| 17 |
+
self.right_cup = head_x > 25.0
|
| 18 |
+
self.use_right = False
|
| 19 |
+
self.base_y = float(np.clip(0.01 * (21.5 - head_x), -0.25, 0.18))
|
| 20 |
+
if self.use_right:
|
| 21 |
+
self.base_y = -self.base_y
|
| 22 |
+
self.place_y = 0.35 if self.use_right else -0.35
|
| 23 |
+
self.mirror = np.array([1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0])
|
| 24 |
+
self.raw[19] = 0.6
|
| 25 |
+
self.left = np.zeros(7, dtype=np.float64)
|
| 26 |
+
self.right = np.zeros(7, dtype=np.float64)
|
| 27 |
+
self.torso = 0.0
|
| 28 |
+
self.attempt = 0
|
| 29 |
+
self._set_stage("pre", obs)
|
| 30 |
+
|
| 31 |
+
def _set_stage(self, name, obs):
|
| 32 |
+
self.stage = name
|
| 33 |
+
self.j = 0
|
| 34 |
+
self.start_left = self.left.copy()
|
| 35 |
+
self.start_right = self.right.copy()
|
| 36 |
+
self.start_torso = self.torso
|
| 37 |
+
self.target_right = None
|
| 38 |
+
sy = float(self.left[2])
|
| 39 |
+
self.target_left = self.left.copy()
|
| 40 |
+
self.target_torso = self.torso
|
| 41 |
+
self.grip = 0.0
|
| 42 |
+
self.mode = "hold"
|
| 43 |
+
|
| 44 |
+
if name == "pre":
|
| 45 |
+
self.duration = 130
|
| 46 |
+
self.target_left = np.array([-0.3, 0, 0, 0, 0, -0.25, 0])
|
| 47 |
+
self.target_right = np.zeros(7)
|
| 48 |
+
self.target_torso = 0.0
|
| 49 |
+
self.mode = "pre"
|
| 50 |
+
elif name == "grasppose":
|
| 51 |
+
self.duration = 75
|
| 52 |
+
self.target_left = np.array([-0.45, 0, sy, 0, 0, 0, 0])
|
| 53 |
+
self.target_torso = 0.2
|
| 54 |
+
self.mode = "forward"
|
| 55 |
+
self.filtered = None
|
| 56 |
+
elif name == "servo":
|
| 57 |
+
self.duration = 125
|
| 58 |
+
self.sy = sy
|
| 59 |
+
self.sp = float(self.left[0])
|
| 60 |
+
self.target_torso = 0.2
|
| 61 |
+
self.torso = 0.2
|
| 62 |
+
self.mode = "forward"
|
| 63 |
+
elif name == "close":
|
| 64 |
+
self.duration = 45
|
| 65 |
+
self.place_x = float(np.clip(0.45 + 0.7 * (self.left[0] + 0.45), 0.25, 0.55))
|
| 66 |
+
self.grip = 1.0
|
| 67 |
+
elif name == "lift":
|
| 68 |
+
self.duration = 85
|
| 69 |
+
self.target_left = np.array([-0.55, 0, sy, 0, 0, 0.3, 0])
|
| 70 |
+
self.target_torso = 0.0
|
| 71 |
+
self.grip = 1.0
|
| 72 |
+
elif name == "return":
|
| 73 |
+
self.duration = 75
|
| 74 |
+
self.target_left = np.array([-0.45, 0, sy, 0, 0, 0, 0])
|
| 75 |
+
self.target_torso = 0.2
|
| 76 |
+
self.grip = 1.0
|
| 77 |
+
self.mode = "forward"
|
| 78 |
+
elif name == "turn":
|
| 79 |
+
self.duration = 125
|
| 80 |
+
self.target_left = np.array([-0.45, 1.0, sy, 0, 1.97, 0, 0])
|
| 81 |
+
self.target_torso = 0.2
|
| 82 |
+
self.grip = 1.0
|
| 83 |
+
self.mode = "forward"
|
| 84 |
+
elif name == "open":
|
| 85 |
+
self.duration = 25
|
| 86 |
+
self.target_torso = 0.2
|
| 87 |
+
self.grip = 1.0
|
| 88 |
+
elif name == "rightplace":
|
| 89 |
+
self.duration = 110
|
| 90 |
+
self.target_torso = 0.2
|
| 91 |
+
self.grip = 1.0
|
| 92 |
+
self.mode = "rightplace"
|
| 93 |
+
elif name == "forwardplace":
|
| 94 |
+
self.duration = 100
|
| 95 |
+
self.target_torso = 0.2
|
| 96 |
+
self.grip = 1.0
|
| 97 |
+
self.mode = "forwardplace"
|
| 98 |
+
elif name == "lower":
|
| 99 |
+
self.duration = 80
|
| 100 |
+
self.target_left = self.left.copy()
|
| 101 |
+
self.target_left[5] = -0.4
|
| 102 |
+
self.target_torso = 0.6
|
| 103 |
+
self.grip = 1.0
|
| 104 |
+
self.mode = "lower"
|
| 105 |
+
self.raw[2] = 0.55
|
| 106 |
+
elif name == "settle":
|
| 107 |
+
self.duration = 10**9
|
| 108 |
+
self.target_torso = 0.6
|
| 109 |
+
self.grip = 0.0
|
| 110 |
+
self.mode = "settle"
|
| 111 |
+
else:
|
| 112 |
+
raise ValueError(name)
|
| 113 |
+
|
| 114 |
+
def _next_stage(self, obs):
|
| 115 |
+
transitions = {
|
| 116 |
+
"pre": "grasppose",
|
| 117 |
+
"grasppose": "servo",
|
| 118 |
+
"servo": "close",
|
| 119 |
+
"close": "lift",
|
| 120 |
+
"return": "turn",
|
| 121 |
+
"turn": "open",
|
| 122 |
+
"open": "rightplace",
|
| 123 |
+
"rightplace": "forwardplace",
|
| 124 |
+
"forwardplace": "lower",
|
| 125 |
+
"lower": "settle",
|
| 126 |
+
}
|
| 127 |
+
if self.stage == "lift":
|
| 128 |
+
finger_slice = slice(19, 21) if self.use_right else slice(10, 12)
|
| 129 |
+
fingers = obs["low_dim_obs"][finger_slice]
|
| 130 |
+
grasped = bool(np.mean(fingers) > -0.017)
|
| 131 |
+
if not grasped and self.attempt < 2:
|
| 132 |
+
self.attempt += 1
|
| 133 |
+
self._set_stage("grasppose", obs)
|
| 134 |
+
else:
|
| 135 |
+
self._set_stage("return", obs)
|
| 136 |
+
return
|
| 137 |
+
self._set_stage(transitions[self.stage], obs)
|
| 138 |
+
|
| 139 |
+
def _base(self, obs):
|
| 140 |
+
raw = self.raw
|
| 141 |
+
mode = self.mode
|
| 142 |
+
if mode in ("lower", "settle"):
|
| 143 |
+
raw[0] = raw[1] = raw[3] = 0.0
|
| 144 |
+
return
|
| 145 |
+
p = obs["low_dim_obs"][21:25]
|
| 146 |
+
yaw = float(p[3])
|
| 147 |
+
if mode == "rightplace":
|
| 148 |
+
target, gain, cap = np.array([0.23, self.place_y]), 3.0, 0.25
|
| 149 |
+
elif mode == "forwardplace":
|
| 150 |
+
target, gain, cap = np.array([0.45, self.place_y]), 3.0, 0.25
|
| 151 |
+
else:
|
| 152 |
+
target = np.array([0.21, self.base_y]) if mode == "pre" else np.array([0.25, self.base_y])
|
| 153 |
+
gain, cap = 2.0, 0.12
|
| 154 |
+
dx, dy = target - p[:2]
|
| 155 |
+
c, s = np.cos(yaw), np.sin(yaw)
|
| 156 |
+
if mode == "forward":
|
| 157 |
+
raw[0] = 0.12
|
| 158 |
+
else:
|
| 159 |
+
raw[0] = float(np.clip(gain * (c * dx + s * dy), -cap, cap))
|
| 160 |
+
raw[1] = float(np.clip(gain * (-s * dx + c * dy), -cap, cap))
|
| 161 |
+
raw[3] = float(np.clip(-3.0 * yaw, -0.35, 0.35))
|
| 162 |
+
for b in (0, 1):
|
| 163 |
+
if abs(raw[b]) < 0.025:
|
| 164 |
+
raw[b] = 0.0
|
| 165 |
+
elif abs(raw[b]) < 0.06:
|
| 166 |
+
raw[b] = np.sign(raw[b]) * 0.06
|
| 167 |
+
|
| 168 |
+
@staticmethod
|
| 169 |
+
def _head_cup_x(image):
|
| 170 |
+
hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
|
| 171 |
+
_, saturation, value = cv2.split(hsv)
|
| 172 |
+
mask = ((saturation < 65) & (value > 65) & (value < 245)).astype(np.uint8)
|
| 173 |
+
mask[20:] = 0
|
| 174 |
+
count, _, stats, cents = cv2.connectedComponentsWithStats(mask)
|
| 175 |
+
best = None
|
| 176 |
+
for index in range(1, count):
|
| 177 |
+
x, y, w, h, area = stats[index]
|
| 178 |
+
if area > 15 and w > 3 and h > 3:
|
| 179 |
+
if best is None or area > best[0]:
|
| 180 |
+
best = (area, float(cents[index, 0]))
|
| 181 |
+
return None if best is None else best[1]
|
| 182 |
+
|
| 183 |
+
@staticmethod
|
| 184 |
+
def _cup_features(image):
|
| 185 |
+
hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
|
| 186 |
+
_, saturation, value = cv2.split(hsv)
|
| 187 |
+
mask = ((saturation < 60) & (value > 70) & (value < 248)).astype(np.uint8)
|
| 188 |
+
mask[78:] = 0
|
| 189 |
+
count, _, stats, cents = cv2.connectedComponentsWithStats(mask)
|
| 190 |
+
best = None
|
| 191 |
+
for index in range(1, count):
|
| 192 |
+
x, y, w, h, area = stats[index]
|
| 193 |
+
if area > 20 and h > 5 and w > 2 and y < 70:
|
| 194 |
+
candidate = (area, float(cents[index, 0]), float(cents[index, 1]), int(w))
|
| 195 |
+
if best is None or candidate[0] > best[0]:
|
| 196 |
+
best = candidate
|
| 197 |
+
return None if best is None else best[1:]
|
| 198 |
+
|
| 199 |
+
def act(self, obs, tools):
|
| 200 |
+
if self.j >= self.duration:
|
| 201 |
+
self._next_stage(obs)
|
| 202 |
+
|
| 203 |
+
name = self.stage
|
| 204 |
+
if name == "servo":
|
| 205 |
+
camera = "right_wrist" if self.use_right else "left_wrist"
|
| 206 |
+
image = tools.image(camera)
|
| 207 |
+
features = self._cup_features(image)
|
| 208 |
+
if features is not None:
|
| 209 |
+
cx, cy, width = features
|
| 210 |
+
if self.filtered is None:
|
| 211 |
+
self.filtered, self.filtered_y, self.filtered_width = cx, cy, float(width)
|
| 212 |
+
else:
|
| 213 |
+
self.filtered = 0.7 * self.filtered + 0.3 * cx
|
| 214 |
+
self.filtered_y = 0.7 * self.filtered_y + 0.3 * cy
|
| 215 |
+
self.filtered_width = 0.7 * self.filtered_width + 0.3 * width
|
| 216 |
+
correction = np.clip(0.0005 * (42.0 - self.filtered), -0.005, 0.005)
|
| 217 |
+
self.sy = float(np.clip(self.sy + correction, -0.8, 0.4))
|
| 218 |
+
if self.filtered_width < 70.0:
|
| 219 |
+
self.torso += min(0.0015, 0.00015 * (70.0 - self.filtered_width))
|
| 220 |
+
elif self.filtered_width > 79.0:
|
| 221 |
+
self.torso -= min(0.0015, 0.00015 * (self.filtered_width - 79.0))
|
| 222 |
+
if self.filtered_y < 52.0:
|
| 223 |
+
self.sp -= min(0.002, 0.0008 * (52.0 - self.filtered_y))
|
| 224 |
+
elif self.filtered_y > 58.0:
|
| 225 |
+
self.sp += min(0.002, 0.0008 * (self.filtered_y - 58.0))
|
| 226 |
+
self.torso = float(np.clip(self.torso, 0.1, 0.45))
|
| 227 |
+
self.sp = float(np.clip(self.sp, -0.75, -0.25))
|
| 228 |
+
self.left[0] = self.sp
|
| 229 |
+
self.left[2] = self.sy
|
| 230 |
+
self.left[5] = 0.2 - self.torso - self.sp
|
| 231 |
+
else:
|
| 232 |
+
alpha = min(1.0, (self.j + 1) / min(55.0, float(self.duration)))
|
| 233 |
+
self.torso = self.start_torso * (1.0 - alpha) + self.target_torso * alpha
|
| 234 |
+
self.left = self.start_left * (1.0 - alpha) + self.target_left * alpha
|
| 235 |
+
if self.target_right is not None:
|
| 236 |
+
self.right = self.start_right * (1.0 - alpha) + self.target_right * alpha
|
| 237 |
+
|
| 238 |
+
self.raw[4] = self.torso
|
| 239 |
+
if self.use_right:
|
| 240 |
+
self.raw[5:12] = 0.0
|
| 241 |
+
self.raw[12:19] = self.left * self.mirror
|
| 242 |
+
self.raw[19] = 0.6
|
| 243 |
+
self.raw[20] = self.grip
|
| 244 |
+
else:
|
| 245 |
+
self.raw[5:12] = self.left
|
| 246 |
+
self.raw[12:19] = self.right
|
| 247 |
+
self.raw[19] = self.grip
|
| 248 |
+
self.raw[20] = 0.6
|
| 249 |
+
self._base(obs)
|
| 250 |
+
self.j += 1
|
| 251 |
+
return self.raw.copy()
|
policies/flip_cup/kimi31pro-s2/episodes.csv
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
seed,success,length,termination,fell
|
| 2 |
+
620000,0,1850,timeout,0
|
| 3 |
+
620001,0,1850,timeout,0
|
| 4 |
+
620002,0,1850,timeout,0
|
| 5 |
+
620003,0,1850,timeout,0
|
| 6 |
+
620004,0,1850,timeout,0
|
| 7 |
+
620005,0,1850,timeout,0
|
| 8 |
+
620006,0,1850,timeout,0
|
| 9 |
+
620007,0,1850,timeout,0
|
| 10 |
+
620008,0,1850,timeout,0
|
| 11 |
+
620009,0,1850,timeout,0
|
| 12 |
+
620010,0,1850,timeout,0
|
| 13 |
+
620011,0,1850,timeout,0
|
| 14 |
+
620012,0,1850,timeout,0
|
| 15 |
+
620013,0,1850,timeout,0
|
| 16 |
+
620014,0,1850,timeout,0
|
| 17 |
+
620015,0,1850,timeout,0
|
| 18 |
+
620016,0,1850,timeout,0
|
| 19 |
+
620017,0,1850,timeout,0
|
| 20 |
+
620018,0,1850,timeout,0
|
| 21 |
+
620019,0,1850,timeout,0
|
| 22 |
+
620020,0,1850,timeout,0
|
| 23 |
+
620021,0,1850,timeout,0
|
| 24 |
+
620022,0,1850,timeout,0
|
| 25 |
+
620023,0,1850,timeout,0
|
| 26 |
+
620024,0,1850,timeout,0
|
| 27 |
+
620025,0,1850,timeout,0
|
| 28 |
+
620026,0,1850,timeout,0
|
| 29 |
+
620027,0,1850,timeout,0
|
| 30 |
+
620028,0,1850,timeout,0
|
| 31 |
+
620029,0,1850,timeout,0
|
| 32 |
+
620030,0,1850,timeout,0
|
| 33 |
+
620031,0,1850,timeout,0
|
| 34 |
+
620032,0,1850,timeout,0
|
| 35 |
+
620033,0,1850,timeout,0
|
| 36 |
+
620034,0,1850,timeout,0
|
| 37 |
+
620035,0,1850,timeout,0
|
| 38 |
+
620036,0,1850,timeout,0
|
| 39 |
+
620037,0,1850,timeout,0
|
| 40 |
+
620038,0,1850,timeout,0
|
| 41 |
+
620039,0,1850,timeout,0
|
| 42 |
+
620040,0,1850,timeout,0
|
| 43 |
+
620041,0,1850,timeout,0
|
| 44 |
+
620042,0,1850,timeout,0
|
| 45 |
+
620043,0,1850,timeout,0
|
| 46 |
+
620044,0,1850,timeout,0
|
| 47 |
+
620045,0,1850,timeout,0
|
| 48 |
+
620046,0,1850,timeout,0
|
| 49 |
+
620047,0,1850,timeout,0
|
| 50 |
+
620048,0,1850,timeout,0
|
| 51 |
+
620049,0,1850,timeout,0
|
| 52 |
+
620050,0,1850,timeout,0
|
| 53 |
+
620051,0,1850,timeout,0
|
| 54 |
+
620052,0,1850,timeout,0
|
| 55 |
+
620053,0,1850,timeout,0
|
| 56 |
+
620054,0,1850,timeout,0
|
| 57 |
+
620055,0,1850,timeout,0
|
| 58 |
+
620056,0,1850,timeout,0
|
| 59 |
+
620057,0,1850,timeout,0
|
| 60 |
+
620058,0,1850,timeout,0
|
| 61 |
+
620059,0,1850,timeout,0
|
| 62 |
+
620060,0,1850,timeout,0
|
| 63 |
+
620061,0,1850,timeout,0
|
| 64 |
+
620062,0,1850,timeout,0
|
| 65 |
+
620063,0,1850,timeout,0
|
| 66 |
+
620064,0,1850,timeout,0
|
| 67 |
+
620065,0,1850,timeout,0
|
| 68 |
+
620066,0,1850,timeout,0
|
| 69 |
+
620067,0,1850,timeout,0
|
| 70 |
+
620068,0,1850,timeout,0
|
| 71 |
+
620069,0,1850,timeout,0
|
| 72 |
+
620070,0,1850,timeout,0
|
| 73 |
+
620071,0,1850,timeout,0
|
| 74 |
+
620072,0,1850,timeout,0
|
| 75 |
+
620073,0,1850,timeout,0
|
| 76 |
+
620074,0,1850,timeout,0
|
| 77 |
+
620075,0,1850,timeout,0
|
| 78 |
+
620076,0,1850,timeout,0
|
| 79 |
+
620077,0,1850,timeout,0
|
| 80 |
+
620078,0,1850,timeout,0
|
| 81 |
+
620079,0,1850,timeout,0
|
| 82 |
+
620080,0,1850,timeout,0
|
| 83 |
+
620081,0,1850,timeout,0
|
| 84 |
+
620082,0,1850,timeout,0
|
| 85 |
+
620083,0,1850,timeout,0
|
| 86 |
+
620084,0,1850,timeout,0
|
| 87 |
+
620085,0,1850,timeout,0
|
| 88 |
+
620086,0,1850,timeout,0
|
| 89 |
+
620087,0,1850,timeout,0
|
| 90 |
+
620088,0,1850,timeout,0
|
| 91 |
+
620089,0,1850,timeout,0
|
| 92 |
+
620090,0,1850,timeout,0
|
| 93 |
+
620091,0,1850,timeout,0
|
| 94 |
+
620092,0,1850,timeout,0
|
| 95 |
+
620093,0,1850,timeout,0
|
| 96 |
+
620094,0,1850,timeout,0
|
| 97 |
+
620095,0,1850,timeout,0
|
| 98 |
+
620096,0,1850,timeout,0
|
| 99 |
+
620097,0,1850,timeout,0
|
| 100 |
+
620098,0,1850,timeout,0
|
| 101 |
+
620099,0,1850,timeout,0
|
policies/flip_cup/kimi31pro-s2/policy.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Deterministic joint-space controller for the flip-cup task.
|
| 2 |
+
|
| 3 |
+
The approach first raises the hand, then descends with a fixed hand orientation.
|
| 4 |
+
The grasp is on the cup body rather than its handle. The flip is measured from
|
| 5 |
+
the initial arm configuration and corrected using proprioception, since contact
|
| 6 |
+
can otherwise leave the wrist short of its target.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Policy:
|
| 13 |
+
def reset(self, obs, tools):
|
| 14 |
+
self.hold = np.asarray(tools.hold_action(), dtype=np.float32)
|
| 15 |
+
self.phase = 0
|
| 16 |
+
self.tick = 0
|
| 17 |
+
self.previous = np.zeros(7, dtype=np.float32)
|
| 18 |
+
self.qflip = np.array(
|
| 19 |
+
[-1.6, 0.28, 0.0, 0.1, 0.0, -1.55, 0.0], dtype=np.float32
|
| 20 |
+
)
|
| 21 |
+
self.safe = np.array(
|
| 22 |
+
[-1.1, 0.1, 0.0, 0.1, 0.0, 0.5, 0.0], dtype=np.float32
|
| 23 |
+
)
|
| 24 |
+
self.high = np.array(
|
| 25 |
+
[-1.45, 0.28, 0.0, 0.8, 0.0, 0.85, 0.0], dtype=np.float32
|
| 26 |
+
)
|
| 27 |
+
self.pre = np.array(
|
| 28 |
+
[-1.45, 0.28, 0.0, 1.15, 0.0, 0.50, 0.0], dtype=np.float32
|
| 29 |
+
)
|
| 30 |
+
self.lift = np.array(
|
| 31 |
+
[-1.65, 0.28, 0.0, 1.15, 0.0, 0.70, 0.0], dtype=np.float32
|
| 32 |
+
)
|
| 33 |
+
self.initial_angle = None
|
| 34 |
+
self.desired_angle = None
|
| 35 |
+
self.forward_target = None
|
| 36 |
+
|
| 37 |
+
@staticmethod
|
| 38 |
+
def _pitch_angle(obs):
|
| 39 |
+
q = obs["low_dim_obs"]
|
| 40 |
+
return float(q[3] + q[6] + q[8])
|
| 41 |
+
|
| 42 |
+
def _advance(self):
|
| 43 |
+
self.phase += 1
|
| 44 |
+
# act() increments tick on exit; zero is the next phase's first step.
|
| 45 |
+
self.tick = -1
|
| 46 |
+
|
| 47 |
+
def act(self, obs, tools):
|
| 48 |
+
t = self.tick
|
| 49 |
+
phase = self.phase
|
| 50 |
+
raw = self.hold.copy()
|
| 51 |
+
raw[0:2] = 0.0
|
| 52 |
+
raw[3] = 0.0
|
| 53 |
+
raw[4] = 0.0
|
| 54 |
+
raw[12:19] = 0.0
|
| 55 |
+
raw[20] = 0.0
|
| 56 |
+
|
| 57 |
+
# phase, duration, target, gripper, pelvis height
|
| 58 |
+
specs = {
|
| 59 |
+
0: (50, self.safe, 0.0, 0.74),
|
| 60 |
+
1: (80, self.high, 0.0, 0.74),
|
| 61 |
+
2: (90, self.pre, 0.0, 0.74),
|
| 62 |
+
3: (100, self.pre, 1.0, 0.74),
|
| 63 |
+
4: (100, self.lift, 1.0, 0.78),
|
| 64 |
+
5: (180, self.qflip, 1.0, 0.78),
|
| 65 |
+
6: (70, self.qflip, 1.0, 0.78),
|
| 66 |
+
7: (70, self.qflip, 1.0, 0.78),
|
| 67 |
+
9: (100, self.qflip, 1.0, 0.58),
|
| 68 |
+
10: (50, self.qflip, 0.0, 0.58),
|
| 69 |
+
11: (140, self.safe, 0.0, 0.74),
|
| 70 |
+
12: (100, self.safe, 0.0, 0.74),
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if phase in (0, 1, 2, 3, 4, 5, 9, 10, 11, 12):
|
| 74 |
+
duration, target, grip, height = specs[phase]
|
| 75 |
+
u = min(1.0, t / max(1.0, duration * 0.75))
|
| 76 |
+
raw[2] = height
|
| 77 |
+
raw[5:12] = (1.0 - u) * self.previous + u * target
|
| 78 |
+
raw[19] = grip
|
| 79 |
+
if phase == 3 and t == duration - 1:
|
| 80 |
+
self.initial_angle = self._pitch_angle(obs)
|
| 81 |
+
self.desired_angle = self.initial_angle - np.pi
|
| 82 |
+
if t >= duration - 1:
|
| 83 |
+
self.previous = target.copy()
|
| 84 |
+
self._advance()
|
| 85 |
+
|
| 86 |
+
elif phase in (6, 7):
|
| 87 |
+
# Correct contact-induced tracking error at the start of each hold.
|
| 88 |
+
if t == 0:
|
| 89 |
+
error = self.desired_angle - self._pitch_angle(obs)
|
| 90 |
+
self.qflip[0] = np.clip(self.qflip[0] + error, -2.6, 1.0)
|
| 91 |
+
duration, target, grip, height = specs[phase]
|
| 92 |
+
raw[2] = height
|
| 93 |
+
raw[5:12] = target
|
| 94 |
+
raw[19] = grip
|
| 95 |
+
if t >= duration - 1:
|
| 96 |
+
self.previous = target.copy()
|
| 97 |
+
self._advance()
|
| 98 |
+
|
| 99 |
+
elif phase == 8:
|
| 100 |
+
# The flip brings the hand toward the torso. Move slightly forward
|
| 101 |
+
# before release so the cup is above the cabinet, not the robot's feet.
|
| 102 |
+
if t == 0:
|
| 103 |
+
self.forward_target = min(0.22, float(obs["low_dim_obs"][21]) + 0.06)
|
| 104 |
+
raw[2] = 0.78
|
| 105 |
+
raw[5:12] = self.qflip
|
| 106 |
+
raw[19] = 1.0
|
| 107 |
+
if float(obs["low_dim_obs"][21]) < self.forward_target:
|
| 108 |
+
raw[0] = 0.12
|
| 109 |
+
if t >= 99:
|
| 110 |
+
self.previous = self.qflip.copy()
|
| 111 |
+
self._advance()
|
| 112 |
+
|
| 113 |
+
else:
|
| 114 |
+
raw[2] = 0.74
|
| 115 |
+
raw[5:12] = self.safe
|
| 116 |
+
raw[19] = 0.0
|
| 117 |
+
|
| 118 |
+
self.tick += 1
|
| 119 |
+
return raw
|