diff --git a/README.md b/README.md index 16e52d51ec517f28c50e23cc7ad12428c5027307..835405df848987587c327368f3dacf33c0e812c3 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,22 @@ trace//_seed.json lines the program ran at each co Sessions are named `opus-s1` … `opus-s3` and `astra-s1` … `astra-s3`; seeds run from 620000 to 620099. +## Programs of all agents + +`policies/` holds the final scored program of every session for seven agents on all +20 tasks (3 sessions each, 420 sessions): Claude Opus 5.5, GPT-6 Astra, GPT-6 Sol, +GPT-6.1 Sol, Kimi K3.1 Pro, DeepSeek V4.1 Flash (1017) and GPT-6.1 Terra. + +``` +policies.csv one row per session: agent, harness, effort, success rate, cost, tokens +policies///policy.py the scored program, with the helper modules it imports +policies///episodes.csv its 100 hidden seeds: seed, success, length, termination, fell +``` + +Sessions are named `-s1` … `-s3`. A session that ended without a +scorable program has a row in `policies.csv` with success 0 and no folder. Running a +program on the seeds 620000–620099 reproduces its episodes. + ## Watching them Each `episodes//` folder opens in the BiGym 2.0 viewer, with every diff --git a/policies/dishwasher_close/astra-s1/episodes.csv b/policies/dishwasher_close/astra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..0d250e573f9cba9c9fb6b41815943090ee3a786d --- /dev/null +++ b/policies/dishwasher_close/astra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,3523,success,0 +620001,1,3523,success,0 +620002,1,3523,success,0 +620003,1,3523,success,0 +620004,1,3523,success,0 +620005,1,3523,success,0 +620006,1,3523,success,0 +620007,1,3523,success,0 +620008,1,3523,success,0 +620009,1,3523,success,0 +620010,1,3523,success,0 +620011,1,3523,success,0 +620012,1,3523,success,0 +620013,1,3523,success,0 +620014,1,3523,success,0 +620015,1,3523,success,0 +620016,1,3523,success,0 +620017,1,3523,success,0 +620018,1,3523,success,0 +620019,1,3523,success,0 +620020,1,3523,success,0 +620021,1,3523,success,0 +620022,1,3523,success,0 +620023,1,3523,success,0 +620024,1,3523,success,0 +620025,1,3523,success,0 +620026,1,3523,success,0 +620027,1,3523,success,0 +620028,1,3523,success,0 +620029,1,3523,success,0 +620030,1,3523,success,0 +620031,1,3523,success,0 +620032,1,3523,success,0 +620033,1,3523,success,0 +620034,1,3523,success,0 +620035,1,3523,success,0 +620036,1,3523,success,0 +620037,1,3523,success,0 +620038,1,3523,success,0 +620039,1,3523,success,0 +620040,1,3523,success,0 +620041,1,3523,success,0 +620042,1,3523,success,0 +620043,1,3523,success,0 +620044,1,3523,success,0 +620045,1,3523,success,0 +620046,1,3523,success,0 +620047,1,3523,success,0 +620048,1,3523,success,0 +620049,1,3523,success,0 +620050,1,3523,success,0 +620051,1,3523,success,0 +620052,1,3523,success,0 +620053,1,3523,success,0 +620054,1,3523,success,0 +620055,1,3523,success,0 +620056,1,3523,success,0 +620057,1,3523,success,0 +620058,1,3523,success,0 +620059,1,3523,success,0 +620060,1,3523,success,0 +620061,1,3523,success,0 +620062,1,3523,success,0 +620063,1,3523,success,0 +620064,1,3523,success,0 +620065,1,3523,success,0 +620066,1,3523,success,0 +620067,1,3523,success,0 +620068,1,3523,success,0 +620069,1,3523,success,0 +620070,1,3523,success,0 +620071,1,3523,success,0 +620072,1,3523,success,0 +620073,1,3523,success,0 +620074,1,3523,success,0 +620075,1,3523,success,0 +620076,1,3523,success,0 +620077,1,3523,success,0 +620078,1,3523,success,0 +620079,1,3523,success,0 +620080,1,3523,success,0 +620081,1,3523,success,0 +620082,1,3523,success,0 +620083,1,3523,success,0 +620084,1,3523,success,0 +620085,1,3523,success,0 +620086,1,3523,success,0 +620087,1,3523,success,0 +620088,1,3523,success,0 +620089,1,3523,success,0 +620090,1,3523,success,0 +620091,1,3523,success,0 +620092,1,3523,success,0 +620093,1,3523,success,0 +620094,1,3523,success,0 +620095,1,3523,success,0 +620096,1,3523,success,0 +620097,1,3523,success,0 +620098,1,3523,success,0 +620099,1,3523,success,0 diff --git a/policies/dishwasher_close/astra-s1/policy.py b/policies/dishwasher_close/astra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..3186242fc5a72e797e326046d6ddff56c52439f1 --- /dev/null +++ b/policies/dishwasher_close/astra-s1/policy.py @@ -0,0 +1,58 @@ +"""Deterministic dishwasher controller using staged contacts and base feedback.""" +import numpy as np + +# Manually specified motions: lift to seat the lower rack, push the upper +# rack, then lift the door again. Positions are in the room's world frame. +STAGES = [{'name': 'front', 'n': 300, 'target': [-0.25, 0, 0], '19': 1, '20': 1}, + {'name': 'low', 'n': 120, '2': 0.4, '4': 0.4, '5': 0.3, '12': 0.3}, + {'name': 'reach', 'n': 100, '5': -0.2, '12': -0.2}, + {'name': 'lift1', 'n': 120, '5': -0.6, '12': -0.6}, + {'name': 'lift2', 'n': 120, '5': -1, '12': -1, '2': 0.55}, + {'name': 'lift3', 'n': 150, '5': -1.5, '12': -1.5, '2': 0.74, '4': 0}, + {'name': 'push', 'n': 500, 'target': [0.5, 0, 0]}, + {'name': 'release', 'n': 200, '5': 0, '12': 0, 'target': [-0.25, 0, 0]}, + {'name': 'align', 'n': 180, 'target': [-0.25, -0.16, 0], '15': 1, '12': 0}, + {'name': 'upper', 'n': 100, '5': 0, '8': 0}, + {'name': 'pushupper', 'n': 350, 'target': [0.4, -0.16, 0]}, + {'name': 'extendupper', 'n': 300, '5': -0.3, '8': 0.3, '4': 0.4, 'target': [0.4, -0.16, 0]}, + {'name': 'back', 'n': 250, 'target': [-0.3, -0.16, 0]}, + {'name': 'front2', 'n': 200, 'target': [-0.25, 0, 0], '5': 0, '8': 0, '15': 0, '4': 0}, + {'name': 'low', 'n': 120, '2': 0.4, '4': 0.4, '5': 0.3, '12': 0.3}, + {'name': 'reach', 'n': 100, '5': -0.2, '12': -0.2}, + {'name': 'lift1', 'n': 120, '5': -0.6, '12': -0.6}, + {'name': 'lift2', 'n': 120, '5': -1, '12': -1, '2': 0.55}, + {'name': 'lift3', 'n': 150, '5': -1.5, '12': -1.5, '2': 0.74, '4': 0}, + {'name': 'push', 'n': 500, 'target': [0.5, 0, 0]}, + {'name': 'finish', 'n': 250, '8': 1.2, '15': 1.2, 'target': [0.5, 0, 0]}] + +class Policy: + def reset(self, obs, tools): + self.action = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.index = -1 + self.end = 0 + self.target = None + + def act(self, obs, tools): + t = int(obs["t"]) + if t >= self.end and self.index + 1 < len(STAGES): + self.index += 1 + stage = STAGES[self.index] + self.end += stage["n"] + self.action[0] = self.action[1] = self.action[3] = 0 + self.target = stage.get("target") + for k, value in stage.items(): + if k not in ("name", "n", "target"): + self.action[int(k)] = value + if self.target is not None: + x, y, z, yaw = obs["low_dim_obs"][21:25] + dx, dy = self.target[0] - x, self.target[1] - y + v = np.array([np.cos(yaw)*dx + np.sin(yaw)*dy, + -np.sin(yaw)*dx + np.cos(yaw)*dy]) * 1.5 + v = np.clip(v, -.22, .22) + norm = np.linalg.norm(v) + if norm < .06: + v *= 0 if norm < .015 else .06 / norm + self.action[:2] = v + error = (self.target[2] - yaw + np.pi) % (2*np.pi) - np.pi + self.action[3] = np.clip(2*error, -.6, .6) + return self.action.copy() diff --git a/policies/dishwasher_close/astra-s2/episodes.csv b/policies/dishwasher_close/astra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..6a5d89dedd92df679a4215b6a3dfe8bfb0adbe11 --- /dev/null +++ b/policies/dishwasher_close/astra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,3235,success,0 +620001,1,3235,success,0 +620002,1,3235,success,0 +620003,1,3235,success,0 +620004,1,3235,success,0 +620005,1,3235,success,0 +620006,1,3235,success,0 +620007,1,3235,success,0 +620008,1,3235,success,0 +620009,1,3235,success,0 +620010,1,3235,success,0 +620011,1,3235,success,0 +620012,1,3235,success,0 +620013,1,3235,success,0 +620014,1,3235,success,0 +620015,1,3235,success,0 +620016,1,3235,success,0 +620017,1,3235,success,0 +620018,1,3235,success,0 +620019,1,3235,success,0 +620020,1,3235,success,0 +620021,1,3235,success,0 +620022,1,3235,success,0 +620023,1,3235,success,0 +620024,1,3235,success,0 +620025,1,3235,success,0 +620026,1,3235,success,0 +620027,1,3235,success,0 +620028,1,3235,success,0 +620029,1,3235,success,0 +620030,1,3235,success,0 +620031,1,3235,success,0 +620032,1,3235,success,0 +620033,1,3235,success,0 +620034,1,3235,success,0 +620035,1,3235,success,0 +620036,1,3235,success,0 +620037,1,3235,success,0 +620038,1,3235,success,0 +620039,1,3235,success,0 +620040,1,3235,success,0 +620041,1,3235,success,0 +620042,1,3235,success,0 +620043,1,3235,success,0 +620044,1,3235,success,0 +620045,1,3235,success,0 +620046,1,3235,success,0 +620047,1,3235,success,0 +620048,1,3235,success,0 +620049,1,3235,success,0 +620050,1,3235,success,0 +620051,1,3235,success,0 +620052,1,3235,success,0 +620053,1,3235,success,0 +620054,1,3235,success,0 +620055,1,3235,success,0 +620056,1,3235,success,0 +620057,1,3235,success,0 +620058,1,3235,success,0 +620059,1,3235,success,0 +620060,1,3235,success,0 +620061,1,3235,success,0 +620062,1,3235,success,0 +620063,1,3235,success,0 +620064,1,3235,success,0 +620065,1,3235,success,0 +620066,1,3235,success,0 +620067,1,3235,success,0 +620068,1,3235,success,0 +620069,1,3235,success,0 +620070,1,3235,success,0 +620071,1,3235,success,0 +620072,1,3235,success,0 +620073,1,3235,success,0 +620074,1,3235,success,0 +620075,1,3235,success,0 +620076,1,3235,success,0 +620077,1,3235,success,0 +620078,1,3235,success,0 +620079,1,3235,success,0 +620080,1,3235,success,0 +620081,1,3235,success,0 +620082,1,3235,success,0 +620083,1,3235,success,0 +620084,1,3235,success,0 +620085,1,3235,success,0 +620086,1,3235,success,0 +620087,1,3235,success,0 +620088,1,3235,success,0 +620089,1,3235,success,0 +620090,1,3235,success,0 +620091,1,3235,success,0 +620092,1,3235,success,0 +620093,1,3235,success,0 +620094,1,3235,success,0 +620095,1,3235,success,0 +620096,1,3235,success,0 +620097,1,3235,success,0 +620098,1,3235,success,0 +620099,1,3235,success,0 diff --git a/policies/dishwasher_close/astra-s2/policy.py b/policies/dishwasher_close/astra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..e15b9eb0b990d57d6e663270e517ffb5ba312863 --- /dev/null +++ b/policies/dishwasher_close/astra-s2/policy.py @@ -0,0 +1,44 @@ +"""Deterministic rack sweeps followed by a crouched, two-handed door lift.""" +import numpy as np + +class Policy: + def reset(self,obs,tools): + self.a=np.asarray(tools.hold_action(),dtype=float) + self.phase=0;self.k=0 + # time, planar target, height, lean, left (pitch, elbow), right, roll, wrist + self.seq=[ + (350,(.02,-.65,1.5708),.74,0,(.4,0),(.4,0),0,0), + (120,(.02,-.54,1.5708),.74,.2,(-.4,.2),(.5,0),0,0), + (340,(.85,-.54,1.5708),.74,.2,(-.4,.2),(.5,0),0,0), + (120,(.85,-.68,1.5708),.74,0,(.4,0),(.5,0),0,0), + (300,(.02,-.65,1.5708),.74,0,(.4,0),(.5,0),0,0), + (120,(.02,-.54,1.5708),.74,.5,(-.5,1),(.5,0),0,0), + (340,(.85,-.54,1.5708),.74,.5,(-.5,1),(.5,0),0,0), + (150,(.85,-.75,1.5708),.74,0,(.4,0),(.4,0),0,0), + (380,(-.35,-.75,0),.74,0,(.4,0),(.4,0),0,0), + (270,(-.35,0,0),.74,0,(-.4,1.2),(-.4,1.2),.8,0), + (130,None,.4,.8,(.1,.7),(.1,.7),.8,0), + (130,(-.2,0,0),.4,.8,(-.8,1.3),(-.8,1.3),.3,0), + (130,(-.15,0,0),.4,.8,(-1.2,1.7),(-1.2,1.7),0,-.6), + (130,(-.1,0,0),.4,.8,(-1.8,1.6),(-1.8,1.6),0,0), + (150,(-.1,0,0),.65,.5,(-1.6,1.3),(-1.6,1.3),0,0), + (350,(.25,0,0),.74,.2,(-1,.8),(-1,.8),0,0), + ] + def act(self,obs,tools): + dur,goal,h,p,l,r,roll,wrist=self.seq[min(self.phase,len(self.seq)-1)] + a=self.a.copy(); target=a.copy() + target[2]=h;target[4]=p;target[5:19]=0 + target[5]=l[0];target[8]=l[1];target[12]=r[0];target[15]=r[1] + target[6]=roll;target[13]=-roll;target[10]=target[17]=wrist;target[19:]=1 + a[2:]+=np.clip(target[2:]-a[2:],-.025,.025) + a[0]=a[1]=a[3]=0 + if goal is not None: + x,y,z,th=obs['low_dim_obs'][21:25] + err=np.array([goal[0]-x,goal[1]-y]); v=np.clip(err*2,-.3,.3) + if np.linalg.norm(err)<.015:v[:]=0 + elif np.linalg.norm(v)<.065:v*=.065/np.linalg.norm(v) + a[0]=np.cos(th)*v[0]+np.sin(th)*v[1];a[1]=-np.sin(th)*v[0]+np.cos(th)*v[1] + a[3]=np.clip(2*((goal[2]-th+np.pi)%(2*np.pi)-np.pi),-.7,.7) + self.a=a;self.k+=1 + if self.k>=dur and self.phase= self.spec['n'] and self.stage < len(STAGES)-1: + self._next() + self.action += np.clip(self.target-self.action, -self.rates, self.rates) + if 'pose' in self.spec: + x, y, yaw = obs['low_dim_obs'][[21,22,24]] + tx, ty, ta = self.spec['pose'] + err = np.array([tx-x, ty-y]) + velocity = np.clip(err*1.4, -.3, .3) + velocity = np.array([[np.cos(yaw),np.sin(yaw)],[-np.sin(yaw),np.cos(yaw)]]) @ velocity + if np.linalg.norm(err) < .018: + velocity *= 0 + elif np.linalg.norm(velocity) < .065: + velocity *= .065/(np.linalg.norm(velocity)+1e-6) + self.action[:2] = velocity + self.action[3] = np.clip(((ta-yaw+np.pi)%(2*np.pi)-np.pi)*2, -.7, .7) + self.elapsed += 1 + return self.action.copy() diff --git a/policies/dishwasher_close/deepseek1017-s1/episodes.csv b/policies/dishwasher_close/deepseek1017-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/deepseek1017-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/deepseek1017-s1/policy.py b/policies/dishwasher_close/deepseek1017-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a8482dd4b4878033a61d647a3f4ae01781850bc5 --- /dev/null +++ b/policies/dishwasher_close/deepseek1017-s1/policy.py @@ -0,0 +1,201 @@ +"""Hand-written control policy for the dishwasher-close task. + +The controller is a timed state machine. It drives the robot up to the +dishwasher, pushes the pulled-out racks in with both arms, then crouches, +hooks the near edge of the open door and stands up while following the door +forward to swing it shut. It finally pushes the door panel closed and holds. +A secondary sweep of the vertical door panel covers the side-hinged layout. +No learned components and no randomness are used. +""" + +import math + +import numpy as np + + +def _wrap(a): + while a > math.pi: + a -= 2.0 * math.pi + while a < -math.pi: + a += 2.0 * math.pi + return a + + +class Policy: + """Timed state machine over the 21-dimensional physical action.""" + + TURN = 110 + WALK = 210 + CENTER = 80 + RACK = 110 + BACK = 25 + SQUAT = 30 + GRIP = 40 + LIFT = 140 + LATCH = 80 + CYCLES = 6 + TURN_SHORT = 45 + SWING_TURN = 90 + SWING_WALK = 120 + SWING = 220 + HOLD = 120 + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.t = 0 + self.phase = 0 + self.x0 = float(obs["low_dim_obs"][21]) + self.y0 = float(obs["low_dim_obs"][22]) + self.xc = self.x0 + self.yc = self.y0 + self.tx = self.x0 + self.ty = self.y0 + self.tyaw = 1.25 + self.cycle_idx = 0 + self.planned = self._plan() + + def _plan(self): + plan = [("turn", self.TURN), ("walk", self.WALK), ("center", self.CENTER)] + for _ in range(self.CYCLES): + plan += [ + ("turn_short", self.TURN_SHORT), + ("rack", self.RACK), + ("back", self.BACK), + ("squat", self.SQUAT), + ("grip", self.GRIP), + ("lift", self.LIFT), + ("latch", self.LATCH), + ("swing_turn", self.SWING_TURN), + ("swing_walk", self.SWING_WALK), + ("swing", self.SWING), + ] + plan += [("hold", self.HOLD)] + return plan + + def _base_hold(self, raw, obs, tx, ty, tyaw, speed=0.15): + x = float(obs["low_dim_obs"][21]) + y = float(obs["low_dim_obs"][22]) + yaw = float(obs["low_dim_obs"][24]) + ex, ey, eyaw = tx - x, ty - y, _wrap(tyaw - yaw) + vxw = float(np.clip(4.0 * ex, -speed, speed)) + vyw = float(np.clip(4.0 * ey, -speed, speed)) + c, s = math.cos(yaw), math.sin(yaw) + vx = c * vxw + s * vyw + vy = -s * vxw + c * vyw + sp = math.hypot(vx, vy) + if 1e-6 < sp < 0.07: + vx *= 0.07 / sp + vy *= 0.07 / sp + raw[0] = float(np.clip(vx, -1.0, 1.0)) + raw[1] = float(np.clip(vy, -1.0, 1.0)) + raw[3] = float(np.clip(2.0 * eyaw, -0.4, 0.4)) + return raw + + def act(self, obs, tools): + raw = np.asarray(tools.hold_action(), dtype=np.float32) + + while self.phase < len(self.planned) and self.t >= self.planned[self.phase][1]: + self.t -= self.planned[self.phase][1] + self.phase += 1 + if self.phase >= len(self.planned): + return raw + tag = self.planned[self.phase][0] + n = self.planned[self.phase][1] + p = self.t / float(max(1, n - 1)) + if tag == "rack" and self.t == 0: + self.cycle_idx += 1 + self.t += 1 + ci = self.cycle_idx % 4 + yaw = float(obs["low_dim_obs"][24]) + yaw_err = float(np.clip(1.2 * _wrap(self.tyaw - yaw), -0.3, 0.3)) + + if tag == "turn": + raw[3] = float(np.clip(1.5 * _wrap(self.tyaw - yaw), -0.5, 0.5)) + raw[2] = 0.74 + + elif tag == "turn_short": + raw[3] = float(np.clip(1.5 * _wrap(self.tyaw - yaw), -0.5, 0.5)) + raw[2] = 0.74 + raw[19] = raw[20] = 0.0 + + elif tag == "walk": + raw[0] = 0.22 + raw[3] = yaw_err + raw[2] = 0.74 + if p > 0.7: + self.xc = float(obs["low_dim_obs"][21]) + self.yc = float(obs["low_dim_obs"][22]) + self.tx = self.xc + 0.2 + self.ty = self.yc + + elif tag == "center": + self._base_hold(raw, obs, self.tx, self.ty, self.tyaw, 0.12) + + elif tag == "rack": + raw[0] = 0.22 + raw[3] = yaw_err + raw[4] = -0.15 + raw[5] = raw[12] = -1.05 - 0.08 * ci + raw[8] = raw[15] = 0.25 + 0.06 * ci + raw[19] = raw[20] = 1.0 + + elif tag == "back": + raw[0] = -0.18 + raw[4] = 0.0 + raw[19] = raw[20] = 1.0 + + elif tag == "squat": + raw[2] = 0.5 + raw[4] = 0.0 + raw[19] = raw[20] = 0.0 + + elif tag == "grip": + raw[2] = 0.5 + raw[4] = 0.0 + raw[5], raw[6], raw[8] = -0.22 - 0.05 * ci, -0.18 - 0.02 * ci, 0.72 + 0.04 * ci + raw[12], raw[13], raw[15] = raw[5], -raw[6], raw[8] + raw[10] = raw[17] = 0.0 + raw[19] = raw[20] = 1.0 + + elif tag == "lift": + raw[2] = 0.5 + 0.45 * p + raw[4] = 0.25 * p + raw[0] = 0.12 + raw[3] = yaw_err + raw[5] = raw[12] = (-0.22 - 0.05 * ci) - 1.35 * p + raw[6], raw[13] = -0.18 - 0.02 * ci, 0.18 + 0.02 * ci + raw[8] = raw[15] = 0.8 - 0.3 * p + raw[10] = raw[17] = 0.0 + raw[19] = raw[20] = 1.0 + + elif tag == "latch": + raw[2] = 0.95 + raw[4] = 0.5 + raw[0] = 0.12 + raw[3] = yaw_err + raw[5] = raw[12] = -1.9 + raw[6], raw[13] = -0.2, 0.2 + raw[8] = raw[15] = 0.5 + raw[10] = raw[17] = 0.0 + raw[19] = raw[20] = 1.0 + + elif tag == "swing_turn": + raw[3] = float(np.clip(1.5 * _wrap(0.6 - yaw), -0.5, 0.5)) + raw[2] = 0.74 + raw[19] = raw[20] = 0.0 + + elif tag == "swing_walk": + raw[0] = 0.2 + raw[3] = float(np.clip(1.2 * _wrap(0.6 - yaw), -0.3, 0.3)) + raw[2] = 0.74 + raw[19] = raw[20] = 0.0 + + elif tag == "swing": + raw[0] = 0.15 + raw[1] = 0.2 if (self.cycle_idx % 2 == 0) else -0.2 + raw[3] = 0.15 if (self.cycle_idx % 2 == 0) else -0.15 + raw[5] = raw[12] = -1.0 + raw[8] = raw[15] = 0.3 + raw[19] = raw[20] = 1.0 + + return raw diff --git a/policies/dishwasher_close/deepseek1017-s2/episodes.csv b/policies/dishwasher_close/deepseek1017-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/deepseek1017-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/deepseek1017-s2/policy.py b/policies/dishwasher_close/deepseek1017-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..ac94118acde8b3cd4f33b55db7317eae9b7d7ea5 --- /dev/null +++ b/policies/dishwasher_close/deepseek1017-s2/policy.py @@ -0,0 +1,230 @@ +"""Hand-written control policy for the Unitree G1 dishwasher task. + +The robot turns and walks to the dishwasher along the demonstrated heading, +then searches for the door/rack contact with a slow arm sweep while watching +the wrist camera. When the wrist view turns bright (a close white surface) +the hand is at the door; the policy latches that joint pose and tries the +closing motions (press down, lift up, push forward) from there. Several +lateral passes along the machine front are made to cover the opening. +""" + +import numpy as np + +ACTION_DIM = 21 + + +def _wrap(a): + return (a + np.pi) % (2.0 * np.pi) - np.pi + + +class Policy: + def reset(self, obs, tools): + self.t = 0 + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.ld = np.asarray(obs["low_dim_obs"], dtype=np.float32) + self.sp = 0.0 + self.contact_sp = None + self.bright = 0.0 + self.sweep_start = 0.0 + self.wp = 0.2 + self.plan = [ + ("settle", 8), + ("turn", 106), + ("walk", 250), + ("sweep", 150), + ("pushcont", 130), + ("press", 90), + ("lift", 90), + ("strafe", 40), + ("sweep", 150), + ("pushcont", 110), + ("press", 90), + ("lift", 90), + ("strafe", 40), + ("sweep", 150), + ("press", 90), + ("lift", 90), + ("strafe", 40), + ("sweep", 130), + ("body", 130), + ("backoff", 150), + ("centerleft", 260), + ("walkcenter", 200), + ("sweep", 150), + ("pushcont", 120), + ("press", 90), + ("lift", 90), + ("squat", 55), + ("stand", 55), + ("squat2", 55), + ("stand2", 55), + ("pushcont", 120), + ("finalsweep", 950), + ("hold", 200), + ] + self.phase = 0 + self.phase_t = 0 + + # ------------------------------------------------------------------ + def _wrist_white(self, tools): + try: + im = np.asarray(tools.image("left_wrist", 84, 84), + dtype=np.float32) + h, w, _ = im.shape + mask = np.ones((h, w), bool) + mask[20:64, 28:56] = False + vals = im[mask] + self.bright = float(vals.mean()) + white = (vals[:, 0] > 135) & (vals[:, 1] > 135) & \ + (vals[:, 2] > 135) + return float(white.mean()) + except Exception: + return 0.0 + + # ------------------------------------------------------------------ + def act(self, obs, tools): + self.ld = np.asarray(obs["low_dim_obs"], dtype=np.float32) + self.t += 1 + while self.phase < len(self.plan) - 1 and \ + self.phase_t >= self.plan[self.phase][1]: + self.phase_t -= self.plan[self.phase][1] + self.phase += 1 + self.sweep_start = self.sp + name, length = self.plan[self.phase] + frac = min(1.0, (self.phase_t + 1.0) / max(1.0, length)) + self.phase_t += 1 + + px, py, pz, yaw = self.ld[21:25] + raw = self.hold.copy() + raw[2] = 0.74 + raw[4] = -0.2 + raw[19] = 0.5 + raw[20] = 0.5 + arms = np.array([0.02, 0.0, 0.0, 0.03, 0.0, 0.04, 0.0], np.float32) + vx = vy = wz = 0.0 + height = 0.74 + pitch = -0.2 + grip = 0.5 + wp = self.wp + + def face(target_yaw, gain=0.8, lim=0.4): + return float(np.clip(gain * _wrap(target_yaw - yaw), -lim, lim)) + + if name == "settle": + arms = np.asarray(self.hold[5:12], np.float32) + + elif name == "turn": + wz = face(0.95, 0.9, 0.5) + arms = np.asarray(self.hold[5:12], np.float32) + + elif name == "walk": + if px < 0.34: + vx = 0.28 + wz = face(0.95, 0.7, 0.35) + arms = np.asarray(self.hold[5:12], np.float32) + + elif name == "sweep": + wht = self._wrist_white(tools) + self.sp = 0.25 - 2.05 * frac # +0.25 -> -1.8 + if self.contact_sp is not None: + self.sp = self.contact_sp + 0.12 * np.sin(0.3 * self.t) + arms = np.array([self.sp, 0.0, 0.0, 0.15, 0.0, wp, 0.0], np.float32) + grip = 0.9 + if frac > 0.35 and wht > 0.35 and self.contact_sp is None: + self._hits = getattr(self, "_hits", 0) + 1 + if self._hits >= 2: + self.contact_sp = self.sp + else: + if self.contact_sp is None: + self._hits = 0 + wz = face(0.10, 0.5, 0.2) + + elif name == "press": + base_sp = self.contact_sp if self.contact_sp is not None else -1.0 + self.sp = base_sp + 0.75 * frac + arms = np.array([self.sp, 0.0, 0.0, 0.15, 0.0, wp, 0.0], np.float32) + grip = 0.5 + vx = 0.05 + pitch = 0.25 * frac + wz = face(0.10, 0.5, 0.2) + + elif name == "lift": + base_sp = self.contact_sp if self.contact_sp is not None else -0.4 + self.sp = base_sp - 0.55 * frac + arms = np.array([self.sp, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0], np.float32) + grip = 0.7 + vx = -0.04 + wz = face(0.10, 0.5, 0.2) + + elif name == "strafe": + self.sp = (self.contact_sp if self.contact_sp is not None else -0.5) + arms = np.array([self.sp, 0.0, 0.0, 0.15, 0.0, wp, 0.0], np.float32) + grip = 0.8 + vy = 0.09 + wz = face(0.10, 0.5, 0.2) + + elif name == "backoff": + arms = np.array([-0.5, 0.0, 0.0, 0.25, 0.0, 0.2, 0.0], np.float32) + vx = -0.25 + wz = face(0.10, 0.5, 0.2) + + elif name == "centerleft": + arms = np.array([-0.5, 0.0, 0.0, 0.25, 0.0, 0.2, 0.0], np.float32) + vy = 0.22 + wz = face(0.10, 0.5, 0.2) + + elif name == "walkcenter": + arms = np.array([-0.5, 0.0, 0.0, 0.25, 0.0, 0.2, 0.0], np.float32) + if px < -0.05: + vx = 0.20 + wz = face(0.10, 0.7, 0.3) + + elif name == "squat" or name == "squat2": + arms = np.array([0.0, 0.0, 0.0, 0.05, 0.0, 0.2, 0.0], np.float32) + height = 0.50 + grip = 0.9 + wz = face(0.10, 0.5, 0.2) + + elif name == "stand" or name == "stand2": + arms = np.array([0.0, 0.0, 0.0, 0.05, 0.0, 0.2, 0.0], np.float32) + height = 0.79 + grip = 0.9 + wz = face(0.10, 0.5, 0.2) + + elif name == "pushcont": + base_sp = self.contact_sp if self.contact_sp is not None else -0.6 + arms = np.array([base_sp, 0.0, 0.0, 0.1, 0.0, 0.2, 0.0], np.float32) + grip = 0.7 + vx = 0.14 + wz = face(0.10, 0.5, 0.2) + + elif name == "body": + arms = np.array([-0.75, 0.0, 0.0, 0.30, 0.0, 0.2, 0.0], np.float32) + grip = 0.5 + vx = 0.16 + pitch = 0.1 + wz = face(0.10, 0.5, 0.2) + + elif name == "finalsweep": + # slow continuous vertical sweep through the whole workspace + self.sp = -1.0 + 1.1 * np.sin(0.035 * self.t) + arms = np.array([self.sp, 0.0, 0.0, 0.15, 0.0, 0.2, 0.0], np.float32) + grip = 0.8 + vx = 0.04 * np.sin(0.02 * self.t) + vy = 0.03 * np.cos(0.013 * self.t) + wz = face(0.10, 0.5, 0.2) + + else: # hold + arms = np.array([-0.4, 0.0, 0.0, 0.2, 0.0, 0.2, 0.0], np.float32) + grip = 0.5 + + raw[0] = vx + raw[1] = vy + raw[2] = height + raw[3] = wz + raw[4] = pitch + raw[5:12] = arms + raw[12:19] = arms + raw[19] = grip + raw[20] = grip + return np.asarray(raw, dtype=np.float32) diff --git a/policies/dishwasher_close/deepseek1017-s3/episodes.csv b/policies/dishwasher_close/deepseek1017-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/deepseek1017-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/deepseek1017-s3/policy.py b/policies/dishwasher_close/deepseek1017-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..b4ac37d3e327d5908309d33e65abc225395ed61d --- /dev/null +++ b/policies/dishwasher_close/deepseek1017-s3/policy.py @@ -0,0 +1,246 @@ +"""Push the dishwasher racks in and close the door. + +Hand-written, deterministic controller. The policy approaches the dishwasher, +sweeps both arms through the rack heights while advancing, then works the door +through a set of whole-arm / whole-body motions (under-lift, body lift and +top-press). All motion is generated from the proprioceptive state so the +policy is fully deterministic and needs no scene model at run time. + +Contract (see docs/api.md): + raw = [vx, vy, height, wz, torso_pitch, left arm(7), right arm(7), + left gripper, right gripper] +""" + +import numpy as np + + +def _clip(x, lo, hi): + return float(min(hi, max(lo, x))) + + +class Policy: + """Phase-based scripted dishwasher policy.""" + + def reset(self, obs, tools): + self.tools = tools + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + low = np.asarray(obs["low_dim_obs"], dtype=np.float64) + self.yaw0 = float(low[24]) + self.target_yaw = self.yaw0 + 1.05 + self.phase = 0 + self.pt = 0 + self.done_steps = 0 + # phase plan: (name, duration) + self.plan = self._build_plan() + + # ------------------------------------------------------------------ plan + def _build_plan(self): + plan = [] + # 0: turn to face the dishwasher + plan.append(["turn", 240]) + # 1: walk up to it + plan.append(["walk", 120]) + # 2: rack sweep -- arms at a series of heights while advancing + for h in (1.35, 1.05, 0.75, 0.45, 1.55, 1.15, 0.60): + plan.append(["push_rack", 34, h]) + # 3: make room in front of the door + plan.append(["back", 26]) + # 4: door under-lift at several heights + for h in (0.05, 0.30, 0.60): + plan.append(["lift", 46, h]) + # 5: squat, get under the door, then stand up + plan.append(["bodylift", 120]) + # 6: press the door down from above + plan.append(["press", 90]) + # 7: repeat a compact door cycle + for h in (0.20, 0.50, 0.80): + plan.append(["lift", 40, h]) + plan.append(["press", 70]) + plan.append(["bodylift", 100]) + # 8: final hold with the hands against the door + plan.append(["hold_door", 160]) + return plan + + # --------------------------------------------------------------- helpers + def _base_action(self): + a = self.hold.copy() + a[0] = 0.0 + a[1] = 0.0 + a[2] = 0.74 + a[3] = 0.0 + a[4] = 0.0 + a[5:19] = 0.0 + a[19] = 0.6 + a[20] = 0.6 + return a + + def _yaw(self, a, obs, target, gain=1.5, limit=0.5): + e = target - float(obs["low_dim_obs"][24]) + w = _clip(gain * e, -limit, limit) + if 0.0 < abs(w) < 0.06: + w = 0.06 if w > 0 else -0.06 + a[3] = w + + def _arms(self, a, sp, elbow=0.0, roll=0.0, wrist=(0.0, 0.0, 0.0), grip=1.0): + for off in (5, 12): + a[off] = _clip(sp, -3.0, 2.6) + a[off + 1] = _clip(roll, -1.5, 2.2) + a[off + 2] = 0.0 + a[off + 3] = _clip(elbow, -1.0, 2.0) + a[off + 4] = _clip(wrist[0], -1.9, 1.9) + a[off + 5] = _clip(wrist[1], -1.6, 1.6) + a[off + 6] = _clip(wrist[2], -1.6, 1.6) + a[19] = grip + a[20] = grip + + def _next_phase(self): + self.phase += 1 + self.pt = 0 + + # ------------------------------------------------------------------- act + def act(self, obs, tools): + low = np.asarray(obs["low_dim_obs"], dtype=np.float64) + self.pt += 1 + if self.phase >= len(self.plan): + # Finished the scripted sequence: keep working the door in a slow, + # safe cycle for the rest of the episode (more attempts can only + # help, and the motions were verified not to topple the robot). + a = self._base_action() + self._yaw(a, obs, self.target_yaw, gain=1.0, limit=0.22) + k = self.done_steps // 70 + mode = k % 8 + f = (self.done_steps % 70) / 70.0 + if mode == 0: + self._arms(a, 0.05 + 1.3 * f, elbow=0.1, grip=1.0) + a[4] = 0.35 + a[0] = 0.05 + elif mode == 1: + self._arms(a, 1.35, elbow=1.0 * (1.0 - f), grip=1.0) + a[4] = 0.25 + 0.5 * f + a[0] = 0.10 + elif mode == 2: + self._arms(a, 0.35, elbow=0.0, grip=1.0) + if f < 0.4: + a[2] = 0.44 + a[4] = 0.45 + else: + g = min(1.0, (f - 0.4) / 0.6) + a[2] = 0.44 + 0.45 * g + a[4] = 0.45 * (1.0 - g) + self._arms(a, 0.35 + 0.5 * g, elbow=0.0, grip=1.0) + a[0] = 0.03 + elif mode == 3: + self._arms(a, 1.35, elbow=0.4, grip=1.0) + a[4] = 0.35 + a[0] = 0.18 + elif mode == 4: + self._arms(a, 0.75, elbow=0.6, grip=1.0) + a[4] = 0.45 + a[0] = 0.10 + elif mode == 5: + self._arms(a, 0.45, elbow=0.2, grip=1.0) + a[4] = 0.20 + a[0] = -0.08 + elif mode == 6: + # lean back while holding the door edge: pulls a sticky door + self._arms(a, 0.90, elbow=0.30, grip=1.0) + a[4] = -0.15 + a[0] = -0.05 + else: + # stand tall and press the upper edge inward + self._arms(a, 1.50, elbow=0.20, grip=1.0) + a[2] = 0.90 + a[4] = 0.75 + a[0] = 0.10 + self.done_steps += 1 + if float(low[23]) < 0.50: + a[0] = min(a[0], 0.02) + return a + + ph = self.plan[self.phase] + name = ph[0] + dur = ph[1] + a = self._base_action() + + if name == "turn": + self._yaw(a, obs, self.target_yaw, gain=1.5, limit=0.5) + if self.pt >= dur or ( + abs(self.target_yaw - float(low[24])) < 0.06 and self.pt > 20 + ): + self._next_phase() + elif name == "walk": + self._yaw(a, obs, self.target_yaw, gain=1.2, limit=0.3) + a[0] = 0.20 + a[4] = 0.15 + if self.pt >= dur: + self._next_phase() + elif name == "push_rack": + h = ph[2] + self._yaw(a, obs, self.target_yaw, gain=1.2, limit=0.3) + a[4] = 0.35 + # a small elbow sweep across the height to catch the rack front + f = min(1.0, self.pt / max(1.0, dur * 0.7)) + self._arms(a, h - 0.15 * f, elbow=0.2 + 0.9 * f, grip=1.0) + a[0] = 0.16 + if self.pt >= dur: + self._next_phase() + elif name == "back": + self._yaw(a, obs, self.target_yaw, gain=1.2, limit=0.3) + a[0] = -0.16 + a[4] = 0.35 + a[2] = 0.70 + if self.pt >= dur: + self._next_phase() + elif name == "lift": + h = ph[2] + self._yaw(a, obs, self.target_yaw, gain=1.2, limit=0.3) + f = min(1.0, self.pt / max(1.0, dur * 0.65)) + # start with the hand below the edge, then raise it while closing + sp = h + 1.35 * f + self._arms(a, sp, elbow=0.15, grip=1.0) + a[4] = 0.35 + a[0] = 0.05 + if self.pt >= dur: + self._next_phase() + elif name == "bodylift": + self._yaw(a, obs, self.target_yaw, gain=1.2, limit=0.3) + # first third: squat and reach; second: stand while hands stay put + if self.pt < dur * 0.35: + a[2] = 0.44 + a[4] = 0.45 + self._arms(a, 0.35, elbow=0.0, grip=1.0) + elif self.pt < dur * 0.65: + a[2] = 0.44 + a[4] = 0.45 + self._arms(a, 0.35, elbow=0.0, grip=1.0) + else: + f = (self.pt - dur * 0.65) / max(1.0, dur * 0.35) + a[2] = 0.44 + 0.45 * min(1.0, f) + a[4] = 0.45 * (1.0 - min(1.0, f)) + self._arms(a, 0.35 + 0.55 * min(1.0, f), elbow=0.0, grip=1.0) + a[0] = 0.04 + if self.pt >= dur: + self._next_phase() + elif name == "press": + self._yaw(a, obs, self.target_yaw, gain=1.2, limit=0.3) + f = min(1.0, self.pt / max(1.0, dur * 0.7)) + # hands on top of the door, elbow extends and torso leans in + self._arms(a, 1.35, elbow=1.0 * (1.0 - f), grip=1.0) + a[4] = 0.25 + 0.55 * f + a[0] = 0.10 + if self.pt >= dur: + self._next_phase() + elif name == "hold_door": + self._yaw(a, obs, self.target_yaw, gain=1.0, limit=0.25) + a[4] = 0.30 + self._arms(a, 0.85, elbow=0.35, grip=0.9) + a[0] = 0.05 + if self.pt >= dur: + self._next_phase() + else: + self._next_phase() + + # Hard safety: never command a large forward speed while very low. + if float(low[23]) < 0.50: + a[0] = min(a[0], 0.02) + return a diff --git a/policies/dishwasher_close/gpt61sol-s1/episodes.csv b/policies/dishwasher_close/gpt61sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt61sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt61sol-s1/policy.py b/policies/dishwasher_close/gpt61sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..8c7f335afff3c69b596ced45376da44809d9d654 --- /dev/null +++ b/policies/dishwasher_close/gpt61sol-s1/policy.py @@ -0,0 +1,157 @@ +"""Deterministic joint and base control for the dishwasher manipulation task.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.action = np.asarray(tools.hold_action(), dtype=float) + self.stage = 0 + self.age = 0 + self.x = 0.35 + self.y = -0.47 + self.heading = 0.0 + + def navigate(self, obs, target): + pose = obs['low_dim_obs'][21:25] + error = np.asarray(target) - pose[:2] + velocity = np.clip(1.8 * error, -0.20, 0.20) + distance = np.linalg.norm(error) + if distance < 0.025: + velocity[:] = 0 + elif np.linalg.norm(velocity) < 0.07: + velocity *= 0.07 / max(np.linalg.norm(velocity), 1e-6) + c, s = np.cos(pose[3]), np.sin(pose[3]) + self.target[0] = c * velocity[0] + s * velocity[1] + self.target[1] = -s * velocity[0] + c * velocity[1] + return distance < 0.035 and abs(((self.heading - pose[3] + np.pi) % (2 * np.pi)) - np.pi) < 0.035 + + def finish_phase(self, duration): + if self.age >= duration: + self.stage += 1 + self.age = 0 + + def left_arm(self, roll, grip): + # The appliance is to the left of the initial forward direction. + # Abduction advances the hand along the rack slide and door closing arc. + self.target[5:12] = [0.8, roll, 0, 0, 0, 0, 1.57] + self.target[19] = grip + + def act(self, obs, tools): + self.age += 1 + self.target = self.action.copy() + a = self.target + a[:2] = 0 + yaw = float(obs['low_dim_obs'][24]) + yaw_error = (self.heading - yaw + np.pi) % (2 * np.pi) - np.pi + a[3] = np.clip(1.8 * yaw_error, -0.45, 0.45) + a[12:19] = [-1.7, -0.2, 0, 0, 0, 0, 0] + a[20] = 1 + stage, age = self.stage, self.age + + if stage == 0: + a[2], a[4] = 0.74, 0 + self.left_arm(0.1, 1) + if self.navigate(obs, [self.x, -0.80]) or age >= 300: + self.stage, self.age = 1, 0 + elif stage == 1: + a[2], a[4] = 0.74, 0.8 + self.left_arm(0.1, 0) + self.finish_phase(180) + elif stage == 2: + self.left_arm(0.1, 0) + self.navigate(obs, [self.x, self.y]) + self.finish_phase(300) + elif stage == 3: + self.left_arm(0.1, 1) + self.finish_phase(80) + elif stage == 4: + r = min(age / 260.0, 1) + self.left_arm(0.1 + 0.9 * r, 1) + a[2] = 0.74 - 0.14 * r + self.finish_phase(360) + elif stage == 5: + r = min(age / 160.0, 1) + self.left_arm(1.0 - 0.9 * r, 0) + a[2] = 0.60 + 0.14 * r + self.finish_phase(200) + elif stage == 6: + self.left_arm(0.1, 0) + a[2] = 0.50 + self.finish_phase(160) + elif stage == 7: + self.left_arm(0.1, 1) + self.finish_phase(80) + elif stage == 8: + r = min(age / 260.0, 1) + self.left_arm(0.1 + 0.9 * r, 1) + a[2] = 0.50 - 0.10 * r + self.finish_phase(360) + elif stage == 9: + r = min(age / 160.0, 1) + self.left_arm(1.0 - 0.9 * r, 0) + a[2] = 0.40 + 0.05 * r + self.finish_phase(200) + elif stage == 10: + self.left_arm(0.1, 0) + a[2] = 0.40 + self.finish_phase(180) + elif stage == 11: + self.left_arm(0.1, 1) + self.finish_phase(100) + elif stage == 12: + r = min(age / 450.0, 1) + self.left_arm(0.1 + 1.25 * r, 1) + a[2] = 0.40 + 0.40 * r + self.finish_phase(600) + elif stage == 13: + self.left_arm(1.45, 1) + a[2], a[4] = 0.80, 0.80 + self.navigate(obs, [self.x, self.y + 0.02]) + self.finish_phase(200) + elif stage == 14: + # Withdraw, then turn to make another push from the front. + self.heading = np.pi / 2 + a[3] = np.clip(1.8 * ((self.heading - yaw + np.pi) % (2*np.pi) - np.pi), -0.45, 0.45) + a[2], a[4] = 0.74, 0 + a[5:12] = [-1.5, 0.15, 0, 0, 0, 0, 0] + a[19] = 1 + self.finish_phase(250) + elif stage == 15: + a[5:12] = [-1.7, 0.2, 0, 0, 0, 0, 0] + if age < 170: + a[2], a[4] = 0.74, 0.60 + a[12:19] = [-0.3, 0, 0, 0, 0, 0, 0] + else: + a[2], a[4] = 0.60, 0.80 + a[12:19] = [0.1, 0, 0, 0, 0, 0, 0] + a[19:21] = 1 + self.navigate(obs, [0.28, -0.15]) + self.finish_phase(350) + elif stage == 16: + a[2], a[4] = 0.40, 0.80 + a[5:12] = [-1.7, 0.2, 0, 0, 0, 0, 0] + a[12:19] = [0, 0, 0, 0, 0, 0.8, 0] + a[20] = 0 + self.finish_phase(150) + elif stage == 17: + a[20] = 1 + self.finish_phase(80) + elif stage == 18: + r = min(age / 300.0, 1) + a[2], a[4] = 0.40 + 0.34*r, 0.80 + a[12:19] = [-0.6*r, 0, 0, 0, 0, 0.8*(1-r), 0] + a[20] = 1 + self.finish_phase(350) + else: + a[2], a[4] = 0.74, 0.60 + a[12:19] = [-0.6, 0, 0, 0, 0, 0, 0] + a[20] = 1 + self.navigate(obs, [0.28, -0.20]) + + # Joint and stance targets change gradually; velocities remain feedback commands. + out = a.copy() + out[2] = self.action[2] + np.clip(a[2] - self.action[2], -0.008, 0.008) + out[4] = self.action[4] + np.clip(a[4] - self.action[4], -0.012, 0.012) + out[5:19] = self.action[5:19] + np.clip(a[5:19] - self.action[5:19], -0.045, 0.045) + self.action = out + return out.astype(np.float32) diff --git a/policies/dishwasher_close/gpt61sol-s2/episodes.csv b/policies/dishwasher_close/gpt61sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt61sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt61sol-s2/policy.py b/policies/dishwasher_close/gpt61sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..03d0657409cc3dae4171404b00689b7756f409cf --- /dev/null +++ b/policies/dishwasher_close/gpt61sol-s2/policy.py @@ -0,0 +1,78 @@ +"""Deterministic control: rack sweeps, obstacle-aware approach, and door lift. + +All targets are physical joint angles or body poses. No demonstration files, +learned parameters, random numbers, or clock are used by this policy. +""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.action=np.asarray(tools.hold_action(),dtype=float) + self.action[19:]=0 + self.phases=[] + neutral=self.action.copy() + neutral[2]=.74;neutral[4]=0;neutral[5:19]=0;neutral[19:]=0 + def add(n,kind,target,yaw): + self.phases.append((n,kind,target,yaw)) + def rack(el,y,g): + p=neutral.copy();p[4]=.4 + p[12:19]=[-.4,0,y,el,0,.1,0];p[20]=g + return p + add(450,'walk',(.15,-.50),1.57) + # The elbow sets rack height; shoulder yaw sweeps toward the cabinet. + # Lower the forearm outside the rack before bringing it back. + for el in (1.3,1.9): + add(100,'rack',rack(0,.7,0),1.57) + add(100,'rack',rack(el,.7,0),1.57) + add(40,'rack',rack(el,.7,1),1.57) + for y in (.3,-.1,-.5,-.9): + add(100,'rack',rack(el,y,1),1.57) + add(40,'rack',rack(el,-.9,0),1.57) + add(100,'rack',rack(0,-.9,0),1.57) + add(100,'pose',neutral,1.57) + # Go around the front corner rather than through the open panel. + for xy in ((-.55,-.50),(-.55,0),(-.12,0)): + add(200,'walk',xy,0) + def front(h,sp,g): + p=neutral.copy();p[2]=h;p[4]=.2;p[19:]=g + for s in (5,12):p[s:s+7]=[sp,0,0,0,0,0,0] + return p + add(180,'pose',front(.60,-.8,0),0) + add(60,'pose',front(.60,-.8,1),0) + add(220,'pose',front(.76,-1.2,1),0) + add(220,'lift',front(.76,-1.7,1),0) + add(180,'lift',front(.76,-1.9,1),0) + add(500,'press',(.2,0),0) + self.phase=0;self.start=0;self.initial=self.action.copy() + + def move(self,obs,raw,target): + p=obs['low_dim_obs'][21:25] + err=np.asarray(target)-p[:2] + c=np.cos(p[3]);s=np.sin(p[3]) + v=2*np.array([c*err[0]+s*err[1],-s*err[0]+c*err[1]]) + if np.linalg.norm(v)<.06:v[:]=0 + raw[:2]=np.clip(v,-.25,.25) + + def act(self,obs,tools): + t=int(obs['t']) + while self.phase=self.phases[self.phase][0]: + self.start+=self.phases[self.phase][0] + self.phase+=1 + self.initial=self.action.copy() + n,kind,target,yaw=self.phases[self.phase] + raw=self.action.copy();raw[:2]=0 + if kind in ('pose','rack','lift'): + u=np.clip((t-self.start)/(n*.75),0,1) + raw[2:]=self.initial[2:]+(target[2:]-self.initial[2:])*u + raw[19:]=target[19:] + if kind=='rack':self.move(obs,raw,(.15,-.50)) + elif kind=='lift':self.move(obs,raw,(.10,0)) + elif kind=='walk': + raw[2]=.74;raw[4]=0;raw[5:19]=0;raw[19:]=0 + self.move(obs,raw,target) + elif kind=='press':self.move(obs,raw,target) + p=obs['low_dim_obs'] + angle=(yaw-float(p[24])+np.pi)%(2*np.pi)-np.pi + raw[3]=np.clip(4*angle,-.6,.6) + self.action=raw.copy() + return raw.astype(np.float32) diff --git a/policies/dishwasher_close/gpt61sol-s3/episodes.csv b/policies/dishwasher_close/gpt61sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt61sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt61sol-s3/policy.py b/policies/dishwasher_close/gpt61sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..ed130ae4e009799b066ce36d3b9e26d3d3166d86 --- /dev/null +++ b/policies/dishwasher_close/gpt61sol-s3/policy.py @@ -0,0 +1,105 @@ +"""Deterministic dishwasher control using body feedback and bounded joint targets.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.action = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.center_y = 0.0 + self.located = False + + def locate(self, obs, tools): + # The appliance is neutral gray and white against the blue floor. + im = tools.image('head').astype(np.int16)[:34] + mask = ((im[:, :, 0] > 130) + & (np.abs(im[:, :, 0]-im[:, :, 1]) < 20) + & (np.abs(im[:, :, 1]-im[:, :, 2]) < 30)) + columns = np.flatnonzero(mask.sum(axis=0) >= 3) + columns = columns[(columns >= 4) & (columns <= 79)] + if len(columns) > 12: + lo, hi = float(columns[0]), float(columns[-1]) + width = hi-lo + lateral = (41.5-(lo+hi)*.5)*.60/max(width, 20.) + self.center_y = float(np.clip(obs['low_dim_obs'][22]+lateral, -.20, .20)) + self.located = True + + def act(self, obs, tools): + t = int(obs['t']) + p = obs['low_dim_obs'][21:25] + if t >= 250 and not self.located: + self.locate(obs, tools) + target = self.action.copy() + target[19:21] = 0.0 + height, pitch = .74, .1 + goal_x, goal_y = -.03, self.center_y-.27 + both = False + anchor = False + + if t < 300: + goal_x, goal_y = -.50, 0. + pitch = 0. + shoulder, elbow = .2, .6 + elif t < 2220: + # Move the central palm through the lower rack's front rail. + k = min(15, (t-300)//120) + shoulder = .2-.4*(k//4) + elbow = .2+.4*(k%4) + elif t < 2900: + # Extend at the upper rail while leaning over the open door. + s = np.clip((t-2320)/450., 0., 1.) + pitch = .7*s + shoulder, elbow = -.7-.8*s, .2+.1*s + goal_x = .02 + elif t < 3180: + goal_x, goal_y = -.10, self.center_y + pitch = 0. + shoulder, elbow = 0., 1.5 + both = True + elif t < 3500: + # Lower the palms beside the front edge before lifting. + goal_x, goal_y = -.10, self.center_y + height, pitch = .4, 0. + shoulder, elbow = 0., 1.5 + both, anchor = True, True + elif t < 4060: + s = np.clip((t-3500)/480., 0., 1.) + height, pitch = .4+.34*s, 0. + shoulder, elbow = -.75*s, 1.5-.2*s + goal_x, goal_y = .04, self.center_y + both = True + anchor = height < .68 + elif t < 4400: + s = np.clip((t-4060)/250., 0., 1.) + pitch = 0. + shoulder, elbow = -.75-.45*s, 1.3 + goal_x, goal_y = .04, self.center_y + both = True + else: + pitch = 0. + shoulder, elbow = -.9, 1.2 + goal_x, goal_y = .20, self.center_y + both = True + + target[2], target[4] = height, pitch + target[5:12] = [shoulder, .10 if both else 0., 0., elbow, 0., 0., 0.] + if both: + target[12:19] = [shoulder, -.10, 0., elbow, 0., 0., 0.] + else: + target[12:19] = [.2, -.4, 0., .4, 0., 0., 0.] + + velocity = np.clip(2.*(np.array([goal_x, goal_y])-p[:2]), -.3, .3) + if 300 <= t < 2900: + velocity[0] = np.clip(4.*(goal_x-p[0]), 0., .85) + c, s = np.cos(p[3]), np.sin(p[3]) + target[:2] = [c*velocity[0]+s*velocity[1], -s*velocity[0]+c*velocity[1]] + if anchor or np.linalg.norm(target[:2]) < .055: + target[:2] = 0. + target[3] = np.clip(-3.*p[3], -.8, .8) + if anchor: + target[3] = 0. + + self.action[:2] = target[:2] + self.action[3] = target[3] + self.action[2] += np.clip(target[2]-self.action[2], -.0025, .0025) + self.action[4:] += np.clip(target[4:]-self.action[4:], -.018, .018) + return self.action.copy() diff --git a/policies/dishwasher_close/gpt61terra-s1/episodes.csv b/policies/dishwasher_close/gpt61terra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt61terra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt61terra-s1/policy.py b/policies/dishwasher_close/gpt61terra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c45f540154598665bcaa36895ce059066801199c --- /dev/null +++ b/policies/dishwasher_close/gpt61terra-s1/policy.py @@ -0,0 +1,54 @@ +"""Deterministic upper-body and base controller for the dishwasher.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = int(obs['t']) + x, y, z, yaw = obs['low_dim_obs'][21:25] + a = self.hold.copy() + a[0:2] = 0 + a[3] = np.clip(-2*yaw, -.4, .4) if abs(yaw) > .025 else 0 + if t < 180: + a[0] = -.2 if x > -.55 else 0 + elif t < 500: + a[1] = .25 if y < .05 else 0 + elif t < 800: + a[0] = .15 if x < -.16 else 0 + elif t < 1500: + a[0] = .12 + if 500 < t < 1500: + elbow = 1.2 if t < 950 else max(0., 1.2-(t-950)/300.) + a[5:12] = [-.5,-.25,0,elbow,0,0,0] + a[12:19] = [-.5,.25,0,elbow,0,0,0] + a[19:21] = 1 + if 1500 <= t < 1750: + a[1] = .12 if y < .02 else 0 + a[5:19] = 0 + if 1750 <= t < 1900: + a[0] = .12 if x < -.05 else 0 + a[5:19] = 0 + if 1900 <= t < 3200: + a[2] = .4 if t < 2200 else min(.8,.4+(t-2200)*.001) + p = .3 if t < 2200 else max(-1.1,.3-(t-2200)*.0025) + a[5:12] = [p,-.25,0,0,0,-.7,0] + a[12:19] = [p,.25,0,0,0,-.7,0] + a[19:21] = 1 + if t >= 3200: + # A second scoop, followed by a forward press at the top of the door. + if t < 3550: + a[2] = .4 + p = .25 + elif t < 4000: + a[2] = min(.8, .4+(t-3550)*.0012) + p = max(-1.2, .25-(t-3550)*.0035) + else: + a[2] = .74 + p = -1.2 + a[0] = .12 + a[5:12] = [p,-.12,0,.2,0,0,0] + a[12:19] = [p,.12,0,.2,0,0,0] + a[19:21] = 1 + return a diff --git a/policies/dishwasher_close/gpt61terra-s2/episodes.csv b/policies/dishwasher_close/gpt61terra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt61terra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt61terra-s2/policy.py b/policies/dishwasher_close/gpt61terra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..8ce2351c1057027da644c2c15159c18b136d1415 --- /dev/null +++ b/policies/dishwasher_close/gpt61terra-s2/policy.py @@ -0,0 +1,74 @@ +"""Deterministic, proprioception-guided dishwasher manipulation.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.initial = np.asarray(tools.hold_action(), dtype=np.float32) + self.phase = 0 + self.start = 0 + + def act(self, obs, tools): + t = int(obs['t']) + x, y, _, yaw = obs['low_dim_obs'][21:25] + a = self.initial.copy() + a[2] = .74 + p = self.phase + elapsed = t - self.start + def change(): + self.phase += 1 + self.start = t + if p == 0: + a[3] = np.clip(2 * (1.57-yaw), -.5, .5) + if yaw > 1.51 or elapsed > 210: change() + elif p == 1: + a[3] = np.clip(2*(1.57-yaw), -.5, .5) + a[0] = .12 if y < -.69 else 0 + if y >= -.69 or elapsed > 140: change() + elif p == 2: + a[3] = np.clip(2*(1.57-yaw), -.5, .5) + a[5] = a[12] = -.8 + a[6] = -.25; a[13] = .25 + a[8] = a[15] = .5 + if elapsed > 80: a[1] = -.16 if x < .45 else 0 + if x > .45 or elapsed > 480: change() + elif p == 3: + a[3] = np.clip(2*(1.57-yaw), -.5, .5) + a[1] = .22 if x > -.7 else 0 + if x <= -.7 or elapsed > 380: change() + elif p == 4: + a[3] = np.clip(2*(1.57-yaw), -.5, .5) + a[0] = .2 if y < .06 else 0 + if y >= .06 or elapsed > 300: change() + elif p == 5: + a[3] = np.clip(-2*yaw, -.5, .5) + if abs(yaw) < .04 or elapsed > 210: change() + elif p == 6: + a[3] = np.clip(-2*yaw, -.4, .4) + a[0] = .16 if x < -.25 else 0 + a[1] = np.clip((.06-y)*1.5, -.2, .2) + if abs(a[1]) < .06: a[1] = 0 + if x >= -.25 or elapsed > 260: change() + elif p == 7: + a[2] = .45 + a[5] = a[12] = 0 if elapsed < 130 else (-.5 if elapsed < 350 else -1.1) + a[6] = -.3; a[13] = .3 + a[8] = a[15] = 0 + a[19] = a[20] = 1 + a[4] = .3 if elapsed > 500 else 0 + if elapsed > 800: change() + elif p == 8: + a[2] = .74 + if elapsed > 100: a[0] = -.14 if x > -.4 else 0 + if elapsed > 260: change() + elif p == 9: + a[2] = .45 if elapsed < 500 else .74 + a[5] = a[12] = 0 if elapsed < 130 else (-.6 if elapsed < 430 else -1.4) + a[6] = -.3; a[13] = .3 + a[8] = a[15] = 0 + a[19] = a[20] = 0 if elapsed < 300 else 1 + if elapsed > 850: change() + else: + a[5] = a[12] = -1.4 + a[6] = -.3; a[13] = .3 + a[19] = a[20] = 1 + return a diff --git a/policies/dishwasher_close/gpt61terra-s3/episodes.csv b/policies/dishwasher_close/gpt61terra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt61terra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt61terra-s3/policy.py b/policies/dishwasher_close/gpt61terra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a52bf3f01c410b35c719fce8336bfb3364f3246b --- /dev/null +++ b/policies/dishwasher_close/gpt61terra-s3/policy.py @@ -0,0 +1,47 @@ +"""Deterministic upper-body and base control for closing the dishwasher.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = int(obs['t']) + x, y, _, yaw = obs['low_dim_obs'][21:25] + a = self.hold.copy() + a[19:21] = 0 + error = 1.57 - float(yaw) + a[3] = np.clip(2 * error, -.5, .5) if abs(error) > .05 else 0 + + # Turn toward the appliance and align with the middle of its opening. + if 190 < t < 450 and x < .40: + a[1] = -.2 + if 450 <= t < 650 and y < -.68: + a[0] = .18 + + # Extend the right arm against the front of the racks in repeated strokes. + if 650 <= t < 2350: + a[2], a[4] = .55, 0 + phase = (t - 650) % 550 + elbow = 1.4 if phase < 150 else max(0., 1.4 - (phase - 150) * .006) + shoulder = -1.35 + a[5:12] = [0, 0, 0, 0, 0, 0, 0] + a[12:19] = [shoulder, 0, 0, elbow, 0, 0, 0] + a[19:21] = 1 + a[0] = 0 + a[1] = np.clip((x - .42) * 1.5, -.2, .2) + + # Back away enough to lower the hands in front of the open door. + elif 2350 <= t < 2600: + a[0] = -.16 if y > -.9 else 0 + + # Reach low, grip, and lift while rising to standing height. + elif t >= 2600: + a[2] = .45 if t < 3600 else min(.8, .45 + (t - 3600) * .0007) + a[4] = .25 + shoulder = -.7 if t < 3100 else max(-1.8, -.7 - (t - 3100) * .002) + a[5:12] = [shoulder, 0, 0, .6, 1.4, 0, 0] + a[12:19] = [shoulder, 0, 0, .6, -1.4, 0, 0] + a[19:21] = 1 + return a diff --git a/policies/dishwasher_close/gpt6sol-s1/episodes.csv b/policies/dishwasher_close/gpt6sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt6sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt6sol-s1/policy.py b/policies/dishwasher_close/gpt6sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..8047385cdd4ef6480fdfc0369066225a293aa559 --- /dev/null +++ b/policies/dishwasher_close/gpt6sol-s1/policy.py @@ -0,0 +1,99 @@ +"""Deterministic position and contact controller for the dishwasher task.""" + +import math +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32) + + def _go(self, x, y, yaw, px, py, speed=0.18): + dx, dy = x - px, y - py + wx = float(np.clip(1.5 * dx, -speed, speed)) + wy = float(np.clip(1.5 * dy, -speed, speed)) + c, s = math.cos(yaw), math.sin(yaw) + vx, vy = c * wx + s * wy, -s * wx + c * wy + if math.hypot(vx, vy) < 0.07: + vx = vy = 0.0 + self.a[0], self.a[1] = vx, vy + + def act(self, obs, tools): + t = int(obs["t"]) + px, py, _, yaw = map(float, obs["low_dim_obs"][21:25]) + a = self.a + a[0] = a[1] = a[3] = 0.0 + if t < 125: + a[0] = 0.2 if px < 0.20 else 0.0 + elif t < 230: + a[3] = 0.8 if yaw < 1.57 else 0.0 + elif t < 320: + a[5:9] = (0.3, 0.0, -0.15, 0.0) + a[12:16] = (0.3, 0.0, 0.15, 0.0) + a[19:21] = 1.0 + elif t < 550: + a[0] = 0.8 if t >= 430 else 0.2 + a[1] = np.clip(1.5 * (px - 0.30), -0.18, 0.18) + a[3] = np.clip(2.0 * (1.57 - yaw), -0.3, 0.3) + if t >= 430: + a[5] = a[12] = 0.3 - 0.7 * min(1.0, (t - 430) / 100.0) + elif t < 610: + a[5:9] = 0.0 + a[12:16] = 0.0 + a[19:21] = 0.6 + elif t < 820: + self._go(0.20, -0.756, yaw, px, py) + a[3] = np.clip(2.0 * (1.60 - yaw), -0.25, 0.25) + elif t < 1000: + a[1] = np.clip(2.0 * (px - 0.35), -0.18, 0.18) + a[3] = np.clip(3.0 * (1.57 - yaw), -0.3, 0.3) + elif t < 1080: + a[5:9] = (-0.4, 0.0, -0.15, 0.0) + a[12:16] = (-0.4, 0.0, 0.15, 0.0) + a[19:21] = 1.0 + elif t < 1250: + a[0] = 0.2 if t < 1130 else 0.8 + a[1] = np.clip(2.0 * (px - 0.35), -0.18, 0.18) + a[3] = np.clip(3.0 * (1.57 - yaw), -0.4, 0.4) + if t >= 1130: + a[5] = a[12] = -0.4 - 0.8 * min(1.0, (t - 1130) / 100.0) + elif t < 1300: + a[5:9] = 0.0 + a[12:16] = 0.0 + a[19:21] = 0.6 + elif t < 1500: + self._go(0.20, -0.756, yaw, px, py) + a[3] = np.clip(2.0 * (1.60 - yaw), -0.25, 0.25) + elif t < 1740: + a[0] = 0.2 if py < -0.53 else 0.0 + a[1] = np.clip(2.0 * (px - 0.23), -0.18, 0.18) + a[3] = np.clip(4.0 * (1.57 - yaw), -0.5, 0.5) + elif t < 1890: + a[2] = 0.4 + elif t < 2050: + a[2] = 0.4 + a[5:9] = (0.3, 0.0, -0.25, 0.8) + a[12:16] = (0.3, 0.0, 0.15, 0.8) + a[19:21] = 0.0 if t < 1980 else 1.0 + elif t < 2300: + f = min(1.0, (t - 2050) / 250.0) + a[2] = 0.4 + 0.45 * f + a[0] = 0.15 + a[3] = np.clip(3.0 * (1.57 - yaw), -0.4, 0.4) + a[5] = a[12] = 0.3 - 0.8 * f + a[8] = a[15] = 0.8 * (1.0 - f) + elif t < 2550: + a[2] = 0.74 + a[0] = 0.2 + a[3] = np.clip(3.0 * (1.57 - yaw), -0.4, 0.4) + a[5] = a[12] = -0.5 + a[8] = a[15] = 0.0 + else: + a[2] = 0.74 + a[4] = 0.0 + a[0] = 0.25 if py < -0.48 else 0.0 + a[3] = np.clip(3.0 * (1.57 - yaw), -0.4, 0.4) + a[5:9] = (-0.45, 0.0, -0.15, 0.0) + a[12:16] = (-0.45, 0.0, 0.15, 0.0) + a[19:21] = 0.6 + return a.copy() diff --git a/policies/dishwasher_close/gpt6sol-s2/episodes.csv b/policies/dishwasher_close/gpt6sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt6sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt6sol-s2/policy.py b/policies/dishwasher_close/gpt6sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..5cd2b22959255e71d1ea56636cbcd5aab1409034 --- /dev/null +++ b/policies/dishwasher_close/gpt6sol-s2/policy.py @@ -0,0 +1,139 @@ +"""Deterministic hand-written dishwasher manipulation policy.""" + +import math +import numpy as np + + +class Policy: + def reset(self, obs, tools): + pass + + @staticmethod + def arm(a, left=None, right=None): + if left is not None: + a[5:12] = left + if right is not None: + a[12:19] = right + + @staticmethod + def move(a, q, xgoal, ygoal, yawgoal, speed=0.24): + x, y, yaw = float(q[21]), float(q[22]), float(q[24]) + wx = float(np.clip(1.7 * (xgoal - x), -speed, speed)) + wy = float(np.clip(1.7 * (ygoal - y), -speed, speed)) + if abs(xgoal - x) < 0.025: + wx = 0.0 + if abs(ygoal - y) < 0.025: + wy = 0.0 + vx = math.cos(yaw) * wx + math.sin(yaw) * wy + vy = -math.sin(yaw) * wx + math.cos(yaw) * wy + if 0 < math.hypot(vx, vy) < 0.06: + vx, vy = 0.0, 0.0 + a[0], a[1] = vx, vy + e = math.atan2(math.sin(yawgoal - yaw), math.cos(yawgoal - yaw)) + a[3] = float(np.clip(2.3 * e, -0.55, 0.55)) if abs(e) > 0.025 else 0.0 + + @staticmethod + def press(a, q, xgoal, yawgoal, wy): + x, yaw = float(q[21]), float(q[24]) + wx = float(np.clip(2.0 * (xgoal - x), -0.18, 0.18)) + a[0] = math.cos(yaw) * wx + math.sin(yaw) * wy + a[1] = -math.sin(yaw) * wx + math.cos(yaw) * wy + e = math.atan2(math.sin(yawgoal - yaw), math.cos(yawgoal - yaw)) + a[3] = float(np.clip(2.3 * e, -0.5, 0.5)) + + def act(self, obs, tools): + t = int(obs["t"]) + q = obs["low_dim_obs"] + a = np.zeros(21, dtype=np.float32) + a[2] = 0.74 + a[19:21] = 0.6 + + if t < 110: + self.move(a, q, 0.26, -0.8, 0.0, 0.2) + elif t < 245: + self.move(a, q, 0.26, -0.8, 1.27, 0.12) + elif t < 390: + self.move(a, q, 0.30, -0.59, 1.27, 0.18) + self.arm(a, right=[-0.2, 0, 0.3, -0.2, 0, 0.5, 0]) + a[20] = 0 + elif t < 440: + self.press(a, q, 0.30, 1.27, 0.1) + self.arm(a, right=[-0.2, 0, 0.3, -0.2, 0, 0.5, 0]) + a[20] = 1 + elif t < 700: + f = min(1.0, (t - 440) / 170) + self.press(a, q, 0.30, 1.27, 0.28) + a[4] = 0.15 * f + self.arm(a, right=[-0.2, 0, 0.3, -0.2, 0, 0.5, 0]) + a[20] = 1 + elif t < 800: + self.move(a, q, 0.30, -0.77, 1.27, 0.18) + a[19:21] = 0 + elif t < 940: + self.move(a, q, 0.30, -0.59, 1.27, 0.15) + a[2] = 0.68 + self.arm(a, right=[-0.5, 0, 0, 0.25, 0, 0.5, 0]) + a[20] = 0 + elif t < 990: + self.press(a, q, 0.30, 1.27, 0.1) + a[2] = 0.68 + self.arm(a, right=[-0.5, 0, 0, 0.25, 0, 0.5, 0]) + a[20] = 1 + elif t < 1260: + f = min(1.0, (t - 990) / 160) + self.press(a, q, 0.30, 1.27, 0.28) + a[2], a[4] = 0.68, 0.20*f + self.arm(a, right=[-0.5, 0, 0, 0.25 - 0.5*f, 0, 0.5, 0]) + a[20] = 1 + elif t < 1390: + self.move(a, q, 0.43, -0.80, 1.57, 0.19) + a[19:21] = 0 + elif t < 1550: + self.press(a, q, 0.43, 1.57, 0.24) + self.arm(a, [-0.7, 0, -0.2, 1, 0, 0.5, 0], [-0.7, 0, 0.2, 1, 0, 0.5, 0]) + a[19:21] = 1 if t >= 1500 else 0 + elif t < 1790: + f = min(1.0, (t - 1550) / 160) + self.press(a, q, 0.43, 1.57, 0.28) + a[4] = 0.2*f + self.arm(a, [-0.7, 0, -0.2, 1-1.4*f, 0, 0.5, 0], [-0.7, 0, 0.2, 1-1.4*f, 0, 0.5, 0]) + a[19:21] = 1 + elif t < 1950: + self.move(a, q, 0.43, -0.62, 1.57, 0.2) + a[19:21] = 0 + elif t < 2070: + a[2], a[4] = 0.42, 0.6 + self.arm(a, [0, 0, -0.15, 0, 0, 1, 0], [0, 0, 0.15, 0, 0, 1, 0]) + a[19:21] = 0 if t < 2030 else 1 + elif t < 2410: + f = min(1.0, (t - 2070) / 230) + a[2], a[4] = 0.42 + 0.32*f, 0.6*(1-f) + self.arm(a, [-1.2*f, 0, -0.15, 0, 0, 1, 0], [-1.2*f, 0, 0.15, 0, 0, 1, 0]) + a[19:21] = 1 + elif t < 2670: + self.press(a, q, 0.43, 1.57, 0.22) + self.arm(a, [-1.2, 0, -0.15, 0, 0, 0.5, 0], [-1.2, 0, 0.15, 0, 0, 0.5, 0]) + a[19:21] = 1 + elif t < 2890: + self.move(a, q, 0.25, -0.82, 1.32, 0.18) + a[19:21] = 0 + elif t < 3170: + f = min(1.0, (t - 2890) / 180) + self.press(a, q, 0.25, 1.32, 0.3) + a[2] = 0.68 + self.arm(a, [-0.65, 0, -0.35, 0.8-1.1*f, 0, 0.5, 0], [-0.65, 0, 0.35, 0.8-1.1*f, 0, 0.5, 0]) + a[19:21] = 1 + elif t < 3380: + self.move(a, q, 0.40, -0.62, 1.57, 0.17) + a[19:21] = 0 + elif t < 3800: + f = min(1.0, max(0.0, (t - 3460) / 250)) + a[2], a[4] = 0.42 + 0.32*f, 0.6*(1-f) + self.arm(a, [-1.2*f, 0, -0.2, 0, 0, 1, 0], [-1.2*f, 0, 0.2, 0, 0, 1, 0]) + a[19:21] = 0 if t < 3460 else 1 + else: + self.press(a, q, 0.43, 1.57, 0.8) + a[4] = 0.5 + self.arm(a, [-0.2, 0, -0.7, -0.7, 0, 0.5, 0], [-0.2, 0, 0.7, -0.7, 0, 0.5, 0]) + a[19:21] = 1 + return a diff --git a/policies/dishwasher_close/gpt6sol-s3/episodes.csv b/policies/dishwasher_close/gpt6sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/gpt6sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/gpt6sol-s3/policy.py b/policies/dishwasher_close/gpt6sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..374a16c46fd75af83b1987dac5cb27a46793846f --- /dev/null +++ b/policies/dishwasher_close/gpt6sol-s3/policy.py @@ -0,0 +1,100 @@ +"""Deterministic dishwasher rack and door controller.""" + +import numpy as np + + +def ramp(t, start, end): + return float(np.clip((t - start) / (end - start), 0.0, 1.0)) + + +class Policy: + def reset(self, obs, tools): + self.home = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = int(obs["t"]) + body = obs["low_dim_obs"] + a = self.home.copy() + a[19:21] = 0 + + # Walk around the open door to face the rack fronts. + if t < 100: + a[0], a[1] = .17, .22 + return a + if t < 225: + a[3] = .8 + return a + + if t < 1460 or 1890 <= t < 2050: + a[3] = float(np.clip(2 * (1.57 - body[24]), -.35, .35)) + + # First upper rack contact. + if t < 300: + a[2] = .8 + a[5] = a[12] = -1.2 + a[8] = a[15] = 1.5 + a[19:21] = 0 if t < 270 else 1 + elif t < 500: + p = ramp(t, 300, 455) + a[0], a[2] = .2, .8 - .2 * p + a[5] = a[12] = -1.2 + a[8] = a[15] = 1.5 * (1 - p) + a[19:21] = 1 + elif t < 575: + a[2] = .74 + # Two more strokes while releasing the handle between strokes. + elif t < 1050: + if t < 775: + start = 575 + elif t < 850: + a[2] = .74 + return a + else: + start = 850 + p = ramp(t, start + 35, start + 170) + a[2], a[4] = .8 - .17 * p, .2 + a[5] = a[12] = -1.0 + a[8] = a[15] = 1.5 * (1 - p) + a[19:21] = 0 if t < start + 25 else 1 + a[0] = .4 if t >= start + 35 else 0 + elif t < 1125: + a[2] = .74 + # Lower rack contact. + elif t < 1195: + a[2] = .58 + a[5] = a[12] = -.8 + a[8] = a[15] = 1.5 + a[19:21] = 0 if t < 1165 else 1 + elif t < 1390: + p = ramp(t, 1195, 1355) + a[0], a[2] = .3, .58 - .18 * p + a[5] = a[12] = -.8 + a[8] = a[15] = 1.5 * (1 - p) + a[19:21] = 1 + elif t < 1460: + a[2] = .74 + # Get close to the free edge of the open door and lift it. + elif t < 1560: + if body[22] < -.55: + a[0] = .2 + a[3] = float(np.clip(2 * (1.57 - body[24]), -.3, .3)) + elif t < 1670: + a[2], a[4] = .4, .7 + a[5] = a[12] = -.1 + elif t < 1730: + a[2], a[4] = .4, .7 + a[5] = a[12] = -.1 + a[19:21] = 1 + elif t < 1890: + p = ramp(t, 1730, 1860) + a[2], a[4] = .4 + .5 * p, .7 - .4 * p + a[5] = a[12] = -.1 - .55 * p + a[19:21] = 1 + elif t < 2050: + a[0], a[2], a[4] = .2, .8, .3 + a[5] = a[12] = -.7 + a[19:21] = 1 + else: + a[2] = .74 + a[5] = a[12] = -.4 + return a diff --git a/policies/dishwasher_close/kimi31pro-s1/episodes.csv b/policies/dishwasher_close/kimi31pro-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/kimi31pro-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/kimi31pro-s1/policy.py b/policies/dishwasher_close/kimi31pro-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..f874962d2a32ffcc3815267e409b18aa218ec2f0 --- /dev/null +++ b/policies/dishwasher_close/kimi31pro-s1/policy.py @@ -0,0 +1,172 @@ +"""Deterministic, hand-written dishwasher closing controller. + +The controller uses a retracted-arm approach, two staged rack insertions, and +an immediate one-handed door lift. A small amount of head-camera centering is +used before contact; all manipulation thereafter uses joint and base feedback. +""" + +import cv2 +import numpy as np + + +BACK = np.array([0.65, 0.0, 0.0, 0.45, 0.0, 0.0, 0.0]) +HIGH = np.array([-0.90, 0.0, 0.0, 0.65, 0.0, 0.0, 0.0]) +LOW1 = np.array([-1.15, 0.0, 0.0, 0.45, 0.0, 0.0, 0.0]) +LOW2 = np.array([-1.35, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0]) +UPPER = np.array([-0.55, 0.0, 0.0, 0.65, 0.0, 0.0, 0.0]) +UP2 = np.array([-0.85, 0.0, 0.0, 0.45, 0.0, 0.0, 0.0]) +UP3 = np.array([-1.00, 0.0, 0.0, 0.30, 0.0, 0.0, 0.0]) +DOOR = np.array([-0.20, 0.0, 0.25, 0.20, 0.0, 0.0, 0.0]) + + +def blend(a, b, u): + u = float(np.clip(u, 0.0, 1.0)) + return (1.0 - u) * a + u * b + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.t = 0 + self.x_goal = 0.34 + self.yaw_goal = 1.55 + self.centered = False + + def _center_from_head(self, tools): + """Make a small, one-shot correction for seed-to-seed placement.""" + self.centered = True + try: + im = tools.image("head") + gray = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY) + mask = ((gray < 65).astype(np.uint8))[5:65, :] + n, _, stats, cents = cv2.connectedComponentsWithStats(mask, 8) + candidates = [] + for j in range(1, n): + x, y, w, h, area = stats[j] + if area >= 12 and w >= 3: + candidates.append((area, cents[j][0])) + if candidates: + cx = max(candidates)[1] + err = float(np.clip(cx - 42.0, -18.0, 18.0)) + self.x_goal = float(np.clip(0.34 + 0.008 * err, 0.18, 0.50)) + self.yaw_goal = float(np.clip(1.55 - 0.008 * err, 1.38, 1.72)) + except Exception: + # The nominal stance is always a valid deterministic fallback. + self.x_goal = 0.34 + self.yaw_goal = 1.55 + + def _drive_to(self, raw, p, target, speed=0.18): + yaw = p[3] + dp = np.asarray(target) - p[:2] + dist = float(np.linalg.norm(dp)) + if dist > 0.025: + c, s = np.cos(yaw), np.sin(yaw) + vx = c * dp[0] + s * dp[1] + vy = -s * dp[0] + c * dp[1] + scale = min(speed, 0.9 * dist) / max(dist, 1e-6) + raw[0] = np.clip(vx * scale, -speed, speed) + raw[1] = np.clip(vy * scale, -speed, speed) + planar = float(np.hypot(raw[0], raw[1])) + if 0.0 < planar < 0.06: + raw[0] *= 0.06 / planar + raw[1] *= 0.06 / planar + + def act(self, obs, tools): + t = self.t + self.t += 1 + q = obs["low_dim_obs"] + p = q[21:25] + yaw = p[3] + raw = self.hold.copy() + raw[19:21] = 0.0 + raw[2] = 0.74 + raw[4] = 0.0 + + if t == 340 and not self.centered: + self._center_from_head(tools) + + # Base approach, with the arms safely retracted. + ye = (self.yaw_goal - yaw + np.pi) % (2.0 * np.pi) - np.pi + raw[3] = np.clip(2.0 * ye, -0.5, 0.5) + if abs(ye) < 0.025: + raw[3] = 0.0 + if 70 <= t < 530: + if t < 170: + ty = -0.79 + elif t < 350: + ty = -0.65 + else: + ty = -0.85 + self._drive_to(raw, p, [self.x_goal, ty]) + elif 530 <= t < 630: + raw[0] = 0.12 + elif 630 <= t < 1120: + raw[0] = 0.40 + elif 1120 <= t < 1180: + self._drive_to(raw, p, [self.x_goal, -0.75]) + elif 1180 <= t < 1650: + raw[0] = 0.40 + elif 1650 <= t < 2080: + self._drive_to(raw, p, [self.x_goal, -0.55]) + elif t >= 2080: + raw[0] = 0.40 + + # Arm trajectories for the two racks. + arms = BACK * min(1.0, (t + 1) / 60.0) + right = None + if 450 <= t < 530: + arms = blend(BACK, HIGH, (t - 450) / 80.0) + elif 530 <= t < 800: + arms = HIGH + elif 800 <= t < 960: + u = (t - 800) / 160.0 + arms = blend(HIGH, LOW1, u) + raw[4] = 0.30 * u + elif 960 <= t < 1120: + u = (t - 960) / 160.0 + arms = blend(LOW1, LOW2, u) + raw[4] = 0.30 + 0.20 * u + elif 1120 <= t < 1330: + arms = UPPER + elif 1330 <= t < 1490: + u = (t - 1330) / 160.0 + arms = blend(UPPER, UP2, u) + raw[4] = 0.30 * u + elif 1490 <= t < 1650: + u = (t - 1490) / 160.0 + arms = blend(UP2, UP3, u) + raw[4] = 0.30 + 0.10 * u + elif 1650 <= t < 2080: + # Keep the left hand on the racks so they cannot roll back out. + arms = UP3 + if t < 1780: + u = (t - 1650) / 130.0 + right = blend(UP3, DOOR, u) + raw[4] = 0.40 - 0.10 * u + raw[2] = 0.74 - 0.19 * u + else: + u = (t - 1780) / 300.0 + right = blend(DOOR, HIGH, u) + raw[4] = 0.30 * (1.0 - u) + raw[2] = 0.55 + 0.19 * u + elif t >= 2080: + arms = BACK + right = HIGH + raw[5:12] = arms + raw[12:19] = arms if right is None else right + if t >= 1650: + raw[14] = 0.25 + if 530 <= t < 1120: + raw[2] = 0.66 + + # Maintain rack contact through the door transition. + if 600 <= t < 1120: + raw[19:21] = 1.0 + if 1160 <= t < 1650: + raw[19:21] = 1.0 + if 1650 <= t < 2080: + raw[19:21] = 1.0 + elif t >= 2080: + raw[19] = 0.0 + raw[20] = 1.0 + return raw diff --git a/policies/dishwasher_close/kimi31pro-s2/episodes.csv b/policies/dishwasher_close/kimi31pro-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/kimi31pro-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/kimi31pro-s2/policy.py b/policies/dishwasher_close/kimi31pro-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..3254ddabc0bf1969dadc4beddcb64cb43a06245f --- /dev/null +++ b/policies/dishwasher_close/kimi31pro-s2/policy.py @@ -0,0 +1,107 @@ +"""Hand-written deterministic controller for the dishwasher task.""" + +import math + +import numpy as np + + +class Policy: + """Push the racks, align with the door, and lift it while standing.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.k = 0 + self.phase_name = "" + # name, duration, pelvis height, torso pitch, shoulder pitch, elbow, vx + self.phases = [ + ("turn", 80, 0.74, 0.0, 0.0, 0.0, 0.0), + ("upper_prepare", 50, 0.74, 0.0, -1.0, 0.8, 0.0), + ("upper_push", 260, 0.74, 0.0, -1.0, 0.8, 0.12), + ("upper_hold", 30, 0.74, 0.0, -1.0, 0.8, 0.0), + ("upper_retract", 60, 0.74, 0.0, -1.2, 0.2, -0.10), + ("reposition", 140, 0.74, 0.0, -0.6, 0.5, 0.0), + ("door_align", 100, 0.40, 0.20, -0.7, 0.7, 0.0), + ("door_close", 320, 0.74, 0.0, -1.45, 1.4, 0.0), + ("door_hold", 100, 0.74, 0.0, -1.45, 1.4, 0.0), + ("release_inspect", 80, 0.74, 0.0, 0.0, 0.0, 0.0), + ("hold_closed", 4650, 0.74, 0.0, 0.0, 0.0, 0.0), + ] + self.starts = np.cumsum([0] + [p[1] for p in self.phases[:-1]]) + self.reposition_index = 5 + + def position_servo(self, raw, obs): + """Servo toward the measured door-alignment base position.""" + p = obs["low_dim_obs"] + yaw = float(p[24]) + dx = 0.125 - float(p[21]) + dy = -0.755 - float(p[22]) + c, s = math.cos(yaw), math.sin(yaw) + raw[0] = 1.5 * (c * dx + s * dy) + raw[1] = 1.5 * (-s * dx + c * dy) + speed = math.hypot(float(raw[0]), float(raw[1])) + distance = math.hypot(dx, dy) + if speed > 0.10: + raw[0] *= 0.10 / speed + raw[1] *= 0.10 / speed + elif speed < 0.06 and distance > 0.008: + raw[0] *= 0.06 / max(speed, 1e-6) + raw[1] *= 0.06 / max(speed, 1e-6) + elif distance <= 0.008: + raw[0] = raw[1] = 0.0 + + def act(self, obs, tools): + k = self.k + self.k += 1 + i = int(np.searchsorted(self.starts, k, side="right") - 1) + i = min(i, len(self.phases) - 1) + name, duration, height, pitch, shoulder, elbow, vx = self.phases[i] + self.phase_name = name + local = k - int(self.starts[i]) + + raw = self.hold.copy() + raw[2] = height + raw[4] = pitch + raw[5] = raw[12] = shoulder + raw[8] = raw[15] = elbow + raw[19:21] = 0.0 + + yaw = float(obs["low_dim_obs"][24]) + target_yaw = 1.30 if i >= self.reposition_index else 0.95 + quiet_yaw = { + "door_align", "door_close", "door_hold", + "release_inspect", "hold_closed", + } + raw[3] = ( + 0.0 if name in quiet_yaw + else float(np.clip(3.0 * (target_yaw - yaw), -0.55, 0.55)) + ) + + if name == "upper_push": + raw[0] = vx + elif name == "upper_retract": + raw[0] = vx if local < 40 else 0.0 + elif name == "reposition": + self.position_servo(raw, obs) + else: + raw[0] = 0.0 + + if name in ("door_close", "door_hold"): + t = local if name == "door_close" else 319 + if t < 80: + # Engage the underside with a vertical lift. + v = (t + 1) / 80.0 + raw[2] = 0.40 + 0.12 * v + raw[4] = 0.20 + raw[10] = raw[17] = 0.0 + shoulder, elbow = -0.7, 0.7 + else: + # Rotate the wrists with the panel as the robot stands. + v = min(1.0, (t - 79) / 240.0) + raw[2] = 0.52 + 0.22 * v + raw[4] = 0.20 * (1.0 - v) + raw[10] = raw[17] = -1.20 * v + shoulder = -0.7 - 0.75 * v + elbow = 0.7 + 0.7 * v + raw[5] = raw[12] = shoulder + raw[8] = raw[15] = elbow + return raw diff --git a/policies/dishwasher_close/kimi31pro-s3/episodes.csv b/policies/dishwasher_close/kimi31pro-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/kimi31pro-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/kimi31pro-s3/policy.py b/policies/dishwasher_close/kimi31pro-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..f84e8c23de52299758d894a6f2ba6873ed02f94d --- /dev/null +++ b/policies/dishwasher_close/kimi31pro-s3/policy.py @@ -0,0 +1,103 @@ +"""Deterministic joint-space controller for the dishwasher task.""" + +import numpy as np + + +class Policy: + """Hand-written, staged control using proprioceptive base feedback.""" + + DEFAULTS = { + "target_x": 0.22, + "target_y": -0.65, + "ready_sp": -0.90, + "ready_roll": 0.45, + "ready_yaw": 0.0, + "ready_elbow": 0.40, + "ready_wrist": 0.0, + "ready_wr": 0.0, + "contact_sp": -0.15, + "contact_roll": 0.45, + "contact_yaw": 0.0, + "contact_elbow": 0.0, + "contact_wrist": 0.0, + "contact_wr": 0.0, + "push_sp": -0.85, + "push_roll": 0.45, + "push_yaw": 0.0, + "push_elbow": 0.55, + "push_wrist": 0.0, + "push_wr": 0.0, + "both": False, + "gripper": 0.6, + "height": 0.74, + "torso": 0.0, + "retract": False, + "stand_after": False, + "release": False, + "close_during_push": False, + } + + def __init__(self): + self.config = dict(self.DEFAULTS) + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + @staticmethod + def _blend(t, start, duration): + return float(np.clip((t - start) / float(duration), 0.0, 1.0)) + + @staticmethod + def _mix(a, b, u): + return (1.0 - u) * np.asarray(a) + u * np.asarray(b) + + def _lower_rack_arm(self, t): + c = self.config + ready = np.array([c["ready_sp"], c["ready_roll"], c["ready_yaw"], + c["ready_elbow"], c["ready_wr"], c["ready_wrist"], 0.0]) + contact = np.array([c["contact_sp"], c["contact_roll"], c["contact_yaw"], + c["contact_elbow"], c["contact_wr"], c["contact_wrist"], 0.0]) + push = np.array([c["push_sp"], c["push_roll"], c["push_yaw"], + c["push_elbow"], c["push_wr"], c["push_wrist"], 0.0]) + if t < 250: + return self._mix(np.zeros(7), ready, self._blend(t, 20, 100)) + if t < 400: + return self._mix(ready, contact, self._blend(t, 250, 150)) + pushed = self._mix(contact, push, self._blend(t, 400, 250)) + if c["retract"] and t >= 650: + return self._mix(push, np.zeros(7), self._blend(t, 650, 150)) + return pushed + + def act(self, obs, tools): + t = int(obs["t"]) + q = np.asarray(obs["low_dim_obs"]) + raw = self.hold.copy() + c = self.config + + # Turn first, then servo the pelvis to the fixed appliance stance. + x, y, _, yaw = q[21:25] + yaw_error = (np.pi / 2 - yaw + np.pi) % (2 * np.pi) - np.pi + raw[3] = np.clip(2.0 * yaw_error, -0.6, 0.6) + if t > 100 and abs(yaw_error) < 0.3: + dx, dy = c["target_x"] - x, c["target_y"] - y + co, si = np.cos(yaw), np.sin(yaw) + raw[0] = np.clip(2.0 * (co * dx + si * dy), -0.15, 0.15) + raw[1] = np.clip(2.0 * (-si * dx + co * dy), -0.15, 0.15) + if abs(raw[0]) < 0.06: + raw[0] = 0.0 + if abs(raw[1]) < 0.06: + raw[1] = 0.0 + + arm = self._lower_rack_arm(t) + body_blend = self._blend(t, 200, 150) + if c["stand_after"] and t >= 800: + body_blend *= 1.0 - self._blend(t, 800, 150) + raw[2] = 0.74 + body_blend * (c["height"] - 0.74) + raw[4] = body_blend * c["torso"] + raw[12:19] = arm + if c["both"]: + raw[5:12] = arm + raw[19:21] = 0.0 if c["release"] and t >= 650 else c["gripper"] + if c["close_during_push"] and 400 <= t < 650: + raw[19:21] = 1.0 + return raw diff --git a/policies/dishwasher_close/opus-s1/episodes.csv b/policies/dishwasher_close/opus-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/opus-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/opus-s1/policy.py b/policies/dishwasher_close/opus-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..60716822f0aa4f9e08f09f625efe61cad8347279 --- /dev/null +++ b/policies/dishwasher_close/opus-s1/policy.py @@ -0,0 +1,161 @@ +"""Dishwasher close policy for the G1: push the racks in, then lift and push the door shut. + +Scripted sequence of phases, all closed-loop on the pelvis pose from low_dim_obs: + 1. walk beside the dishwasher (facing +y) and push the upper rack in by side-stepping + with the left hand inside the rack, + 2. walk in front of the open door (facing +x), squat and push the lower rack in low, + 3. squat again with hands under the door tip, stand up lifting the door, + 4. walk forward pressing the door closed and hold. +""" + +import numpy as np + +YAW_SIDE = np.pi / 2 + +# planar arm model (sagittal plane), pelvis-relative +SH = 0.30 # pelvis -> shoulder height +L1, L2 = 0.20, 0.30 +EL_MAX = 1.5 # elbow: pi/2 = straight arm, 0 = right angle + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +def ik(hx, hz, pz, pitch): + """Hand target (forward of pelvis, world height) -> shoulder pitch, elbow.""" + sx, sz = SH * np.sin(pitch), pz + SH * np.cos(pitch) + dx, dz = hx - sx, hz - sz + d = np.hypot(dx, dz) + bmin = np.pi / 2 - EL_MAX + dmax = np.sqrt(L1 ** 2 + L2 ** 2 + 2 * L1 * L2 * np.cos(bmin)) + d = min(d, dmax - 1e-4) + c = (L1 ** 2 + L2 ** 2 - d ** 2) / (2 * L1 * L2) + bend = np.pi - np.arccos(np.clip(c, -1, 1)) + phi = np.arctan2(dx, -dz) + off = np.arcsin(np.clip(L2 * np.sin(bend) / max(d, 1e-6), -1, 1)) + a1 = phi - off + return -(a1 - pitch), np.pi / 2 - bend + + +def arm(sp, sr, sy, el, wr=0.0, wp=0.0, wy=0.0): + return [sp, sr, sy, el, wr, wp, wy] + + +REST = (arm(0.3, 0.2, 0, 1.2), arm(0.3, -0.2, 0, 1.2)) +TUCK = (arm(0.5, 0.15, 0, 1.4), arm(0.5, -0.15, 0, 1.4)) +RL = -0.12 + +STEPS = [ + # upper rack: from the side, left hand in the rack, side-step toward +x + dict(kind='nav', x=-0.25, y=-0.62, yaw=YAW_SIDE), + dict(kind='nav', x=-0.25, y=-0.5, yaw=YAW_SIDE), + dict(kind='pose', n=50, hands=(0.3, 0.84, 0.42, 0.72), roll=0.1, only='L'), + dict(kind='pose', n=560, base=(0.0, -0.1), yaw=YAW_SIDE, yhold=-0.5), + dict(kind='pose', n=40, hands=(0.42, 0.72, 0.3, 1.05), roll=0.1, only='L'), + dict(kind='pose', n=30, arms=REST), + # lower rack: in front of the door, squat and push low + dict(kind='nav', x=-0.45, y=-0.6, yaw=0.0), + dict(kind='nav', x=-0.45, y=0.0, yaw=0.0), + dict(kind='nav', x=-0.2, y=0.0, yaw=0.0, vmax=0.12), + dict(kind='pose', n=60, h=0.45, p=0.7, hands=(0.3, 0.84, 0.2, 0.5), roll=0.0), + dict(kind='pose', n=30, hands=(0.2, 0.5, 0.2, 0.25), roll=0.0), + dict(kind='pose', n=120, hands=(0.2, 0.25, 0.8, 0.25), roll=0.0), + dict(kind='pose', n=30, hands=(0.8, 0.25, 0.3, 0.6), roll=0.0), + dict(kind='pose', n=60, h=0.74, p=0.0, arms=REST), + dict(kind='nav', x=-0.2, y=0.0, yaw=0.0, vmax=0.12), + # door: hands under the tip, stand up lifting it + dict(kind='pose', n=60, h=0.5, p=0.3, hands=(0.3, 0.84, 0.15, 0.45), roll=RL), + dict(kind='pose', n=80, hands=(0.15, 0.45, 0.32, 0.45), roll=RL), + dict(kind='pose', n=200, h=0.74, p=0.0, hands=(0.32, 0.45, 0.35, 0.72), roll=RL, + base=(0.08, 0.0), yaw=0.0, yline=0.0), + dict(kind='pose', n=100, hands=(0.35, 0.72, 0.45, 1.0), roll=RL, + base=(0.1, 0.0), yaw=0.0, yline=0.0), + # push it shut while walking in + dict(kind='pose', n=150, p=0.4, hands=(0.45, 1.0, 0.62, 0.85), roll=RL, + base=(0.1, 0.0), yaw=0.0, yline=0.0), + dict(kind='pose', n=200, base=(0.12, 0.0), yaw=0.0, yline=0.0), + # final shove: lean further and straighten the arms at door-face height + dict(kind='pose', n=150, p=0.65, hands=(0.62, 0.85, 0.85, 0.75), roll=RL, + base=(0.12, 0.0), yaw=0.0, yline=0.0), + dict(kind='pose', n=10 ** 6, base=(0.12, 0.0), yaw=0.0, yline=0.0), +] + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.steps = [dict(s) for s in STEPS] + self.i = 0 + self.k = 0 + self.L, self.R = list(REST[0]), list(REST[1]) + self.h, self.p = 0.74, 0.0 + self.tgt = None + + def nav(self, o, tx, ty, tyaw, a, vmax=None): + x, y, yaw = o[21], o[22], o[24] + vmax = vmax or 0.25 + dx, dy = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + bx, by = c * dx + s * dy, -s * dx + c * dy + d = np.hypot(bx, by) + ey = wrap(tyaw - yaw) + a[3] = np.clip(1.5 * ey, -0.6, 0.6) + if abs(a[3]) < 0.06: + a[3] = 0.0 if abs(ey) < 0.03 else 0.06 * np.sign(ey) + if d > 0.03: + v = np.clip(1.2 * d, 0.08, vmax) + a[0], a[1] = v * bx / d, v * by / d + return d < 0.03 and abs(ey) < 0.05 + + def act(self, obs, tools): + o = obs['low_dim_obs'] + a = self.hold.copy() + a[2], a[4] = self.h, self.p + a[5:12], a[12:19] = self.L, self.R + st = self.steps[self.i] + if st['kind'] == 'nav': + self.tgt = (st['x'], st['y'], st['yaw']) + if self.nav(o, st['x'], st['y'], st['yaw'], a, st.get('vmax')): + self.i += 1 + self.k = 0 + return a + n = st['n'] + s = min(1.0, (self.k + 1) / n) + if self.k == 0: + st['_h0'], st['_p0'] = self.h, self.p + st['_L0'], st['_R0'] = list(self.L), list(self.R) + h0, p0 = st['_h0'], st['_p0'] + a[2] = h0 + (st.get('h', h0) - h0) * s + a[4] = p0 + (st.get('p', p0) - p0) * s + if 'hands' in st: + hx0, hz0, hx1, hz1 = st['hands'] + sp, el = ik(hx0 + (hx1 - hx0) * s, hz0 + (hz1 - hz0) * s, a[2], a[4]) + r = st.get('roll', 0.15) + L, R = arm(sp, r, 0, el), arm(sp, -r, 0, el) + if st.get('only') == 'L': + R = st['_R0'] + elif 'arms' in st: + L = [x0 + (x1 - x0) * s for x0, x1 in zip(st['_L0'], st['arms'][0])] + R = [x0 + (x1 - x0) * s for x0, x1 in zip(st['_R0'], st['arms'][1])] + else: + L, R = st['_L0'], st['_R0'] + a[5:12], a[12:19] = L, R + if 'base' in st: + a[0], a[1] = st['base'] + a[3] = np.clip(1.5 * wrap(st['yaw'] - o[24]), -0.3, 0.3) + if 'yhold' in st: # facing +y: hold world y with forward velocity + vx = np.clip(1.5 * (st['yhold'] - o[22]), -0.1, 0.1) + a[0] += vx if abs(vx) > 0.03 else 0.0 + if 'yline' in st: # facing +x: hold world y with lateral velocity + vy = np.clip(-1.5 * (o[22] - st['yline']), -0.1, 0.1) + a[1] = vy if abs(vy) > 0.03 else 0.0 + self.k += 1 + if self.k >= n and self.i < len(self.steps) - 1: + self.L, self.R = list(L), list(R) + self.h, self.p = float(a[2]), float(a[4]) + self.i += 1 + self.k = 0 + return a diff --git a/policies/dishwasher_close/opus-s2/episodes.csv b/policies/dishwasher_close/opus-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..8bdd4e6043da73ac776c1ce5081f089e7a50e206 --- /dev/null +++ b/policies/dishwasher_close/opus-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,4650,timeout,0 +620001,0,4650,timeout,0 +620002,0,4650,timeout,0 +620003,0,4650,timeout,0 +620004,0,4650,timeout,0 +620005,0,4650,timeout,0 +620006,0,4650,timeout,0 +620007,0,4650,timeout,0 +620008,0,4650,timeout,0 +620009,0,4650,timeout,0 +620010,0,4650,timeout,0 +620011,0,4650,timeout,0 +620012,0,4650,timeout,0 +620013,0,4650,timeout,0 +620014,0,4650,timeout,0 +620015,0,4650,timeout,0 +620016,0,4650,timeout,0 +620017,0,4650,timeout,0 +620018,0,4650,timeout,0 +620019,0,4650,timeout,0 +620020,0,4650,timeout,0 +620021,0,4650,timeout,0 +620022,0,4650,timeout,0 +620023,0,4650,timeout,0 +620024,0,4650,timeout,0 +620025,0,4650,timeout,0 +620026,0,4650,timeout,0 +620027,0,4650,timeout,0 +620028,0,4650,timeout,0 +620029,0,4650,timeout,0 +620030,0,4650,timeout,0 +620031,0,4650,timeout,0 +620032,0,4650,timeout,0 +620033,0,4650,timeout,0 +620034,0,4650,timeout,0 +620035,0,4650,timeout,0 +620036,0,4650,timeout,0 +620037,0,4650,timeout,0 +620038,0,4650,timeout,0 +620039,0,4650,timeout,0 +620040,0,4650,timeout,0 +620041,0,4650,timeout,0 +620042,0,4650,timeout,0 +620043,0,4650,timeout,0 +620044,0,4650,timeout,0 +620045,0,4650,timeout,0 +620046,0,4650,timeout,0 +620047,0,4650,timeout,0 +620048,0,4650,timeout,0 +620049,0,4650,timeout,0 +620050,0,4650,timeout,0 +620051,0,4650,timeout,0 +620052,0,4650,timeout,0 +620053,0,4650,timeout,0 +620054,0,4650,timeout,0 +620055,0,4650,timeout,0 +620056,0,4650,timeout,0 +620057,0,4650,timeout,0 +620058,0,4650,timeout,0 +620059,0,4650,timeout,0 +620060,0,4650,timeout,0 +620061,0,4650,timeout,0 +620062,0,4650,timeout,0 +620063,0,4650,timeout,0 +620064,0,4650,timeout,0 +620065,0,4650,timeout,0 +620066,0,4650,timeout,0 +620067,0,4650,timeout,0 +620068,0,4650,timeout,0 +620069,0,4650,timeout,0 +620070,0,4650,timeout,0 +620071,0,4650,timeout,0 +620072,0,4650,timeout,0 +620073,0,4650,timeout,0 +620074,0,4650,timeout,0 +620075,0,4650,timeout,0 +620076,0,4650,timeout,0 +620077,0,4650,timeout,0 +620078,0,4650,timeout,0 +620079,0,4650,timeout,0 +620080,0,4650,timeout,0 +620081,0,4650,timeout,0 +620082,0,4650,timeout,0 +620083,0,4650,timeout,0 +620084,0,4650,timeout,0 +620085,0,4650,timeout,0 +620086,0,4650,timeout,0 +620087,0,4650,timeout,0 +620088,0,4650,timeout,0 +620089,0,4650,timeout,0 +620090,0,4650,timeout,0 +620091,0,4650,timeout,0 +620092,0,4650,timeout,0 +620093,0,4650,timeout,0 +620094,0,4650,timeout,0 +620095,0,4650,timeout,0 +620096,0,4650,timeout,0 +620097,0,4650,timeout,0 +620098,0,4650,timeout,0 +620099,0,4650,timeout,0 diff --git a/policies/dishwasher_close/opus-s2/policy.py b/policies/dishwasher_close/opus-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..dec4063867c025d233c601c07a460eb0718b6eb5 --- /dev/null +++ b/policies/dishwasher_close/opus-s2/policy.py @@ -0,0 +1,153 @@ +"""Scripted policy for dishwasher_close: push both racks in, then lift the door closed. + +The robot walks in front of the dishwasher (it sits on the +y side of the start pose), +pushes the lower and the upper rack in with both hands, backs off, squats, slides both +hands under the edge of the open door, lifts it and walks forward pressing it shut. + +Arm targets are given as hand positions (forward from pelvis, world height) and turned +into shoulder-pitch / elbow angles with a planar two-link model; the base is closed-loop +on the pelvis pose from low_dim_obs. No learned components, no randomness. +""" + +import numpy as np + +L1, L2 = 0.197, 0.28 +YAW = np.pi / 2 + + +def ik(fwd, up): + """Hand (fwd, up) relative to the shoulder in the torso frame -> (shoulder pitch, elbow, forearm angle).""" + d = min(np.hypot(fwd, up), L1 + L2 - 1e-4) + gam = np.arccos(np.clip((L1 * L1 + L2 * L2 - d * d) / (2 * L1 * L2), -1, 1)) + bend = np.pi - gam + phi = np.arctan2(fwd, -up) + alpha = np.arccos(np.clip((L1 * L1 + d * d - L2 * L2) / (2 * L1 * d), -1, 1)) + t1 = phi - alpha + return -t1, np.pi / 2 - bend, t1 + bend + + +def goto(lo, tx, ty, tyaw, vmax=0.3, kp=1.2, tol=0.02): + """Body-frame velocity command towards a world pose; returns (vx, vy, wz, done).""" + x, y, yaw = lo[21], lo[22], lo[24] + dx, dy = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + bx, by = c * dx + s * dy, -s * dx + c * dy + eyaw = (tyaw - yaw + np.pi) % (2 * np.pi) - np.pi + vx = np.clip(kp * bx, -vmax, vmax) + vy = np.clip(kp * by, -vmax, vmax) + sp = np.hypot(vx, vy) + dist = np.hypot(bx, by) + if dist < tol: + vx = vy = 0.0 + elif sp < 0.07: + vx, vy = vx / sp * 0.07, vy / sp * 0.07 + wz = np.clip(1.5 * eyaw, -0.6, 0.6) + if abs(eyaw) < 0.02: + wz = 0.0 + elif abs(wz) < 0.1: + wz = 0.1 * np.sign(wz) + return vx, vy, wz, (dist < tol and abs(eyaw) < 0.03) + + +# ---------------------------------------------------------------- the script +Z_LOW, Z_HIGH = 0.68, 0.86 +CLOSED = [1.0, 1.0] + + +def _h(n, x, y=-0.60, **kw): + return dict(x=x, y=y, yaw=YAW, vmax=0.2, kp=3.0, n=n, timeout=n, **kw) + + +def push(x, z, retract): + """Both hands push a rack at height z while the base holds x; then retract without dragging it.""" + s = [dict(height=0.74, pitch=0.0, x=x, y=-0.66, yaw=YAW, timeout=400, n=10), + dict(hwl=(0.15, 0.95), hwr=(0.15, 0.95), g=CLOSED, n=40), + dict(height=0.58, pitch=0.6, hwl=(0.30, z + 0.25), hwr=(0.30, z + 0.25), n=50), + dict(hwl=(0.30, z), hwr=(0.30, z), **_h(40, x))] + for f in (0.4, 0.5, 0.6, 0.7): + s.append(dict(hwl=(f, z), hwr=(f, z), **_h(70, x))) + dz = 0.10 if retract == "up" else -0.10 + s.append(dict(hwl=(0.67, z + dz), hwr=(0.67, z + dz), **_h(50, x))) + s.append(dict(hwl=(0.30, z + dz), hwr=(0.30, z + dz), **_h(50, x))) + s.append(dict(hwl=(0.30, z + 0.25), hwr=(0.30, z + 0.25), n=40)) + return s + + +DX, DY = 0.33, -0.90 +DOOR = [ + dict(height=0.74, pitch=0.0, L=[0.0] * 7, R=[0.0] * 7, g=[0.6, 0.6], x=DX, y=DY, yaw=YAW, timeout=400, n=20), + dict(height=0.42, pitch=0.5, hwl=(0.25, 0.12), hwr=(0.25, 0.12), **_h(80, DX, DY)), + dict(hwl=(0.45, 0.12), hwr=(0.45, 0.12), **_h(80, DX, DY)), + dict(hwl=(0.45, 0.50), hwr=(0.45, 0.50), **_h(100, DX, DY)), + dict(hwl=(0.48, 0.80), hwr=(0.48, 0.80), **_h(100, DX, DY)), + dict(hwl=(0.52, 1.00), hwr=(0.52, 1.00), **_h(100, DX, DY)), + dict(height=0.74, pitch=0.2, hwl=(0.52, 1.00), hwr=(0.52, 1.00), **_h(80, DX, DY)), + dict(hwl=(0.52, 0.85), hwr=(0.52, 0.85), **_h(150, DX, -0.65)), + dict(hwl=(0.55, 0.75), hwr=(0.55, 0.75), **_h(150, DX, -0.55)), + dict(hwl=(0.60, 0.75), hwr=(0.60, 0.75), **_h(10 ** 6, DX, -0.55)), +] + +SEQ = (push(0.36, Z_LOW, "up") + push(0.55, Z_LOW, "up") + + push(0.40, Z_HIGH, "down") + push(0.55, Z_HIGH, "down") + DOOR) + + +class Policy: + """Open-loop script over segments, closed-loop base and hand-height tracking.""" + + def reset(self, obs, tools): + self.prev = np.asarray(tools.hold_action(), dtype=np.float64) + self.i = 0 + self.k = 0 + self.hw = {} + + def _target(self, g): + a = self.prev.copy() + if "height" in g: + a[2] = g["height"] + if "pitch" in g: + a[4] = g["pitch"] + if "L" in g: + a[5:12] = g["L"] + if "R" in g: + a[12:19] = g["R"] + if "g" in g: + a[19:21] = g["g"] + return a + + def act(self, obs, tools): + lo = np.asarray(obs["low_dim_obs"], dtype=np.float64) + g = SEQ[min(self.i, len(SEQ) - 1)] + tgt = self._target(g) + n = g.get("n", 1) + self.k += 1 + al = min(1.0, self.k / max(1, n)) + a = self.prev + (tgt - self.prev) * al + a[0] = a[1] = a[3] = 0.0 + for key, sl in (("hwl", slice(5, 12)), ("hwr", slice(12, 19))): + if key in g: + p0 = np.array(self.hw.get(key, g[key])) + p1 = np.array(g[key]) + p = p0 + (p1 - p0) * al + if self.k >= n: + self.hw[key] = tuple(p1) + pw, pz = lo[2], lo[23] + f = p[0] - 0.25 * np.sin(pw) + u = (p[1] - pz) - (0.044 + 0.25 * np.cos(pw)) + ft = f * np.cos(pw) - u * np.sin(pw) + ut = f * np.sin(pw) + u * np.cos(pw) + sp, e, t2 = ik(ft, ut) + w = t2 - np.pi / 2 - pw + a[sl] = [sp, 0.0, 0.0, e, 0.0, float(np.clip(w, -1.6, 1.6)), 0.0] + tgt[sl] = a[sl] + if "x" in g: + vx, vy, wz, done = goto(lo, g["x"], g["y"], g["yaw"], vmax=g.get("vmax", 0.3), kp=g.get("kp", 1.2)) + a[0], a[1], a[3] = vx, vy, wz + fin = (done and self.k >= n) or self.k > g.get("timeout", 400) + else: + fin = self.k >= n + if fin and self.i < len(SEQ) - 1: + self.prev = tgt.copy() + self.prev[0] = self.prev[1] = self.prev[3] = 0.0 + self.i += 1 + self.k = 0 + return a.astype(np.float32).tolist() diff --git a/policies/dishwasher_close/opus-s3/episodes.csv b/policies/dishwasher_close/opus-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..fef106af7b45e5721c6b0db96bdb1133fec91c7b --- /dev/null +++ b/policies/dishwasher_close/opus-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,3357,success,0 +620001,1,3357,success,0 +620002,1,3357,success,0 +620003,1,3357,success,0 +620004,1,3357,success,0 +620005,1,3357,success,0 +620006,1,3357,success,0 +620007,1,3357,success,0 +620008,1,3357,success,0 +620009,1,3357,success,0 +620010,1,3357,success,0 +620011,1,3357,success,0 +620012,1,3357,success,0 +620013,1,3357,success,0 +620014,1,3357,success,0 +620015,1,3357,success,0 +620016,1,3357,success,0 +620017,1,3357,success,0 +620018,1,3357,success,0 +620019,1,3357,success,0 +620020,1,3357,success,0 +620021,1,3357,success,0 +620022,1,3357,success,0 +620023,1,3357,success,0 +620024,1,3357,success,0 +620025,1,3357,success,0 +620026,1,3357,success,0 +620027,1,3357,success,0 +620028,1,3357,success,0 +620029,1,3357,success,0 +620030,1,3357,success,0 +620031,1,3357,success,0 +620032,1,3357,success,0 +620033,1,3357,success,0 +620034,1,3357,success,0 +620035,1,3357,success,0 +620036,1,3357,success,0 +620037,1,3357,success,0 +620038,1,3357,success,0 +620039,1,3357,success,0 +620040,1,3357,success,0 +620041,1,3357,success,0 +620042,1,3357,success,0 +620043,1,3357,success,0 +620044,1,3357,success,0 +620045,1,3357,success,0 +620046,1,3357,success,0 +620047,1,3357,success,0 +620048,1,3357,success,0 +620049,1,3357,success,0 +620050,1,3357,success,0 +620051,1,3357,success,0 +620052,1,3357,success,0 +620053,1,3357,success,0 +620054,1,3357,success,0 +620055,1,3357,success,0 +620056,1,3357,success,0 +620057,1,3357,success,0 +620058,1,3357,success,0 +620059,1,3357,success,0 +620060,1,3357,success,0 +620061,1,3357,success,0 +620062,1,3357,success,0 +620063,1,3357,success,0 +620064,1,3357,success,0 +620065,1,3357,success,0 +620066,1,3357,success,0 +620067,1,3357,success,0 +620068,1,3357,success,0 +620069,1,3357,success,0 +620070,1,3357,success,0 +620071,1,3357,success,0 +620072,1,3357,success,0 +620073,1,3357,success,0 +620074,1,3357,success,0 +620075,1,3357,success,0 +620076,1,3357,success,0 +620077,1,3357,success,0 +620078,1,3357,success,0 +620079,1,3357,success,0 +620080,1,3357,success,0 +620081,1,3357,success,0 +620082,1,3357,success,0 +620083,1,3357,success,0 +620084,1,3357,success,0 +620085,1,3357,success,0 +620086,1,3357,success,0 +620087,1,3357,success,0 +620088,1,3357,success,0 +620089,1,3357,success,0 +620090,1,3357,success,0 +620091,1,3357,success,0 +620092,1,3357,success,0 +620093,1,3357,success,0 +620094,1,3357,success,0 +620095,1,3357,success,0 +620096,1,3357,success,0 +620097,1,3357,success,0 +620098,1,3357,success,0 +620099,1,3357,success,0 diff --git a/policies/dishwasher_close/opus-s3/policy.py b/policies/dishwasher_close/opus-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a43e6b919c974d56e51a3bfbf09affd55a95fccd --- /dev/null +++ b/policies/dishwasher_close/opus-s3/policy.py @@ -0,0 +1,291 @@ +"""Dishwasher close: push both racks in, then lift the door shut. + +Scripted policy. The scene layout is fixed (the dishwasher faces -x, its door +hinge is at about x=0.62, z=0.47 in the world frame); the robot localises with +the pelvis pose from low_dim_obs. Hand targets are converted to joint targets +with an approximate G1 arm model and a small numerical IK. +""" + +import numpy as np +from scipy.optimize import least_squares + +L, R = 5, 12 +Y0 = -0.03 # lateral position in front of the dishwasher +XS = -0.14 # standing x in front of the open door +YSIDE = -0.47 # lateral position beside the door for pushing the racks +HX, HZ = 0.62, 0.47 # door hinge (world x, z) + +# ---------------------------------------------------------------- kinematics + + +def _rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def _ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def _rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +def arm_fk(q, side, waist_pitch=0.0, tip=0.12): + """Wrist and gripper-tip positions in the pelvis frame (x fwd, y left, z up).""" + sg = 1 if side == 'left' else -1 + Rm = _ry(waist_pitch) + p = np.array([-0.0039635, 0, 0.054]) + p = p + Rm @ np.array([0.0039563, sg * 0.10022, 0.23778]) + Rm = Rm @ _rx(sg * 0.2793) + Rm = Rm @ _ry(q[0]) + p = p + Rm @ np.array([0, sg * 0.038, -0.013831]) + Rm = Rm @ _rx(-sg * 0.2793) @ _rx(q[1]) + p = p + Rm @ np.array([0, sg * 0.00624, -0.1032]) + Rm = Rm @ _rz(q[2]) + p = p + Rm @ np.array([0.015783, 0, -0.080518]) + Rm = Rm @ _ry(q[3]) + p = p + Rm @ np.array([0.100, sg * 0.00188791, -0.010]) + Rm = Rm @ _rx(q[4]) + p = p + Rm @ np.array([0.038, 0, 0]) + Rm = Rm @ _ry(q[5]) + p = p + Rm @ np.array([0.046, 0, 0]) + Rm = Rm @ _rz(q[6]) + return p, p + Rm @ np.array([tip, 0, 0]) + + +_LO = np.array([-3.0892, -0.3, -0.6, -1.0472, -1.97, -1.614, -1.614]) +_HI = np.array([2.6704, 1.2, 0.6, 2.0944, 1.97, 1.614, 1.614]) +_FREE = [0, 1, 2, 3, 5] + + +def ik(tip, side, wp, q0=None): + """Joint angles putting the gripper tip at `tip` (pelvis frame).""" + sg = 1 if side == 'left' else -1 + lo, hi = _LO.copy(), _HI.copy() + if side == 'right': + lo[[1, 2, 4, 6]], hi[[1, 2, 4, 6]] = -_HI[[1, 2, 4, 6]], -_LO[[1, 2, 4, 6]] + if q0 is None: + q0 = np.array([-0.5, sg * 0.2, 0, 0.8, 0, 0, 0]) + tip = np.asarray(tip, float) + wpa = wp - 0.07 + + def full(x): + q = np.zeros(7) + q[_FREE] = x + return q + + def res(x): + _, t = arm_fk(full(x), side, wpa) + return np.concatenate([t - tip, 0.02 * (x - q0[_FREE])]) + + def err(x): + return np.linalg.norm(arm_fk(full(x), side, wpa)[1] - tip) + + starts = [q0[_FREE], np.array([-0.5, sg * 0.2, 0, 0.8, 0]), + np.array([-1.2, sg * 0.2, 0, 1.2, 0])] + best = None + for x0 in starts: + x0 = np.clip(x0, lo[_FREE] + 1e-3, hi[_FREE] - 1e-3) + s = least_squares(res, x0, bounds=(lo[_FREE], hi[_FREE]), max_nfev=40) + e = err(s.x) + if best is None or e < best[1] - 0.01: + best = (s.x, e) + if best[1] < 0.03: + break + return full(best[0]), best[1] + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +# ---------------------------------------------------------------- policy + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + def reset(self, obs, tools): + self.obs = obs + self.q = [None, None] + self.gen = self.plan(np.array(tools.hold_action(), dtype=np.float64)) + self.last = None + + def act(self, obs, tools): + self.obs = obs + try: + a = next(self.gen) + self.last = a + except StopIteration: + a = self.last.copy() + a[0] = a[1] = a[3] = 0.0 + return np.asarray(a, dtype=np.float32) + + # ---- helpers + def pose(self): + lo = self.obs['low_dim_obs'] + return float(lo[21]), float(lo[22]), float(lo[24]) + + def base_cmd(self, tx, ty, tyaw, kp=1.2, vmax=0.4, mind=0.02): + x, y, yaw = self.pose() + dx, dy = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + vx, vy = kp * (c * dx + s * dy), kp * (-s * dx + c * dy) + n = np.hypot(vx, vy) + if n > vmax: + vx, vy = vx * vmax / n, vy * vmax / n + n = np.hypot(vx, vy) + if n < 0.065: + if n > 1e-6 and np.hypot(dx, dy) > mind: + vx, vy = vx * 0.065 / n, vy * 0.065 / n + else: + vx = vy = 0.0 + wz = float(np.clip(1.5 * wrap(tyaw - yaw), -0.8, 0.8)) + if abs(wz) < 0.05: + wz = 0.0 + return vx, vy, wz, np.hypot(dx, dy), abs(wrap(tyaw - yaw)) + + def goto(self, a, tx, ty, tyaw, tol=0.03, ytol=0.05, maxsteps=500, settle=30): + for _ in range(maxsteps): + vx, vy, wz, d, dyaw = self.base_cmd(tx, ty, tyaw, mind=tol * 0.7) + if d < tol and dyaw < ytol: + break + a[0], a[1], a[3] = vx, vy, wz + yield a.copy() + a[0] = a[1] = a[3] = 0.0 + for _ in range(settle): + yield a.copy() + + def hold(self, a, n): + for _ in range(n): + yield a.copy() + + def arms_to(self, a, xw, zw, lat=0.17): + """Both gripper tips to world x=xw, height zw, +-lat sideways of the pelvis.""" + lo = self.obs['low_dim_obs'] + x, _, _ = self.pose() + zp, wp = float(lo[23]), float(lo[2]) + f = xw - x + ql, el = ik([f, lat, zw - zp], 'left', wp, self.q[0]) + qr, _ = ik([f, -lat, zw - zp], 'right', wp, self.q[1]) + self.q = [ql, qr] + a[L:L + 7] = ql + a[R:R + 7] = qr + return el + + @staticmethod + def tuck_up(a): + for base, sg in ((L, 1), (R, -1)): + a[base:base + 7] = 0 + a[base + 0], a[base + 1], a[base + 3] = 0.3, sg * 0.25, -1.0 + + @staticmethod + def tuck_down(a): + for base, sg in ((L, 1), (R, -1)): + a[base:base + 7] = 0 + a[base + 0], a[base + 1], a[base + 3] = 0.0, sg * 0.15, 1.4 + + def side_push(self, a, zw, x_end, f=0.35, lat=0.3): + """Beside the door, hold the left hand inward at height zw and walk forward.""" + self.q = [None, None] + self.tuck_up(a) + yield from self.goto(a, -0.45, YSIDE, 0.0, tol=0.02, ytol=0.02) + lo = self.obs['low_dim_obs'] + for _ in range(40): + ql, _ = ik([f, lat, zw - float(lo[23])], 'left', float(lo[2]), self.q[0]) + self.q[0] = ql + a[L:L + 7] = ql + yield a.copy() + for _ in range(700): + x, _, _ = self.pose() + if x > x_end: + break + _, vy, wz, _, _ = self.base_cmd(x_end, YSIDE, 0.0, kp=2.0) + a[0], a[1], a[3] = 0.12, vy, wz + lo = self.obs['low_dim_obs'] + ql, _ = ik([f, lat, zw - float(lo[23])], 'left', float(lo[2]), self.q[0]) + self.q[0] = ql + a[L:L + 7] = ql + yield a.copy() + a[0] = a[1] = a[3] = 0.0 + yield from self.hold(a, 30) + self.tuck_up(a) + yield from self.hold(a, 30) + yield from self.goto(a, -0.45, YSIDE, 0.0, tol=0.03, ytol=0.05) + + def push(self, a, zp, n=250, lat=0.08): + """Sweep both hands forward at height zp to push a rack in.""" + self.arms_to(a, self.pose()[0] + 0.15, zp, lat=lat) + yield from self.hold(a, 30) + for k in range(n + 30): + f = 0.15 + 0.5 * min(1.0, k / n) + if a[2] > 0.7: + vx, vy, wz, _, _ = self.base_cmd(XS, Y0, 0.0, kp=2.0, vmax=0.2) + a[0], a[1], a[3] = vx, vy, wz + self.arms_to(a, self.pose()[0] + f, zp, lat=lat) + yield a.copy() + for k in range(30): + self.arms_to(a, self.pose()[0] + 0.1, zp + 0.05, lat=lat) + yield a.copy() + a[0] = a[1] = a[3] = 0.0 + + @staticmethod + def door_pt(th, push=0.02): + r = 0.5 - 0.1 * min(1.0, th / 1.57) + return (HX - r * np.cos(th) + push * np.sin(th), + HZ + r * np.sin(th) + push * np.cos(th) - 0.03) + + # ---- the task + def plan(self, a): + a[19] = a[20] = 0.0 + self.tuck_up(a) + yield from self.goto(a, -0.6, -0.8, 0.0, tol=0.03, ytol=0.05) + + # 1. push the racks in from beside the door, walking forward + a[4] = 0.3 + yield from self.side_push(a, 0.8, 0.25) + yield from self.side_push(a, 0.62, 0.35) + a[4] = 0.0 + + # 2. arms down-forward, go in front of the door and squat + yield from self.goto(a, -0.6, YSIDE, 0.0, tol=0.03, ytol=0.05) + yield from self.goto(a, -0.6, Y0, 0.0, tol=0.02, ytol=0.02) + self.q = [None, None] + yield from self.goto(a, XS - 0.25, Y0, 0.0, tol=0.02, ytol=0.02) + self.tuck_down(a) + yield from self.hold(a, 30) + yield from self.goto(a, XS, Y0, 0.0, tol=0.012, ytol=0.015) + a[2], a[4] = 0.62, 0.7 + yield from self.hold(a, 70) + x0 = self.pose()[0] + for xw in np.linspace(x0 + 0.15, 0.12, 5): + self.arms_to(a, xw, 0.43) + yield from self.hold(a, 15) + + # 3. lift the door along its arc, standing up and walking in behind it + th, k, e = 0.0, 0, 0.0 + while th < 1.75 and k < 1400: + k += 1 + px, pz = self.door_pt(th) + a[2] = 0.62 + 0.12 * np.clip((th - 0.08) / 0.25, 0, 1) + a[4] = 0.7 if th < 0.8 else 0.5 + if a[2] >= 0.7: + tx = min(px - 0.33, 0.3) + vx, vy, wz, _, _ = self.base_cmd(tx, Y0, 0.0, kp=2.0, vmax=0.3) + a[0], a[1], a[3] = vx, vy, wz + if e < 0.06: + th += 0.004 + if k % 2 == 0: + e = self.arms_to(a, px, pz) + yield a.copy() + + # 4. keep pressing the door shut + while True: + px, pz = self.door_pt(1.75) + vx, vy, wz, _, _ = self.base_cmd(px - 0.33, Y0, 0.0, kp=2.0, vmax=0.3) + a[0], a[1], a[3] = vx, vy, wz + self.arms_to(a, px + 0.03, pz) + yield a.copy() diff --git a/policies/dishwasher_load_cups/astra-s1/episodes.csv b/policies/dishwasher_load_cups/astra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..aa19ab7f5eaa3a9affcbc5daec7a819416b8984a --- /dev/null +++ b/policies/dishwasher_load_cups/astra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,1,1618,success,0 +620005,0,2000,timeout,0 +620006,1,1976,success,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,1,1704,success,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,1563,terminated,0 +620021,1,1735,success,0 +620022,1,1433,success,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,1,1753,success,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,1,1680,success,0 +620050,0,2000,timeout,0 +620051,1,1920,success,0 +620052,0,2000,timeout,0 +620053,0,1786,terminated,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,1,1671,success,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,1,1740,success,0 +620061,0,2000,timeout,0 +620062,1,1557,success,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,1,1447,success,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,1828,terminated,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,1,1591,success,0 +620078,0,2000,timeout,0 +620079,1,1911,success,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,1,1752,success,0 +620083,0,1651,terminated,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,1,1696,success,0 +620093,0,2000,timeout,0 +620094,1,1771,success,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,1,1777,success,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/astra-s1/policy.py b/policies/dishwasher_load_cups/astra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..b6865bcefb9713b06c108a3fcba60160cc9cae34 --- /dev/null +++ b/policies/dishwasher_load_cups/astra-s1/policy.py @@ -0,0 +1,541 @@ +"""Deterministic hand-written control for loading two mugs into the upper rack. + +The controller uses color thresholds, connected components, and handle-opening +contours from the wrist cameras. Proprioception closes the navigation loop and +checks gripper closure. Arm targets interpolate during lifting and placement. +No learned components, external files, randomness, or clock inputs are used. +""" +import numpy as np +import cv2 + +def _near_handles(im, side=0): + a = im.astype(np.int16) + lo = a.min(2) + hi = a.max(2) + gray = (hi - lo < 18) & (lo > 70) & (hi < 225) + near = cv2.boxFilter(gray.astype(np.float32), -1, (9, 9), normalize=False) + m = (lo > 205) & (hi - lo < 18) & (near > 10) + if True: + contours, hierarchy = cv2.findContours(((hi - lo < 20) & (lo > 70)).astype('uint8'), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) + holes = [] + if hierarchy is not None: + for k, c in enumerate(contours): + x, y, w, h = cv2.boundingRect(c) + if hierarchy[0, k, 3] >= 0 and 10 < x < 72 and (y < 50) and (h > 12) and (h > w * 1.4) and (cv2.contourArea(c) > 12): + left = gray[y:y + h, max(0, x - 18):x].sum() + right = gray[y:y + h, x + w:min(84, x + w + 18)].sum() + hx = x + w + 1 if left > right else x - 2 + holes.append((h / (1 + abs(hx - 42) * 0.025), np.array([hx, y + h * 0.5, w, h * 1.3, cv2.contourArea(c)]))) + if holes: + return max(holes, key=lambda a: a[0])[1] + if side: + m = cv2.morphologyEx(m.astype('uint8'), cv2.MORPH_OPEN, np.ones((5, 2), np.uint8)) > 0 + m[:7] = False + m[64:] = False + m[:, :4] = False + m[:, 80:] = False + n, lab, st, ct = cv2.connectedComponentsWithStats(m.astype('uint8')) + out = [] + for j in range(1, n): + x, y, w, h, area = st[j] + if area >= 7 and h >= 6 and (w < 40) and (h > w * 0.8): + score = area * h / (w + 3) / (1 + abs(ct[j, 0] - 42) * 0.035) + ys, xs = np.where(lab == j) + lower = xs[ys > y + h * 0.5] + hx = float(np.mean(lower)) if len(lower) > 2 else ct[j, 0] + out.append((score, np.array([hx, ct[j, 1], w, h, area], float))) + return max(out, key=lambda z: z[0])[1] if out else None + +def mug_region(im): + a = im.astype(np.int16) + lo = a.min(2) + hi = a.max(2) + m = ((hi - lo < 18) & (lo > 80) & (hi < 225)).astype('uint8') + m[64:] = 0 + n, lb, st, ct = cv2.connectedComponentsWithStats(m) + cand = [] + for k in range(1, n): + x, y, w, h, area = st[k] + if area > 65 and h > 12 and (y < 45): + cand.append((area / (1 + abs(ct[k, 0] - 42) * 0.02), (x, y, w, h))) + return max(cand, key=lambda z: z[0])[1] if cand else None + +class _NearPolicy: + """Approach close mugs from the initial stance.""" + + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), float) + self.a[19:] = 0 + self.state = 'raise' + self.age = 0 + self.side = 0 + self.tries = 0 + self.cycles = 0 + self.target = self.a.copy() + self.start = self.a.copy() + self.initial = obs['low_dim_obs'][21:25].copy() + self.navtarget = None + self.held = [False, False] + self.last_seen = None + self.align = 0 + self.target[5:12] = [-1, 0, 0, -0.5, 0, 0, 0] + self.target[12:19] = [-1, 0, 0, -0.5, 0, 0, 0] + + def enter(self, name): + self.state = name + self.age = 0 + self.start = self.a.copy() + self.target = self.a.copy() + self.target[:2] = 0 + self.target[3] = 0 + + def arm(self, q): + j = 5 + 7 * self.side + self.target[j:j + 7] = q + + def nav(self, obs, tar, speed=0.2): + p = obs['low_dim_obs'][21:25] + e = np.asarray(tar[:2]) - p[:2] + v = e * 2.5 + norm = np.linalg.norm(v) + if np.linalg.norm(e) < 0.018: + v *= 0 + elif norm < 0.065: + v *= 0.065 / max(norm, 1e-06) + elif norm > speed: + v *= speed / norm + c, s = (np.cos(p[3]), np.sin(p[3])) + self.a[0] = c * v[0] + s * v[1] + self.a[1] = -s * v[0] + c * v[1] + self.a[3] = np.clip((tar[2] - p[3]) * 2, -0.5, 0.5) + return np.linalg.norm(e) < 0.03 and abs(tar[2] - p[3]) < 0.06 + + def act(self, obs, tools): + self.age += 1 + p = obs['low_dim_obs'] + j = 5 + 7 * self.side + g = 19 + self.side + self.a[:2] = 0 + self.a[3] = 0 + st = self.state + if st == 'raise': + self.a = self.start + (self.target - self.start) * min(1, self.age / 45) + if self.age >= 75: + self.enter('initial_settle') + elif st == 'initial_settle': + self.a = self.target.copy() + if self.age >= 20: + self.enter('prepare') + self.arm([-1.1, 0.24, 0, 1.1, 0, -0.3, 0]) + elif st == 'prepare': + self.a = self.start + (self.target - self.start) * min(1, self.age / 40) + if self.age >= 55: + self.enter('align') + self.align = 0 + elif st == 'align': + self.a = self.target.copy() + if self.age % 8 == 0: + im = tools.image('left_wrist' if self.side == 0 else 'right_wrist') + h = _near_handles(im, self.side) + self.last_seen = h + if h is not None: + ex = 42 - h[0] + ey = h[1] - 30 + axis = j + 1 if self.side == 0 else j + 2 + self.target[axis] = np.clip(self.target[axis] + np.clip(ex * 0.0015, -0.018, 0.018), -0.45, 0.65) + self.target[j + 6] = np.clip(self.target[j + 6] + np.clip(ex * 0.001, -0.012, 0.012), -0.35, 0.35) + self.target[j + 5] = np.clip(self.target[j + 5] + np.clip(ey * 0.0015, -0.018, 0.018), -1.3, 0.45) + if abs(ex) < 7 and abs(ey) < 11: + self.align += 1 + else: + self.align = 0 + if self.age > 35 and self.align >= 2: + if h[3] >= 34 or (self.side == 1 and self.cycles >= 1 and (h[3] >= 26)) or self.cycles >= 8: + self.enter('close') + self.target[g] = 1 + else: + self.enter('approach') + self.navtarget = [float(p[21] + (0.055 if self.side == 0 else 0.075)), float(self.initial[1]), 0] + self.cycles += 1 + else: + box = mug_region(im) + if box is not None: + x, y, w, hb = box + axis = j + 1 if self.side == 0 else j + 2 + if x < 5: + self.target[axis] = min(0.65, self.target[axis] + 0.025) + self.target[j + 6] = min(0.35, self.target[j + 6] + 0.015) + elif x + w > 79: + self.target[axis] = max(-0.45, self.target[axis] - 0.025) + self.target[j + 6] = max(-0.35, self.target[j + 6] - 0.015) + self.target[j + 5] = np.clip(self.target[j + 5] + np.clip((y + hb - 52) * 0.002, -0.022, 0.022), -1.3, 0.45) + if self.age > 220: + self.enter('close') + self.target[g] = 1 + elif st == 'approach': + self.a = self.target.copy() + self.nav(obs, self.navtarget, 0.14 if self.side == 0 else 0.2) + if self.age >= 80: + self.enter('settle') + elif st == 'settle': + self.a = self.target.copy() + if self.age >= 25: + self.enter('align') + self.align = 0 + elif st == 'close': + self.a = self.target.copy() + if self.age >= 25: + inds = [10, 11] if self.side == 0 else [19, 20] + if np.mean(p[inds]) > -0.0155: + self.held[self.side] = True + self.enter('lift') + delta = min(0.85, 2.05 - self.target[j + 3]) + self.target[j] -= delta + self.target[j + 3] += delta + if self.side == 0: + self.target[j + 1] = 0.55 + self.target[j + 6] = 0 + elif self.tries < 5: + self.tries += 1 + self.enter('reopen') + self.target[g] = 0 + else: + self.enter('lift') + self.target[j] -= 0.55 + self.target[j + 3] += 0.55 + elif st == 'reopen': + self.a = self.target.copy() + if self.age >= 15: + self.enter('approach') + self.navtarget = [float(p[21] + 0.06), float(self.initial[1]), 0] + self.cycles += 1 + elif st == 'lift': + self.a = self.start + (self.target - self.start) * min(1, self.age / 65) + if self.age >= 75: + if self.side == 0: + self.side = 1 + self.tries = 0 + self.cycles = 0 + self.enter('right_retreat') + else: + self.enter('carry') + self.target[5:12] = [-1.8, 0.35, 0, 1.8, 0, -0.03, 0] + self.right_carry = self.target[12:19].copy() + elif st == 'right_retreat': + self.a = self.target.copy() + if self.age >= 5: + self.enter('right_settle') + elif st == 'right_settle': + self.a = self.target.copy() + if self.age >= 10: + self.enter('prepare') + self.arm([-1.1, 0.1, 0, 1.5, 0, -1.0, 0]) + elif st == 'carry': + self.a = self.start + (self.target - self.start) * min(1, self.age / 50) + if self.age >= 60: + self.enter('to_rack') + elif st == 'to_rack': + self.a = self.target.copy() + reached = self.nav(obs, [-0.055, -0.55, 0.65], 0.18) + if reached and self.age > 90 or self.age > 200: + self.side = 0 + self.enter('lower') + self.target[5] = -1.0 + self.target[8] = 1.0 + self.target[2] = 0.67 + elif st == 'lower': + self.a = self.start + (self.target - self.start) * min(1, self.age / 80) + if self.age >= 100: + self.enter('release') + self.target[g] = 0 + elif st == 'release': + self.a = self.target.copy() + if self.age >= 55: + if self.side == 0: + self.enter('retract') + self.target[5] = -1.5 + self.target[8] = -0.3 + self.target[2] = 0.74 + else: + self.enter('done') + elif st == 'retract': + self.a = self.start + (self.target - self.start) * min(1, self.age / 60) + if self.age >= 65: + self.side = 1 + self.enter('right_rack') + elif st == 'right_rack': + self.a = self.target.copy() + reached = self.nav(obs, [-0.055, -0.5, 1.3], 0.15) + if reached and self.age > 80 or self.age > 160: + self.enter('lower') + self.target[12] = -0.95 + self.target[15] = 1.35 + self.target[2] = 0.67 + else: + self.a = self.target.copy() + return self.a.copy() + +def _far_handles(im, side=0): + a = im.astype(np.int16) + lo = a.min(2) + hi = a.max(2) + gray = (hi - lo < 18) & (lo > 70) & (hi < 225) + near = cv2.boxFilter(gray.astype(np.float32), -1, (9, 9), normalize=False) + m = (lo > 205) & (hi - lo < 18) & (near > 10) + if side: + contours, hierarchy = cv2.findContours(((hi - lo < 20) & (lo > 70)).astype('uint8'), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) + holes = [] + if hierarchy is not None: + for k, c in enumerate(contours): + x, y, w, h = cv2.boundingRect(c) + if hierarchy[0, k, 3] >= 0 and 10 < x < 72 and (y < 50) and (h > 12) and (h > w * 1.4) and (cv2.contourArea(c) > 12): + holes.append((h / (1 + abs(x - 42) * 0.025), np.array([x - 2, y + h * 0.5, w, h * 1.3, cv2.contourArea(c)]))) + if holes: + return max(holes, key=lambda a: a[0])[1] + m = cv2.morphologyEx(m.astype('uint8'), cv2.MORPH_OPEN, np.ones((5, 2), np.uint8)) > 0 + m[:7] = False + m[64:] = False + m[:, :4] = False + m[:, 80:] = False + n, lab, st, ct = cv2.connectedComponentsWithStats(m.astype('uint8')) + out = [] + for j in range(1, n): + x, y, w, h, area = st[j] + if area >= 7 and h >= 6 and (w < 40) and (h > w * 0.8): + score = area * h / (w + 3) / (1 + abs(ct[j, 0] - 42) * 0.035) + ys, xs = np.where(lab == j) + lower = xs[ys > y + h * 0.5] + hx = float(np.mean(lower)) if len(lower) > 2 else ct[j, 0] + out.append((score, np.array([hx, ct[j, 1], w, h, area], float))) + return max(out, key=lambda z: z[0])[1] if out else None + +class _FarPolicy: + """Approach farther mugs with the wrists raised clear of the counter.""" + + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), float) + self.a[19:] = 0 + self.state = 'raise' + self.age = 0 + self.side = 0 + self.tries = 0 + self.cycles = 0 + self.target = self.a.copy() + self.start = self.a.copy() + self.initial = obs['low_dim_obs'][21:25].copy() + self.navtarget = None + self.held = [False, False] + self.last_seen = None + self.align = 0 + self.target[5:12] = [-1, 0, 0, -0.5, 0, 0, 0] + self.target[12:19] = [-1, 0, 0, -0.5, 0, 0, 0] + + def enter(self, name): + self.state = name + self.age = 0 + self.start = self.a.copy() + self.target = self.a.copy() + self.target[:2] = 0 + self.target[3] = 0 + + def arm(self, q): + j = 5 + 7 * self.side + self.target[j:j + 7] = q + + def nav(self, obs, tar, speed=0.2): + p = obs['low_dim_obs'][21:25] + e = np.asarray(tar[:2]) - p[:2] + v = e * 2.5 + norm = np.linalg.norm(v) + if np.linalg.norm(e) < 0.018: + v *= 0 + elif norm < 0.065: + v *= 0.065 / max(norm, 1e-06) + elif norm > speed: + v *= speed / norm + c, s = (np.cos(p[3]), np.sin(p[3])) + self.a[0] = c * v[0] + s * v[1] + self.a[1] = -s * v[0] + c * v[1] + self.a[3] = np.clip((tar[2] - p[3]) * 2, -0.5, 0.5) + return np.linalg.norm(e) < 0.03 and abs(tar[2] - p[3]) < 0.06 + + def act(self, obs, tools): + self.age += 1 + p = obs['low_dim_obs'] + j = 5 + 7 * self.side + g = 19 + self.side + self.a[:2] = 0 + self.a[3] = 0 + st = self.state + if st == 'raise': + self.a = self.start + (self.target - self.start) * min(1, self.age / 45) + if self.age > 35: + self.nav(obs, [0.02, float(self.initial[1]), 0], 0.16) + if self.age >= 130: + self.enter('initial_settle') + elif st == 'initial_settle': + self.a = self.target.copy() + if self.age >= 35: + self.enter('prepare') + self.arm([-1.1, 0.24, 0, 1.1, 0, -0.3, 0]) + elif st == 'prepare': + self.a = self.start + (self.target - self.start) * min(1, self.age / 40) + if self.age >= 60: + self.enter('align') + self.align = 0 + elif st == 'align': + self.a = self.target.copy() + if self.age % 8 == 0: + im = tools.image('left_wrist' if self.side == 0 else 'right_wrist') + h = _far_handles(im, self.side) + self.last_seen = h + if h is not None: + ex = 42 - h[0] + ey = h[1] - 30 + axis = j + 1 if self.side == 0 else j + 2 + self.target[axis] = np.clip(self.target[axis] + np.clip(ex * 0.0015, -0.018, 0.018), -0.45, 0.65) + self.target[j + 6] = np.clip(self.target[j + 6] + np.clip(ex * 0.001, -0.012, 0.012), -0.35, 0.35) + self.target[j + 5] = np.clip(self.target[j + 5] + np.clip(ey * 0.0015, -0.018, 0.018), -1.3, 0.45) + if abs(ex) < 7 and abs(ey) < 11: + self.align += 1 + else: + self.align = 0 + if self.age > 35 and self.align >= 2: + if h[3] >= 42 or (self.side == 1 and self.cycles >= 1 and (h[3] >= 26)) or self.cycles >= 8: + self.enter('close') + self.target[g] = 1 + else: + self.enter('approach') + self.navtarget = [float(p[21] + (0.055 if self.side == 0 else 0.1)), float(p[22]), 0] + self.cycles += 1 + elif self.age > 40 and self.side == 1: + box = mug_region(im) + if box is not None: + x, y, w, hb = box + if x < 5: + self.target[j + 2] = min(0.65, self.target[j + 2] + 0.02) + self.target[j + 6] = min(0.35, self.target[j + 6] + 0.012) + elif x + w > 79: + self.target[j + 2] = max(-0.45, self.target[j + 2] - 0.02) + self.target[j + 6] = max(-0.35, self.target[j + 6] - 0.012) + self.target[j + 5] = np.clip(self.target[j + 5] + np.clip((y + hb - 52) * 0.002, -0.022, 0.022), -1.3, 0.6) + if self.age > 220: + self.enter('close') + self.target[g] = 1 + elif st == 'approach': + self.a = self.target.copy() + self.nav(obs, self.navtarget, 0.14 if self.side == 0 else 0.2) + if self.age >= 80: + self.enter('settle') + elif st == 'settle': + self.a = self.target.copy() + if self.age >= 25: + self.enter('align') + self.align = 0 + elif st == 'close': + self.a = self.target.copy() + if self.age >= 45: + inds = [10, 11] if self.side == 0 else [19, 20] + if np.mean(p[inds]) > -0.016: + self.held[self.side] = True + self.enter('lift') + delta = min(0.85, 2.05 - self.target[j + 3]) + self.target[j] -= delta + self.target[j + 3] += delta + if self.side == 0: + self.target[j + 1] = 0.55 + self.target[j + 6] = 0 + elif self.tries < 5: + self.tries += 1 + self.enter('reopen') + self.target[g] = 0 + else: + self.enter('lift') + self.target[j] -= 0.55 + self.target[j + 3] += 0.55 + elif st == 'reopen': + self.a = self.target.copy() + if self.age >= 30: + self.enter('approach') + self.navtarget = [float(p[21] + 0.06), float(p[22]), 0] + self.cycles += 1 + elif st == 'lift': + self.a = self.start + (self.target - self.start) * min(1, self.age / 65) + if self.age >= 90: + if self.side == 0: + self.side = 1 + self.tries = 0 + self.cycles = 0 + self.enter('right_retreat') + else: + self.enter('carry') + self.target[5:12] = [-1.8, 0.35, 0, 1.8, 0, -0.03, 0] + self.right_carry = self.target[12:19].copy() + elif st == 'right_retreat': + self.a = self.target.copy() + if self.age >= 20: + self.enter('right_settle') + elif st == 'right_settle': + self.a = self.target.copy() + if self.age >= 30: + self.enter('prepare') + self.arm([-1.1, 0.1, 0, 1.5, 0, -1.0, 0]) + elif st == 'carry': + self.a = self.start + (self.target - self.start) * min(1, self.age / 50) + if self.age >= 60: + self.enter('to_rack') + elif st == 'to_rack': + self.a = self.target.copy() + reached = self.nav(obs, [-0.055, -0.55, 0.65], 0.18) + if reached and self.age > 120 or self.age > 230: + self.side = 0 + self.enter('lower') + self.target[5] = -1.0 + self.target[8] = 1.0 + self.target[2] = 0.67 + elif st == 'lower': + self.a = self.start + (self.target - self.start) * min(1, self.age / 80) + if self.age >= 100: + self.enter('release') + self.target[g] = 0 + elif st == 'release': + self.a = self.target.copy() + if self.age >= 55: + if self.side == 0: + self.enter('retract') + self.target[5] = -1.5 + self.target[8] = -0.3 + self.target[2] = 0.74 + else: + self.enter('done') + elif st == 'retract': + self.a = self.start + (self.target - self.start) * min(1, self.age / 60) + if self.age >= 65: + self.side = 1 + self.enter('right_rack') + elif st == 'right_rack': + self.a = self.target.copy() + reached = self.nav(obs, [-0.055, -0.5, 1.3], 0.15) + if reached and self.age > 100 or self.age > 170: + self.enter('lower') + self.target[12] = -0.95 + self.target[15] = 1.35 + self.target[2] = 0.67 + else: + self.a = self.target.copy() + return self.a.copy() + +class Policy: + """Select the initial approach using the visible counter shadow.""" + + def reset(self, obs, tools): + im = tools.image('head').astype(np.float32) + nearby = np.any(im[1:6, :45].mean(axis=2) < 190) + self.control = _NearPolicy() if nearby else _FarPolicy() + self.control.reset(obs, tools) + + def act(self, obs, tools): + return self.control.act(obs, tools) + + def __getattr__(self, name): + return getattr(self.control, name) diff --git a/policies/dishwasher_load_cups/astra-s2/episodes.csv b/policies/dishwasher_load_cups/astra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..ba63c0ba4ee619d18e9b433f9f11d99a3954b939 --- /dev/null +++ b/policies/dishwasher_load_cups/astra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,1,1638,success,0 +620002,0,2000,timeout,0 +620003,1,1577,success,0 +620004,0,2000,timeout,0 +620005,1,1573,success,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,1,1581,success,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,1,1589,success,0 +620018,0,2000,timeout,0 +620019,0,1134,terminated,0 +620020,1,1582,success,0 +620021,0,2000,timeout,0 +620022,1,1403,success,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,1,1547,success,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,1,1142,success,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,1,1481,success,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,1,1545,success,0 +620064,1,1528,success,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,1,1580,success,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,1,1440,success,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,1,1562,success,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,1,1429,success,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/astra-s2/policy.py b/policies/dishwasher_load_cups/astra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..b7018303fb59136bbd2ea4290fdab7f5e13429de --- /dev/null +++ b/policies/dishwasher_load_cups/astra-s2/policy.py @@ -0,0 +1,163 @@ +"""Hand-written wrist-camera feedback and gentle dishwasher placement.""" +import numpy as np +import cv2 + +class Policy: + def reset(self,obs,tools): + self.a=np.asarray(tools.hold_action(),float);self.a[19:]=0 + self.x=-.30;self.y=-.55;self.side=0;self.phase='init';self.pt=0 + self.sh=[-1.25,-1.35];self.roll=[0.,-.10];self.held=[False,False] + self.walk=0;self.settle=0;self.walkspeed=0;self.walkaxis=0 + self.gt=0;self.grasp=False;self.shoulder=-1.25;self.last=None + self.holdarms=[None,None] + self.lost=0 + self.distant=None + def base(self,o,x,y,yaw=0): + p=o['low_dim_obs'][21:25];v=np.array([x,y])-p[:2] + if np.linalg.norm(v)<.028:v*=0 + else: + speed=.23 if self.phase=='transfer' and not self.distant else .18 + v=np.clip(v*1.6,-speed,speed) + if np.linalg.norm(v)<.06:v*=.06/np.linalg.norm(v) + c,s=np.cos(p[3]),np.sin(p[3]);self.a[0:2]=[c*v[0]+s*v[1],-s*v[0]+c*v[1]] + self.a[3]=np.clip(2*(yaw-p[3]),-.35,.35) + @staticmethod + def mug(im,side=0): + lo=im.min(2).astype(float);hi=im.max(2).astype(float) + mask=((hi-lo<28)&(lo>65)&(hi<235)).astype('uint8');mask[78:]=0 + def candidates(mm): + n,ll,ss,cc=cv2.connectedComponentsWithStats(mm) + kk=[k for k in range(1,n) if ss[k,4]>100 and ss[k,2]>=15 and ss[k,3]>7 and ss[k,3]>.7*ss[k,2] and ss[k,1]<55] + return ll,ss,cc,kk + def select(ss,kk): + return min(kk,key=lambda k:ss[k,0]) if side==0 else max(kk,key=lambda k:ss[k,0]+ss[k,2]) + l,st,ce,kk=candidates(mask) + clean=cv2.morphologyEx(mask,cv2.MORPH_OPEN,np.ones((5,5),np.uint8)) + lc,sc,cc,kc=candidates(clean) + i=select(st,kk) if kk else None + repair=False + if kc: + k=select(sc,kc);xx,yy,ww,hh,aa=sc[k] + if i is None:repair=True + elif side==0 and xx=78 and yy+hh<75 and aa>st[i,4]*.35:repair=True + if repair: + cut=mask.copy();cut[yy+hh+3:]=0 + cut[:,:max(0,xx-5)]=0;cut[:,min(84,xx+ww+5):]=0 + n,l,st,ce=cv2.connectedComponentsWithStats(cut) + if n>1:i=max(range(1,n),key=lambda k:st[k,4]) + if i is None:return None + x,y,w,h,area=st[i];cx,cy=ce[i] + hm=np.zeros((84,84),np.uint8) + pts=np.argwhere(l==i)[:,::-1].astype(np.int32) + cv2.fillConvexPoly(hm,cv2.convexHull(pts),1) + hm=cv2.erode(hm,np.ones((3,3),np.uint8)) + hm[:int(y+h*.28)]=0;hm[int(y+h*.90):]=0 + bright=((lo>190)&(hi-lo<25)&(hm>0)).astype(np.uint8) + nn,ll,ss,cc=cv2.connectedComponentsWithStats(bright) + handles=[k for k in range(1,nn) if ss[k,4]>4 and ss[k,3]>h*.18] + if handles: + k=max(handles,key=lambda k:ss[k,4]);cx=cc[k,0] + return x,y,w,h,area,cx,cy + @staticmethod + def distant_mug(im,side=0): + lo=im.min(2).astype(float);hi=im.max(2).astype(float) + mask=((hi-lo<28)&(lo>65)&(hi<235)).astype('uint8');mask[78:]=0 + n,l,st,ce=cv2.connectedComponentsWithStats(mask) + cand=[] + for i,(x,y,w,h,area) in enumerate(st[1:],1): + if area>35 and 57 and h>0.7*w and y<55: + cand.append((x,y,w,h,area,ce[i][0],ce[i][1],i)) + if not cand:return None + # At an open hand the mug is the large gray component. + c=max(cand,key=lambda c:c[4]) if side==0 else max(cand,key=lambda c:c[0]+c[2]) + x,y,w,h,area,cx,cy,i=c + hm=np.zeros((84,84),np.uint8) + pts=np.argwhere(l==i)[:,::-1].astype(np.int32) + cv2.fillConvexPoly(hm,cv2.convexHull(pts),1) + hm=cv2.erode(hm,np.ones((3,3),np.uint8)) + hm[:int(y+h*.28)]=0;hm[int(y+h*.90):]=0 + bright=((lo>190)&(hi-lo<25)&(hm>0)).astype(np.uint8) + nn,ll,ss,cc=cv2.connectedComponentsWithStats(bright) + handles=[k for k in range(1,nn) if ss[k,4]>4 and ss[k,3]>h*.18] + if handles: + k=max(handles,key=lambda k:ss[k,4]);cx=cc[k,0] + return x,y,w,h,area,cx,cy + def act(self,o,tools): + t=o['t'];self.a[:2]=0;self.a[3]=0 + if t>=200 and self.distant is None: + visible=self.distant_mug(tools.image('left_wrist')) + self.distant=bool(visible is not None and visible[3]<=33) + targets=[np.array([-1.25,0,0,1.25,0,-.12,0.]),np.array([-1.4,-.2,0,1.4,0,-.12,0.])] + if self.phase=='init': + if t<120: + self.x=-.20;targets=[np.array([-2.6,0,0,2.09,0,.4,0.])]*2 + elif t<220: + self.x=-.14;targets=[np.array([-1.5,.16,0,1.5,0,-.12,0.]),np.array([-1.4,-.1,0,1.4,0,-.12,0.])] + else: + self.phase='align';self.sh[0]=-1.5;self.roll[0]=.16;self.settle=t+30 + self.base(o,self.x,self.y) + if self.phase in ('align','close','lift'): + i=self.side + for j in range(2): + if self.held[j]:targets[j]=self.holdarms[j].copy() + targets[i]=np.array([self.sh[i],self.roll[i],0,-self.sh[i],0,-.12,0.]) + self.shoulder=self.sh[i] + if self.phase=='align': + if t%5==0 and self.walk==0: + detector=self.distant_mug if self.distant else self.mug + m=detector(tools.image('left_wrist' if i==0 else 'right_wrist'),i) + self.last=m + if m is None and not self.distant: + self.lost+=5 + if self.lost>40: + im=tools.image('left_wrist' if i==0 else 'right_wrist') + lo=im.min(2).astype(float);hi=im.max(2).astype(float) + mask=((hi-lo<28)&(lo>65)&(hi<235)).astype(np.uint8) + nn,ll,ss,cc=cv2.connectedComponentsWithStats(mask) + loose=[k for k in range(1,nn) if ss[k,4]>50] + if loose: + k=max(loose,key=lambda k:ss[k,4]);cy=cc[k,1] + self.sh[i]=np.clip(self.sh[i]+np.clip((cy-40)*.001,-.025,.025),-1.9,-.7) + if m: + self.lost=0 + x,y,w,h,area,cx,cy=m + self.roll[i]=np.clip(self.roll[i]+np.clip((42-cx)*.0007,-.02,.02),-.5,.6 if i==0 else .13) + self.sh[i]=np.clip(self.sh[i]-np.clip((60-(y+h))*.0007,-.015,.015),-1.7,-.7) + if abs(cx-42)<5 and abs(y+h-60)<22 and h<60 and t>self.settle: + if self.distant: + self.walk=t+(50 if w<45 else 35);self.walkspeed=.14 if w<45 else .10 + else: + self.walk=t+(65 if w<35 else 35);self.walkspeed=.16 if w<35 else .10 + self.settle=self.walk+60;self.walkaxis=0 + if i==1 and self.roll[i]>.12 and cx<32 and t>self.settle: + self.walk=t+55;self.settle=self.walk+60;self.walkspeed=.15;self.walkaxis=1 + if abs(cx-42)<4 and h>=53 and abs(y+h-60)<8 and t>self.settle: + self.phase='close';self.gt=t;self.grasp=True + targets[i]=np.array([self.sh[i],self.roll[i],0,-self.sh[i],0,-.12,0.]) + if self.walk>t:self.a[self.walkaxis]=self.walkspeed + elif self.walk:self.walk=0 + if self.phase=='close': + self.a[19+i]=1 + if t-self.gt>40:self.phase='lift' + if self.phase=='lift': + targets[i]=np.array([-1.6,self.roll[i],0,1.45,0,-.12,0.]) + if t-self.gt>115: + self.held[i]=True;self.holdarms[i]=targets[i].copy() + if i==0: + self.side=1;self.phase='align';self.walk=0;self.settle=t+60;self.grasp=False + else:self.phase='transfer';self.pt=t + if self.phase=='transfer': + targets=[h.copy() for h in self.holdarms] + self.base(o,-.46,.02,0) + if np.linalg.norm(o['low_dim_obs'][21:23]-np.array([-.46,.02]))<.06: + self.phase='lower';self.pt=t + if self.phase=='lower': + targets=[h.copy() for h in self.holdarms] + self.a[2]=max(.51,.74-(t-self.pt)*.0015) + if t-self.pt>180:self.phase='release';self.pt=t + if self.phase=='release': + targets=[h.copy() for h in self.holdarms];self.a[19:]=0 + for j in range(2): + sl=slice(5+7*j,12+7*j);self.a[sl]+=np.clip(targets[j]-self.a[sl],-.025,.025) + return self.a.copy() diff --git a/policies/dishwasher_load_cups/astra-s3/episodes.csv b/policies/dishwasher_load_cups/astra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..f1130e14abc5282f697b14dce52982f4a56de0ca --- /dev/null +++ b/policies/dishwasher_load_cups/astra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,1,1523,success,0 +620003,1,1655,success,0 +620004,1,1495,success,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,1,1428,success,0 +620009,1,1668,success,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,1,1656,success,0 +620016,0,2000,timeout,0 +620017,1,1765,success,0 +620018,0,2000,timeout,0 +620019,1,1400,success,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,1,1412,success,0 +620023,1,1659,success,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,1,1720,success,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,1,1654,success,0 +620038,1,1515,success,0 +620039,1,1660,success,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,1,1509,success,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,1,1453,success,0 +620049,1,1513,success,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,1,1409,success,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,1,1657,success,0 +620065,1,1434,success,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,1,1732,success,0 +620072,1,1663,success,0 +620073,1,1656,success,0 +620074,1,1601,success,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,1,1557,success,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,1,1814,success,0 +620083,0,2000,timeout,0 +620084,1,1503,success,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,1,1401,success,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,1,1676,success,0 +620097,1,1659,success,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/astra-s3/policy.py b/policies/dishwasher_load_cups/astra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..99a5a62870f6f863ef46407af8c3baf2c4e8dfe4 --- /dev/null +++ b/policies/dishwasher_load_cups/astra-s3/policy.py @@ -0,0 +1,140 @@ +"""Deterministic visual servoing for the two dishwasher mugs.""" +import cv2 +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32) + self.a[19:] = .3 + self.a[5:12] = [-.35,.2,0,0,0,-.05,0] + self.a[12:19] = [-.35,0,.4,0,0,.15,0] + self.carry = None + self.phase=0;self.phase_start=0;self.lift_start=None;self.search_pose=None;self.last_cup=None;self.grip_count=0 + + @staticmethod + def cup(im, side): + hsv=cv2.cvtColor(im,cv2.COLOR_RGB2HSV) + mask=((hsv[:,:,1]<40)&(hsv[:,:,2]>65)&(hsv[:,:,2]<245)).astype('uint8') + mask[80:]=0; mask[:,:5]=0; mask[:,79:]=0 + _,_,st,_=cv2.connectedComponentsWithStats(mask) + cand=[] + for x,y,w,h,area in st[1:]: + if area>150 and h>12 and w>8 and w<=74 and y<60: + cand.append((x+w/2,y+h,w,h,area)) + return min(cand,key=lambda z:-z[4] if side==0 else abs(z[0]-42)) if cand else None + + + @staticmethod + def handle(im,z): + x,y,w,h,area=z;y0=max(4,int(y-h)+max(6,int(h*.22)));y1=min(y0+10,int(y)-6) + if y1<=y0+3:return x + hsv=cv2.cvtColor(im,cv2.COLOR_RGB2HSV);v=hsv[:,:,2].astype(float) + m=((hsv[:,:,1]<40)&(v>70)&(v<245)).astype('uint8') + row=(m[y0:y1].mean(axis=0)>.5).astype('uint8')[None,:] + row=cv2.morphologyEx(row,cv2.MORPH_CLOSE,np.ones((1,9),np.uint8)) + n,la,st,ce=cv2.connectedComponentsWithStats(row) + cand=[r for r in st[1:] if r[2]>12] + if not cand:return x + r=max(cand,key=lambda r:r[2]);l=r[0]+3;rr=r[0]+r[2]-3 + p=v[y0:y1].mean(axis=0);hi=cv2.GaussianBlur(p[None,:],(0,0),.7)[0];lo=cv2.GaussianBlur(p[None,:],(0,0),6)[0];score=hi-lo + score[:l]=-100;score[rr:]=-100;i=int(np.argmax(score)) + return i if score[i]>7 else x + + def act(self, obs, tools): + t=obs['t']; a=self.a; p=obs['low_dim_obs'][21:25] + if self.phase < 2: + side=self.phase; k=t-self.phase_start; j=5+7*side + if k==0 and side==1: + a[12:19]=[-.35,0,.4,0,0,.15,0] + a[:2]=0; a[3]=0 + if self.lift_start is not None: + f=min(1.,(t-self.lift_start)/40.) + a[j]=self.grasp_pose[j]-.35*f + a[j+5]=self.grasp_pose[j+5]+.35*f + if side==0:a[j+1]=self.grasp_pose[j+1]+.10*f + if f>=1: + self.phase+=1;self.phase_start=t+1;self.lift_start=None + self.last_cup=None;self.search_pose=None + return a.copy() + if 80.012 else 0 + if 0=330: + a[19+side]=1 + self.grip_count = self.grip_count+1 if .75=10: + self.lift_start=t;self.grasp_pose=a.copy() + a[:2]=0;a[3]=0 + elif k>=350: + if self.search_pose is None:self.search_pose=a.copy() + u=k-350 + if u<80: + a[19+side]=.3 + if u>=10 and u%10==0: + im=tools.image(['left_wrist','right_wrist'][side]) + z=self.cup(im,side) + if z: + self.last_cup=z + cx=self.handle(im,z) + a[j+6]+=np.clip(.003*(42-cx),-.035,.035) + a[j+5]+=np.clip(.003*(z[1]-52),-.035,.035) + if u<60 and self.last_cup is not None and self.last_cup[4]<2500: + a[0]=.065;a[3]=np.clip(-p[3]*3,-.3,.3) + self.search_pose=a.copy() + elif u<110: + a[19+side]=1 + else: + cycle=min((u-110)//50,2);tick=(u-110)%50 + a[19+side]=.3 if tick<18 else 1 + d=[0,-.16,.16][cycle] + dz=[.12,-.08,-.08][cycle] + a[j+2]=self.search_pose[j+2]+d + a[j+6]=self.search_pose[j+6]+d + a[j]=self.search_pose[j]+dz + a[j+5]=self.search_pose[j+5]-dz + if u>=250: + a[19+side]=1 + self.lift_start=t;self.grasp_pose=a.copy();a[:2]=0;a[3]=0 + else: + k=t-self.phase_start + if self.carry is None:self.carry=a.copy() + start=self.carry; yaw=p[3] + if k<360: + delta=np.array([.28,-.45])-p[:2];v=delta*1.5;n=np.linalg.norm(v) + if n>.15:v*=.15/n + if np.linalg.norm(delta)<.025:v*=0 + elif n<.065:v*=.065/(n+1e-9) + a[:2]=np.array([[np.cos(yaw),np.sin(yaw)],[-np.sin(yaw),np.cos(yaw)]])@v + a[3]=np.clip(2*(1.57-yaw),-.55,.55) + else:a[:2]=0;a[3]=0 + if 290<=k<380: + f=(k-290)/89 + a[6]=start[6]*(1-f) + a[7]=-.5*f + a[14]=start[14]*(1-f)+.2*f + if 390<=k<540: + f=(k-390)/150;a[2]=.74-.10*f + for j in [5,12]:a[j+3]=start[j+3]+.8*f;a[j+5]=start[j+5]-.8*f + if k==570:a[19:]=0 + if 590<=k<650: + a[19:]=.4 + f=(k-590)/59 + for j in [5,12]: + a[j]=start[j]+.45*f + a[j+5]=start[j+5]-.8-.45*f + if 660<=k<730:a[2]=.64+.10*(k-660)/70 + return a.copy() diff --git a/policies/dishwasher_load_cups/deepseek1017-s1/episodes.csv b/policies/dishwasher_load_cups/deepseek1017-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..97b5a1565fc1fb59d3f628bff6fe533d8d53f9a2 --- /dev/null +++ b/policies/dishwasher_load_cups/deepseek1017-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,1347,terminated,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,1145,terminated,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,1152,terminated,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,1236,terminated,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,1231,terminated,0 +620050,0,2000,timeout,0 +620051,0,1144,terminated,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,1153,terminated,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,1268,terminated,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,1341,terminated,0 +620092,0,1223,terminated,0 +620093,0,1114,terminated,0 +620094,0,2000,timeout,0 +620095,0,1223,terminated,0 +620096,0,2000,timeout,0 +620097,0,1217,terminated,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/deepseek1017-s1/policy.py b/policies/dishwasher_load_cups/deepseek1017-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..209334a2c65fa88923d6bfe76b945991da96399d --- /dev/null +++ b/policies/dishwasher_load_cups/deepseek1017-s1/policy.py @@ -0,0 +1,111 @@ +"""Control policy for the dishwasher mug-loading task (Unitree G1). + +Task: move two mugs from the counter into the wire rack of the dishwasher. + +The counter is relatively tall for the robot, so the arms work near full +stretch and the base tends to be pushed away when an arm presses on the +counter; the policy keeps station with a small forward velocity command. +The rack sits on the floor just to the robot's left / in front of the +counter, so the scripted arm sweeps are always directed towards that side, +followed by a low sweep and a couple of gripper attempts at the rack. +Everything is deterministic hand-written joint-space logic (no learned +components). +""" + +import numpy as np + + +class Policy: + """Deterministic scripted attempt at loading the mugs into the rack.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.t = 0 + + @staticmethod + def _arm(a, off, sp, sr, sy, el, wr, wp, wy): + a[off] = sp + a[off + 1] = sr + a[off + 2] = sy + a[off + 3] = el + a[off + 4] = wr + a[off + 5] = wp + a[off + 6] = wy + + def act(self, obs, tools): + a = self.hold.copy() + t = self.t + a[2] = 0.82 + a[4] = 0.20 + a[19] = 0.0 + a[20] = 0.0 + + if t < 25: + # settle and back away a little to free the arms + a[0] = -0.30 + a[2] = 0.74 + a[4] = 0.0 + elif t < 70: + # stand tall, lean towards the counter, hold station + a[0] = 0.12 + a[2] = 0.88 + for off in (5, 12): + self._arm(a, off, 0.8, 0.10, 0.0, 0.0, 0.0, -0.5, 0.0) + elif t < 1000: + # sweep the counter top, always moving the hands to the rack + # side (increasing shoulder yaw), resetting between passes. + a[0] = 0.10 + a[2] = 0.82 + a[4] = 0.20 + cyc = (t - 70) % 100 + f = cyc / 99.0 + band = (t - 70) // 100 + sps = (1.35, 1.55, 1.75, 1.95, 2.15, 2.35) + srs = (-0.4, -0.1, 0.1, 0.3) + els = (-0.5, -0.2, 0.1, 0.4) + wps = (-1.1, -0.8, -0.5, -0.2) + sp = sps[band % len(sps)] + sr = srs[(band // len(sps)) % len(srs)] + el = els[(band // (len(sps) * len(srs))) % len(els)] + wp = wps[(band // (len(sps) * len(srs) * len(els))) % len(wps)] + if f < 0.15: + # lift the hand out of the counter and return to the start + sy = -1.0 + sp_l = min(sp + 0.25, 2.5) + else: + sy = -1.0 + (f - 0.15) / 0.85 * 2.0 + sp_l = sp + for off in (5, 12): + self._arm(a, off, sp_l, sr, sy, el, 0.0, wp, 0.0) + elif t < 1350: + # low sweep at the rack level to gather anything that fell + a[0] = 0.04 + a[2] = 0.78 + a[4] = 0.28 + cyc = (t - 1000) % 88 + f = cyc / 87.0 + band = (t - 1000) // 88 + sy = -1.0 + f * 2.0 + sp = 0.55 + 0.15 * (band % 3) + el = -0.55 + 0.15 * ((band // 3) % 2) + for off in (5, 12): + self._arm(a, off, sp, 0.20, sy, el, 0.0, -0.55, 0.0) + elif t < 1500: + # gripper attempts at the rack + a[0] = 0.0 + a[2] = 0.78 + a[4] = 0.28 + cyc = (t - 1350) % 50 + g = 1.0 if cyc < 25 else 0.0 + for off in (5, 12): + self._arm(a, off, 0.75, 0.20, 0.0, -0.45, 0.0, -0.55, 0.0) + a[19] = g + a[20] = g + else: + # safe rest + a[2] = 0.74 + a[4] = 0.0 + for off in (5, 12): + self._arm(a, off, 0.15, 0.0, 0.0, 0.1, 0.0, 0.0, 0.0) + self.t += 1 + return a diff --git a/policies/dishwasher_load_cups/deepseek1017-s2/episodes.csv b/policies/dishwasher_load_cups/deepseek1017-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..bb558511390eaaecfd3a2b2c81d19681eb1b325a --- /dev/null +++ b/policies/dishwasher_load_cups/deepseek1017-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/deepseek1017-s2/policy.py b/policies/dishwasher_load_cups/deepseek1017-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c3bb800fb53c4416eb414176430c2b299f9952f8 --- /dev/null +++ b/policies/dishwasher_load_cups/deepseek1017-s2/policy.py @@ -0,0 +1,168 @@ +"""Hand-written control policy for "place the two mugs into the dishwasher +upper rack". + +Scene (measured from the robot's own cameras and by probing): + * reset: robot at about (-0.07, -0.60) facing +x. Two mugs stand on the + counter directly ahead. The dishwasher's upper rack is a large white + wire rack to the robot's left, low down. + * the reach that actually puts the left gripper around a mug (verified by + the finger joints staying open after a vertical lift) is: lean the torso + forward (+0.5 rad) and extend both arms straight ahead/down + (shoulder pitch -1.9, elbow 0.2), then close. + +Behaviour: lean forward and extend the arms, close the grippers, lift by +standing up, carry the mug(s) sideways over the rack, lower the body and the +arms and open the grippers. Then return to the counter and repeat once with +a small lateral offset so the right hand can pick the second mug. All +control is deterministic feedback; constants were tuned by running episodes. +""" + +import numpy as np + +# Arm targets (shoulder_pitch, shoulder_roll, shoulder_yaw, elbow, +# wrist_roll, wrist_pitch, wrist_yaw). +GRASP = np.array([-1.90, 0.00, 0.00, 0.20, 0.00, 0.00, 0.00], np.float32) +CARRY = np.array([-1.70, 0.00, 0.00, 0.60, 0.00, 0.00, 0.00], np.float32) +PLACE_ARM = np.array([-0.55, 0.00, 0.00, 0.55, 0.00, 0.25, 0.00], np.float32) + +RACK_X = -0.15 +RACK_Y = 0.15 +COUNTER_X = -0.08 +COUNTER_Y = -0.60 + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + ld = np.asarray(obs["low_dim_obs"], dtype=np.float32) + self.ld = ld + self.base = np.array([ld[21], ld[22], ld[24]], np.float32) + self.phase = "reach" + self.phase_t = 0 + self.cycle = 0 # 0: first mug, 1: second mug + self.grabbed = False + self.done = False + + # ------------------------------------------------------------------ utils + @staticmethod + def _wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + def _arm_targets(self, des_l, des_r): + ml = self.ld[3:10] + mr = self.ld[12:19] + corr_l = np.clip(1.6 * (des_l - ml), -0.8, 0.8) + corr_r = np.clip(1.6 * (des_r - mr), -0.8, 0.8) + return des_l + corr_l, des_r + corr_r + + def _base_cmd(self, tx, ty, tyaw, vmax, kv=3.0): + x, y, yaw = float(self.ld[21]), float(self.ld[22]), float(self.ld[24]) + dx, dy = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + vx_b = c * dx + s * dy + vy_b = -s * dx + c * dy + vx = float(np.clip(kv * vx_b, -vmax, vmax)) if abs(vx_b) > 0.02 else 0.0 + vy = float(np.clip(kv * vy_b, -vmax, vmax)) if abs(vy_b) > 0.02 else 0.0 + ey = self._wrap(tyaw - yaw) + wz = float(np.clip(1.8 * ey, -0.4, 0.4)) if abs(ey) > 0.01 else 0.0 + return vx, vy, wz + + def _make(self, gl, gr, des_l, des_r, height, pitch, vx, vy, wz): + tl, tr = self._arm_targets(des_l, des_r) + raw = self.hold.copy() + raw[0], raw[1], raw[2], raw[3], raw[4] = vx, vy, height, wz, pitch + raw[5:12] = tl + raw[12:19] = tr + raw[19], raw[20] = gl, gr + return raw + + def _next(self, phase): + self.phase = phase + self.phase_t = 0 + + def _blocked(self): + return (float(np.max(self.ld[10:12])) > -0.008 or + float(np.max(self.ld[19:21])) > -0.008) + + # ---------------------------------------------------------------- behaviour + def act(self, obs, tools): + self.ld = np.asarray(obs["low_dim_obs"], dtype=np.float32) + self.phase_t += 1 + pitch = 0.5 + # lateral offset used to line up the other hand on the second mug + dy = 0.0 if self.cycle == 0 else -0.10 + + if self.phase == "reach": + # lean forward and extend the arms over the counter + vx, vy, wz = self._base_cmd(self.base[0] + 0.02 if self.cycle == 0 else COUNTER_X, + self.base[1] + dy if self.cycle == 0 else COUNTER_Y + dy, + self.base[2], 0.10) + raw = self._make(0.0, 0.0, GRASP, GRASP, 0.74, pitch, vx, vy, wz) + if self.phase_t >= 115: + self._next("close") + + elif self.phase == "close": + vx, vy, wz = self._base_cmd(self.ld[21], self.ld[22], 0.0, 0.05) + raw = self._make(1.0, 1.0, GRASP, GRASP, 0.74, pitch, vx, vy, wz) + if self.phase_t >= 32: + self.grabbed = self._blocked() + self._next("lift") + + elif self.phase == "lift": + # stand up while keeping the arm pose: vertical lift preserves + # the grasp + vx, vy, wz = self._base_cmd(self.ld[21], self.ld[22], 0.0, 0.05) + raw = self._make(1.0, 1.0, GRASP, GRASP, 0.90, pitch, vx, vy, wz) + if self.phase_t >= 38: + self._next("back") + + elif self.phase == "back": + # back away from the counter before moving sideways + vx, vy, wz = self._base_cmd(-0.55, self.ld[22], 0.0, 0.40) + raw = self._make(1.0, 1.0, CARRY, CARRY, 0.84, 0.2, vx, vy, wz) + x = float(self.ld[21]) + if x < -0.48 or self.phase_t > 110: + self._next("side") + + elif self.phase == "side": + # strafe to the rack + y = float(self.ld[22]) + vy = 0.55 if y < RACK_Y - 0.05 else (0.0 if y < RACK_Y + 0.10 else -0.30) + wz = float(np.clip(-1.8 * self.ld[24], -0.4, 0.4)) + raw = self._make(1.0, 1.0, CARRY, CARRY, 0.84, 0.2, 0.0, vy, wz) + if (abs(y - RACK_Y) < 0.12 and self.phase_t > 40) or self.phase_t > 230: + self._next("over") + + elif self.phase == "over": + # move in over the rack + vx, vy, wz = self._base_cmd(RACK_X, RACK_Y, 0.0, 0.30) + raw = self._make(1.0, 1.0, PLACE_ARM, PLACE_ARM, 0.60, 0.4, vx, vy, wz) + if self.phase_t >= 80: + self._next("release") + + elif self.phase == "release": + vx, vy, wz = self._base_cmd(RACK_X, RACK_Y, 0.0, 0.10) + raw = self._make(0.0, 0.0, PLACE_ARM, PLACE_ARM, 0.46, 0.5, vx, vy, wz) + if self.phase_t >= 60: + if self.cycle == 0: + self.cycle = 1 + self._next("return") + else: + self.done = True + + elif self.phase == "return": + # walk back in front of the counter for the second mug + vx, vy, wz = self._base_cmd(COUNTER_X, COUNTER_Y, 0.0, 0.40) + raw = self._make(0.0, 0.0, CARRY, CARRY, 0.80, 0.2, vx, vy, wz) + x, y = float(self.ld[21]), float(self.ld[22]) + if (abs(x - COUNTER_X) < 0.15 and abs(y - COUNTER_Y) < 0.15 + and self.phase_t > 30) or self.phase_t > 260: + self._next("reach") + + else: + raw = self.hold.copy() + + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + return np.asarray(raw, dtype=np.float32) diff --git a/policies/dishwasher_load_cups/deepseek1017-s3/episodes.csv b/policies/dishwasher_load_cups/deepseek1017-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..bb558511390eaaecfd3a2b2c81d19681eb1b325a --- /dev/null +++ b/policies/dishwasher_load_cups/deepseek1017-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/deepseek1017-s3/policy.py b/policies/dishwasher_load_cups/deepseek1017-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..e0a563d9b555c28e571850bb737e15bc480bf171 --- /dev/null +++ b/policies/dishwasher_load_cups/deepseek1017-s3/policy.py @@ -0,0 +1,157 @@ +"""Hand-written control policy for the Unitree G1 dishwasher-loading task. + +The floating base is regulated with a P controller (raising the arms otherwise +pushes the robot away from the counter). The base walks up to the counter with +the arms hanging (raised arms collide with the counter and stall the walk), then +a fixed sequence of grasp attempts is executed. Each attempt raises/lowers the +arms to a different configuration, closes both grippers, lifts, swings the arms +down over the pulled-out upper rack of the dishwasher and opens the grippers. +The last attempt presses the grippers into the mugs at counter height and drags +back towards the machine. + +The policy is deterministic; the active phase is a function of obs["t"] only. +""" + +import numpy as np + + +class Policy: + """Deterministic scripted policy.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + ld = np.asarray(obs["low_dim_obs"]) + self.btgt = [float(ld[21]), float(ld[22]), float(ld[24])] + self._plan = self._build_plan() + + # ------------------------------------------------------------------ + @staticmethod + def _base_cmd(a, ld, tgt): + x, y, yaw = ld[21], ld[22], ld[24] + tx, ty, tyaw = tgt + ex, ey = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + a[0] = np.clip(3.5 * (c * ex + s * ey), -0.55, 0.55) + a[1] = np.clip(3.5 * (-s * ex + c * ey), -0.55, 0.55) + eyaw = ((tyaw - yaw + np.pi) % (2 * np.pi)) - np.pi + a[3] = np.clip(2.0 * eyaw, -0.6, 0.6) + return a + + @staticmethod + def _arms(a, sp, sr, el, wp, sy): + a[5] = sp + a[6] = sr + a[7] = sy + a[8] = el + a[9] = 0.0 + a[10] = wp + a[11] = 0.0 + a[12] = sp + a[13] = -sr + a[14] = -sy + a[15] = el + a[16] = 0.0 + a[17] = wp + a[18] = 0.0 + + # ------------------------------------------------------------------ + def _build_plan(self): + plan = [] + + def add(n, h=0.74, sp=0.0, sr=0.0, el=0.0, wp=0.0, sy=0.0, + grip=0.0, tp=0.0, walk=0.0, walky=0.0, dy=0.0): + plan.append(dict(n=int(n), h=h, sp=sp, sr=sr, el=el, wp=wp, + sy=sy, grip=grip, tp=tp, walk=walk, + walky=walky, dy=dy)) + + def release(dy, drag=0): + # swing the arms down over the pulled-out upper rack and open + add(14, h=0.74, sp=-0.45, sr=0.60, el=0.90, wp=0.0, + grip=1.0, tp=0.15, dy=dy) + add(14, h=0.72, sp=0.30, sr=1.20, el=0.50, wp=0.0, + grip=1.0, tp=0.30, dy=dy) + add(10, h=0.62, sp=0.30, sr=1.20, el=0.50, wp=0.0, + grip=1.0, tp=0.30, dy=dy) + add(12, h=0.62, sp=0.30, sr=1.20, el=0.50, wp=0.0, + grip=0.0, tp=0.30, dy=dy) + if drag: + # drag the closed grippers back towards the front edge + add(16, h=0.60, sp=-0.90, sr=0.70, el=0.60, wp=0.0, + grip=1.0, tp=0.20, walk=-0.18, dy=dy) + add(10, h=0.74, sp=-0.30, sr=0.50, el=0.80, wp=0.0, + grip=0.0, tp=0.10, walk=-0.10, dy=dy) + + def grasp(sp, sr, el, wp, hclose, dy): + add(16, h=0.74, sp=sp, sr=sr, el=el, wp=wp, dy=dy) + if hclose < 0.70: + for i in range(1, 6): + h = 0.74 + (hclose - 0.74) * i / 5.0 + add(5, h=h, sp=sp, sr=sr, el=el, wp=wp, dy=dy) + add(14, h=hclose, sp=sp, sr=sr, el=el, wp=wp, dy=dy, grip=1.0) + add(10, h=0.74, sp=sp, sr=sr, el=el, wp=wp, dy=dy, grip=1.0) + + # ---- approach with the arms hanging down ------------------------- + add(30, walk=0.25) + add(8) + + # ---- grasp attempt A : extended arm at counter height ------------ + grasp(-0.60, 0.30, 0.00, 0.00, 0.74, -0.020) + release(-0.020) + # ---- grasp attempt B : straight arm --------------------------------- + grasp(-0.30, 0.30, 0.00, 0.00, 0.74, 0.020) + release(0.020) + # ---- grasp attempt C : torch the mugs at counter height and push --- + add(10, h=0.74, sp=-0.50, sr=0.30, el=0.20, wp=0.0) + add(30, h=0.74, sp=-0.50, sr=0.30, el=0.20, wp=0.0, walk=0.22) + add(14, h=0.74, sp=-0.50, sr=0.30, el=0.20, wp=0.0, grip=1.0) + add(12, h=0.74, sp=-1.30, sr=0.30, el=0.20, wp=0.0, grip=1.0) + add(18, h=0.74, sp=-1.30, sr=0.30, el=0.20, wp=0.0, grip=1.0, + walk=-0.18) + release(0.0, drag=1) + # ---- grasp attempt D : squat from above ----------------------------- + grasp(-1.05, 0.30, 0.30, 0.10, 0.61, -0.015) + release(-0.015, drag=1) + # ---- final push-and-drag over the rack ----------------------------- + add(10, h=0.74, sp=-0.50, sr=0.30, el=0.20, wp=0.0, grip=0.0) + add(36, h=0.74, sp=-0.50, sr=0.30, el=0.20, wp=0.0, walk=0.22) + add(14, h=0.74, sp=-0.50, sr=0.30, el=0.20, wp=0.0, grip=1.0) + add(20, h=0.60, sp=-0.90, sr=0.70, el=0.60, wp=0.0, grip=1.0, + tp=0.20, walk=-0.18) + add(20, h=0.62, sp=0.30, sr=1.20, el=0.50, wp=0.0, grip=1.0, + tp=0.30) + add(30, h=0.62, sp=0.30, sr=1.20, el=0.50, wp=0.0, grip=0.0, + tp=0.30) + + # ---- finish --------------------------------------------------------- + add(500, h=0.74, tp=0.0) + return plan + + # ------------------------------------------------------------------ + def act(self, obs, tools): + raw = np.asarray(tools.hold_action(), dtype=np.float32).copy() + ld = np.asarray(obs["low_dim_obs"]) + i = int(obs["t"]) + st = self._plan[-1] + acc = 0 + for p in self._plan: + if i < acc + p["n"]: + st = p + break + acc += p["n"] + raw[2] = st["h"] + raw[4] = st["tp"] + raw[19] = st["grip"] + raw[20] = st["grip"] + self._arms(raw, st["sp"], st["sr"], st["el"], st["wp"], st["sy"]) + if st["walk"] != 0.0 or st["walky"] != 0.0: + raw[0] = st["walk"] + raw[1] = st["walky"] + raw[3] = 0.0 + self.btgt[0] = float(ld[21]) + self.btgt[1] = float(ld[22]) + self.btgt[2] = float(ld[24]) + else: + self._base_cmd(raw, ld, [self.btgt[0], + self.btgt[1] + st["dy"], + self.btgt[2]]) + return raw diff --git a/policies/dishwasher_load_cups/gpt61sol-s1/episodes.csv b/policies/dishwasher_load_cups/gpt61sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..7f5c02595b84789a231590964bc74a552148867d --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,1,1397,success,0 +620002,0,2000,timeout,0 +620003,1,1132,success,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,1,1123,success,0 +620010,0,2000,timeout,0 +620011,1,1138,success,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,869,terminated,0 +620015,0,2000,timeout,0 +620016,1,1135,success,0 +620017,0,2000,timeout,0 +620018,1,1144,success,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,1,1141,success,0 +620023,1,1137,success,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,1,1130,success,0 +620027,1,1143,success,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,1,1156,success,0 +620032,1,1143,success,0 +620033,0,2000,timeout,0 +620034,1,1134,success,0 +620035,1,1391,success,0 +620036,1,1389,success,0 +620037,0,2000,timeout,0 +620038,1,1387,success,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,1,1131,success,0 +620042,0,2000,timeout,0 +620043,1,1134,success,0 +620044,0,2000,timeout,0 +620045,0,857,terminated,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,1,1167,success,0 +620049,1,1156,success,0 +620050,1,1395,success,0 +620051,1,1161,success,0 +620052,1,1146,success,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,1,1143,success,0 +620061,0,2000,timeout,0 +620062,1,1379,success,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,1,1398,success,0 +620067,0,673,terminated,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,1,1146,success,0 +620078,1,1126,success,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,1,1127,success,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,1,1136,success,0 +620085,0,2000,timeout,0 +620086,1,1145,success,0 +620087,1,1385,success,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,1,1138,success,0 +620091,0,2000,timeout,0 +620092,1,1135,success,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,851,terminated,0 +620097,0,2000,timeout,0 +620098,1,1384,success,0 +620099,1,1132,success,0 diff --git a/policies/dishwasher_load_cups/gpt61sol-s1/policy.py b/policies/dishwasher_load_cups/gpt61sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..6316945e2b9f52e3e5ddab4e7bca2d2669d886c7 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61sol-s1/policy.py @@ -0,0 +1,77 @@ +"""Deterministic, hand-written mug loading controller. + +Proprioceptive feedback closes the base motion loop. Wrist camera colour +components guide a second grasp when the fingers have closed on empty space. +All stage timers count control steps, and arm targets are rate limited. +""" + +import numpy as np +import cv2 + +class Policy: + def reset(self, obs, tools): + self.a=np.asarray(tools.hold_action(),dtype=float) + self.a[19:]=0 + self.phase=0;self.start=0;self.missing=[] + self.target=np.array([.14,-.50]) + self.arm=np.array([-.65,.05,0,0,0,.65,0,-.65,.15,0,0,0,.65,0]) + def act(self, obs, tools): + t=obs['t'];v=obs['low_dim_obs'];elapsed=t-self.start + if self.phase==0 and t>=330: + self.a[19:]=1;self.phase=1;self.start=t + elif self.phase==1 and elapsed>=70: + self.missing=[j for j,sl in enumerate((slice(10,12),slice(19,21))) if max(v[sl])<-.018] + self.arm[[0,7]]=-1.05;self.arm[[5,12]]=.90 + if self.missing: + self.phase=8;self.start=t + for j in self.missing: + self.a[19+j]=0;self.arm[7*j]=-.65;self.arm[5+7*j]=.65 + else: + self.phase=2;self.start=t + elif self.phase==8: + if 40<=elapsed<180 and elapsed%20==0: + for j in self.missing: + im=tools.image(('left_wrist','right_wrist')[j]).astype(np.int16) + mean=im.mean(axis=2) + mask=((im.max(axis=2)-im.min(axis=2)<22)&(mean>125)&(mean<215)).astype(np.uint8) + mask[78:]=0 + n,labels,stats,centers=cv2.connectedComponentsWithStats(mask) + candidates=[k for k in range(1,n) if stats[k,4]>120 and stats[k,2]>12 and stats[k,3]>15 and stats[k,1]<60] + if candidates: + k=max(candidates,key=lambda k:stats[k,4]);cx,cy=centers[k] + wh=((im.max(axis=2)-im.min(axis=2)<25)&(im.min(axis=2)>205)).astype(np.uint8) + wn,wl,ws,wc=cv2.connectedComponentsWithStats(wh) + hc=[h for h in range(1,wn) if 6020 and ws[h,3]>ws[h,2]*1.25 and 8=180: + for j in self.missing:self.a[19+j]=1 + if elapsed>=250: + self.arm[[0,7]]=-1.05;self.arm[[5,12]]=.90 + self.phase=2;self.start=t + elif self.phase==2 and elapsed>=100: + self.target=np.array([-.35,-.50]);self.phase=3;self.start=t + elif self.phase==3 and (v[21]<-.32 or elapsed>250): + self.target=np.array([-.35,.0]);self.phase=4;self.start=t + elif self.phase==4 and (v[22]>-.025 or elapsed>450): + self.target=np.array([-.32,.0]);self.phase=5;self.start=t + elif self.phase==5 and elapsed>=100: + self.phase=6;self.start=t + elif self.phase==6 and elapsed>=150: + self.a[19:]=0;self.phase=7;self.start=t + self.a[5:19]+=np.clip(self.arm-self.a[5:19],-.018,.018) + self.a[2]=.74 if self.phase<6 or self.phase==8 else max(.68,self.a[2]-.002) + err=self.target-v[21:23];speed=.12 if self.phase<3 else .25 + vel=np.clip(1.5*err,-speed,speed) + if np.linalg.norm(err)<.015 or (self.phase>=6 and self.phase!=8):vel*=0 + elif np.linalg.norm(vel)<.06:vel*=.06/np.linalg.norm(vel) + if self.phase==8:vel=np.clip(vel,-.12,.12) + yaw=v[24] + self.a[:2]=[np.cos(yaw)*vel[0]+np.sin(yaw)*vel[1],-np.sin(yaw)*vel[0]+np.cos(yaw)*vel[1]] + self.a[3]=np.clip(-3*yaw,-.2,.2) + return self.a.copy() diff --git a/policies/dishwasher_load_cups/gpt61sol-s2/episodes.csv b/policies/dishwasher_load_cups/gpt61sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..775806c95577c1d9b9d1a781e4f7aebbf7f6bebe --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,598,terminated,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,1,1998,success,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,665,terminated,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,885,terminated,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,607,terminated,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,1670,terminated,0 +620038,0,2000,timeout,0 +620039,0,1945,terminated,0 +620040,0,997,terminated,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,603,terminated,0 +620048,0,1975,terminated,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,829,terminated,0 +620057,0,2000,timeout,0 +620058,0,603,terminated,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,617,terminated,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,673,terminated,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,668,terminated,0 +620071,0,2000,timeout,0 +620072,0,755,fell,1 +620073,0,2000,timeout,0 +620074,1,2000,success,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,606,terminated,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,500,terminated,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,616,terminated,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/gpt61sol-s2/policy.py b/policies/dishwasher_load_cups/gpt61sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..96797376d5ea016702d3802c96c9d2f7a5017888 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61sol-s2/policy.py @@ -0,0 +1,120 @@ +"""Deterministic control using wrist segmentation and pelvis feedback. + +The motion phases and geometric thresholds are manually tuned constants. +There are no fitted models, seed-dependent actions, or demonstration reads. +""" + +import numpy as np +import cv2 + +class Policy: + + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=float) + self.a[19:] = 0 + self.stage = 0 + self.age = 0 + self.roll = 0.36 + self.sp = -1.4 + self.wp = 1.6 + self.lastcup = None + self.retried = False + up = [-2.4, 0.36, 0, 0.9, 0, 1.35, 0] + carry = [-2.3, 0, 0, 1.4, 0, 0.9, 0] + place = [-1.8, 0, 0, 0.2, 0, 1.6, 0] + self.plan = [(100, up, 0.74, 0.3, 0, None, 'raise'), + (140, up, 0.74, 0.3, 0, [0.065, -0.6], 'walk'), + (150, None, 0.74, 0.3, 0, None, 'aim'), + (40, None, 0.74, 0.3, 1, None, 'close'), + (75, [-2.3, 0.36, 0, 0.9, 0, 1.35, 0], 0.74, 0.3, 1, None, 'lift'), + (230, carry, 0.74, 0, 1, [-0.5, -0.1], 'transfer'), + (100, carry, 0.74, 0, 1, [-0.27, -0.13], 'advance'), + (80, place, 0.74, 0.3, 1, None, 'place'), + (40, place, 0.7, 0.3, 1, None, 'lower'), + (40, place, 0.7, 0.3, 0, None, 'release'), + (140, up, 0.74, 0.3, 0, [-0.45, -0.6], 'return'), + (130, up, 0.74, 0.3, 0, [0.065, -0.6], 'walk'), + (90, None, 0.74, 0.3, 0, None, 'aim'), + (40, None, 0.74, 0.3, 1, None, 'close'), + (70, [-2.3, 0.36, 0, 0.9, 0, 1.35, 0], 0.74, 0.3, 1, None, 'lift'), + (230, carry, 0.74, 0, 1, [-0.5, -0.1], 'transfer'), + (100, carry, 0.74, 0, 1, [-0.27, -0.13], 'advance'), + (80, [-1.8, 0.1, 0, 0.2, 0, 1.6, 0], 0.74, 0.3, 1, None, 'place'), + (40, [-1.8, 0.1, 0, 0.2, 0, 1.6, 0], 0.7, 0.3, 1, None, 'lower'), + (40, [-1.8, 0.1, 0, 0.2, 0, 1.6, 0], 0.7, 0.3, 0, None, 'release')] + + def cup(self, im): + """Find a neutral-colored mug body in the wrist view.""" + hi = im.max(2) + lo = im.min(2) + m = ((hi.astype(int) - lo < 35) & (lo > 65) & (hi < 215)).astype(np.uint8) + m[65:] = 0 + n, l, st, ct = cv2.connectedComponentsWithStats(m) + ids = [i for i in range(1, n) if st[i, 4] > 40 and st[i, 2] > 5 and (st[i, 3] > 7) and (st[i, 1] < 50)] + if not ids: + return None + i = min(ids, key=lambda i: abs(ct[i, 0] - 42) - min(st[i, 4], 1000) * 0.012) + return (ct[i], st[i]) + + def walk(self, o, xy): + """Track a base destination, allowing for velocity lag.""" + p = o['low_dim_obs'] + yaw = p[24] + err = np.array(xy) - p[21:23] - 0.22 * p[46:48] + v = np.clip(err * 2.0, -0.32, 0.32) + for j in range(2): + if abs(err[j]) < 0.015: + v[j] = 0 + elif abs(v[j]) < 0.065: + v[j] = np.sign(v[j]) * 0.065 + c = np.cos(yaw) + s = np.sin(yaw) + return np.array([c * v[0] + s * v[1], -s * v[0] + c * v[1]]) + + def act(self, obs, tools): + self.age += 1 + self.a[0:2] = 0 + self.a[3] = np.clip(-obs['low_dim_obs'][24] * 2, -0.3, 0.3) + idx = min(self.stage, len(self.plan) - 1) + n, q, h, p, g, xy, name = self.plan[idx] + if name == 'aim' and self.age == 1: + self.sp = -1.4 + self.roll = 0.36 if idx < 9 else 0.105 + self.wp = 1.6 + if name == 'aim' and idx < 9 and (self.age > 50) and (self.age % 10 == 0): + cup = self.cup(tools.image('left_wrist')) + if cup is not None: + (x, y), st = cup + self.lastcup = [float(x), float(y), int(st[4])] + self.roll = np.clip(self.roll + np.clip((42 - x) * 0.0013, -0.035, 0.035), -0.1, 0.65) + if not self.retried: + self.wp = np.clip(self.wp + (y - 25) * 0.001, 1.3, 1.61) + self.sp = np.clip(self.sp + np.clip((y - 25) * 0.001, -0.03, 0.03), -1.65, -0.9) + # Preserve steep grasp angles during the first transfer. + if name in ('lift', 'transfer', 'advance') and idx < 10 and (self.sp + 0.2 + self.wp + 0.3 > 0.65): + q = [self.sp - 0.5, self.roll, 0, 0.7, 0, self.wp, 0] + p = 0.3 + if q is None: + q = [self.sp, self.roll, 0, 0.2, 0, self.wp, 0] + target = self.a.copy() + target[5:12] = q + target[2] = h + target[4] = p + target[19] = g + limits = np.array([0.01] * 5 + [0.022] * 14 + [0.06, 0.06]) + self.a += np.clip(target - self.a, -limits, limits) + if xy and obs['low_dim_obs'][23] > 0.69: + self.a[0:2] = self.walk(obs, xy) + if self.age >= n: + fingers = obs['low_dim_obs'][10:12] + # Fully closed fingers indicate an empty first pickup. + if idx == 3 and (not self.retried) and (float(np.mean(fingers)) < -0.0185): + self.retried = True + self.sp = min(-1.1, self.sp + 0.12) + self.wp = max(1.2, self.wp - 0.12) + self.stage = 2 + self.age = 100 + else: + self.stage += 1 + self.age = 0 + return self.a.copy() diff --git a/policies/dishwasher_load_cups/gpt61sol-s3/episodes.csv b/policies/dishwasher_load_cups/gpt61sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..6f308d52b1896f95a6cff2d9b8c8809605c03b3e --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,860,terminated,0 +620004,1,1712,success,0 +620005,0,862,terminated,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,782,terminated,0 +620010,0,2000,timeout,0 +620011,0,790,terminated,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,867,terminated,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,994,terminated,0 +620021,0,918,terminated,0 +620022,0,2000,timeout,0 +620023,1,1780,success,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,1,1758,success,0 +620037,0,2000,timeout,0 +620038,0,793,terminated,0 +620039,0,865,terminated,0 +620040,1,1714,success,0 +620041,1,1706,success,0 +620042,1,1912,success,0 +620043,0,778,terminated,0 +620044,0,851,terminated,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,1,1703,success,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,763,terminated,0 +620053,1,1712,success,0 +620054,1,1750,success,0 +620055,0,2000,timeout,0 +620056,1,1707,success,0 +620057,0,2000,timeout,0 +620058,0,798,terminated,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,781,terminated,0 +620071,0,2000,timeout,0 +620072,0,859,terminated,0 +620073,1,1694,success,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,861,terminated,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,1,1919,success,0 +620081,0,859,terminated,0 +620082,1,1757,success,0 +620083,1,1699,success,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,882,terminated,0 +620089,0,750,terminated,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,1,1709,success,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,858,terminated,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/gpt61sol-s3/policy.py b/policies/dishwasher_load_cups/gpt61sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..7113c2e63760635f2926f5fc8974cf06f9fb5f22 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61sol-s3/policy.py @@ -0,0 +1,125 @@ +"""Deterministic, hand-written mug loading controller. + +Proprioceptive feedback holds the base near each waypoint. A single wrist +camera measurement adjusts the initial reaches; all motions use control steps. +""" + +import cv2 +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=float) + self.roll_offsets = np.zeros(2) + self.pitch_offsets = np.zeros(2) + + def align(self, tools): + # Gray cup walls provide a simple reference before the fingers close. + for side, camera in enumerate(("left_wrist", "right_wrist")): + im = tools.image(camera) + maximum = im.max(axis=2) + minimum = im.min(axis=2) + mask = ((maximum - minimum < 20) & + (maximum > 75) & (maximum < 240)).astype(np.uint8) + mask[:, :5] = 0 + mask[:, 79:] = 0 + mask[70:] = 0 + mask = cv2.morphologyEx( + mask, cv2.MORPH_OPEN, np.ones((2, 2), np.uint8)) + stats = cv2.connectedComponentsWithStats(mask)[2][1:] + cups = [b for b in stats if b[4] > 100 and b[2] > 8 + and b[3] > 2 and b[1] < 40] + if not cups: + continue + box = (min(cups, key=lambda b: b[0]) if side == 0 + else max(cups, key=lambda b: b[4])) + center = float(box[0] + box[2] / 2) + bottom = float(box[1] + box[3]) + horizontal_error = (22 if side == 0 else 34) - center + vertical_error = bottom - (33 if side == 0 else 13) + if abs(horizontal_error) > 3: + self.roll_offsets[side] = np.clip( + .003 * horizontal_error, -.10, .10) + if abs(vertical_error) > 3: + self.pitch_offsets[side] = np.clip( + .004 * vertical_error, -.12, .12) + + def act(self, obs, tools): + t = obs["t"] + if t == 180: + self.align(tools) + action = self.hold.copy() + action[:5] = [0, 0, .74, 0, 0] + shoulder, elbow, pitch, grip = -.8, .6, 0, 0 + goal_x, goal_y = -.07, -.6 + + # Approach, close, and lift clear of the countertop. + if t >= 100: + goal_x = -.07 + min(.36, (t - 100) * .0013) + if t >= 280: + fraction = min(1, (t - 280) / 90) + shoulder = -.8 + .15 * fraction + pitch = .2 * fraction + if t >= 410: + grip = 1 + if t >= 500: + shoulder -= .55 * min(1, (t - 500) / 80) + if t >= 590: + goal_x = -.2 + + # Go around the open door and approach the rack from the front. + if t >= 820: + goal_x = -.75 + if t >= 1010: + goal_y, goal_x = 0., -.75 + if t >= 1260: + goal_x = -.35 + + # Lower, orient the mugs, release, and withdraw the fingers. + if t >= 1410: + fraction = min(1, (t - 1410) / 170) + shoulder = -1.2 + .55 * fraction + action[2] = .74 - .02 * fraction + if t >= 1630: + grip = 0 + if t >= 1710: + fraction = min(1, (t - 1710) / 80) + shoulder = -.65 + .25 * fraction + if t >= 1820: + fraction = min(1, (t - 1820) / 100) + shoulder = -.4 - 1.6 * fraction + elbow = .6 + fraction + + action[4] = pitch + wrist_pitch = -shoulder - elbow - pitch + ramp = min(1, (t + 1) / 70) + turn = min(1, max(0, (t - 1430) / 150)) + alignment = (min(1, max(0, (t - 180) / 100)) if t < 820 + else max(0, (1120 - t) / 300)) + left_pitch, right_pitch = self.pitch_offsets * alignment + left_roll, right_roll = self.roll_offsets * alignment + action[5:12] = np.array([ + shoulder + left_pitch, .2 + left_roll, 0, elbow, 0, + wrist_pitch - left_pitch + 1.2 * turn, 0]) * ramp + action[12:19] = np.array([ + shoulder - .2 + right_pitch, .3 + right_roll, 0, elbow, + -1.2 * turn, wrist_pitch + .2 - right_pitch, 0]) * ramp + action[19:] = grip + + x, y, _, yaw = obs["low_dim_obs"][21:25] + delta = np.array([goal_x - x, goal_y - y]) + speed = .3 if t >= 820 else .18 + velocity = np.array([ + np.clip(2 * delta[0], -speed, speed) + if abs(delta[0]) > .025 else 0, + np.clip(2 * delta[1], -.25, .25) + if abs(delta[1]) > .03 else 0]) + if t < 820: + velocity[1] = np.clip(velocity[1], -.15, .15) + # Yaw is held near zero, keeping the waypoint axes aligned with the body. + action[0:2] = velocity + action[3] = np.clip(-2 * yaw, -.2, .2) + if t >= 1410: + action[:2] = 0 + return action diff --git a/policies/dishwasher_load_cups/gpt61terra-s1/episodes.csv b/policies/dishwasher_load_cups/gpt61terra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..21bdf9f77809312ddd77fd3e95131351b01576ea --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61terra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,962,terminated,0 +620003,0,2000,timeout,0 +620004,0,977,terminated,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,1933,terminated,0 +620009,0,960,terminated,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,1949,terminated,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,1839,terminated,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,979,terminated,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,962,terminated,0 +620028,0,971,terminated,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,1881,terminated,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,956,terminated,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,1496,terminated,0 +620056,0,958,terminated,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,1360,terminated,0 +620060,0,2000,timeout,0 +620061,0,959,terminated,0 +620062,0,686,terminated,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,1914,terminated,0 +620066,0,956,terminated,0 +620067,0,2000,timeout,0 +620068,0,1905,terminated,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,951,terminated,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,974,terminated,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,1047,terminated,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,1902,terminated,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,973,terminated,0 +620096,0,2000,timeout,0 +620097,0,1756,terminated,0 +620098,0,689,terminated,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/gpt61terra-s1/policy.py b/policies/dishwasher_load_cups/gpt61terra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..d87c8815ae28078d151dbdb8f9caf23e3b5287c4 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61terra-s1/policy.py @@ -0,0 +1,68 @@ +"""Deterministic joint-space controller for the dishwasher task.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.base = np.asarray(tools.hold_action(), dtype=np.float32) + self.phase = 0 + self.start = int(obs['t']) + self.cycle = 0 + + def advance(self, obs): + self.phase += 1 + self.start = int(obs['t']) + + def act(self, obs, tools): + t = int(obs['t']) - self.start + q = obs['low_dim_obs'] + a = self.base.copy() + a[:5] = [0, 0, .74, 0, 0] + a[5:12] = [-2, 0, 0, 0, 0, 0, 0] + a[12:19] = [-2, 0, 0, 0, 0, 0, 0] + a[19:21] = 0 + if self.phase == 0: + if t >= 70: self.advance(obs) + elif self.phase == 1: + a[5:12] = [-1.5, -.3, .5, 1, 0, .1, 0] + a[12:19] = [-1.5, .3, -.5, 1, 0, .1, 0] + if t >= 70: self.advance(obs) + elif self.phase in (2, 3, 4, 5, 6, 7, 8): + a[5:12] = [-1.5, -.3, .5, 1, 0, .1, 0] + a[12:19] = [-1.5, .3, -.5, 1, 0, .1, 0] + if self.phase == 2: + if q[21] < -.03 and t < 120: a[0] = .15 + else: self.advance(obs) + elif self.phase == 3: + if t >= 50: self.advance(obs) + elif self.phase in (4, 5): + a[2] = .64 + a[5] = a[12] = -1.2 + a[10] = a[17] = -.2 + if self.phase == 5: a[19:21] = 1 + if t >= 80: self.advance(obs) + else: + a[5] = a[12] = -1.8 + a[10] = a[17] = .4 + a[19:21] = 1 + if self.phase == 6: + if t >= 100: self.advance(obs) + elif self.phase == 7: + if q[24] < 1.13 and t < 400: a[3] = .18 + else: self.advance(obs) + else: + a[5] = a[12] = -1.35 + a[10] = a[17] = -.05 + if t >= 80: self.advance(obs) + elif self.phase == 9: + a[5:12] = [-1.35, -.3, .5, 1, 0, -.05, 0] + a[12:19] = [-1.35, .3, -.5, 1, 0, -.05, 0] + if t >= 100: self.advance(obs) + elif self.phase == 10: + if q[24] > .04 and t < 400: a[3] = -.2 + else: + self.cycle += 1 + if self.cycle < 2: + self.phase = 1 + self.start = int(obs['t']) + else: self.advance(obs) + return a diff --git a/policies/dishwasher_load_cups/gpt61terra-s2/episodes.csv b/policies/dishwasher_load_cups/gpt61terra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..bb558511390eaaecfd3a2b2c81d19681eb1b325a --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61terra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/gpt61terra-s2/policy.py b/policies/dishwasher_load_cups/gpt61terra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..2500aed1fd6b25da7d2cb37cc36a9ab6c0995fe6 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61terra-s2/policy.py @@ -0,0 +1,44 @@ +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.start_yaw = float(obs['low_dim_obs'][24]) + self.turn_yaw = None + + def act(self, obs, tools): + t = int(obs['t']) + a = self.hold.copy() + a[19:21] = 0.0 + if t < 120: + p, roll, pitch = -1.9, .15, 0.0 + elif t < 220: + p, roll, pitch = -1.9, -.15, 0.0 + elif t < 500: + p, roll, pitch = -1.9, -.15, .35 + elif t < 650: + p, roll, pitch = -1.9 + 1.1*(t-500)/150, -.15, .35 + elif t < 750: + p, roll, pitch = -0.8, -.15, .35 + a[19:21] = 1.0 + elif t < 850: + p, roll, pitch = -0.8 - .9*(t-750)/100, -.15, .35 + a[19:21] = 1.0 + else: + p, roll, pitch = -1.7, -.15, .15 + a[19:21] = 1.0 + if 350 <= t < 455: + a[0] = .1 + if 900 <= t < 1300: + yaw = float(obs['low_dim_obs'][24]) + error = (self.start_yaw + 1.5 - yaw + np.pi) % (2*np.pi) - np.pi + a[3] = np.clip(1.1*error, -.35, .35) if abs(error) > .04 else 0.0 + if t >= 1350: + p = -1.7 + .55*min((t-1350)/120, 1) + pitch = .2 + if t >= 1550: + a[19:21] = 0.0 + a[4] = pitch + a[5:12] = [p, roll, 0, .4, 0, 0, 0] + a[12:19] = [p, -roll, 0, .4, 0, 0, 0] + return a diff --git a/policies/dishwasher_load_cups/gpt61terra-s3/episodes.csv b/policies/dishwasher_load_cups/gpt61terra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..d4d4922567b8b5777fb3f3bd7e4954295adce951 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61terra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,1,1964,success,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,1,1971,success,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,1,1988,success,0 +620010,1,1957,success,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,1932,terminated,0 +620016,0,1565,terminated,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,1,1968,success,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,1932,terminated,0 +620023,1,1974,success,0 +620024,0,709,terminated,0 +620025,0,2000,timeout,0 +620026,1,1963,success,0 +620027,1,1968,success,0 +620028,0,2000,timeout,0 +620029,1,1976,success,0 +620030,1,1983,success,0 +620031,0,1329,terminated,0 +620032,0,2000,timeout,0 +620033,1,1992,success,0 +620034,1,1967,success,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,1,1981,success,0 +620039,1,1975,success,0 +620040,1,1978,success,0 +620041,0,1441,terminated,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,1,1974,success,0 +620045,0,2000,timeout,0 +620046,0,833,terminated,0 +620047,0,1330,terminated,0 +620048,1,1958,success,0 +620049,0,2000,timeout,0 +620050,1,1976,success,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,1,1968,success,0 +620054,1,1960,success,0 +620055,1,1983,success,0 +620056,0,2000,timeout,0 +620057,1,1962,success,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,1429,terminated,0 +620061,1,1955,success,0 +620062,1,1961,success,0 +620063,0,2000,timeout,0 +620064,1,1975,success,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,1330,terminated,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,1,1964,success,0 +620072,0,2000,timeout,0 +620073,1,1790,success,0 +620074,1,1966,success,0 +620075,0,2000,timeout,0 +620076,1,1971,success,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,1,1967,success,0 +620080,1,1962,success,0 +620081,0,2000,timeout,0 +620082,1,1956,success,0 +620083,1,1968,success,0 +620084,1,1965,success,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,1,1960,success,0 +620096,0,1328,terminated,0 +620097,0,2000,timeout,0 +620098,1,1983,success,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/gpt61terra-s3/policy.py b/policies/dishwasher_load_cups/gpt61terra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..2706294ec1d37038a1f5d9e7ef8528488902a78d --- /dev/null +++ b/policies/dishwasher_load_cups/gpt61terra-s3/policy.py @@ -0,0 +1,43 @@ +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = obs['t']; a = self.hold.copy(); a[0:5] = [0,0,.74,0,0] + a[5:12]=[-.65,-.2,0,0,0,.8,0]; a[12:19]=[-.65,.2,0,0,0,.8,0]; a[19:21]=0 + if t < 1060: + if 60<=t<180: a[0]=.15 + if t>=210: a[19:21]=1 + if t>=270: a[5]=a[12]=-.95 + if 320<=t<430: a[0]=-.15 + if 440<=t<595: a[3]=.4 + if 630<=t<860: a[0]=.12 + if t>=760: a[5]=a[12]=-1.4 + if t>=860: a[4]=.3 + if t>=950: a[5]=a[12]=-1.15 + if t>=970: a[19:21]=0 + else: + x,y,_,yaw=obs['low_dim_obs'][21:25] + if t<1220: + a[5]=a[12]=-1.2 + if yaw>.05: a[3]=-.5 + elif t<1310: + a[5]=a[12]=-1.2 + dx,dy=-.15-x,-.47-y + a[0]=np.clip(dx*1.6,-.22,.22) if abs(dx)>.025 else 0 + a[1]=np.clip(dy*1.6,-.22,.22) if abs(dy)>.025 else 0 + else: + if 1350<=t<1510: a[0]=.2 + if 1350<=t<1600: a[4]=.15 + if t>=1530: a[19:21]=1 + if t>=1570: a[5]=a[12]=-.95 + if 1600<=t<1670: a[0]=-.18 + if 1670<=t<1810 and yaw<1.13: a[3]=.5 + if 1780<=t<1870: a[0]=.12; a[1]=.10 + if t>=1780: a[5]=a[12]=-1.4 + if t>=1820: a[4]=.3 + if t>=1860: a[5]=a[12]=-1.15 + if t>=1890: a[19:21]=0 + return a diff --git a/policies/dishwasher_load_cups/gpt6sol-s1/episodes.csv b/policies/dishwasher_load_cups/gpt6sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..f72bfe4b7b143b422a104f3d6b8c4e365b38c371 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt6sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,1974,terminated,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,1923,terminated,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,223,terminated,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,1972,terminated,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,1,1862,success,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,1922,terminated,0 +620065,0,2000,timeout,0 +620066,1,1948,success,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,1937,terminated,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,1902,terminated,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,1797,terminated,0 +620099,0,1888,terminated,0 diff --git a/policies/dishwasher_load_cups/gpt6sol-s1/policy.py b/policies/dishwasher_load_cups/gpt6sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..73b9f0b75f7f907910000f2139abf8c0e3d8ffcb --- /dev/null +++ b/policies/dishwasher_load_cups/gpt6sol-s1/policy.py @@ -0,0 +1,83 @@ +"""Deterministic joint and base controller for the two dishwasher mugs.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.a[0:5] = [0, 0, 0.74, 0, 0] + self.a[5:12] = [-0.3, 0, -0.15, 0, 0, 0, 0] + self.a[12:19] = [-0.3, 0, 0, 0, 0, 0, 0] + self.a[19:21] = 0 + self.stage = 0 + self.elapsed = 0 + # Each move ends at a measured pelvis coordinate or at its safety cap. + # Holds let the joint servos settle before contact or release. + self.stages = [ + ("move", 0, 0.11, 0.12, 180, {}), + ("hold", 30, {19: 1}), + ("hold", 40, {5: -0.8}), + ("move", 0, -0.35, -0.18, 300, {}), + ("move", 1, -0.11, 0.25, 400, {}), + ("move", 0, -0.35, 0.12, 150, {}), + ("hold", 65, {5: 0.32}), + ("hold", 25, {19: 0}), + ("hold", 40, {5: -0.4}), + ("turn", 60), + ("move", 1, -0.62, -0.25, 350, {}), + ("hold", 50, {5: -0.3}), + ("turn", 40), + ("move", 0, 0.11, 0.2, 300, {}), + ("move", 1, -0.42, 0.16, 150, {}), + ("move", 0, 0.19, 0.12, 100, {}), + ("hold", 40, {7: -0.05}), + ("hold", 30, {19: 1}), + ("hold", 40, {5: -0.8}), + ("move", 0, -0.35, -0.18, 300, {}), + ("move", 1, -0.11, 0.3, 250, {}), + ("move", 0, -0.35, 0.12, 120, {}), + ("hold", 45, {7: -0.35}), + ("hold", 65, {5: 0.32}), + ("hold", 25, {19: 0}), + ("hold", 40, {5: -0.4}), + ("hold", 40, {7: 0.5}), + ("hold", 2000, {}), + ] + + def _enter(self, i): + self.stage = i + self.elapsed = 0 + self.a[0] = self.a[1] = self.a[3] = 0 + if i >= len(self.stages): + return + s = self.stages[i] + changes = s[2] if s[0] == "hold" else s[5] if s[0] == "move" else {} + for k, v in changes.items(): + self.a[k] = v + + def act(self, obs, tools): + pelvis = obs["low_dim_obs"][21:25] + while self.stage < len(self.stages): + s = self.stages[self.stage] + kind = s[0] + if kind == "move": + _, axis, target, velocity, cap, _ = s + p = pelvis[axis] + reached = p >= target if velocity > 0 else p <= target + if reached or self.elapsed >= cap: + self._enter(self.stage + 1) + continue + self.a[axis] = velocity + elif kind == "turn": + if self.elapsed >= s[1]: + self._enter(self.stage + 1) + continue + self.a[3] = np.clip(-2.0 * pelvis[3], -0.4, 0.4) + else: + if self.elapsed >= s[1]: + self._enter(self.stage + 1) + continue + self.elapsed += 1 + return self.a.copy() + return self.a.copy() diff --git a/policies/dishwasher_load_cups/gpt6sol-s2/episodes.csv b/policies/dishwasher_load_cups/gpt6sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..1eaf2d6c3014f153fc87cc244f019b9b521960af --- /dev/null +++ b/policies/dishwasher_load_cups/gpt6sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,554,terminated,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,991,terminated,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/gpt6sol-s2/policy.py b/policies/dishwasher_load_cups/gpt6sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c5e94677bb4bed08359b18ecf0692e4646039c27 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt6sol-s2/policy.py @@ -0,0 +1,108 @@ +"""Deterministic joint and body feedback policy for two mugs.""" +import math +import numpy as np + +def walk(error, limit=.15, dead=.01): + if abs(error) < dead: + return 0.0 + return math.copysign(max(.06, min(limit, 2 * abs(error))), error) + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.right_held = False + self.left_second_held = False + self.first_grasped = False + self.right_stage = 0 + + def pose(self, a, side, pitch, roll, yaw, wrist_pitch, wrist_yaw): + j = 5 if side == "left" else 12 + a[j:j+7] = (pitch, roll, yaw, 0, 0, wrist_pitch, wrist_yaw) + + def toward(self, a, q, x_goal, y_goal, yaw_goal=0): + x, y, yaw = float(q[21]), float(q[22]), float(q[24]) + dx, dy = x_goal-x, y_goal-y + a[0] = walk(dx*math.cos(yaw)+dy*math.sin(yaw)) + a[1] = walk(-dx*math.sin(yaw)+dy*math.cos(yaw), .12, .02) + delta = (yaw_goal-yaw+math.pi)%(2*math.pi)-math.pi + a[3] = max(-.25, min(.25, 2*delta)) if abs(delta)>.03 else 0 + + def act(self, obs, tools): + t = int(obs["t"]) + q = obs["low_dim_obs"] + a = self.hold.copy() + a[0] = a[1] = a[3] = 0 + a[2] = .74 + a[4] = 0 + a[19] = a[20] = 0 + + if t < 525: + self.pose(a, "left", -.65 if t<175 else -.9, .1, 0, + .65 if t<175 else .9, 0) + a[19] = 1 if t>=125 else 0 + if t == 190: + self.first_grasped = min(q[10],q[11]) > -.018 + if t < 100: + x,y,yaw = float(q[21]),float(q[22]),float(q[24]) + a[0] = max(.06,min(.15,2*(.03-x))) if x<.02 else 0 + a[1] = walk(-.61-y,.12,.02) + a[3] = max(-.2,min(.2,-2*yaw)) if abs(yaw)>.03 else 0 + return a + if t < 200: + return a + if t in (345,435,524) and not self.right_held: + self.right_held = min(q[19],q[20]) > -.018 + if self.right_held: + self.pose(a,"right",-1.05,.1,self.right_stage,1.05,-self.right_stage) + a[20] = 1 + return a + if t < 345: + yaw,pitch,yg = -.3,-.85,-.57 + a[20] = 1 if t>=300 else 0 + elif t < 435: + yaw,pitch,yg = 0,-.65,-.50 + a[20] = 1 if t>=385 else 0 + else: + yaw,pitch,yg = .4,-.65,-.50 + a[20] = 1 if t>=475 else 0 + self.right_stage = yaw + self.pose(a,"right",pitch,.1,yaw,-pitch,-yaw) + if t<300 or 345<=t<385 or 435<=t<475: + self.toward(a,q,.04,yg) + return a + + if t < 925: + self.pose(a,"left",-.9,.1,-.6 if t>=735 else 0,.9,0) + a[19] = 1 if t<900 else 0 + if self.right_held: + ryaw = self.right_stage if t<735 else .6 + self.pose(a,"right",-1.05,.1,ryaw,1.05,-ryaw) + a[20] = 1 if t<900 else 0 + if t < 700: + yaw,y = float(q[24]),float(q[22]) + a[3] = .35 if yaw<.93 else 0 + a[1] = .12 if y<-.50 else 0 + return a + + if self.right_held: + return a + self.pose(a,"right",0,0,0,0,0) + if t < 1120: + self.pose(a,"left",0,0,0,0,0) + self.toward(a,q,-.04,-.61,0) + elif t < 1330: + self.pose(a,"left",-1.0,.1,-1.1,.65,1.1) + a[4] = .25 + a[19] = 1 if t>=1270 else 0 + if t < 1270: + self.toward(a,q,.045,-.61,0) + if t == 1325: + self.left_second_held = min(q[10],q[11]) > -.018 + elif t < 1660: + self.pose(a,"left",-1.2,.1,-1.1 if t<1500 else -.6,.9,.6) + a[19] = 1 if t<1630 else 0 + if t<1500: + yaw,y = float(q[24]),float(q[22]) + a[3] = .35 if yaw<.93 else 0 + a[1] = .12 if y<-.50 else 0 + return a diff --git a/policies/dishwasher_load_cups/gpt6sol-s3/episodes.csv b/policies/dishwasher_load_cups/gpt6sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..e1117a8594b2952549575022d4dfe923c66d93a9 --- /dev/null +++ b/policies/dishwasher_load_cups/gpt6sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,1238,terminated,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,1,1689,success,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,794,terminated,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,1,1691,success,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,1276,terminated,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,1,1846,success,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/gpt6sol-s3/policy.py b/policies/dishwasher_load_cups/gpt6sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..6023e640704fe08e410d2aa6d04a5a016831edfb --- /dev/null +++ b/policies/dishwasher_load_cups/gpt6sol-s3/policy.py @@ -0,0 +1,178 @@ +"""Deterministic hand control for loading the dishwasher mugs.""" + +import numpy as np +import cv2 + + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.a[19:21] = 0.0 + self.phase = 0 + self.age = 0 + self.corrected_right = False + + @staticmethod + def _right_mug_top(tools): + im = tools.image("right_wrist") + lo = im.min(axis=2) + hi = im.max(axis=2) + mask = np.uint8((lo > 170) & ((hi - lo) < 40)) + count, _, stats, _ = cv2.connectedComponentsWithStats(mask) + boxes = [stats[k] for k in range(1, count) + if stats[k, cv2.CC_STAT_AREA] > 500 + and stats[k, cv2.CC_STAT_WIDTH] > 25 + and stats[k, cv2.CC_STAT_HEIGHT] > 20] + if not boxes: + return 0 + box = max(boxes, key=lambda b: b[cv2.CC_STAT_AREA]) + return int(box[cv2.CC_STAT_TOP]) + + @staticmethod + def _left_mug_edge(tools): + im = tools.image("left_wrist").astype(np.int16) + lo = im.min(axis=2) + hi = im.max(axis=2) + mask = (lo > 85) & (hi < 238) & ((hi - lo) < 18) + cols = mask[:60, :55].sum(axis=0) + xs = np.flatnonzero(cols > 10) + return int(xs[-1]) if len(xs) else 58 + + def act(self, obs, tools): + q = obs["low_dim_obs"] + x, y, yaw = float(q[21]), float(q[22]), float(q[24]) + limits = [50, 55, 50, 50, 40, 60, 70, 50, 80, 70, + 60, 40, 60, 60, 360, 30, + 100, 30, 80, 100, 80, 200, 30, 80, 120, 80] + + while True: + if self.phase >= 100: + extra_limits = {100: 50, 101: 45, 102: 80, 103: 60} + done = self.age >= extra_limits[self.phase] + if self.phase == 102 and self.age and y >= -.47: + done = True + elif self.phase == 90: + done = self.age >= 40 + elif self.phase < len(limits): + done = self.age >= limits[self.phase] + else: + break + if self.age: + if self.phase == 6 and y >= -0.585: + done = True + elif self.phase == 8 and x >= 0.05: + done = True + elif self.phase == 9 and y >= -0.545: + done = True + elif self.phase == 14 and yaw >= 1.0: + done = True + elif self.phase == 16 and x <= -0.22: + done = True + elif self.phase == 21 and self.age >= 20 and abs(x + .04) < .02 and abs(y + .69) < .02: + done = True + if not done: + break + if self.phase == 3: + edge = self._left_mug_edge(tools) + if edge < 42: + self.align_roll = float(np.clip(.72 + .015 * (39 - edge), .55, .8)) + self.phase = 90 + self.age = 0 + continue + if self.phase == 10 and not self.corrected_right: + self.corrected_right = True + if self._right_mug_top(tools) >= 25: + self.phase = 100 + self.age = 0 + continue + self.phase = 4 if self.phase == 90 else (11 if self.phase == 103 else self.phase + 1) + self.age = 0 + + a = self.a + a[:4] = [0.0, 0.0, a[2], 0.0] + p = self.phase + if p == 0: + a[2], a[4] = .74, .2 + a[5:12] = [-.5, .2, 0, 0, 0, 0, 0] + a[12:19] = [-.5, -.1, 0, 0, 0, 0, 0] + elif p == 1: + a[0] = .14 + elif p == 2: + a[5:12] = [-.7, .25, 0, .2, 0, 0, 0] + elif p == 3: + a[4] = .35 + elif p == 4: + a[19] = 1.0 + elif p == 5: + a[4], a[5] = .15, -.45 + elif p == 6: + a[1] = .14 + elif p == 7: + a[2], a[4] = .79, .15 + a[12:19] = [-.9, .15, .05, .2, 0, 0, 0] + elif p == 8: + a[0] = .12 + elif p == 9: + a[1] = .14 + elif p == 10: + a[2], a[4] = .74, .35 + a[12:19] = [-.7, .15, .05, .2, 0, 0, 0] + elif p == 11: + a[20] = 1.0 + elif p == 12: + a[4], a[12], a[15] = .15, -.9, .2 + elif p == 13: + a[0] = -.14 + elif p == 14: + a[3] = .25 + elif p == 15: + pass + elif p == 16: + a[1] = .14 + elif p == 17: + pass + elif p == 18: + a[2] = .62 + elif p == 19: + a[20] = 0.0 + elif p == 20: + a[2] = .74 + a[12:19] = [-.3, -.1, 0, .2, 0, 0, 0] + elif p == 21: + c, s = np.cos(yaw), np.sin(yaw) + ux = np.clip(1.8 * (-.04 - x), -.15, .15) + uy = np.clip(1.8 * (-.69 - y), -.15, .15) + vx = c * ux + s * uy + vy = -s * ux + c * uy + speed = np.hypot(vx, vy) + if speed > .15: + vx *= .15 / speed + vy *= .15 / speed + elif 0 < speed < .06: + vx *= .06 / speed + vy *= .06 / speed + a[0], a[1] = vx, vy + elif p == 22: + pass + elif p == 23: + a[2] = .62 + a[5:12] = [-.7, -.3, 0, .2, 0, 0, 0] + elif p == 24: + a[19] = 0.0 + elif p == 25: + a[5:12] = [-.3, .3, 0, .2, 0, 0, 0] + elif p == 90: + a[6] = self.align_roll + elif p == 100: + a[2], a[4] = .79, .15 + a[12:19] = [-.9, .15, .05, .2, 0, 0, 0] + elif p == 101: + a[0], a[1] = -.1, .1 + elif p == 102: + a[1] = .14 + elif p == 103: + a[2], a[4] = .74, .35 + a[12:19] = [-.7, .15, .05, .2, 0, 0, 0] + + self.age += 1 + return a.copy() diff --git a/policies/dishwasher_load_cups/kimi31pro-s1/episodes.csv b/policies/dishwasher_load_cups/kimi31pro-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..d6346dd7494e5843a496bf989b64dc4976b74071 --- /dev/null +++ b/policies/dishwasher_load_cups/kimi31pro-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,1172,terminated,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,1278,terminated,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,1,1751,success,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,1278,terminated,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,1,1672,success,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,1,1779,success,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,1642,terminated,0 +620062,0,1470,terminated,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,1,1703,success,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,1345,terminated,0 +620091,0,1299,terminated,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/kimi31pro-s1/policy.py b/policies/dishwasher_load_cups/kimi31pro-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..98a55f9e2578dc44083a9fa7eeb945d496232a40 --- /dev/null +++ b/policies/dishwasher_load_cups/kimi31pro-s1/policy.py @@ -0,0 +1,258 @@ +"""Deterministic two-arm controller with grasp verification and recovery.""" + +import math +import cv2 +import numpy as np + + +class Policy: + HIGH_L = np.array([-1.7, 0.0, 0.0, 1.7, 0.0, 0.0, 0.0]) + HIGH_R = np.array([-1.7, -0.15, 0.0, 1.7, 0.0, 0.0, 0.0]) + LOW_L = np.array([-1.3, 0.0, 0.0, 1.3, 0.0, 0.0, 0.0]) + LOW_R = np.array([-1.3, -0.15, 0.0, 1.3, 0.0, 0.0, 0.0]) + LEFT_FINAL = np.array([-1.3, 0.05, 0.0, 1.3, 0.0, 0.0, 0.0]) + CARRY_L = np.array([-1.95, 0.05, 0.0, 1.95, 0.0, 0.0, 0.0]) + CARRY_R = np.array([-1.95, -0.15, 0.0, 1.95, 0.0, 0.0, 0.0]) + + DURATIONS = { + "raise": 90, "approach": 150, "lower": 60, + "right_settle": 60, "right_close": 80, "right_lift": 110, + "left_forward": 100, "left_settle": 60, "left_align": 50, + "left_close": 80, "left_lift": 120, + "right_retry_open": 40, "right_retry_settle": 30, + "right_retry_close": 70, "right_retry_lift": 100, + "left_retry_open": 40, "left_retry_settle": 30, + "left_retry_close": 70, "left_retry_lift": 100, + "release": 70, "retreat": 80, + } + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.arm_l = self.hold[5:12].astype(float).copy() + self.arm_r = self.hold[12:19].astype(float).copy() + self.grip = np.zeros(2) + self.low_l = self.LOW_L.copy() + self.low_r = self.LOW_R.copy() + self.left_final = self.LEFT_FINAL.copy() + self.carry_l = self.CARRY_L.copy() + self.carry_r = self.CARRY_R.copy() + self.turn_xy = np.zeros(2) + self.retreat_target = np.zeros(3) + self.left_x = None + self.right_retries = 0 + self.left_retries = 0 + self.stage = "" + self.stage_k = 0 + self.duration = 0 + self._enter("raise") + + @property + def retries(self): + return self.right_retries + self.left_retries + + def _enter(self, stage): + self.stage = stage + self.stage_k = 0 + self.start_l = self.arm_l.copy() + self.start_r = self.arm_r.copy() + self.start_grip = self.grip.copy() + if stage == "turn": + self.duration = 450 if self.retries == 0 else 270 + elif stage == "center": + self.duration = 160 if self.retries == 0 else 80 + elif stage == "place_lower": + self.duration = 90 if self.retries == 0 else 50 + elif stage == "release" and self.retries: + self.duration = 50 + else: + self.duration = self.DURATIONS.get(stage, 10**9) + + @staticmethod + def _empty(fingers): + return bool(np.max(fingers) < -0.0175) + + def _next(self, obs): + s = self.stage + if s == "right_lift" and self._empty(obs["low_dim_obs"][19:21]) and not self.right_retries: + self.right_retries = 1 + return "right_retry_open" + if s == "left_lift" and self._empty(obs["low_dim_obs"][10:12]) and not self.left_retries: + self.left_retries = 1 + return "left_retry_open" + following = { + "raise": "approach", "approach": "lower", "lower": "right_settle", + "right_settle": "right_close", "right_close": "right_lift", + "right_lift": "left_forward", + "right_retry_open": "right_retry_settle", + "right_retry_settle": "right_retry_close", + "right_retry_close": "right_retry_lift", + "right_retry_lift": "left_forward", + "left_forward": "left_settle", "left_settle": "left_align", + "left_align": "left_close", "left_close": "left_lift", + "left_lift": "turn", + "left_retry_open": "left_retry_settle", + "left_retry_settle": "left_retry_close", + "left_retry_close": "left_retry_lift", + "left_retry_lift": "turn", "retreat": "turn", "turn": "center", + "center": "place_lower", "place_lower": "release", + "release": "retract", "retract": "retract", + } + return following[s] + + def _arms(self, target_l, target_r): + u = (self.stage_k + 1) / self.duration + s = float(np.clip(u, 0.0, 1.0)) + s = s * s * (3.0 - 2.0 * s) + self.arm_l = (1.0 - s) * self.start_l + s * target_l + self.arm_r = (1.0 - s) * self.start_r + s * target_r + + def _grip(self, target): + s = float(np.clip((self.stage_k + 1) / self.duration, 0.0, 1.0)) + self.grip = (1.0 - s) * self.start_grip + s * np.asarray(target) + + @staticmethod + def _mug_x(image, side): + hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) + mask = ((hsv[:, :, 1] < 55) & (hsv[:, :, 2] > 55) + & (hsv[:, :, 2] < 240)).astype(np.uint8) + n, _, stats, cents = cv2.connectedComponentsWithStats(mask, 8) + candidates = [] + for i in range(1, n): + x, y, w, h, area = stats[i] + cx, cy = cents[i] + if area < 80 or w < 6 or h < 10: + continue + if side == "left" and cx > 70: + continue + if side == "right" and cx < 18: + continue + candidates.append((area, cx)) + return max(candidates)[1] if candidates else None + + def _align_right(self, tools): + x = self._mug_x(tools.image("right_wrist"), "right") + if x is not None and abs(49.1 - x) > 11.0: + roll = self.LOW_R[1] + 0.0035 * (49.1 - x) + self.low_r[1] = float(np.clip(roll, -0.35, 0.05)) + self.carry_r[1] = self.low_r[1] + + def _prepare_left(self): + if self.left_x is not None and abs(38.5 - self.left_x) > 5.0: + roll = self.LEFT_FINAL[1] + 0.0035 * (38.5 - self.left_x) + self.left_final[1] = float(np.clip(roll, -0.05, 0.12)) + self.carry_l[1] = self.left_final[1] + + @staticmethod + def _wrap(x): + return math.atan2(math.sin(x), math.cos(x)) + + def _base(self, obs, target, speed, turn): + x, y, _, yaw = obs["low_dim_obs"][21:25] + ex, ey = target[0] - x, target[1] - y + c, s = math.cos(yaw), math.sin(yaw) + vx = 2.5 * (c * ex + s * ey) + vy = 2.5 * (-s * ex + c * ey) + norm = math.hypot(vx, vy) + if norm > speed: + vx *= speed / norm + vy *= speed / norm + if math.hypot(vx, vy) < 0.07: + vx = vy = 0.0 + wz = float(np.clip(1.8 * self._wrap(target[2] - yaw), -turn, turn)) + return vx, vy, wz + + def act(self, obs, tools): + if self.stage_k >= self.duration: + self._enter(self._next(obs)) + s = self.stage + raw = self.hold.copy() + base_target = None + base_speed, base_turn = 0.22, 0.35 + + if s == "raise": + self._arms(self.HIGH_L, self.HIGH_R) + self._grip([0, 0]) + elif s == "approach": + base_target = (0.05, -0.48, 0.0) + elif s == "lower": + self._arms(self.low_l, self.low_r) + base_target = (0.05, -0.48, 0.0) + elif s == "right_settle": + if self.stage_k == 0: + self._align_right(tools) + elif self.stage_k == self.duration - 1: + self.left_x = self._mug_x(tools.image("left_wrist"), "left") + self._arms(self.low_l, self.low_r) + elif s == "right_close": + self._grip([0, 1]) + elif s == "right_lift": + self._arms(self.low_l, self.carry_r) + elif s == "right_retry_open": + self._arms(self.low_l, self.low_r) + self._grip([0, 0]) + base_target = (0.09, -0.48, 0.0) + base_speed, base_turn = 0.08, 0.20 + elif s == "right_retry_settle": + self._arms(self.low_l, self.low_r) + elif s == "right_retry_close": + self._grip([0, 1]) + elif s == "right_retry_lift": + self._arms(self.low_l, self.carry_r) + elif s == "left_forward": + if self.stage_k == 0: + self._prepare_left() + self._arms(self.left_final, self.carry_r) + base_target = (0.09 if self.right_retries else 0.05, -0.48, 0.0) + base_speed, base_turn = 0.08, 0.20 + elif s == "left_settle": + pass + elif s == "left_align": + self._arms(self.left_final, self.carry_r) + elif s == "left_close": + self._grip([1, 1]) + elif s == "left_lift": + self._arms(self.carry_l, self.carry_r) + elif s == "left_retry_open": + self._arms(self.left_final, self.carry_r) + self._grip([0, 1]) + base_target = (0.12 if self.right_retries else 0.09, -0.48, 0.0) + base_speed, base_turn = 0.06, 0.20 + elif s == "left_retry_settle": + self._arms(self.left_final, self.carry_r) + elif s == "left_retry_close": + self._grip([1, 1]) + elif s == "left_retry_lift": + self._arms(self.carry_l, self.carry_r) + elif s == "retreat": + if self.stage_k == 0: + x, y, _, yaw = obs["low_dim_obs"][21:25] + self.retreat_target = np.array([x - 0.14, y, 0.0]) + base_target = tuple(self.retreat_target) + base_speed, base_turn = 0.14, 0.20 + elif s == "turn": + if self.stage_k == 0: + self.turn_xy = obs["low_dim_obs"][21:23].copy() + base_target = (self.turn_xy[0], self.turn_xy[1], math.pi / 2) + base_speed, base_turn = 0.08, 0.18 if not self.retries else 0.30 + elif s == "center": + base_target = (0.16, -0.58, math.pi / 2) + base_speed, base_turn = (0.10, 0.20) if not self.retries else (0.16, 0.30) + elif s == "place_lower": + self._arms(self.left_final, self.low_r) + base_target = (0.16, -0.58, math.pi / 2) + base_speed, base_turn = 0.08, 0.20 + elif s == "release": + self._grip([0, 0]) + else: + self._arms(self.HIGH_L, self.HIGH_R) + + if base_target is not None: + vx, vy, wz = self._base(obs, base_target, base_speed, base_turn) + raw[0], raw[1], raw[3] = vx, vy, wz + raw[2] = 0.74 + raw[4] = 0.0 + raw[5:12] = self.arm_l + raw[12:19] = self.arm_r + raw[19:21] = self.grip + self.stage_k += 1 + return raw diff --git a/policies/dishwasher_load_cups/kimi31pro-s2/episodes.csv b/policies/dishwasher_load_cups/kimi31pro-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..fada29b1f867f2e12405801b9122a4b73fc762b7 --- /dev/null +++ b/policies/dishwasher_load_cups/kimi31pro-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,255,terminated,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/kimi31pro-s2/policy.py b/policies/dishwasher_load_cups/kimi31pro-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..6e60b084f33c7431377ce5095612bfc488c5f65f --- /dev/null +++ b/policies/dishwasher_load_cups/kimi31pro-s2/policy.py @@ -0,0 +1,120 @@ +"""Deterministic, hand-written control for loading the two dishwasher mugs.""" + +import numpy as np + + +def _smooth(x): + x = float(np.clip(x, 0.0, 1.0)) + return x * x * (3.0 - 2.0 * x) + + +class Policy: + """Joint-space pick/place controller with proprioceptive grasp checks.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.t = 0 + self.q_pick = np.array([-.8, 0., 0., -.4, 0., .6, 0.]) + self.q_place = np.array([-.6, 0., 0., 0., 0., 0., 0.]) + # The rear mug needs a longer reach. The alternatives are fallbacks, + # selected only when the finger joints report an empty gripper. + self.second_poses = [ + np.array([-1.2, 0., 0., .4, 0., .2, 0.]), + np.array([-1.0, 0., 0., 0., 0., .4, 0.]), + self.q_pick.copy(), + ] + self.phase = "first" + self.second_index = 0 + self.cycle_start = 650 + self.q_cycle_start = self.q_place.copy() + self.place_start = 0 + self.q_place_from = self.q_pick.copy() + + @staticmethod + def _yaw_hold(raw, obs): + yaw = float(obs["low_dim_obs"][24]) + raw[3] = float(np.clip(-1.5 * yaw, -.25, .25)) + + @staticmethod + def _second_base_servo(raw, obs): + """Counteract the backward balance drift during the long reach.""" + state = obs["low_dim_obs"] + x, yaw = float(state[21]), float(state[24]) + error = .025 - x + forward = float(np.clip(3.0 * error, -.18, .18)) + if abs(error) > .007: + forward = float(np.copysign(max(abs(forward), .065), forward)) + else: + forward = 0.0 + raw[0] = np.cos(yaw) * forward + raw[1] = -np.sin(yaw) * forward + raw[3] = float(np.clip(-2.0 * yaw, -.3, .3)) + + def _advance_second_state(self, obs): + if self.phase != "second_approach": + return + if self.t - self.cycle_start < 200: + return + fingers = obs["low_dim_obs"][19:21] + if float(np.mean(fingers)) > -.0195: + self.phase = "second_place" + self.place_start = self.t + self.q_place_from = self.second_poses[self.second_index].copy() + elif self.second_index + 1 < len(self.second_poses): + self.q_cycle_start = self.second_poses[self.second_index].copy() + self.second_index += 1 + self.cycle_start = self.t + else: + self.phase = "finished" + + def act(self, obs, tools): + t = self.t + raw = self.hold.copy() + raw[5:12] = 0.0 + u = _smooth(t / 70.0) + raw[4] = .65 * u + + if self.phase == "first" and t < 650: + move = _smooth((t - 260) / 240.0) + raw[12:19] = (self.q_pick + (self.q_place - self.q_pick) * move) * u + raw[2] = (.74 + .26 * _smooth((t - 190) / 70.0) + - .35 * _smooth((t - 520) / 70.0)) + raw[20] = 0.0 if t < 145 else (1.0 if t < 630 else 0.0) + if t < 45: + raw[0] = .2 + else: + self._yaw_hold(raw, obs) + else: + if self.phase == "first": + self.phase = "second_approach" + self.cycle_start = t + self.q_cycle_start = self.q_place.copy() + self._advance_second_state(obs) + + if self.phase == "second_approach": + local = t - self.cycle_start + target = self.second_poses[self.second_index] + move = _smooth(local / 150.0) + raw[12:19] = self.q_cycle_start + (target - self.q_cycle_start) * move + raw[2] = .65 + .09 * _smooth(local / 70.0) + raw[20] = 0.0 if local < 150 else 1.0 + if 50 <= local < 150: + self._second_base_servo(raw, obs) + else: + self._yaw_hold(raw, obs) + elif self.phase == "second_place": + local = t - self.place_start + move = _smooth((local - 70) / 240.0) + raw[12:19] = self.q_place_from + (self.q_place - self.q_place_from) * move + raw[2] = (.74 + .26 * _smooth((local) / 70.0) + - .35 * _smooth((local - 330) / 70.0)) + raw[20] = 1.0 if local < 430 else 0.0 + self._yaw_hold(raw, obs) + else: + raw[12:19] = self.q_place + raw[2] = .65 + raw[20] = 0.0 + self._yaw_hold(raw, obs) + + self.t += 1 + return np.asarray(raw, dtype=np.float32) diff --git a/policies/dishwasher_load_cups/kimi31pro-s3/episodes.csv b/policies/dishwasher_load_cups/kimi31pro-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..0073e45195aeca582d1c664498dee5118a283684 --- /dev/null +++ b/policies/dishwasher_load_cups/kimi31pro-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,1632,terminated,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,1223,terminated,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,1319,terminated,0 +620033,0,1276,terminated,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,1301,terminated,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,2000,timeout,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/kimi31pro-s3/policy.py b/policies/dishwasher_load_cups/kimi31pro-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..f53c400a2e92776b2e8629094e9b998bee321d6a --- /dev/null +++ b/policies/dishwasher_load_cups/kimi31pro-s3/policy.py @@ -0,0 +1,191 @@ +"""Deterministic, hand-written joint/base controller for the dishwasher task. + +The controller is a timed sequence of Cartesian-inspired arm poses. Arm pitch +is expressed in the world frame and the waist pitch is compensated so the +fingers keep their orientation while the torso moves. No learned models, +lookup data, or external files are used. +""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + # side identifies which hand is carrying a mug. The home segment is + # assigned to R so that all later defaults belong to the right pickup. + self.segments = [ + ("back", 40, "L"), ("forward", 60, "L"), + ("approach", 60, "L"), ("grasp", 40, "L"), + ("lift", 60, "L"), ("secure", 20, "L"), + ("stand", 80, "L"), ("clamp", 20, "L"), + ("retract", 60, "L"), ("yaw", 60, "L"), + ("side", 140, "L"), ("align", 100, "L"), + ("lower", 80, "L"), ("upright", 40, "L"), + ("drop", 60, "L"), + ("home", 100, "R"), + ("back", 40, "R"), ("forward", 60, "R"), + ("approach", 60, "R"), ("pickup_align", 60, "R"), ("grasp", 40, "R"), + ("lift", 60, "R"), ("secure", 20, "R"), + ("stand", 80, "R"), ("clamp", 20, "R"), + ("retract", 60, "R"), ("yaw", 60, "R"), + ("side", 120, "R"), ("align", 60, "R"), + ("lower", 80, "R"), ("upright", 40, "R"), + ("drop", 50, "R"), + ("home", 60, "R"), + ] + self.index = 0 + self.j = 0 + self.last = self.hold.copy() + + def act(self, obs, tools): + if self.index >= len(self.segments): + a = self.last.copy() + a[0:2] = 0.0 + a[3] = 0.0 + return a + + name, n, side = self.segments[self.index] + j = self.j + u = j / max(n - 1, 1) + ld = obs["low_dim_obs"] + waist = float(ld[2]) + + Q1, E, S = -1.0, 0.0, -0.45 + pitch, height, g = 0.0, 0.74, 0.0 + yaw_target = 0.0 + roll = 0.2 + + if name == "back": + v = np.clip((j - 20) / 20.0, 0.0, 1.0) + Q1, E = -0.8 - 0.2 * v, 0.7 * (1.0 - v) + if name == "approach": + v = min(j / 40.0, 1.0) + Q1, E = -1.0 - 0.05 * v, 0.0 + S, pitch, height = -0.45 + 0.1 * v, 0.2 * v, 0.74 - 0.10 * v + if name == "pickup_align": + Q1, E, S = -1.05, 0.0, -0.35 + pitch, height, roll, yaw_target = 0.2, 0.64, 0.24, 0.026 + + pickup = ("grasp", "lift", "secure", "stand", "clamp") + transport = ("retract", "yaw", "side", "align", "lower", "upright", "drop") + if name in pickup + transport: + Q1, E, S = -1.2, 0.0, -0.35 + pitch, height, roll = 0.58, 0.55, 0.2 + + if side == "L": + if name == "grasp": + g = 0.7 if j >= 25 else 0.0 + elif name == "lift": + height, g = 0.55 + 0.06 * u, 0.7 + elif name == "secure": + height, g = 0.61, 0.8 + elif name == "stand": + height, g = 0.61 + 0.13 * u, 0.8 + elif name == "clamp": + height, g = 0.74, 1.0 + if name in transport: + pitch, height, g, S = 0.3, 0.74, 1.0, -0.8 + Q1 = -1.2 + 0.3 * u if name == "retract" else -0.9 + roll = 0.2 * (1.0 - u) if name == "retract" else 0.0 + if name == "yaw" or name in ("side", "align", "lower", "upright", "drop"): + yaw_target = 1.0 + if name == "lower": + height, Q1 = 0.74 - 0.14 * u, -0.9 + if name == "upright": + height, Q1, S = 0.60, -0.9, -0.8 + 0.45 * u + if name == "drop": + height, Q1, S, g = 0.60, -0.9, -0.35, 1.0 - u + else: + if name == "grasp": + g = 0.7 if j >= 25 else 0.0 + elif name == "lift": + height, g = 0.55 + 0.06 * u, 0.7 + elif name == "secure": + height, g = 0.61, 0.7 + elif name == "stand": + height, g = 0.61 + 0.13 * u, 0.7 + elif name == "clamp": + height, g = 0.74, 0.7 + if name in transport: + pitch, height, g, S = 0.58, 0.74, 0.7, -0.35 + Q1, roll = -1.2, 0.1 + if name == "yaw" or name in ("side", "align", "lower", "upright", "drop"): + yaw_target = 1.0 + if name == "lower": + height, Q1 = 0.74 - 0.14 * u, -1.2 + if name == "upright": + height, Q1, S = 0.60, -1.2, -0.35 + if name == "drop": + height, Q1, S, g = 0.60, -1.2, -0.35, 0.7 * (1.0 - u) + + if name in ("inspect", "home"): + Q1, E, S = -0.8, 0.8, -0.45 + pitch, height, roll, g = 0.0, 0.74, 0.2, 0.0 + yaw_target = 0.0 + + if name in ("back", "forward", "approach"): + roll = 0.24 + + pl = np.array([Q1 - waist, roll, 0.0, E, 0.0, S - Q1 - E, 0.0]) + pr = np.array([Q1 - waist, -0.16, 0.0, E, 0.0, S - Q1 - E, 0.0]) + + if side == "R" and name in pickup: + pr[1] = -0.1 + if side == "L" and name in transport: + pr = np.array([-0.5 - waist, -0.5, 0.0, 0.0, 0.0, 0.15, 0.0]) + if side == "R" and name in transport: + pr = pl.copy() + pr[1] = -roll + # Keep the empty left arm in its supporting pickup posture. + pl[1] = 0.2 + + a = self.hold.copy() + a[2], a[4] = height, pitch + a[5:12], a[12:19] = pl, pr + if side == "L": + a[19], a[20] = g, 0.0 + else: + a[19], a[20] = 0.0, g + + if name == "back": + a[0] = -0.3 + if name == "forward": + a[0] = 0.4 + if name == "approach": + a[0] = 0.25 if j < 30 else 0.0 + + post_base = ("yaw", "side", "align", "lower", "upright", "drop", "inspect", "home", "pickup_align") + if name in post_base: + dx = (-0.07 if name == "home" else (0.027 if name == "pickup_align" else 0.0)) - ld[21] + target_y = -0.6 + if name == "pickup_align": + target_y = -0.581 + if name == "inspect": + target_y = -0.5 + elif name in ("side", "align", "lower", "upright", "drop"): + target_y = -0.32 + dy = target_y - ld[22] + c, s = np.cos(ld[24]), np.sin(ld[24]) + a[0] = np.clip(2.0 * (c * dx + s * dy), -0.3, 0.3) + a[1] = np.clip(2.0 * (-s * dx + c * dy), -0.3, 0.3) + a[3] = np.clip(2.0 * (yaw_target - ld[24]), -0.4, 0.4) + for k in (0, 1): + if abs(dx) + abs(dy) > 0.015 and 0 < abs(a[k]) < 0.06: + a[k] = np.sign(a[k]) * 0.06 + if abs(dx) + abs(dy) <= 0.015: + a[0:2] = 0.0 + else: + a[3] = np.clip(-1.5 * ld[24], -0.4, 0.4) if abs(ld[24]) > 0.01 else 0.0 + ey = -0.6 - ld[22] + if abs(ey) > 0.015: + a[1] = np.clip(3.0 * ey, -0.3, 0.3) + if abs(a[1]) < 0.06: + a[1] = np.sign(a[1]) * 0.06 + + self.last = a.copy() + self.j += 1 + if self.j >= n: + self.index += 1 + self.j = 0 + return a diff --git a/policies/dishwasher_load_cups/opus-s1/episodes.csv b/policies/dishwasher_load_cups/opus-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..25a3d088078cd641b75474cb732a76eac89274f1 --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,1391,success,0 +620001,1,1521,success,0 +620002,1,1402,success,0 +620003,1,1451,success,0 +620004,1,1456,success,0 +620005,1,1421,success,0 +620006,0,1030,terminated,0 +620007,1,1450,success,0 +620008,0,2000,timeout,0 +620009,1,1422,success,0 +620010,1,1503,success,0 +620011,1,1407,success,0 +620012,1,1401,success,0 +620013,1,1454,success,0 +620014,1,1446,success,0 +620015,0,2000,timeout,0 +620016,1,1460,success,0 +620017,0,2000,timeout,0 +620018,1,1474,success,0 +620019,1,1479,success,0 +620020,1,1393,success,0 +620021,1,1436,success,0 +620022,1,1547,success,0 +620023,1,1479,success,0 +620024,1,1433,success,0 +620025,1,1510,success,0 +620026,1,1410,success,0 +620027,1,1606,success,0 +620028,1,1474,success,0 +620029,0,2000,timeout,0 +620030,1,1409,success,0 +620031,1,1469,success,0 +620032,0,2000,timeout,0 +620033,1,1469,success,0 +620034,1,1370,success,0 +620035,0,2000,timeout,0 +620036,1,1478,success,0 +620037,0,2000,timeout,0 +620038,1,1435,success,0 +620039,1,1435,success,0 +620040,1,1463,success,0 +620041,1,1430,success,0 +620042,0,2000,timeout,0 +620043,1,1424,success,0 +620044,1,1391,success,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,1,1435,success,0 +620048,1,1429,success,0 +620049,1,1505,success,0 +620050,1,1494,success,0 +620051,1,1469,success,0 +620052,1,1423,success,0 +620053,1,1440,success,0 +620054,1,1385,success,0 +620055,0,2000,timeout,0 +620056,1,1496,success,0 +620057,1,1449,success,0 +620058,1,1462,success,0 +620059,1,1505,success,0 +620060,1,1393,success,0 +620061,1,1384,success,0 +620062,0,1084,terminated,0 +620063,1,1456,success,0 +620064,1,1410,success,0 +620065,1,1413,success,0 +620066,1,1456,success,0 +620067,1,1461,success,0 +620068,1,1499,success,0 +620069,1,1418,success,0 +620070,1,1427,success,0 +620071,1,1440,success,0 +620072,0,2000,timeout,0 +620073,1,1401,success,0 +620074,1,1480,success,0 +620075,1,1432,success,0 +620076,1,1564,success,0 +620077,1,1465,success,0 +620078,1,1434,success,0 +620079,0,2000,timeout,0 +620080,1,1474,success,0 +620081,1,1457,success,0 +620082,1,1341,success,0 +620083,1,1436,success,0 +620084,1,1522,success,0 +620085,1,1446,success,0 +620086,1,1407,success,0 +620087,1,1409,success,0 +620088,1,1473,success,0 +620089,1,1425,success,0 +620090,1,1510,success,0 +620091,1,1456,success,0 +620092,0,2000,timeout,0 +620093,1,1426,success,0 +620094,1,1413,success,0 +620095,1,1372,success,0 +620096,1,1409,success,0 +620097,0,2000,timeout,0 +620098,1,1465,success,0 +620099,1,1398,success,0 diff --git a/policies/dishwasher_load_cups/opus-s1/policy.py b/policies/dishwasher_load_cups/opus-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c764307e73fdf9dbf43b80370c83b50e9fe2ea7c --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s1/policy.py @@ -0,0 +1,745 @@ +"""Unitree G1: load the two mugs from the counter into the dishwasher's upper rack. + +Hand-written control: G1 arm kinematics (menagerie constants), a pinhole model of +the wrist cameras (calibrated on the floor checkerboard), mug localisation by +fitting cylinder silhouettes in both wrist cameras, Cartesian arm trajectories +through damped least-squares IK, and a closed-loop base controller on the +pelvis pose reported in low_dim_obs. +""" + +import os + +import cv2 +import numpy as np +from scipy.optimize import least_squares, minimize + +DEBUG = os.environ.get("POLICY_DEBUG") + +# ----------------------------------------------------------------------------- kinematics + + +def rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +SH_TILT = 0.2793 +GRASP_OFF = np.array([0.165, 0.0, 0.028]) # finger pad centre in the wrist_yaw_link frame +QLO = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443]) +QHI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443]) +NOMINAL = np.array([-0.4, 0.25, 0.0, 0.6, 0.0, 0.0, 0.0]) +ROLL_IN = 0.12 + + +def arm_fk(q, side, waist=(0, 0, 0), off=GRASP_OFF): + """Hand frame (R, p) in the pelvis frame. side=+1 left, -1 right.""" + s = side + R = rz(waist[0]) + p = R @ np.array([-0.0039635, 0, 0.044]) + R = R @ rx(waist[1]) @ ry(waist[2]) + p = p + R @ np.array([0.0039563, 0.10022 * s, 0.24778]) + R = R @ rx(SH_TILT * s) @ ry(q[0]) + p = p + R @ np.array([0, 0.038 * s, -0.013831]) + R = R @ rx(-SH_TILT * s) @ rx(q[1]) + p = p + R @ np.array([0, 0.00624 * s, -0.1032]) + R = R @ rz(q[2]) + p = p + R @ np.array([0.015783, 0, -0.080518]) + R = R @ ry(q[3]) + p = p + R @ np.array([0.1, 0.00188791 * s, -0.01]) + R = R @ rx(q[4]) + p = p + R @ np.array([0.038, 0, 0]) + R = R @ ry(q[5]) + p = p + R @ np.array([0.046, 0, 0]) + R = R @ rz(q[6]) + p = p + R @ np.asarray(off) + return R, p + + +def limits(side): + lo, hi = QLO.copy(), QHI.copy() + if side < 0: + lo[1], hi[1] = -2.2515, 1.5882 + hi[1] = ROLL_IN # the upper arm meets the torso + else: + lo[1] = -ROLL_IN + # keep the wrist in a sane branch + lo[4], hi[4] = -1.2, 1.2 + return lo, hi + + +def nominal(side): + q = NOMINAL.copy() + q[[1, 2, 4, 6]] *= side + return q + + +def hand_R(pitch_up=0.0, yaw=0.0): + return rz(yaw) @ ry(-pitch_up) + + +def ik(side, p_t, R_t, q0, waist, w_rot=0.3, w_post=0.02, nfev=60): + lo, hi = limits(side) + qn = nominal(side) + + def res(q): + R, p = arm_fk(q, side, waist) + eo = 0.5 * (np.cross(R[:, 0], R_t[:, 0]) + np.cross(R[:, 1], R_t[:, 1]) + np.cross(R[:, 2], R_t[:, 2])) + return np.concatenate([p - p_t, w_rot * eo, w_post * (q - qn)]) + + q0 = np.clip(np.asarray(q0, float), lo + 1e-4, hi - 1e-4) + r = least_squares(res, q0, bounds=(lo, hi), max_nfev=nfev, xtol=1e-5, ftol=1e-7) + return r.x, np.linalg.norm(r.fun[:3]) + + +# ----------------------------------------------------------------------------- cameras + +F_PX = 75.0 +C0 = 41.5 +CAM_ALPHA = np.radians(37.5) +CAM_OFF = np.array([0.08, 0.0, 0.07]) + + +def wrist_cam(o, side): + """World pose of a wrist camera: origin, R with columns (right, down, forward).""" + q = o[3:10] if side > 0 else o[12:19] + R, p = arm_fk(q, side, o[0:3], off=np.zeros(3)) + Rw = rz(o[24]) + Rh = Rw @ R + ph = o[21:24] + Rw @ p + org = ph + Rh @ CAM_OFF + fwd = Rh @ np.array([np.cos(CAM_ALPHA), 0, -np.sin(CAM_ALPHA)]) + right = Rh @ np.array([0, -1.0, 0]) + down = np.cross(fwd, right) + return org, np.stack([right, down, fwd], 1) + + +def pix_ray(org, Rc, u, v): + d = Rc @ np.array([(u - C0) / F_PX, (v - C0) / F_PX, 1.0]) + return d / np.linalg.norm(d) + + +def project_pts(org, Rc, P): + c = (P - org) @ Rc + return np.stack([C0 + F_PX * c[:, 0] / c[:, 2], C0 + F_PX * c[:, 1] / c[:, 2]], 1), c[:, 2] + + +# ----------------------------------------------------------------------------- mug perception + +ZC = 0.85 # counter top height +MUG_R = 0.045 +MUG_H = 0.10 +_ANG = np.linspace(0, 2 * np.pi, 24, endpoint=False) + + +def image_masks(im): + im = im.astype(int) + R, G, B = im[..., 0], im[..., 1], im[..., 2] + V = im.max(-1) + gray = (np.abs(R - B) < 8) & (np.abs(R - G) < 8) & (V >= 70) + stick = (V < 200) & (R - B > 25) & (R >= G) & (G >= B) + return gray, stick + + +def cyl_mask(org, Rc, x, y): + P = np.concatenate([np.stack([x + MUG_R * np.cos(_ANG), y + MUG_R * np.sin(_ANG), np.full_like(_ANG, z)], 1) + for z in (ZC, ZC + MUG_H)]) + uv, dep = project_pts(org, Rc, P) + m = np.zeros((84, 84), np.uint8) + if (dep <= 0.02).any(): + return m.astype(bool) + cv2.fillConvexPoly(m, cv2.convexHull((uv * 8).astype(np.int32)), 1, shift=3) + return m.astype(bool) + + +def fit_mugs(views, inits): + n = len(inits) + + def cost(v): + tot = 0.0 + for org, Rc, gm in views: + pred = np.zeros_like(gm) + for i in range(n): + pred |= cyl_mask(org, Rc, v[2 * i], v[2 * i + 1]) + tot += 1 - (pred & gm).sum() / max((pred | gm).sum(), 1) + for i in range(n): + for j in range(i + 1, n): + dd = np.hypot(v[2 * i] - v[2 * j], v[2 * i + 1] - v[2 * j + 1]) + if dd < 2 * MUG_R: + tot += 5 * (2 * MUG_R - dd) + return tot + + x0 = np.array(inits, float).ravel() + best = None + for dx in (-0.03, 0.0, 0.03): + for dy in (-0.03, 0.0, 0.03): + s = x0 + np.tile([dx, dy], n) + c = cost(s) + if best is None or c < best[0]: + best = (c, s) + v = minimize(cost, best[1], method='Nelder-Mead', options=dict(xatol=1e-3, fatol=1e-4, maxiter=400)).x + sim = np.array([v] + [v + 0.01 * np.eye(2 * n)[k] for k in range(2 * n)]) + r = minimize(cost, v, method='Nelder-Mead', options=dict(xatol=5e-4, fatol=1e-5, maxiter=400, initial_simplex=sim)) + return r.x.reshape(n, 2), r.fun + + +def handle_protrusion(views, mugs, rh=0.062): + """Handle yaw from mug pixels sticking out of the fitted body silhouettes.""" + out = [] + for i, (x, y) in enumerate(mugs): + az = [] + for org, Rc, gm, stick in views: + body = cyl_mask(org, Rc, x, y) + others = np.zeros_like(body) + for j, (x2, y2) in enumerate(mugs): + if j != i: + others |= cyl_mask(org, Rc, x2, y2) + near = cv2.dilate(body.astype(np.uint8), np.ones((9, 9), np.uint8)).astype(bool) + grown = cv2.dilate(body.astype(np.uint8), np.ones((3, 3), np.uint8)).astype(bool) + cand = gm & near & ~grown & ~others + ys, xs = np.nonzero(cand) + for u, v in zip(xs, ys): + d = pix_ray(org, Rc, float(u), float(v)) + # intersect with vertical cylinder of radius rh about the mug axis + ox, oy = org[0] - x, org[1] - y + a = d[0] ** 2 + d[1] ** 2 + b = 2 * (ox * d[0] + oy * d[1]) + c = ox ** 2 + oy ** 2 - rh ** 2 + disc = b * b - 4 * a * c + if a < 1e-9: + continue + if disc < 0: + tt = -b / (2 * a) # closest approach + else: + tt = (-b - np.sqrt(disc)) / (2 * a) + P3 = org + tt * d + if ZC - 0.01 < P3[2] < ZC + MUG_H + 0.01: + az.append(np.arctan2(P3[1] - y, P3[0] - x)) + if len(az) >= 4: + az = np.array(az) + out.append((float(np.arctan2(np.sin(az).mean(), np.cos(az).mean())), len(az))) + else: + out.append((None, len(az))) + return out + + +def handle_dirs(views, mugs): + """Handle yaw of each mug, from the handle's shadow on the counter.""" + out = [] + for (x, y) in mugs: + pts = [] + for org, Rc, gm, stick in views: + ys, xs = np.nonzero(stick) + for u, v in zip(xs, ys): + d = pix_ray(org, Rc, float(u), float(v)) + if d[2] >= -1e-3: + continue + P = org + d * (ZC - org[2]) / d[2] + dd = np.hypot(P[0] - x, P[1] - y) + if MUG_R * 0.8 < dd < MUG_R + 0.06: + pts.append(P[:2]) + if len(pts) >= 3: + p = np.mean(pts, 0) + out.append(float(np.arctan2(p[1] - y, p[0] - x))) + else: + out.append(np.pi) + return out + + +# ----------------------------------------------------------------------------- base + + +WZ_MIN = 0.12 + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +def goto_cmd(o, x, y, yaw, vmax=0.2, wmax=0.5, kp=1.5, kw=1.5, tol=0.03, ytol=0.03): + px, py, pyaw = o[21], o[22], o[24] + dx, dy = x - px, y - py + c, s = np.cos(pyaw), np.sin(pyaw) + bx, by = c * dx + s * dy, -s * dx + c * dy + eyaw = wrap(yaw - pyaw) + vx, vy = kp * bx, kp * by + n = np.hypot(vx, vy) + if n > vmax: + vx, vy = vx * vmax / n, vy * vmax / n + n = np.hypot(vx, vy) + if n < 0.06: + if np.hypot(bx, by) > tol: + vx, vy = vx * 0.06 / max(n, 1e-6), vy * 0.06 / max(n, 1e-6) + else: + vx, vy = 0.0, 0.0 + wz = float(np.clip(kw * eyaw, -wmax, wmax)) + if abs(eyaw) < ytol: + wz = 0.0 + elif abs(wz) < WZ_MIN: + wz = WZ_MIN * np.sign(wz) + done = np.hypot(bx, by) < tol and abs(eyaw) < ytol + return (float(vx), float(vy), wz), done + + +# ----------------------------------------------------------------------------- arm motion + + +class ArmMover: + """Cartesian straight-line moves of the grasp point, in world or pelvis frame.""" + + def __init__(self, side): + self.side = side + self.q = nominal(side) * 0.0 + self.seg = None # (p0, yaw0, pitch0, p1, yaw1, pitch1, n, k, frame) + self.target = None # (p, yaw, pitch, frame) + self.pc = np.zeros(3) + self.ac = np.zeros(2) + self.comp = True + + def pose_now(self, o, frame): + q = o[3:10] if self.side > 0 else o[12:19] + R, p = arm_fk(q, self.side, o[0:3]) + yaw = np.arctan2(R[1, 0], R[0, 0]) + pitch = np.arcsin(np.clip(R[2, 0], -1, 1)) + if frame == 'world': + p = o[21:24] + rz(o[24]) @ p + yaw = yaw + o[24] + return p, yaw, pitch + + def move(self, o, p1, yaw1, pitch1, n, frame='world', from_target=True): + if from_target and self.target is not None and self.target[3] == frame: + p0, y0, pi0 = self.target[0], self.target[1], self.target[2] + else: + p0, y0, pi0 = self.pose_now(o, frame) + self.seg = [np.array(p0), y0, pi0, np.array(p1, float), yaw1, pitch1, max(int(n), 1), 0, frame] + + def busy(self): + return self.seg is not None and self.seg[7] < self.seg[6] + + def step(self, o): + if self.seg is not None: + p0, y0, pi0, p1, y1, pi1, n, k, frame = self.seg + k = min(k + 1, n) + self.seg[7] = k + s = 0.5 - 0.5 * np.cos(np.pi * k / n) + p = p0 + (p1 - p0) * s + yaw = y0 + wrap(y1 - y0) * s + pitch = pi0 + (pi1 - pi0) * s + self.target = (p, yaw, pitch, frame) + if self.target is None: + return self.q + p, yaw, pitch, frame = self.target + if frame == 'world': + Rw = rz(o[24]) + p_rel = Rw.T @ (p - o[21:24]) + yaw_rel = yaw - o[24] + else: + p_rel, yaw_rel = p, yaw + # Cartesian integral correction of the steady tracking error (gravity sag, contacts excluded) + q_act = o[3:10] if self.side > 0 else o[12:19] + Ra, pa = arm_fk(q_act, self.side, o[0:3]) + ya = np.arctan2(Ra[1, 0], Ra[0, 0]) + pia = np.arcsin(np.clip(Ra[2, 0], -1, 1)) + if self.comp: + g = 0.012 if self.busy() else 0.035 + self.pc = np.clip(self.pc + g * (p_rel - pa), -0.06, 0.06) + self.ac = np.clip(self.ac + g * np.array([wrap(yaw_rel - ya), pitch - pia]), -0.25, 0.25) + self.q, self.err = ik(self.side, p_rel + self.pc, hand_R(pitch + self.ac[1], yaw_rel + self.ac[0]), self.q, o[0:3]) + return self.q + + +# ----------------------------------------------------------------------------- policy + +LOOK_P = np.array([0.40, 0.15, 0.20]) +LOOK_PITCH = 0.2 +LOOK_YAW = 0.3 +BASE1 = (0.04, -0.52, 0.0) +LEAN = 0.3 +GR_IN = 0.005 +HANDLE_R = 0.068 +YAW_ALIGN = 0.5 +GR_Z = 0.08 +REACH_X = 0.57 # mug centre ahead of the pelvis when grasping +SIDE_OFF = 0.12 # mug centre beside the pelvis (towards the grasping hand) +CARRY_P = np.array([0.38, 0.15, 0.24]) +WALK_P = np.array([0.25, 0.15, 0.25]) +CARRY_PITCH = 0.0 # hand pitch while grasping and carrying +GRIP_OPEN = 0.25 +WALK_V = 0.20 +WALK_W = 0.7 +PLACE_BASE = (0.19, -0.545, np.pi / 2) # facing the upper rack +PLACE_H = 0.72 +PLACE_LEAN = 0.32 +PLACE_SPOTS = ((0.10, -0.03), (0.28, -0.03)) # mug centres in the upper rack (world x, y) +PLACE_Z_HI = 0.89 +PLACE_Z_LO = 0.52 +CONTACT_DZ = 0.015 + + +WRIST_REL = (0.33, 0.12) # wrist ahead of / beside the pelvis when grasping +GRASP_BASE_YAW = (0.0, 0.35) # base yaw while grasping the left / right mug +BASE_Y_MAX = -0.47 # the open dishwasher door blocks the legs beyond this + + +def grasp_geometry(mug, handle): + """Handle point H (world), handle yaw phi and hand yaw for a mug.""" + dev = float(np.clip(wrap(handle - np.pi), -0.6, 0.6)) + phi = np.pi + dev + app = YAW_ALIGN * dev + H = np.array([mug[0] + HANDLE_R * np.cos(phi), mug[1] + HANDLE_R * np.sin(phi), ZC + GR_Z]) + return H, phi, app + + +def look_pose(mug, psi, dist=0.24, height=0.17): + """Pad target and hand pitch that put a wrist camera dist back / height above the mug, looking at it.""" + c = np.array([mug[0] - dist * np.cos(psi), mug[1] - dist * np.sin(psi), ZC + 0.05 + height]) + dep = np.arctan2(height, dist) + pitch = CAM_ALPHA - dep + Rh = rz(psi) @ ry(-pitch) + wrist = c - Rh @ CAM_OFF + return wrist + Rh @ GRASP_OFF, float(pitch) + + +def window_mask(org, Rc, mugs, grow=10): + m = np.zeros((84, 84), bool) + for x, y in mugs: + m |= cyl_mask(org, Rc, x, y) + return cv2.dilate(m.astype(np.uint8), np.ones((2 * grow + 1, 2 * grow + 1), np.uint8)).astype(bool) + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + def reset(self, obs, tools): + self.tools = tools + self.arms = {1: ArmMover(1), -1: ArmMover(-1)} + self.grip = {1: 0.0, -1: 0.0} + self.pitch = 0.0 + self.height = 0.74 + self.base = (0.0, 0.0, 0.0) + self.o = np.asarray(obs['low_dim_obs'], dtype=float) + self.t = 0 + self.mug_rel = {} + self.pitch_goal = 0.0 + self.height_goal = 0.74 + self.gen = self.script() + + # ------------------------------------------------------------------ helpers + def dbg(self, *a): + if DEBUG: + print(f'[{self.t}]', *a, flush=True) + + def snap(self, tag): + if DEBUG: + for c in ('head', 'left_wrist', 'right_wrist'): + self.tools.render(c, f'frames/dbg_{tag}_{c}.png') + + def wait(self, n): + for _ in range(int(n)): + yield + + def wait_arms(self, sides=(1, -1), extra=0, timeout=400): + k = 0 + while any(self.arms[s].busy() for s in sides) and k < timeout: + k += 1 + yield + yield from self.wait(extra) + + def walk_to(self, x, y, yaw, timeout=300, tol=0.025, vmax=0.15, ytol=0.03, wmax=0.5, acc=0.004): + cur = np.array(self.base, float) + for k in range(timeout): + cmd, done = goto_cmd(self.o, x, y, yaw, vmax=vmax, tol=tol, ytol=ytol, wmax=wmax) + if done: + break + cmd = np.array(cmd) + # limit accelerations, but never command a planar speed inside the dead band + step = np.clip(cmd - cur, -acc, acc) + step[2] = np.clip(cmd[2] - cur[2], -2 * acc, 2 * acc) + cur = cur + step + out = cur.copy() + sp = np.hypot(out[0], out[1]) + if 0 < sp < 0.06 and np.hypot(cmd[0], cmd[1]) >= 0.06: + out[:2] *= 0.06 / sp + elif sp < 0.06 and np.hypot(cmd[0], cmd[1]) < 0.06: + out[:2] = cmd[:2] + if 0 < abs(out[2]) < WZ_MIN and abs(cmd[2]) >= WZ_MIN: + out[2] = WZ_MIN * np.sign(out[2]) + self.base = tuple(out) + yield + self.base = (0.0, 0.0, 0.0) + self.dbg('walk_to', (round(x, 3), round(y, 3), round(yaw, 3)), 'at', np.round(self.o[[21, 22, 24]], 3), 'k', k) + + def lean_to(self, p, rate=0.01): + self.pitch_goal = p + while abs(self.pitch - p) > 1e-6: + yield + + def views(self, sides): + out = [] + for s in sides: + im = self.tools.image('left_wrist' if s > 0 else 'right_wrist') + org, Rc = wrist_cam(self.o, s) + gm, st = image_masks(im) + out.append((org, Rc, gm, st)) + return out + + def perceive(self, inits, sides=(1, -1), window=True, protrusion=False): + vs = self.views(sides) + fv = [] + for org, Rc, gm, st in vs: + if window: + gm = gm & window_mask(org, Rc, inits, 12) + fv.append((org, Rc, gm)) + mugs, cost = fit_mugs(fv, inits) + hd = handle_dirs(vs, mugs) + if protrusion: + hp = handle_protrusion([(a, b, c, d[3]) for (a, b, c), d in zip(fv, vs)], mugs) + self.dbg('protrusion', [(None if a is None else round(np.degrees(a)), n) for a, n in hp], 'stick', np.degrees(hd).round(0)) + # The silhouette cue fails when the handle faces the camera; the shadow cue is only + # unbiased when the handle points back towards the robot (shadows fall towards it). + out = [] + for (a, n), st in zip(hp, hd): + if a is None or n < 8: + out.append(None) + elif abs(wrap(st - np.pi)) < np.radians(15) and abs(wrap(a - st)) > np.radians(30): + out.append(st) + else: + out.append(a) + hd = out + self.dbg('perceive', np.round(mugs, 3).tolist(), 'cost', round(cost, 3), 'handles', np.degrees(hd).round(0)) + return mugs, hd, cost + + def refine_handle(self, s, mug_c, phi): + """Handle yaw from the handle's shadow on the counter, seen close up by the grasping hand. + + At the stand-off pose the shadow lies almost under the handle, so the blob in the + annulus around the mug whose azimuth is nearest the current estimate gives the handle yaw. + """ + org, Rc, gm, st = self.views((s,))[0] + ys, xs = np.nonzero(st) + best = None + if len(xs): + from scipy import ndimage + lab, n = ndimage.label(st) + for i in range(1, n + 1): + sel = lab[ys, xs] == i + if sel.sum() < 4: + continue + pts = [] + for u, v in zip(xs[sel], ys[sel]): + d = pix_ray(org, Rc, float(u), float(v)) + if d[2] < -1e-3: + pts.append((org + d * (ZC - org[2]) / d[2])[:2]) + if len(pts) < 10: + continue + pts = np.array(pts) + c = pts.mean(0) + r = np.hypot(*(c - mug_c)) + ang = float(np.arctan2(c[1] - mug_c[1], c[0] - mug_c[0])) + dang = abs(wrap(ang - phi)) + if 0.035 < r < 0.09 and dang < np.radians(60) and (best is None or dang < best[0]): + best = (dang, ang, len(pts), r) + if best is None: + self.dbg('refine: no stick') + return None + self.dbg('refine: stick at yaw', round(np.degrees(best[1])), 'r', round(best[3], 3), + 'expected', round(np.degrees(phi)), 'n', best[2]) + return best[1] + + # ------------------------------------------------------------------ skills + def grasp(self, s, mug, handle): + arm = self.arms[s] + mx, my = mug + H, phi, app = grasp_geometry(mug, handle) + dvec = np.array([np.cos(app), np.sin(app), 0.0]) + + def G(back, dz=0.0): + return H - back * dvec + [0, 0, dz] + + self.grip[s] = GRIP_OPEN + arm.move(self.o, G(0.11, 0.06), app, CARRY_PITCH, 35) + yield from self.wait_arms((s,)) + arm.move(self.o, G(0.08), app, CARRY_PITCH, 20) + yield from self.wait_arms((s,), extra=10) + mug_c = np.array([mx, my]) + for it in range(1): + a = self.refine_handle(s, mug_c, phi) + if a is None: + break + # the shadow sits slightly off the handle: move half way towards it + phi = phi + 0.5 * wrap(a - phi) + phi = np.pi + float(np.clip(wrap(phi - np.pi), -0.8, 0.8)) + H[:2] = mug_c + HANDLE_R * np.array([np.cos(phi), np.sin(phi)]) + app = float(np.clip(wrap(phi - np.pi), -0.6, 0.6)) + dvec[:] = [np.cos(app), np.sin(app), 0.0] + self.dbg('refine it', it, 'phi', round(np.degrees(phi)), 'app', round(np.degrees(app))) + arm.move(self.o, G(0.08), app, CARRY_PITCH, 15) + yield from self.wait_arms((s,), extra=6) + arm.move(self.o, G(-GR_IN), app, CARRY_PITCH, 45) + yield from self.wait_arms((s,), extra=8) + self.snap(f'pregrip{s}') + q_act = self.o[3:10] if s > 0 else self.o[12:19] + Rw = rz(self.o[24]) + Ra, pa = arm_fk(q_act, s, self.o[0:3]) + Ra, pa = Rw @ Ra, self.o[21:24] + Rw @ pa + mug_c = np.r_[H[:2] - HANDLE_R * np.array([np.cos(phi), np.sin(phi)]), ZC] + self.mug_rel[s] = Ra.T @ (mug_c - pa) + self.dbg('mug_rel', s, np.round(self.mug_rel[s], 3)) + arm.comp = False + for k in range(16): + self.grip[s] = GRIP_OPEN + (1 - GRIP_OPEN) * (k + 1) / 16 + yield + yield from self.wait(5) + arm.move(self.o, G(-GR_IN, 0.12), app, CARRY_PITCH, 30) + yield from self.wait_arms((s,)) + arm.comp = True + self.snap(f'lifted{s}') + gstate = self.o[50] if s > 0 else self.o[51] + self.dbg('grasp', s, 'gripper state', round(float(gstate), 3)) + + def script(self): + for s in (1, -1): + self.arms[s].move(self.o, LOOK_P * [1, s, 1], -LOOK_YAW * s, LOOK_PITCH, 50, frame='pelvis', from_target=False) + yield from self.wait(15) + self.pitch_goal = LEAN + yield from self.walk_to(*BASE1, timeout=250) + yield from self.lean_to(LEAN) + yield from self.wait(35) + mugs, hd, _ = self.perceive([(0.60, -0.45), (0.58, -0.60)], window=False) + self.snap('perceive') + + # ---- grasp each mug from a base pose suited to its handle + for s in (1, -1): + i = 0 if s > 0 else 1 + H, phi, app = grasp_geometry(mugs[i], hd[i]) + pad = H + GR_IN * np.array([np.cos(app), np.sin(app), 0.0]) + th = GRASP_BASE_YAW[i] + rel = np.array([WRIST_REL[0] + 0.165 * np.cos(app - th), s * WRIST_REL[1] + 0.165 * np.sin(app - th)]) + rel = rz(th)[:2, :2] @ rel + bx, by = pad[0] - rel[0], min(pad[1] - rel[1], BASE_Y_MAX) + yield from self.walk_to(bx, by, th, timeout=200, vmax=0.1, tol=0.02, ytol=0.03) + # close look at this mug with the grasping hand's camera + psi = float(np.arctan2(mugs[i][1] - self.o[22], mugs[i][0] - self.o[21])) + 0.25 * s + p_look, pitch_look = look_pose(mugs[i], psi) + self.arms[s].move(self.o, p_look, psi, pitch_look, 35) + yield from self.wait_arms((s,), extra=10) + m2, h2, c2 = self.perceive([mugs[i]], sides=(s,), protrusion=True) + self.snap(f'look{s}') + if c2 < 0.45 and np.hypot(*(m2[0] - mugs[i])) < 0.09: + mugs[i] = m2[0] + if h2[0] is not None: + hd[i] = h2[0] + H, phi, app = grasp_geometry(mugs[i], hd[i]) + pad = H + GR_IN * np.array([np.cos(app), np.sin(app), 0.0]) + rel = np.array([WRIST_REL[0] + 0.165 * np.cos(app - th), s * WRIST_REL[1] + 0.165 * np.sin(app - th)]) + rel = rz(th)[:2, :2] @ rel + bx, by = pad[0] - rel[0], min(pad[1] - rel[1], BASE_Y_MAX) + yield from self.walk_to(bx, by, th, timeout=100, vmax=0.08, tol=0.02, ytol=0.03) + yield from self.wait(5) + yield from self.grasp(s, mugs[i], hd[i]) + self.arms[s].move(self.o, CARRY_P * [1, s, 1], 0.0, CARRY_PITCH, 50, frame='pelvis') + yield from self.wait(15) + self.snap('carry') + + # ---- carry to the dishwasher + yield from self.wait_arms() + self.pitch_goal = 0.0 + yield from self.walk_to(*PLACE_BASE, timeout=350, tol=0.02, ytol=0.025, vmax=WALK_V, wmax=WALK_W) + self.pitch_goal = PLACE_LEAN + self.height_goal = PLACE_H + yield from self.wait(75) + self.snap('atrack') + yield from self.place() + self.snap('placed') + while True: # hold still while the success condition is checked + yield + + def place(self): + """Lower both mugs into the upper rack, release and withdraw.""" + tgt = {1: np.array(PLACE_SPOTS[0]), -1: np.array(PLACE_SPOTS[1])} + yaw_h = PLACE_BASE[2] + Rh = rz(yaw_h) @ ry(-CARRY_PITCH) + pads = {} + for s in (1, -1): + v = self.mug_rel.get(s, np.array([HANDLE_R, 0.0, -GR_Z])) + pad_xy = tgt[s] - (Rh @ v)[:2] + pads[s] = pad_xy + # above the rack, mug bottom clear of the front rim + for s in (1, -1): + self.arms[s].move(self.o, np.r_[pads[s], PLACE_Z_HI], yaw_h, CARRY_PITCH, 60) + yield from self.wait_arms(extra=10) + self.snap('above') + for s in (1, -1): + self.arms[s].comp = False + # lower both slowly until contact + z = PLACE_Z_HI + done = {1: False, -1: False} + dz0 = {} + k = 0 + while not all(done.values()) and z > PLACE_Z_LO: + z -= 0.0009 + k += 1 + for s in (1, -1): + if done[s]: + continue + arm = self.arms[s] + arm.target = (np.r_[pads[s], z], yaw_h, CARRY_PITCH, 'world') + arm.seg = None + q_act = self.o[3:10] if s > 0 else self.o[12:19] + Rw = rz(self.o[24]) + za = (self.o[21:24] + Rw @ arm_fk(q_act, s, self.o[0:3])[1])[2] + if k == 40: + dz0[s] = za - z + if k > 40 and (za - z - dz0[s] > CONTACT_DZ or arm.err > 0.012): + done[s] = True + self.dbg('contact', s, 'cmd z', round(z, 3), 'act z', round(za, 3), 'ik err', round(arm.err, 4)) + yield + self.dbg('lowered', done, 'z', round(z, 3)) + yield from self.wait(15) + self.snap('lowered') + for k in range(20): + for s in (1, -1): + self.grip[s] = max(0.0, 1.0 - (k + 1) / 20) + yield + yield from self.wait(20) + self.snap('released') + for s in (1, -1): + p, yw, pi, fr = self.arms[s].target + back = np.array([np.cos(yw), np.sin(yw), 0.0]) + self.arms[s].move(self.o, p - 0.08 * back, yw, pi, 50) + yield from self.wait_arms() + for s in (1, -1): + p, yw, pi, fr = self.arms[s].target + self.arms[s].move(self.o, p + [0, 0, 0.12], yw, pi, 50) + yield from self.wait_arms() + + def act(self, obs, tools): + self.o = np.asarray(obs['low_dim_obs'], dtype=float) + self.t = int(obs['t']) + try: + next(self.gen) + except StopIteration: + pass + qL = self.arms[1].step(self.o) + qR = self.arms[-1].step(self.o) + raw = np.zeros(21, dtype=np.float32) + raw[0:2] = self.base[0:2] + self.pitch += float(np.clip(self.pitch_goal - self.pitch, -0.004, 0.004)) + self.height += float(np.clip(self.height_goal - self.height, -0.001, 0.001)) + raw[2] = self.height + raw[3] = self.base[2] + raw[4] = self.pitch + raw[5:12] = qL + raw[12:19] = qR + raw[19] = self.grip[1] + raw[20] = self.grip[-1] + return raw diff --git a/policies/dishwasher_load_cups/opus-s2/episodes.csv b/policies/dishwasher_load_cups/opus-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..7c8085e5ca316df1d8d995b2153e133d283d2101 --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,1073,terminated,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,2000,timeout,0 +620014,0,2000,timeout,0 +620015,0,1550,terminated,0 +620016,0,1607,terminated,0 +620017,0,2000,timeout,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,2000,timeout,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,2000,timeout,0 +620029,0,2000,timeout,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,1592,terminated,0 +620034,0,2000,timeout,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,2000,timeout,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,2000,timeout,0 +620049,0,2000,timeout,0 +620050,0,2000,timeout,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,2000,timeout,0 +620065,0,2000,timeout,0 +620066,0,1392,terminated,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,0,2000,timeout,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,569,terminated,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,1,1773,success,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,2000,timeout,0 +620089,0,2000,timeout,0 +620090,0,2000,timeout,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,2000,timeout,0 +620096,0,2000,timeout,0 +620097,0,556,terminated,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/opus-s2/policy.py b/policies/dishwasher_load_cups/opus-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..013513137c44a2dddf91efcf334f8708afaa5e17 --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s2/policy.py @@ -0,0 +1,440 @@ +"""Hand-written policy: load two mugs from the counter into the dishwasher upper rack. + +Structure: a generator-based state machine (sequential code that yields one +action per control step). Perception is colour segmentation of the robot's +cameras; arm motion uses an approximate G1 arm kinematic model (from the +URDF) with damped IK and integral sag compensation. +""" + +import numpy as np +from scipy import ndimage +from scipy.optimize import least_squares + +# ----------------------------------------------------------------------------- kinematics + + +def rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +AX = {'x': rx, 'y': ry, 'z': rz} + + +def _chain(side): + s = 1.0 if side == 'L' else -1.0 + return [ + (np.array([0.0039563, s * 0.10022, 0.23778]), rx(s * 0.27931), 'y'), + (np.array([0, s * 0.038, -0.013831]), rx(-s * 0.27925), 'x'), + (np.array([0, s * 0.00624, -0.1032]), np.eye(3), 'z'), + (np.array([0.015783, 0, -0.080518]), np.eye(3), 'y'), + (np.array([0.100, s * 0.00188791, -0.010]), np.eye(3), 'x'), + (np.array([0.038, 0, 0]), np.eye(3), 'y'), + (np.array([0.046, 0, 0]), np.eye(3), 'z'), + ] + + +CHAIN = {'L': _chain('L'), 'R': _chain('R')} +TOOL = np.array([0.16, 0, 0]) +LIM_LO = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443]) +LIM_HI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443]) + + +def limits(side): + lo, hi = LIM_LO.copy(), LIM_HI.copy() + if side == 'R': + lo[1], hi[1] = -LIM_HI[1], -LIM_LO[1] + return lo, hi + + +def fk(q, side, frames=False): + p = np.zeros(3) + R = np.eye(3) + out = [] + for (off, R0, ax), qi in zip(CHAIN[side], q): + p = p + R @ off + R = R @ R0 @ AX[ax](qi) + out.append(p.copy()) + pt = p + R @ TOOL + if frames: + return pt, R, out + return pt, R + + +def rot_err(Rc, Rt): + E = Rt @ Rc.T + ang = np.arccos(np.clip((np.trace(E) - 1) / 2, -1, 1)) + if ang < 1e-6: + return np.zeros(3) + w = np.array([E[2, 1] - E[1, 2], E[0, 2] - E[2, 0], E[1, 0] - E[0, 1]]) / (2 * np.sin(ang)) + return w * ang + + +QPREF = {'L': np.array([-0.4, 0.25, 0.0, 0.3, 0.0, 0.0, 0.0])} +QPREF['R'] = QPREF['L'] * np.array([1, -1, -1, 1, -1, 1, -1]) + + +def ik(pt, Rt, side, q0): + s = 1.0 if side == 'L' else -1.0 + lo, hi = limits(side) + q0 = np.clip(np.asarray(q0, float), lo + 1e-3, hi - 1e-3) + + def res(q): + p, R, fr = fk(q, side, frames=True) + er = rot_err(R, Rt) + ey = s * fr[3][1] + wy = s * fr[4][1] + pen = [max(0.0, 0.14 - ey) * 3, max(0.0, 0.03 - wy) * 3] + return np.concatenate([(p - pt), 0.15 * er, 0.02 * (q - QPREF[side]), pen]) + + sol = least_squares(res, q0, bounds=(lo, hi), xtol=1e-7, ftol=1e-9, max_nfev=200) + return sol.x + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +# ----------------------------------------------------------------------------- vision + + +def neutral_mask(im): + im = im.astype(int) + mx, mn = im.max(2), im.min(2) + return ((mx - mn) < 14) & (mx > 60) & (mx < 236) + + +def wrist_blobs(im, min_area=120): + m = ndimage.binary_opening(neutral_mask(im), iterations=1) + lab, n = ndimage.label(m) + out = [] + for i in range(1, n + 1): + comp = lab == i + a = int(comp.sum()) + if a < min_area: + continue + ys, xs = np.nonzero(comp) + y1 = ys.max() + band = comp[max(0, y1 - 6):y1 + 1] + bx = np.nonzero(band.any(0))[0] + out.append(dict(u=float(xs.mean()), ub=float(bx.min() + bx.max()) / 2, area=a, y1=int(y1))) + return out + + +def head_mugs(im): + """Mugs seen by the head camera at the counter stance: dark-gray blobs above the counter edge.""" + im = im.astype(int) + mx, mn = im.max(2), im.min(2) + m = ((mx - mn) < 16) & (mx > 50) & (mx < 215) + m[55:] = False + m = ndimage.binary_opening(m, iterations=1) + lab, n = ndimage.label(m) + out = [] + for i in range(1, n + 1): + comp = lab == i + a = int(comp.sum()) + if a < 25: + continue + ys, xs = np.nonzero(comp) + out.append(dict(u=float(xs.mean()), v=float(ys.mean()), area=a, y1=int(ys.max()))) + return out + + +# ----------------------------------------------------------------------------- policy + +REST = {'L': np.array([0.12, 0.25, -0.1]), 'R': np.array([0.12, -0.25, -0.1])} +RAISED = {'L': np.array([0.25, 0.28, 0.27]), 'R': np.array([0.25, -0.28, 0.27])} +STANCE_X = 0.20 +Z_GRASP = 0.14 +Z_LOOK = 0.28 +Z_PRE = 0.22 +YAW = {'L': 0.0, 'R': 0.0} +DEEP = 0.015 +U_CANON = {'R': 40.0, 'L': 44.0} +APP_N = 10 +LOOK_Y = {'R': 0.045, 'L': -0.03} +PLACE_BASE = (0.12, -0.62) +PLACE_X = 0.44 +PLACE_Y = 0.07 +SQUAT_H = 0.55 +STALL = 0.015 + + +class NoList: + def append(self, x): + pass + + +class DbgList(list): + pass + + +class Policy: + def reset(self, obs, tools): + self.tools = tools + self.obs = obs + self.a = np.asarray(tools.hold_action(), dtype=float) + self.qt = {'L': self.a[5:12].copy(), 'R': self.a[12:19].copy()} + self.qcmd = {'L': self.qt['L'].copy(), 'R': self.qt['R'].copy()} + self.off = {'L': np.zeros(7), 'R': np.zeros(7)} + self.base_t = None + self.y_adj = {} + self.log = [] + self.dbg = DbgList() if getattr(self, 'debug', False) else NoList() + self.gen = self.run() + + # ---- low level + @property + def lo(self): + return self.obs['low_dim_obs'] + + def qmeas(self, side): + return self.lo[3:10] if side == 'L' else self.lo[12:19] + + def tool(self, side): + return fk(self.qmeas(side), side) + + def act(self, obs, tools): + self.obs = obs + try: + next(self.gen) + except StopIteration: + pass + return self.a.astype(np.float32) + + def _update(self): + lo = self.lo + for s, sl in (('L', slice(5, 12)), ('R', slice(12, 19))): + err = self.qcmd[s] - self.qmeas(s) + self.off[s] = np.clip(self.off[s] + 0.05 * err, -0.4, 0.4) + self.a[sl] = self.qcmd[s] + self.off[s] + if self.base_t is not None: + xt, yt, yawt = self.base_t + c, s_ = np.cos(lo[24]), np.sin(lo[24]) + dx, dy = xt - lo[21], yt - lo[22] + ex, ey = c * dx + s_ * dy, -s_ * dx + c * dy + vx = np.clip(1.5 * ex, -0.25, 0.25) + vy = np.clip(1.5 * ey, -0.2, 0.2) + sp = np.hypot(vx, vy) + if np.hypot(ex, ey) < 0.015: + vx = vy = 0.0 + elif sp < 0.07: + vx, vy = vx / sp * 0.07, vy / sp * 0.07 + e = wrap(yawt - lo[24]) + wz = float(np.clip(2.0 * e, -0.6, 0.6)) if abs(e) > 0.02 else 0.0 + self.a[0], self.a[1], self.a[3] = vx, vy, wz + + def wait(self, n): + for _ in range(n): + self._update() + yield + + def move(self, side, P, R, n): + """IK to (P, R) and interpolate the joint targets over n steps.""" + q1 = ik(np.asarray(P, float), R, side, self.qt[side]) + q0 = self.qcmd[side].copy() + self.qt[side] = q1 + n = max(1, n) + for i in range(n): + self.qcmd[side] = q0 + (q1 - q0) * (i + 1) / n + self._update() + yield + + def move2(self, PL, RL, PR, RR, n): + """Move both arms simultaneously.""" + q1L = ik(np.asarray(PL, float), RL, 'L', self.qt['L']) + q1R = ik(np.asarray(PR, float), RR, 'R', self.qt['R']) + q0L, q0R = self.qcmd['L'].copy(), self.qcmd['R'].copy() + self.qt['L'], self.qt['R'] = q1L, q1R + for i in range(n): + f = (i + 1) / n + self.qcmd['L'] = q0L + (q1L - q0L) * f + self.qcmd['R'] = q0R + (q1R - q0R) * f + self._update() + yield + + def grip(self, side, g): + self.a[19 if side == 'L' else 20] = g + + # ---- behaviour + def run(self): + lo = self.lo + self.y0 = float(lo[22]) + self.grip('L', 0.0) + self.grip('R', 0.0) + # raise the hands above counter height (wide, out of the head view), walk in + yield from self.move2(RAISED['L'], np.eye(3), RAISED['R'], np.eye(3), 40) + self.base_t = (STANCE_X, self.y0, 0.0) + yield from self.wait(120) + self.held = {} + # right mug with the right arm + yield from self.center_mug('R') + self.held['R'] = yield from self.grasp_one('R') + pr, _ = self.tool('R') + yield from self.move('R', np.array([0.22, -0.30, 0.26]), np.eye(3), 40) + # left mug with the left arm + yield from self.center_mug('L') + self.held['L'] = yield from self.grasp_one('L') + pl, _ = self.tool('L') + yield from self.move('L', np.array([0.22, 0.30, 0.26]), np.eye(3), 40) + self.log.append(('held', self.held, int(self.obs['t']))) + # back off and turn to the dishwasher + self.base_t = (STANCE_X - 0.2, float(self.lo[22]), 0.0) + yield from self.wait(70) + self.base_t = (STANCE_X - 0.2, float(self.lo[22]), np.pi / 2) + for _ in range(25): + yield from self.wait(8) + if abs(wrap(self.lo[24] - np.pi / 2)) < 0.12: + break + self.log.append(('turned', int(self.obs['t']))) + yield from self.place() + while True: + yield from self.wait(10) + + def center_mug(self, side): + """Shift the base sideways so the target mug is at a canonical head-image column.""" + for it in range(2): + mugs = head_mugs(self.tools.image('head')) + mugs = [m for m in mugs if m['area'] >= 60] + mugs = sorted(mugs, key=lambda m: -m['area'])[:2] + self.log.append(('head_mugs', side, [(round(m['u'], 1), round(m['v'], 1), m['area']) for m in mugs])) + if not mugs: + return + if len(mugs) == 2: + m = max(mugs, key=lambda m: m['u']) if side == 'R' else min(mugs, key=lambda m: m['u']) + else: + m = mugs[0] + dy = float(np.clip((U_CANON[side] - m['u']) * 0.0045, -0.2, 0.2)) + if it > 0 and abs(dy) < 0.02: + break + self.base_t = (STANCE_X, float(self.lo[22]) + dy, 0.0) + for _ in range(25): + yield from self.wait(8) + if abs(self.base_t[1] - self.lo[22]) < 0.015: + break + yield from self.wait(15) + self.log.append(('centered', side, round(dy, 3), round(float(self.base_t[1] - self.lo[22]), 3), int(self.obs['t']))) + # final measurement: residual offset handled by the arm + mugs = [m for m in head_mugs(self.tools.image('head')) if m['area'] >= 60] + mugs = sorted(mugs, key=lambda m: -m['area'])[:2] + self.y_adj[side] = 0.0 + if mugs: + if len(mugs) == 2: + m = max(mugs, key=lambda m: m['u']) if side == 'R' else min(mugs, key=lambda m: m['u']) + else: + m = mugs[0] + self.y_adj[side] = float(np.clip((U_CANON[side] - m['u']) * 0.0045, -0.08, 0.08)) + self.log.append(('y_adj', side, round(self.y_adj[side], 3))) + + def grasp_one(self, side): + cam = 'left_wrist' if side == 'L' else 'right_wrist' + Rg = np.eye(3) + fwd, lat = Rg[:, 0], Rg[:, 1] + base = np.array([0.20, LOOK_Y[side] + self.y_adj.get(side, 0.0), Z_LOOK]) + yield from self.move(side, base, Rg, 30) + lat_off = 0.0 + base = base.copy() + base[2] = Z_PRE + yield from self.move(side, base, Rg, 20) + for k in range(6): + im = self.tools.image(cam) + bs = wrist_blobs(im) + bs = [b for b in bs if b['area'] >= 200] + b = (min(bs, key=lambda b: b['u']) if side == 'L' else max(bs, key=lambda b: b['u'])) if bs else None + self.dbg.append((f'pre{k}{side}', im, b)) + if b is None: + if k >= 2: + break + lat_off += 0.04 if side == 'R' else -0.04 + yield from self.move(side, base + lat_off * lat, Rg, 15) + continue + d = float(np.clip(-(b['ub'] - 42) * 0.0012, -0.03, 0.03)) + lat_off = float(np.clip(lat_off + d, -0.12, 0.12)) + yield from self.move(side, base + lat_off * lat, Rg, 12) + if abs(b['ub'] - 42) < 4: + break + base[2] = Z_GRASP + yield from self.move(side, base + lat_off * lat, Rg, 20) + s = 0.0 + k = 0 + while s < 0.25: + k += 1 + if s < 0.12: + im = self.tools.image(cam) + bs = wrist_blobs(im) + b = min(bs, key=lambda b: abs(b['ub'] - 42) - 0.01 * b['area']) if bs else None + self.dbg.append((f'app{k}{side}', im, b)) + if b is not None: + lat_off += float(np.clip(-(b['ub'] - 42) * 0.0008, -0.012, 0.012)) + lat_off = float(np.clip(lat_off, -0.09, 0.09)) + s += 0.01 + yield from self.move(side, base + s * fwd + lat_off * lat, Rg, APP_N) + pm, _ = self.tool(side) + prog = (pm - base - lat_off * lat) @ fwd + if s - prog > STALL and s > 0.06: + break + yield from self.move(side, base + (s + 0.01) * fwd + lat_off * lat, Rg, 15) + self.grip(side, 1.0) + yield from self.wait(35) + g = float(self.lo[50 if side == 'L' else 51]) + pm, _ = self.tool(side) + for i in range(8): + yield from self.move(side, pm + np.array([0, 0, 0.012 * (i + 1)]), Rg, 5) + yield from self.wait(5) + g2 = float(self.lo[50 if side == 'L' else 51]) + self.log.append(('grasp', side, round(g, 2), round(g2, 2), round(s, 3), round(lat_off, 3), int(self.obs['t']))) + return g2 < 0.97 + + def place(self): + self.base_t = (PLACE_BASE[0], PLACE_BASE[1], np.pi / 2) + for _ in range(20): + yield from self.wait(8) + lo = self.lo + if np.hypot(lo[21] - PLACE_BASE[0], lo[22] - PLACE_BASE[1]) < 0.02 and abs(wrap(lo[24] - np.pi / 2)) < 0.04: + break + self.log.append(('at_rack', [round(float(v), 3) for v in self.lo[21:25]], int(self.obs['t']))) + P = {'L': np.array([PLACE_X, PLACE_Y, 0.14]), 'R': np.array([PLACE_X, -PLACE_Y, 0.14])} + yield from self.move2(P['L'], np.eye(3), P['R'], np.eye(3), 40) + self.base_t = None + self.a[0] = self.a[1] = self.a[3] = 0.0 + h0 = float(self.a[2]) + for i in range(60): + self.a[2] = h0 + (SQUAT_H - h0) * (i + 1) / 60 + yield from self.wait(1) + yield from self.wait(20) + done = {'L': not self.held.get('L'), 'R': not self.held.get('R')} + d0 = {} + z = 0.14 + while not all(done.values()) and z > -0.2: + z -= 0.01 + for s in ('L', 'R'): + if not done[s]: + P[s][2] = z + yield from self.move2(P['L'], np.eye(3), P['R'], np.eye(3), 10) + for s in ('L', 'R'): + if done[s]: + continue + pm, _ = self.tool(s) + d = pm[2] - P[s][2] + if s not in d0: + d0[s] = d + if d - d0[s] > 0.012: + done[s] = True + self.log.append(('lowered', round(z, 3), int(self.obs['t']))) + self.grip('L', 0.0) + self.grip('R', 0.0) + yield from self.wait(25) + pl, _ = self.tool('L') + pr, _ = self.tool('R') + yield from self.move2(pl + np.array([-0.10, 0, 0.06]), np.eye(3), pr + np.array([-0.10, 0, 0.06]), np.eye(3), 40) + self.log.append(('released', int(self.obs['t']))) diff --git a/policies/dishwasher_load_cups/opus-s3/episodes.csv b/policies/dishwasher_load_cups/opus-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..52f917985b157fbd9851102ef5c0e3ed61c372ee --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2000,timeout,0 +620001,0,2000,timeout,0 +620002,0,2000,timeout,0 +620003,0,2000,timeout,0 +620004,0,2000,timeout,0 +620005,0,2000,timeout,0 +620006,0,2000,timeout,0 +620007,0,2000,timeout,0 +620008,0,2000,timeout,0 +620009,0,2000,timeout,0 +620010,0,2000,timeout,0 +620011,0,2000,timeout,0 +620012,0,2000,timeout,0 +620013,0,1831,terminated,0 +620014,0,2000,timeout,0 +620015,0,2000,timeout,0 +620016,0,2000,timeout,0 +620017,0,1873,terminated,0 +620018,0,2000,timeout,0 +620019,0,2000,timeout,0 +620020,0,2000,timeout,0 +620021,0,2000,timeout,0 +620022,0,1891,terminated,0 +620023,0,2000,timeout,0 +620024,0,2000,timeout,0 +620025,0,2000,timeout,0 +620026,0,2000,timeout,0 +620027,0,2000,timeout,0 +620028,0,1945,terminated,0 +620029,0,1825,terminated,0 +620030,0,2000,timeout,0 +620031,0,2000,timeout,0 +620032,0,2000,timeout,0 +620033,0,2000,timeout,0 +620034,0,1987,terminated,0 +620035,0,2000,timeout,0 +620036,0,2000,timeout,0 +620037,0,2000,timeout,0 +620038,0,2000,timeout,0 +620039,0,2000,timeout,0 +620040,0,2000,timeout,0 +620041,0,2000,timeout,0 +620042,0,2000,timeout,0 +620043,0,1733,terminated,0 +620044,0,2000,timeout,0 +620045,0,2000,timeout,0 +620046,0,2000,timeout,0 +620047,0,2000,timeout,0 +620048,0,1972,terminated,0 +620049,0,2000,timeout,0 +620050,0,1767,terminated,0 +620051,0,2000,timeout,0 +620052,0,2000,timeout,0 +620053,0,2000,timeout,0 +620054,0,2000,timeout,0 +620055,0,2000,timeout,0 +620056,0,2000,timeout,0 +620057,0,2000,timeout,0 +620058,0,2000,timeout,0 +620059,0,2000,timeout,0 +620060,0,2000,timeout,0 +620061,0,2000,timeout,0 +620062,0,2000,timeout,0 +620063,0,2000,timeout,0 +620064,0,1913,terminated,0 +620065,0,1973,terminated,0 +620066,0,2000,timeout,0 +620067,0,2000,timeout,0 +620068,0,2000,timeout,0 +620069,0,2000,timeout,0 +620070,0,2000,timeout,0 +620071,0,2000,timeout,0 +620072,1,1971,success,0 +620073,0,2000,timeout,0 +620074,0,2000,timeout,0 +620075,0,2000,timeout,0 +620076,0,2000,timeout,0 +620077,0,2000,timeout,0 +620078,0,2000,timeout,0 +620079,0,2000,timeout,0 +620080,0,2000,timeout,0 +620081,0,2000,timeout,0 +620082,0,1840,terminated,0 +620083,0,2000,timeout,0 +620084,0,2000,timeout,0 +620085,0,2000,timeout,0 +620086,0,2000,timeout,0 +620087,0,2000,timeout,0 +620088,0,1447,terminated,0 +620089,0,2000,timeout,0 +620090,0,1324,terminated,0 +620091,0,2000,timeout,0 +620092,0,2000,timeout,0 +620093,0,2000,timeout,0 +620094,0,2000,timeout,0 +620095,0,1914,terminated,0 +620096,0,1999,terminated,0 +620097,0,2000,timeout,0 +620098,0,2000,timeout,0 +620099,0,2000,timeout,0 diff --git a/policies/dishwasher_load_cups/opus-s3/g1kin.py b/policies/dishwasher_load_cups/opus-s3/g1kin.py new file mode 100644 index 0000000000000000000000000000000000000000..c6aedd2026838e9ab1fd788a7282eb8bafc8656a --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s3/g1kin.py @@ -0,0 +1,131 @@ +"""Approximate Unitree G1 kinematics and a small IK for the policy (hand-written, no learning).""" +import numpy as np +from scipy.optimize import least_squares + + +def rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +def T(R=np.eye(3), p=(0, 0, 0)): + M = np.eye(4) + M[:3, :3] = R + M[:3, 3] = p + return M + + +AX = {'x': rx, 'y': ry, 'z': rz} +LO = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443]) +HI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443]) +TOOL = (0.15, 0.0, 0.0) + + +def _chain(side): + s = 1 if side == 'l' else -1 + return [ + ((0.0039563, s * 0.10022, 0.23778), rx(s * 0.27931), 'y'), + ((0, s * 0.038, -0.013831), rx(-s * 0.27925), 'x'), + ((0, s * 0.00624, -0.1032), np.eye(3), 'z'), + ((0.015783, 0, -0.080518), np.eye(3), 'y'), + ((0.100, s * 0.00188791, -0.010), np.eye(3), 'x'), + ((0.038, 0, 0), np.eye(3), 'y'), + ((0.046, 0, 0), np.eye(3), 'z'), + ] + + +CHAIN = {'l': _chain('l'), 'r': _chain('r')} + + +def limits(side): + if side == 'l': + return LO, HI + lo, hi = LO.copy(), HI.copy() + lo[1], hi[1] = -HI[1], -LO[1] + lo[2], hi[2] = -HI[2], -LO[2] + lo[4], hi[4] = -HI[4], -LO[4] + lo[6], hi[6] = -HI[6], -LO[6] + return lo, hi + + +def torso_T(waist): + M = T(rz(waist[0])) + M = M @ T(rx(waist[1]), (-0.0039635, 0, 0.035)) + M = M @ T(ry(waist[2]), (0, 0, 0.019)) + return M + + +def arm_T(side, q, tool=TOOL): + M = np.eye(4) + for (p, R, ax), qi in zip(CHAIN[side], q): + M = M @ T(R, p) @ T(AX[ax](qi)) + return M @ T(np.eye(3), tool) + + +def pelvis_T(ld): + x, y, z, yaw = ld[21:25] + return T(rz(yaw), (x, y, z)) + + +def torso_world(ld): + return pelvis_T(ld) @ torso_T(ld[0:3]) + + +def arm_q(ld, side): + return np.array(ld[3:10] if side == 'l' else ld[12:19], dtype=float) + + +def solve(side, pos, xdir, zdir, q0, tool=TOOL, wori=0.3, wreg=0.05, qnom=None, lock=None): + """IK in torso frame: tool point at pos, tool x along xdir, tool z near zdir. + + lock: dict joint index -> fixed value. + """ + lo, hi = limits(side) + q0 = np.clip(np.asarray(q0, float), lo + 1e-4, hi - 1e-4) + full = q0.copy() + free = np.arange(7) + if lock: + for i, v in lock.items(): + full[i] = v + free = np.array([i for i in range(7) if i not in lock]) + qn = full.copy() if qnom is None else np.asarray(qnom, float) + pos = np.asarray(pos, float) + xdir = np.asarray(xdir, float) + zdir = None if zdir is None else np.asarray(zdir, float) + + def expand(v): + q = full.copy() + q[free] = v + return q + + def r(v): + q = expand(v) + M = arm_T(side, q, tool) + e = [M[:3, 3] - pos, wori * (M[:3, 0] - xdir)] + if zdir is not None: + e.append(wori * 0.5 * (M[:3, 2] - zdir)) + e.append(wreg * (q - qn)[free]) + return np.concatenate(e) + + s = least_squares(r, full[free], bounds=(lo[free], hi[free]), xtol=1e-6, ftol=1e-6) + q = expand(s.x) + M = arm_T(side, q, tool) + return q, float(np.linalg.norm(M[:3, 3] - pos)) + + +def world_to_torso(ld, p=None, d=None): + Tw = torso_world(ld) + R, t = Tw[:3, :3], Tw[:3, 3] + if p is not None: + return R.T @ (np.asarray(p) - t) + return R.T @ np.asarray(d) diff --git a/policies/dishwasher_load_cups/opus-s3/policy.py b/policies/dishwasher_load_cups/opus-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..0884356897a2b6a9fb09df660e0da0a4b611db85 --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s3/policy.py @@ -0,0 +1,441 @@ +"""Scripted policy: load two mugs from the counter into the dishwasher upper rack. + +Hand-written control: approximate G1 arm kinematics + IK (g1kin.py), colour +segmentation of the wrist cameras (vision.py), and a fixed choreography. +""" + +import numpy as np + +import g1kin as K +import vision + +QNOM = np.array([-0.8, 0.15, 0.0, 0.6, 0.0, 0.0, 0.0]) +DEBUG = False +LOCK = None +Q_PRE_L = np.array([-0.56, 0.23, 0.43, -1.05, -0.36, 1.61, 0.02]) + +P = dict( + stand=(0.15, -0.60), stand2_dy=0.02, ys_l=0.14, ys_r=-0.14, + zg=0.90, # tool height for the handle grasp (world z) + x0=0.22, xmax=0.37, + ustar=40.0, vstar=40.0, # handle-shadow start: column target, row trigger + dx_blind=0.15, # forward move from trigger to grasp + hold_fj=-0.017, # finger joint above this after closing = something in the hand + va=23.66, vh=-42.5, # wrist camera ground-plane model: distance = va / (row - vh) + vstop=55.0, xgmax=0.53, + mug_r=0.04, bar_r=0.075, grip_off=0.09, + carry_l=(0.30, 0.24, 1.16), carry_r=(0.30, -0.24, 1.16), ylim=0.04, + do_right=True, + dw=(0.17, -0.52, 1.5708), # stand in front of the open dishwasher, clear of the door + place_h=0.62, place_pitch=0.3, + place_x=0.55, place_y=0.10, place_zhi=1.02, place_zmin=0.76, + gpre=0.3, # gripper pre-shape before the final approach + kpx=0.0018, # servo gain m/px +) + + +def qnom(side): + q = QNOM.copy() + if side == 'r': + q[[1, 2, 4, 6]] *= -1 + return q + + +def mirror(q): + q = np.array(q, float).copy() + q[[1, 2, 4, 6]] *= -1 + return q + + +def body_to_world(ld, p): + x, y, yaw = ld[21], ld[22], ld[24] + c, s = np.cos(yaw), np.sin(yaw) + return np.array([x + c * p[0] - s * p[1], y + s * p[0] + c * p[1], p[2]]) + + +class Arm: + """Tool target in the body frame (pelvis x, y, yaw; world z).""" + + def __init__(self, side, q): + self.s = side + self.q = np.array(q, float) + self.pb = None + self.hd = 0.0 + self.pt = 0.0 + self.frozen = True + + def set(self, pb, hd=0.0, pt=0.0): + self.pb = np.array(pb, float) + self.hd, self.pt = hd, pt + self.frozen = False + + def freeze(self): + self.frozen = True + + def solve(self, ld, frame): + if self.frozen or self.pb is None: + return + pw = body_to_world(frame, self.pb) + h = frame[24] + self.hd + d = np.array([np.cos(h) * np.cos(self.pt), np.sin(h) * np.cos(self.pt), -np.sin(self.pt)]) + pt = K.world_to_torso(ld, p=pw) + dt = K.world_to_torso(ld, d=d) + zt = K.world_to_torso(ld, d=[0, 0, 1]) + best = None + for q0 in (self.q, qnom(self.s)): + q, err = K.solve(self.s, pt, dt, zt, q0, qnom=qnom(self.s), wreg=0.02, lock=LOCK) + M = K.arm_T(self.s, q) + cost = err + 0.1 * np.linalg.norm(M[:3, 0] - dt) + 0.02 * np.linalg.norm(q - qnom(self.s)) + if best is None or cost < best[0] - 1e-3: + best = (cost, q, err) + _, self.q, self.err = best + + def tool_body(self, ld): + """Current tool position in body frame (from measured joints).""" + M = K.torso_world(ld) @ K.arm_T(self.s, K.arm_q(ld, self.s)) + p = M[:3, 3] + x, y, yaw = ld[21], ld[22], ld[24] + c, s = np.cos(yaw), np.sin(yaw) + dx, dy = p[0] - x, p[1] - y + return np.array([c * dx + s * dy, -s * dx + c * dy, p[2]]) + + +class Policy: + def reset(self, obs, tools): + self.tools = tools + self.base = np.asarray(tools.hold_action(), dtype=np.float64) + self.base[0] = self.base[1] = self.base[3] = 0.0 + self.base[2] = 0.74 + self.base[4] = 0.0 + self.base[19] = self.base[20] = 0.0 + self.arms = {'l': Arm('l', Q_PRE_L), 'r': Arm('r', mirror(Q_PRE_L))} + self.off = np.zeros(14) + self.obs = obs + self.frame = None + self.face = 0.0 + self.holding_active = False + self.nowalk = False + self.k = 0 + self.log = [] + self.gen = self.script() + + # ---------------------------------------------------------------- helpers + def action(self): + ld = self.obs['low_dim_obs'] + if self.k % 5 == 0: + fr = ld if self.frame is None else self.frame + for A in self.arms.values(): + A.solve(ld, fr) + if DEBUG: + self.log.append(('dbg', self.obs['t'], ld[21:25].round(3), self.arms['l'].q.round(2), + None if self.arms['l'].pb is None else self.arms['l'].pb.round(3), + round(float(getattr(self.arms['l'], 'err', -1)), 3), self.base[:4].round(2))) + self.k += 1 + qt = np.concatenate([self.arms['l'].q, self.arms['r'].q]) + qa = np.concatenate([ld[3:10], ld[12:19]]) + self.off = np.clip(self.off + 0.1 * (qt - qa), -0.3, 0.3) + a = self.base.copy() + a[5:19] = qt + self.off + return a + + def steps(self, n, walk=None): + for _ in range(n): + if walk is not None: + if walk(self.obs['low_dim_obs']): + break + elif self.frame is not None: + self.hold_base(self.obs['low_dim_obs']) + yield self.action() + + def move(self, side, goal, speed=0.1, settle=10, hd=None): + """Move one tool target in a straight line at a limited speed (m/s).""" + A = self.arms[side] + goal = np.array(goal, float) + if A.pb is None: + A.set(goal) + start = A.pb.copy() + h0 = A.hd + h1 = h0 if hd is None else hd + n = max(1, int(np.ceil(np.linalg.norm(goal - start) / (speed * 0.02)))) + for i in range(1, n + 1): + A.pb = start + (goal - start) * i / n + A.hd = h0 + (h1 - h0) * i / n + A.frozen = False + yield self.action_with_hold() + yield from self.steps(settle) + + def action_with_hold(self): + if self.frame is not None: + self.hold_base(self.obs['low_dim_obs']) + return self.action() + + def goto(self, x, y, yaw, n=400): + """Walk to a pose with the arm targets following the body, then fix the task frame there.""" + self.frame = None + yield from self.steps(n, self.walker(x, y, yaw)) + self.stop_base() + fr = np.zeros(56) + fr[21:25] = self.obs['low_dim_obs'][21:25] + self.log.append(('goto', (x, y, yaw), fr[21:25].round(3), self.obs['t'])) + self.frame = fr + self.holding_active = False + yield from self.steps(20) + + def hold_base(self, ld): + """Keep the pelvis near the task frame; correct only when drift is large.""" + fr = self.frame + if self.nowalk: + self.stop_base() + return + dx, dy = fr[21] - ld[21], fr[22] - ld[22] + c, s = np.cos(ld[24]), np.sin(ld[24]) + bx, by = c * dx + s * dy, -s * dx + c * dy + ey = (fr[24] - ld[24] + np.pi) % (2 * np.pi) - np.pi + d = np.hypot(bx, by) + if not self.holding_active and (d > 0.08 or abs(ey) > 0.10): + self.holding_active = True + if self.holding_active and d < 0.03 and abs(ey) < 0.03: + self.holding_active = False + if not self.holding_active: + self.stop_base() + return + v = np.array([bx, by]) * 1.5 + sp = np.linalg.norm(v) + if d < 0.015: + v[:] = 0 + elif sp < 0.07: + v *= 0.07 / max(sp, 1e-6) + elif sp > 0.12: + v *= 0.12 / sp + self.base[0], self.base[1] = v + self.base[3] = np.clip(1.2 * ey, -0.3, 0.3) if abs(ey) > 0.02 else 0.0 + + def walker(self, tx, ty, tyaw, vmax=0.2, tol=0.03): + def w(ld): + x, y, yaw = ld[21], ld[22], ld[24] + dx, dy = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + bx, by = c * dx + s * dy, -s * dx + c * dy + ey = (tyaw - yaw + np.pi) % (2 * np.pi) - np.pi + v = np.array([bx, by]) * 1.5 + sp = np.linalg.norm(v) + if sp > vmax: + v *= vmax / sp + close = np.hypot(bx, by) < tol + if close: + v[:] = 0 + elif sp < 0.07: + v *= 0.07 / max(sp, 1e-6) + self.base[0], self.base[1] = v + self.base[3] = np.clip(1.5 * ey, -0.5, 0.5) if abs(ey) > 0.03 else 0.0 + if close and abs(ey) < 0.04: + self.base[0] = self.base[1] = self.base[3] = 0.0 + return True + return False + return w + + def stop_base(self): + self.base[0] = self.base[1] = self.base[3] = 0.0 + + # ---------------------------------------------------------------- vision + def foot(self, side, pick): + cam = 'left_wrist' if side == 'l' else 'right_wrist' + im = self.tools.image(cam) + f = vision.mug_obs(im, pick) + if f is None or f['us'] is None: + return None + return (f['us'], f['vs']) + + # ---------------------------------------------------------------- script + def holding(self, side): + ld = self.obs['low_dim_obs'] + fj = ld[10] if side == 'l' else ld[19] + return fj > P['hold_fj'] + + def center_base(self, side, cam, pick, u0, tol=6, search_vy=0.0): + """Side-step (base vy) until the tracked mug is centred in the wrist camera.""" + good = 0 + miss = 0 + self.frame = None + for it in range(40): + f = vision.mug_obs(self.tools.image(cam), pick, near=self.track) + if f is None: + miss += 1 + if miss >= 2: + self.track = None + self.stop_base() + if search_vy != 0.0 and miss >= 2: + self.base[1] = search_vy + self.log.append(('search', side, it, self.obs['low_dim_obs'][21:25].round(3))) + yield from self.steps(10) + continue + miss = 0 + self.track = f['cx'] + err = f['cx'] - u0 + self.log.append(('center', side, it, round(err, 1), self.obs['low_dim_obs'][21:25].round(3))) + if abs(err) < tol: + self.stop_base() + good += 1 + if good >= 2: + break + yield from self.steps(15) + continue + good = 0 + vy = -np.clip(0.004 * err, -0.15, 0.15) + vy = np.sign(vy) * max(abs(vy), 0.07) + ld = self.obs['low_dim_obs'] + ey = (self.face - ld[24] + np.pi) % (2 * np.pi) - np.pi + self.base[0] = 0.0 + self.base[1] = vy + self.base[3] = np.clip(1.5 * ey, -0.3, 0.3) if abs(ey) > 0.03 else 0.0 + yield from self.steps(10) + self.stop_base() + yield from self.steps(25) + fr = np.zeros(56) + fr[21:25] = self.obs['low_dim_obs'][21:25] + self.frame = fr + self.holding_active = False + + def grasp(self, side, pick, ys): + """Visual approach to the mug handle and close; returns via self.result.""" + A = self.arms[side] + gi = 19 if side == 'l' else 20 + self.base[gi] = 0.0 + cam = 'left_wrist' if side == 'l' else 'right_wrist' + u0 = P['ustar'] if side == 'l' else 84 - P['ustar'] + A.set((P['x0'], ys, P['zg'] + 0.07)) + yield from self.steps(20) + A.set((P['x0'], ys, P['zg'])) + yield from self.steps(20) + # side-step until the target mug is centred in this hand's wrist camera + self.track = None + if side == 'r': + yield from self.center_base(side, cam, pick, u0, search_vy=-0.08) + track = self.track + mode = 'front' + extra = 0.0 + for attempt in range(3): + est = [] + sin_psi = {'left': 1.0, 'right': -1.0}.get(mode, 0.0) + for it in range(50): + im = self.tools.image(cam) + f = vision.mug_obs(im, pick, near=track) + if f is not None: + track = f['cx'] + self.log.append(('servo', side, attempt, it, None if f is None else + (f['uc'], f['vb'], f['w'], f['us']), A.pb.copy())) + ok_lat = False + if f is not None and f['touch']: + # mug cut by the image border: shift sideways toward it + A.pb[1] += 0.008 if f['uc'] < 42 else -0.008 + A.pb[1] = float(np.clip(A.pb[1], ys - P['ylim'], ys + P['ylim'])) + ok_lat = True + elif f is not None and f['w'] >= 8: + if mode == 'front': + if f['us'] is not None: + sin_psi = float(np.clip((f['uc'] - f['us']) / (0.5 * f['w']), -0.4, 0.4)) + ub = f['uc'] - sin_psi * 0.94 * f['w'] + else: + e = vision.side_edges(im, pick, near=track) + ub = e[0] + 1.5 if mode == 'left' else e[1] - 1.5 + err = ub - u0 + ynew = A.pb[1] + np.clip(-P['kpx'] * err, -0.008, 0.008) + ynew = float(np.clip(ynew, ys - P['ylim'], ys + P['ylim'])) + at_lim = abs(ynew - A.pb[1]) < 1e-4 and abs(err) >= 4 + A.pb[1] = ynew + ok_lat = abs(err) < 4 or at_lim + if 22 <= f['vb'] <= 78: + est.append(A.pb[0] + P['va'] / (f['vb'] - P['vh'])) + if f['vb'] >= P['vstop'] and len(est) >= 2 and ok_lat: + break + if A.pb[0] >= P['xmax']: + break + if ok_lat or f is None: + A.pb[0] += 0.015 + yield from self.steps(9) + self.base[gi] = P['gpre'] + x0 = A.pb[0] + if est: + xf = float(np.median(est[-3:])) + cpsi = np.sqrt(1 - sin_psi ** 2) + xg = xf + P['mug_r'] - P['bar_r'] * cpsi - P['grip_off'] + extra + else: + xg = x0 + P['dx_blind'] + extra + xg = float(np.clip(xg, x0, P['xgmax'])) + self.log.append(('xg', side, attempt, round(xg, 3), round(sin_psi, 2), len(est))) + n = max(1, int(round((xg - x0) / 0.01))) + for i in range(1, n + 1): + A.pb[0] = x0 + (xg - x0) * i / n + yield from self.steps(6) + yield from self.steps(15) + self.base[gi] = 1.0 + yield from self.steps(35) + ok = self.holding(side) + self.log.append(('close', side, attempt, A.pb.copy(), ok)) + if ok: + yield from self.move(side, A.pb + (0, 0, 0.06), speed=0.05) + if self.holding(side): + self.result = True + return + # retry: open, back off, go deeper next time + self.base[gi] = 0.0 + yield from self.steps(15) + A.pb[2] = P['zg'] + A.pb[0] = x0 - 0.06 + yield from self.steps(40) + extra += 0.02 + self.result = False + + def script(self): + yield from self.steps(10) + yield from self.goto(*P['stand'], 0.0) + yield from self.grasp('l', 'left', P['ys_l']) + self.log.append(('grasp_l', self.result, self.obs['t'])) + yield from self.move('l', P['carry_l'], speed=0.15) + self.log.append(('carry_l', self.holding('l'), self.obs['t'])) + if P['do_right']: + # the remaining mug is to the right of the first one: put the right hand + # just right of where the left hand took the first mug + y1 = self.frame[22] + P['ys_l'] + yield from self.goto(self.frame[21], y1 + P['stand2_dy'], 0.0) + yield from self.grasp('r', 'big', P['ys_r']) + self.log.append(('grasp_r', self.result, self.obs['t'])) + yield from self.move('r', P['carry_r'], speed=0.15) + yield from self.goto(*P['dw'], n=300) + self.log.append(('turned', self.holding('l'), self.holding('r'), self.obs['t'])) + # squat and lean over the rack; re-anchor the task frame where the pelvis settles + self.frame = None + self.base[2] = P['place_h'] + self.base[4] = P['place_pitch'] + yield from self.steps(60) + fr = np.zeros(56) + fr[21:25] = self.obs['low_dim_obs'][21:25] + self.frame = fr + self.nowalk = True # never walk while squatting + self.log.append(('squat', fr[21:25].round(3), self.obs['t'])) + for side in ('l', 'r') if P['do_right'] else ('l',): + yield from self.place(side) + while True: + yield from self.steps(50) + + def place(self, side): + A = self.arms[side] + gi = 19 if side == 'l' else 20 + s = 1 if side == 'l' else -1 + yield from self.move(side, (P['place_x'], s * P['place_y'], P['place_zhi']), speed=0.08) + z = P['place_zhi'] + while z > P['place_zmin']: + z -= 0.01 + yield from self.move(side, (P['place_x'], s * P['place_y'], z), speed=0.04, settle=3) + tb = A.tool_body(self.obs['low_dim_obs']) + if tb[2] - z > 0.015: + break + self.log.append(('place', side, round(z, 3), self.obs['t'])) + self.base[gi] = 0.0 + yield from self.steps(25) + yield from self.move(side, A.pb + (0, 0, 0.10), speed=0.06) + yield from self.move(side, A.pb + (-0.10, 0, 0), speed=0.08) + + def act(self, obs, tools): + self.obs = obs + return next(self.gen) diff --git a/policies/dishwasher_load_cups/opus-s3/vision.py b/policies/dishwasher_load_cups/opus-s3/vision.py new file mode 100644 index 0000000000000000000000000000000000000000..9fc3072a7252cf3a4981e38edb1a1d5d50aa1195 --- /dev/null +++ b/policies/dishwasher_load_cups/opus-s3/vision.py @@ -0,0 +1,323 @@ +"""Colour segmentation helpers for the mug task (hand-written thresholds).""" +import numpy as np +import cv2 + + +def mug_mask(im): + im = im.astype(np.int16) + r, g, b = im[..., 0], im[..., 1], im[..., 2] + v = im.max(-1) + grey = (np.abs(r - b) < 14) & (np.abs(r - g) < 10) & (v > 70) & (v < 246) + m = grey.astype(np.uint8) + m = cv2.morphologyEx(m, cv2.MORPH_CLOSE, np.ones((3, 3), np.uint8)) + return m + + +def stick_mask(im): + im = im.astype(np.int16) + r, g, b = im[..., 0], im[..., 1], im[..., 2] + v = im.max(-1) + return ((r - b > 22) & (r - b < 90) & (v > 80) & (v < 180) & (r >= g)).astype(np.uint8) + + +def blobs(mask, min_area=20): + n, lab, stats, cent = cv2.connectedComponentsWithStats(mask, 8) + out = [] + for i in range(1, n): + x, y, w, h, a = stats[i] + if a >= min_area: + out.append(dict(label=i, x0=int(x), y0=int(y), x1=int(x + w - 1), y1=int(y + h - 1), area=int(a), + cx=float(cent[i][0]), cy=float(cent[i][1]), mask=(lab == i))) + return out + + +def sticks(im, min_area=3): + """Handle-shadow blobs: returns list with endpoints.""" + out = [] + for s in blobs(stick_mask(im), min_area): + if s['area'] > 150: + continue + ys, xs = np.where(s['mask']) + s['pts'] = np.stack([xs, ys], 1).astype(float) + out.append(s) + return out + + +def mug_blobs_all(im): + out = [] + for b in blobs(mug_mask(im), 60): + w = b['x1'] - b['x0'] + 1 + h = b['y1'] - b['y0'] + 1 + if b['y1'] >= 80 or w > 45 or b['area'] > 2500: + continue + if h < 0.8 * w and b['y0'] > 0: + continue + b['edge'] = b['x0'] == 0 or b['x1'] == 83 + out.append(b) + return out + + +def mug_blobs(im): + out = [] + for b in blobs(mug_mask(im), 60): + w = b['x1'] - b['x0'] + 1 + h = b['y1'] - b['y0'] + 1 + if b['y1'] >= 80: + continue # cabinet front / things at the bottom edge + if w > 45 or b['area'] > 2500: + continue + if h < 0.8 * w and b['y0'] > 0: + continue + b['edge'] = b['x0'] == 0 or b['x1'] == 83 + out.append(b) + full = [b for b in out if not b['edge']] + return full if full else out + + +def handle_foot(im, pick='left'): + """Image point of the far end of the handle shadow of the chosen mug (u, v) or None.""" + mugs = mug_blobs(im) + if not mugs: + return None + if pick == 'left': + mugs.sort(key=lambda b: b['cx']) + elif pick == 'right': + mugs.sort(key=lambda b: -b['cx']) + else: + mugs.sort(key=lambda b: abs(b['cx'] - 42)) + ss = sticks(im, 3) + for mb in mugs: + grown = cv2.dilate(mb['mask'].astype(np.uint8), np.ones((5, 5), np.uint8)) > 0 + mk = mb['mask'] + rows = np.where(mk.any(1))[0] + y1 = rows[-1] + hb = max(2, int(0.2 * (y1 - rows[0] + 1))) + cols = np.where(mk[y1 - hb + 1:y1 + 1].any(0))[0] + c = np.array([0.5 * (cols[0] + cols[-1]), float(y1)]) + best = None + for s in ss: + if not (grown & s['mask']).any(): + continue + if best is None or s['area'] > best['area']: + best = s + if best is None: + continue + d = np.linalg.norm(best['pts'] - c, axis=1) + p = best['pts'][int(np.argmax(d))] + return (float(p[0]), float(p[1]), c[0], c[1]) + return None + + +def mug_obs(im, pick='left', near=None): + """Body bottom-centre (uc, vb), body width w, handle-shadow start column us (or None). + + near: image column of the mug tracked so far; the blob closest to it is used. + """ + mugs = mug_blobs_all(im) if (near is not None or pick == 'big') else mug_blobs(im) + if not mugs: + return None + if near is not None: + mb = min(mugs, key=lambda b: abs(b['cx'] - near)) + if abs(mb['cx'] - near) > 25: + return None + elif pick == 'big': + mb = max(mugs, key=lambda b: b['area']) + elif pick == 'left': + mb = min(mugs, key=lambda b: b['cx']) + elif pick == 'right': + mb = max(mugs, key=lambda b: b['cx']) + else: + mb = min(mugs, key=lambda b: abs(b['cx'] - 42)) + mk = mb['mask'] + rows = np.where(mk.any(1))[0] + y0, y1 = rows[0], rows[-1] + hb = max(2, int(0.15 * (y1 - y0 + 1))) + cols = np.where(mk[y1 - hb + 1:y1 + 1].any(0))[0] + uc = 0.5 * (cols[0] + cols[-1]) + w = float(cols[-1] - cols[0] + 1) + # body bottom row at the centre column + cc = int(round(uc)) + colr = np.where(mk[:, cc])[0] + vb = float(colr[-1]) if len(colr) else float(y1) + grown = cv2.dilate(mk.astype(np.uint8), np.ones((5, 5), np.uint8)) > 0 + best = None + for s in sticks(im, 3): + if not (grown & s['mask']).any(): + continue + if best is None or s['area'] > best['area']: + best = s + us = vs = None + if best is not None: + d = np.abs(best['pts'][:, 0] - uc) + np.abs(best['pts'][:, 1] - vb) + near = best['pts'][d <= d.min() + 1.5] + us, vs = float(near[:, 0].mean()), float(near[:, 1].mean()) + if abs(us - uc) > 1.3 * max(w, 8) or abs(vs - vb) > 6: + us = vs = None + touch = mb['x0'] == 0 or mb['x1'] == 83 + # handle protruding past the body outline (sideways handle) + protL = protR = 0.0 + edgeL, edgeR = float(cols[0]), float(cols[-1]) + if y0 > 0 and y1 - y0 >= 10: + top = [np.where(mk[r])[0] for r in range(y0 + 1, y0 + 4)] + top = [c for c in top if len(c)] + if top: + xl = max(c[0] for c in top) + xr = min(c[-1] for c in top) + for r in range(y0 + 4, y1 + 1): + c = np.where(mk[r])[0] + if len(c): + if xl - c[0] > protL: + protL, edgeL = float(xl - c[0]), float(c[0]) + if c[-1] - xr > protR: + protR, edgeR = float(c[-1] - xr), float(c[-1]) + return dict(uc=uc, vb=vb, w=w, us=us, vs=vs, y0=int(y0), touch=touch, cx=float(mb['cx']), + protL=float(protL), protR=float(protR), edgeL=edgeL, edgeR=edgeR) + + +def side_edges(im, pick, near=None): + """Leftmost / rightmost silhouette column of the chosen mug above its bottom rows.""" + mugs = mug_blobs_all(im) if near is not None else mug_blobs(im) + if not mugs: + return None + if near is not None: + mb = min(mugs, key=lambda b: abs(b['cx'] - near)) + elif pick == 'left': + mb = min(mugs, key=lambda b: b['cx']) + elif pick == 'right': + mb = max(mugs, key=lambda b: b['cx']) + else: + mb = min(mugs, key=lambda b: abs(b['cx'] - 42)) + mk = mb['mask'] + rows = np.where(mk.any(1))[0] + y0, y1 = rows[0], rows[-1] + sub = mk[y0:max(y0 + 1, y1 - int(0.12 * (y1 - y0)))] + cols = np.where(sub.any(0))[0] + return float(cols[0]), float(cols[-1]) + + +def handle_bar(f): + """(column of the handle's outer bar, sin of handle direction; + = toward image left).""" + w = f['w'] + if f['protL'] >= 3 and f['protL'] >= f['protR'] + 2: + return f['edgeL'] + 1.5, float(np.clip((0.5 * w + f['protL']) / (0.94 * w), 0.4, 1.0)) + if f['protR'] >= 3 and f['protR'] >= f['protL'] + 2: + return f['edgeR'] - 1.5, -float(np.clip((0.5 * w + f['protR']) / (0.94 * w), 0.4, 1.0)) + s = 0.0 + if f['us'] is not None: + s = float(np.clip((f['uc'] - f['us']) / (0.5 * w), -0.4, 0.4)) + return f['uc'] - s * 0.94 * w, s + + +def mug_handle(im, pick='left', ratio=1.6): + """Mug body + handle estimate. + + Returns dict(uc, vb, w, uh, side, psi) where uh is the image column of the + handle's outer bar and psi the handle yaw relative to the camera (+ = handle + toward image right). + """ + mugs = mug_blobs(im) + if not mugs: + return None + if pick == 'left': + mb = min(mugs, key=lambda b: b['cx']) + elif pick == 'right': + mb = max(mugs, key=lambda b: b['cx']) + else: + mb = min(mugs, key=lambda b: abs(b['cx'] - 42)) + mk = mb['mask'].copy() + # fill enclosed highlights (handle shine) : holes inside the blob + filled = mk.astype(np.uint8).copy() + h, w_ = filled.shape + ff = np.zeros((h + 2, w_ + 2), np.uint8) + inv = (1 - filled).astype(np.uint8) + cv2.floodFill(inv, ff, (0, h - 1), 0) + holes = inv > 0 + full = mk | holes + rows = np.where(full.any(1))[0] + y0, y1 = int(rows[0]), int(rows[-1]) + H = y1 - y0 + 1 + L = np.array([np.where(full[r])[0][0] if full[r].any() else -1 for r in range(84)], float) + R = np.array([np.where(full[r])[0][-1] if full[r].any() else -1 for r in range(84)], float) + nb = max(2, int(0.12 * H)) + bot = list(range(y1 - nb + 1, y1 + 1)) + top = [r for r in range(y0, y0 + nb) if y0 > 0] + fitrows = bot + top + fr = np.array(fitrows, float) + if len(top) >= 2: + pl = np.polyfit(fr, L[fitrows], 1); pr = np.polyfit(fr, R[fitrows], 1) + else: + pl = np.array([0.0, np.median(L[bot])]); pr = np.array([0.0, np.median(R[bot])]) + mid = [r for r in range(y0 + nb, y1 - nb + 1)] + uc = 0.5 * (np.median(L[bot]) + np.median(R[bot])) + wb = float(np.median(R[bot]) - np.median(L[bot]) + 1) + cc = int(round(uc)) + colr = np.where(mk[:, cc])[0] + vb = float(colr[-1]) if len(colr) else float(y1) + protL = protR = 0.0 + rl = rr = None + for r in mid: + dl = np.polyval(pl, r) - L[r] + dr = R[r] - np.polyval(pr, r) + if dl > protL: + protL, rl = dl, r + if dr > protR: + protR, rr = dr, r + touchL = mb['x0'] == 0 + touchR = mb['x1'] == 83 + side = 0 + if protL > 2.5 and protL >= protR and not touchL: + side = -1 + uh = L[rl] + 1.0 + elif protR > 2.5 and not touchR: + side = 1 + uh = R[rr] - 1.0 + else: + hm = holes.copy() + hm[:y0 + nb] = False + hm[y1 - nb + 1:] = False + ys, xs = np.where(hm) + uh = float(xs.mean()) if len(xs) >= 2 else uc + s = (uh - uc) / (ratio * wb / 2) + psi = float(np.arcsin(np.clip(s, -1, 1))) + return dict(uc=float(uc), vb=vb, w=wb, uh=float(uh), side=side, psi=psi, + protL=float(protL), protR=float(protR), y0=y0, y1=y1, + touch=bool(touchL or touchR)) + + +def mug_features(im, pick='left'): + """Find mug blobs; return features of the chosen one (leftmost/rightmost/center).""" + m = mug_mask(im) + cands = [] + for b in blobs(m, 40): + w = b['x1'] - b['x0'] + 1 + if b['y1'] >= 82 and w > 50: + continue + cands.append(b) + if not cands: + return None + if pick == 'left': + b = min(cands, key=lambda b: b['cx']) + elif pick == 'right': + b = max(cands, key=lambda b: b['cx']) + else: + b = min(cands, key=lambda b: abs(b['cx'] - 42) + abs(b['cy'] - 42)) + mk = b['mask'] + rows = np.where(mk.any(1))[0] + y0, y1 = rows[0], rows[-1] + hb = max(2, int(0.2 * (y1 - y0 + 1))) + lo = mk[y1 - hb + 1:y1 + 1] + cols = np.where(lo.any(0))[0] + xl, xr = cols[0], cols[-1] + f = dict(x0=b['x0'], x1=b['x1'], y0=int(y0), y1=int(y1), xl=int(xl), xr=int(xr), + uc=0.5 * (xl + xr), w=float(xr - xl + 1), area=b['area'], cx=b['cx'], cy=b['cy']) + sm = stick_mask(im) + best = None + for s in blobs(sm, 2): + if s['y0'] >= y1 - 6 and s['y0'] <= y1 + 4 and s['x0'] >= b['x0'] - 4 and s['x1'] <= b['x1'] + 4 and s['area'] < 80: + if best is None or s['area'] > best['area']: + best = s + if best is not None: + top = best['mask'][best['y0']] + f['uh'] = float(np.mean(np.where(top)[0])) + f['vh'] = float(best['y0']) + return f diff --git a/policies/dishwasher_load_cutlery/astra-s1/episodes.csv b/policies/dishwasher_load_cutlery/astra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..1ce59ec860c568e82ab2ec8c66158bc3fec2c1f0 --- /dev/null +++ b/policies/dishwasher_load_cutlery/astra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2437,terminated,0 +620002,0,2312,terminated,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,1,1809,success,0 +620007,0,2650,timeout,0 +620008,0,188,terminated,0 +620009,0,1319,terminated,0 +620010,0,2650,timeout,0 +620011,0,1952,terminated,0 +620012,0,2448,terminated,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2378,terminated,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,1,2453,success,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2014,terminated,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,1949,terminated,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,1267,terminated,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,1367,terminated,0 +620037,0,2650,timeout,0 +620038,0,1382,terminated,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2327,terminated,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,1544,terminated,0 +620056,0,2448,terminated,0 +620057,0,2313,terminated,0 +620058,0,221,terminated,0 +620059,0,2650,timeout,0 +620060,0,2339,terminated,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2382,terminated,0 +620066,0,2650,timeout,0 +620067,0,1645,terminated,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,1733,terminated,0 +620072,0,186,terminated,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2312,terminated,0 +620076,0,2650,timeout,0 +620077,0,1491,terminated,0 +620078,1,1805,success,0 +620079,0,2310,terminated,0 +620080,1,1982,success,0 +620081,0,2378,terminated,0 +620082,0,2438,terminated,0 +620083,0,2353,terminated,0 +620084,0,1503,terminated,0 +620085,0,2650,timeout,0 +620086,0,1735,terminated,0 +620087,0,2650,timeout,0 +620088,0,2302,terminated,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,1,1801,success,0 +620093,0,1355,terminated,0 +620094,0,2650,timeout,0 +620095,0,1395,terminated,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/astra-s1/policy.py b/policies/dishwasher_load_cutlery/astra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..6f7c5c0dd48693c4a0ec2f714bc467b3d8494e11 --- /dev/null +++ b/policies/dishwasher_load_cutlery/astra-s1/policy.py @@ -0,0 +1,187 @@ +"""Deterministic, hand-written controller for loading cutlery. + +Only joint/base observations and the robot's wrist images are used. Classical +colour segmentation supplies lateral grasp and basket corrections. Timed grasp +phases include contact checks and retries; walking closes the loop on pelvis +position. All distances, gains, thresholds, and arm poses are fixed constants. +""" + +import numpy as np +import cv2 + +class Policy: + + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=float) + self.a[19:] = 0 + self.a[5] = self.a[12] = -0.6 + self.left_wide = False + self.stage = 'start' + self.k = 0 + self.retry = 0 + self.retry_left = 0 + self.queue = [] + self.drop_roll = 0.0 + + def goto(self, stage): + self.stage = stage + self.k = 0 + + def metal_x(self, im): + p = im.astype(float) + m = (p.max(2) - p.min(2) < 25) & (p.mean(2) > 45) & (p.mean(2) < 215) + m[:, :4] = 0 + m[:, 80:] = 0 + m[52:] = 0 + n, lab, stats, cents = cv2.connectedComponentsWithStats(m.astype(np.uint8)) + candidates = [] + for i in range(1, n): + x, y, w, h, area = stats[i] + if area < 7 or h < 7 or w > 48: + continue + yy, xx = np.where(lab == i) + cut = yy < min(42, y + max(10, h * 0.7)) + if cut.sum(): + candidates.append((h + area * 0.06 - w * 0.25, float(np.median(xx[cut])))) + return max(candidates)[1] if candidates else None + + def basket_x(self, im, edge=False): + p = im.astype(float) + m = ((p.max(2) - p.min(2) < 22) & (p.mean(2) < 75)).astype(np.uint8) + m[28:] = 0 + margin = 1 if edge else 7 + m[:, :margin] = 0 + m[:, 84 - margin:] = 0 + m = cv2.erode(m, np.ones((3, 3), np.uint8)) + n, lab, stats, c = cv2.connectedComponentsWithStats(m) + cand = [(stats[i, 4], c[i, 0]) for i in range(1, n) if stats[i, 4] > (6 if edge else 12) and stats[i, 2] > (2 if edge else 4)] + if cand: + return max(cand)[1] + if not edge: + return None + white = (p.min(2) > 175) & (p.max(2) - p.min(2) < 50) + left = white[:45, :12].mean() + right = white[:45, 72:].mean() + if left > right + 0.04: + return 4.0 + if right > left + 0.04: + return 79.0 + return None + + def drive(self, obs, target): + q = obs['low_dim_obs'] + e = np.asarray(target) - q[21:23] + v = np.clip(2 * e, -0.3, 0.3) + yaw = q[24] + if np.linalg.norm(v) < 0.06: + v *= 0 + self.a[0] = np.cos(yaw) * v[0] + np.sin(yaw) * v[1] + self.a[1] = -np.sin(yaw) * v[0] + np.cos(yaw) * v[1] + self.a[3] = np.clip(-2 * yaw, -0.4, 0.4) + + def stop(self): + self.a[0] = self.a[1] = self.a[3] = 0 + + def transport(self): + left_y = -0.3 if self.left_wide else -0.4 + self.queue = [(160, {}, (-0.55, -0.6)), (20, {}, None), (145, {}, (-0.55, -0.12)), (20, {}, None), (100, {}, (-0.22, -0.12)), (20, {}, None), (80, {2: 0.65, 4: 0.4, 12: -1.0, 15: 0.2, 13: -0.06, 17: 1.1}, None), (120, {}, 'right'), (85, {20: 0}, None), (60, {2: 0.74, 4: 0, 12: 0.3, 15: 1.3, 17: 0, 13: -0.4, 5: -1.2, 8: 0.25, 6: 0}, None), (90, {}, (-0.5, left_y)), (20, {}, None), (80, {}, (-0.22, left_y)), (20, {}, None), (80, {2: 0.65, 4: 0.4, 5: -1.0, 8: 0.2, 6: -0.05, 10: 1.1}, None), (120, {}, 'left'), (170, {19: 0}, None)] + self.goto('transport') + + def act(self, obs, tools): + a = self.a + q = obs['low_dim_obs'] + k = self.k + self.k += 1 + if self.stage == 'start': + a[0] = 0.3 + a[1] = -0.1 + if k >= 59: + self.stop() + self.goto('settle') + elif self.stage == 'settle': + if k >= 39: + a[5] = -0.75 + a[8] = 0.25 + a[19] = 1 + self.goto('left_close') + elif self.stage == 'left_close': + if k >= 39: + a[5] = -1.2 + self.goto('left_lift') + elif self.stage == 'left_lift': + if k >= 49: + if q[10] + q[11] < -0.0375 and self.retry_left < 2: + self.retry_left += 1 + a[19] = 0 + a[5] = -0.75 + a[8] = 0.25 + a[6] = [0, -0.08, 0.08][self.retry_left] + self.goto('left_retry') + else: + a[6] = 0.6 + self.goto('right_move') + elif self.stage == 'left_retry': + if k >= 35: + a[19] = 1 + self.goto('left_close') + elif self.stage == 'right_move': + self.drive(obs, (0.21, -0.53)) + if k >= 109: + self.stop() + self.goto('right_settle') + elif self.stage == 'right_settle': + if k >= 29: + a[12] = -0.8 + a[15] = 0.3 + a[13] = 0 + a[20] = 0 + self.goto('right_align') + elif self.stage == 'right_align': + if k >= 30 and k % 8 == 0: + x = self.metal_x(tools.image('right_wrist')) + if x is not None: + a[13] = np.clip(a[13] + np.clip((42 - x) * 0.0016, -0.02, 0.02), -0.45, 0.18) + if k >= 105: + a[20] = 1 + self.goto('right_close') + elif self.stage == 'right_close': + if k >= 34: + a[12] -= 0.45 + self.goto('right_lift') + elif self.stage == 'right_lift': + if k >= 44: + im = tools.image('right_wrist') + p = im.astype(float) + count = ((p.max(2) - p.min(2) < 25) & (p.mean(2) > 45) & (p.mean(2) < 215))[:20, 28:58].sum() + if (q[19] + q[20] > -0.0392 or count > 25) or self.retry >= 3 or obs['t'] > 1100: + self.left_wide = q[10] + q[11] > -0.03 + self.transport() + else: + self.retry += 1 + a[20] = 0 + a[12] = -0.8 + a[15] = [0.3, 0.4, 0.22, 0.48][self.retry] + self.goto('right_align') + elif self.stage == 'transport': + if not self.queue: + self.stop() + return a.copy() + duration, changes, target = self.queue[0] + if k == 0: + self.stop() + for i, v in changes.items(): + a[i] = v + if isinstance(target, tuple): + self.drive(obs, target) + elif target in ('left', 'right'): + if k % 10 == 0: + cam = target + '_wrist' + x = self.basket_x(tools.image(cam), target == 'left' and self.left_wide) + j = 6 if target == 'left' else 13 + if x is not None: + a[j] = np.clip(a[j] + np.clip((42 - x) * 0.003, -0.025, 0.025), -0.45, 0.5 if target == 'left' else 0.18) + if k >= duration - 1: + self.stop() + self.queue.pop(0) + self.k = 0 + return a.copy() diff --git a/policies/dishwasher_load_cutlery/astra-s2/episodes.csv b/policies/dishwasher_load_cutlery/astra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..5dc3094285e760a3bf98963a91a29c54ee754f3a --- /dev/null +++ b/policies/dishwasher_load_cutlery/astra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,326,terminated,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,330,terminated,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,332,terminated,0 +620064,0,321,terminated,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,1805,terminated,0 +620079,0,2650,timeout,0 +620080,0,326,terminated,0 +620081,0,334,terminated,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,330,terminated,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/astra-s2/policy.py b/policies/dishwasher_load_cutlery/astra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..ad362bf49354cb4789fad6b4f13f9e87aa30c346 --- /dev/null +++ b/policies/dishwasher_load_cutlery/astra-s2/policy.py @@ -0,0 +1,134 @@ +import numpy as np +import cv2 + +class Policy: + """Deterministic camera-guided pickup and sequential cutlery placement.""" + + def reset(self, obs, tools): + self.a=np.asarray(tools.hold_action(),float) + self.stage=0; self.age=0;self.start=self.a.copy();self.yaw_correction=0.; self.walk_done=None; self.base_target=np.array([.2,-.6]); self.rightcorr=0.;self.move_done=None + # Joint targets are hand tuned. Durations are control ticks at 50 Hz. + self.poses=[ + (45,{8:-1,15:-1,13:-.6,19:0,20:0}), + (50,{5:-.5,10:1}), + (200,{}), + (60,{4:.4,5:-.9,10:1}), + (65,{5:-1.4,8:.5,10:0,7:-.3,19:.3}), + (60,{5:-1.1,10:-.3}), + (50,{7:-.24}), + (60,{5:-1.3,8:.9,10:-.5,7:-.21}), + (60,{5:-1.5,8:1.3,10:-.7,7:-.25}), + (40,{19:1}), + (70,{5:-1.8,10:-.4}), + (70,{5:-2.1,10:-.1}), + (90,{6:.4,7:0}), + (60,{12:-.9,13:0,15:-1,17:1}), + (65,{12:-1.1,15:.5,17:-.3,14:.15,20:.3}), + (60,{12:-1.3,17:-.1,14:-.1}), + (70,{12:-1.55,15:1.3,17:-.65,14:-.12}), + (70,{4:.5,12:-1.7,15:1.6,17:-.8,14:-.22}), + (70,{12:-1.85,17:-.65,13:.02}), + (40,{20:1}), + (140,{12:-2.25,17:-.25}), + (100,{4:0,13:-.15,6:.6,7:0}), + (180,{}), + (240,{}), + (330,{}), + # Keep the other hand clear while inserting and releasing each tool. + (100,{2:.65,4:.4,5:-1.5,6:-.2,7:0,8:1.,10:-.65,13:-.4}), + (20,{19:0}), + (70,{5:-2.1,6:.5,8:1.3,10:-.1}), + (100,{12:-1.5,13:.2,14:0,15:1.,17:-.65}), + (20,{20:0}), + (70,{12:-2.1,13:-.4,15:1.3,17:-.1}), + ] + @staticmethod + def feature(im): + x=im.astype(float);m=(x.max(2)-x.min(2)<38)&(x[:,:,2]-x[:,:,0]<30)&(x.mean(2)>75)&(x.mean(2)<225) + m[:12]=False;m[63:]=False;m[:,:8]=False;m[:,76:]=False + n,lab,stats,cents=cv2.connectedComponentsWithStats(m.astype('uint8')) + candidates=[] + for i in range(1,n): + if stats[i,4]<12 or stats[i,3]<10:continue + yy,xx=np.where((lab==i)&(np.indices(m.shape)[0]>40)) + if len(xx)<3: yy,xx=np.where(lab==i) + cx=float(np.median(xx));candidates.append((abs(cx-42),cx)) + return min(candidates)[1] if candidates else None + @staticmethod + def steel(im): + # Exclude the broad mug body before measuring a narrow metal component. + x=im.astype(float) + mask=(x.max(2)-x.min(2)<42)&(x[:,:,2]-x[:,:,0]<32)&(x.mean(2)>65)&(x.mean(2)<238) + mask[:,:7]=False;mask[:,77:]=False + wide=[] + for y in range(84): + z=np.r_[False,mask[y],False].astype(int); edges=np.flatnonzero(np.diff(z)) + wide.append(max(edges[1::2]-edges[::2],default=0)) + cut=74 + for y in range(18,72): + if min(wide[y:y+3])>28:cut=y;break + mask[max(0,cut-2):]=False + n,lab,stats,cents=cv2.connectedComponentsWithStats(mask.astype('uint8')) + candidates=[] + for i in range(1,n): + if stats[i,4]<10 or stats[i,3]<10:continue + yy,xx=np.where(lab==i); bot=yy.max(); cx=float(np.median(xx[yy>=bot-9])) + candidates.append((abs(cx-42)+.2*(cut-bot),cx)) + return min(candidates)[1] if candidates else None + def act(self,obs,tools): + if self.stage>=len(self.poses):return self.a.copy() + duration,changes=self.poses[self.stage] + if self.age==0: + self.start=self.a.copy();self.move_done=None + for k,v in changes.items(): + f=min(1.,(self.age+1)/(80. if self.stage in (25,28) else 90. if self.stage in (20,21) else 50.)) if self.stage>=10 else 1. + self.a[k]=v if k in (19,20) else self.start[k]+f*(v-self.start[k]) + if self.stage==2: + q=obs['low_dim_obs'];ex=self.base_target[0]-q[21];ey=self.base_target[1]-q[22];yaw=q[24] + vel=np.clip(np.array([ex,ey])*2,-.18,.18) + if np.linalg.norm(vel)<.06 and np.linalg.norm([ex,ey])>.012:vel*=.06/max(.0001,np.linalg.norm(vel)) + if abs(ex)<.012 and abs(ey)<.02:vel[:]=0 + self.a[0]=np.cos(yaw)*vel[0]+np.sin(yaw)*vel[1];self.a[1]=-np.sin(yaw)*vel[0]+np.cos(yaw)*vel[1];self.a[3]=np.clip(-yaw*2,-.3,.3) + if self.age>60 and abs(ex)<.025 and self.walk_done is None:self.walk_done=self.age + if self.walk_done is not None: + self.a[0]=self.a[1]=0 + if self.age-self.walk_done>=40:self.age=duration + else:self.a[0]=self.a[1]=self.a[3]=0 + if self.stage in (22,23,24): + goals={22:(-.25,self.base_target[1],0),23:(-.25,-.55,1.57),24:(.22,-.35,1.57)} + if self.stage==24 and obs['low_dim_obs'][21]<.20:goals[24]=(.24,-.55,1.57) + q=obs['low_dim_obs'];target=np.array(goals[self.stage]);err=target-q[[21,22,24]];err[2]=(err[2]+np.pi)%(2*np.pi)-np.pi + vel=np.clip(err[:2]*2,-.22,.22) + if np.linalg.norm(vel)<.06 and np.linalg.norm(err[:2])>.015:vel*=.06/max(1e-5,np.linalg.norm(vel)) + if np.linalg.norm(err[:2])<.015:vel[:]=0 + yaw=q[24];self.a[0]=np.cos(yaw)*vel[0]+np.sin(yaw)*vel[1];self.a[1]=-np.sin(yaw)*vel[0]+np.cos(yaw)*vel[1];self.a[3]=np.clip(err[2]*2,-.6,.6) + if np.linalg.norm(err[:2])<.025 and abs(err[2])<.05 and self.move_done is None:self.move_done=self.age + if self.move_done is not None: + self.a[0]=self.a[1]=self.a[3]=0 + if self.age-self.move_done>=30:self.age=duration + if self.stage in (15,16) and self.age in (20,40): + f=self.steel(tools.image('right_wrist')) + if f is not None:self.rightcorr+=np.clip((42-f)*.003,-.055,.055) + if 15<=self.stage<=20:self.a[14]+=self.rightcorr + # Object alignment is corrected from the wrist image at the stationary approach. + if self.stage in (6,8) and self.age in (20,40): + f=self.feature(tools.image('left_wrist')) + if f is not None:self.yaw_correction+=np.clip((42-f)*.002,-.035,.035) + if 6<=self.stage<=11:self.a[7]+=self.yaw_correction + if self.stage==1 and self.age==49: + im=tools.image('left_wrist').astype(float) + mask=(im.max(2)-im.min(2)<40)&(im[:,:,2]-im[:,:,0]<30)&(im.mean(2)>60)&(im.mean(2)<220) + mask[:43]=False + n,l,st,c=cv2.connectedComponentsWithStats(mask.astype('uint8')) + if n>1: + k=1+np.argmax(st[1:,4]); yy,xx=np.where(l==k) + if len(xx)>40: + v=max(10.,float(yy.max())-40.); u=float(np.mean(xx)) + self.base_target=np.array([np.clip(.2+4./v-4./17.,.03,.26),np.clip(-.50936-.12*(u-42)/v,-.8,-.35)]) + out=self.a.copy() + # Do not accumulate the image correction into the nominal posture. + if 6<=self.stage<=11:self.a[7]-=self.yaw_correction + if 15<=self.stage<=20:self.a[14]-=self.rightcorr + self.age+=1 + if self.age>=duration:self.stage+=1;self.age=0 + return out diff --git a/policies/dishwasher_load_cutlery/astra-s3/episodes.csv b/policies/dishwasher_load_cutlery/astra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..0d147a166d5071b75ad3fbca7e7589acfb585524 --- /dev/null +++ b/policies/dishwasher_load_cutlery/astra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2056,terminated,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2238,terminated,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2144,terminated,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2220,terminated,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/astra-s3/policy.py b/policies/dishwasher_load_cutlery/astra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a7fae57e3e417ee4328593f230ad412d4d633b38 --- /dev/null +++ b/policies/dishwasher_load_cutlery/astra-s3/policy.py @@ -0,0 +1,92 @@ +"""Deterministic, hand-written cutlery transfer controller. + +The wrist camera supplies a geometric lateral alignment correction. Joint +poses and dwell times define approach, grasp retries, transport, and release. +No demonstration files, seed identifiers, or fitted models are used at runtime. +""" +import numpy as np +import cv2 + +def locate(im): + im=im.astype(float) + m=(im.max(2)-im.min(2)<18)&(im[:,:,0]>65)&(im[:,:,0]<190) + m[:,:3]=False;m[:,81:]=False + n,lab,stats,cent=cv2.connectedComponentsWithStats(m.astype('uint8')) + candidates=[i for i in range(1,n) if stats[i,4]>30 and stats[i,2]>3] + if not candidates:return None + k=max(candidates,key=lambda i:stats[i,4]);m=lab==k + widths=np.zeros(84);centers=np.zeros(84) + for y in range(84): + xs=np.where(m[y])[0] + if len(xs):widths[y]=xs[-1]-xs[0]+1;centers[y]=(xs[-1]+xs[0])/2 + w=np.percentile(widths[widths>0],85) + ys=np.where(widths>max(18,.7*w))[0] + rim=int(ys[0]) if len(ys) else 83 + y=min(45,rim-10);y=max(5,y) + xs=np.where(m[max(0,y-3):y+4])[1] + if len(xs)<3:xs=np.where(m[:max(10,rim-5)])[1] + if len(xs)<3:return None + return float(np.median(xs)),rim,float(w) + +class Policy: + def reset(self,obs,tools): + self.a=np.asarray(tools.hold_action(),dtype=float) + self.a[19:]=0 + self.stage='approach' + def act(self,obs,tools): + t=obs['t'];self.a[:2]=0;self.a[3]=0 + if t<80: + self.a[5:12]=[-.7,.3,0,.15,0,0,0];self.a[12:19]=[-.7,-.3,0,.15,0,0,0] + elif t<350: + self.a[5:12]=[-1.05,0,0,.6,0,0,0] + if obs["low_dim_obs"][21]<.10:self.a[0]=.18 + elif t<410:self.a[19]=1 + elif t<480:self.a[5]=-1.3 + elif t<550:self.a[6]=.4 + elif t<650:self.a[12:19]=[-1.15,0,0,.6,0,0,0] + elif t<650: + self.a[12:19]=[-1.15,0,0,.6,0,0,0] + elif t<950: + if t<800 and obs['low_dim_obs'][21]<.17:self.a[0]=.12 + if t%8==0: + z=locate(tools.image('right_wrist')) + if z is not None: + u,y,w=z + self.a[13]+=np.clip((42-u)*.0015,-.02,.02) + + else: + elapsed=t-950 + sequence=[ + (60,{20:1},[-1.15,.14,0,.6,0,0,0]), + (60,{4:.1},None), + (60,{4:.25},[-1.25,.1,0,.6,0,0,0]), + (70,{},[-1.15,.1,0,.6,0,0,0]), + (40,{20:0},[-1.25,.04,0,.6,0,0,0]), + (40,{20:1},None), + (40,{20:0},[-1.25,.1,0,.6,0,0,0]), + (40,{20:1},None), + (50,{20:0},[-1.45,.1,0,.85,0,0,0]), + (40,{20:1},None), + (40,{20:0},[-1.45,.065,0,.85,0,0,0]), + (40,{20:1},None), + (40,{20:0},[-1.35,.02,0,.85,0,0,0]), + (40,{20:1},None), + (60,{20:0,0:.1},None), + (50,{20:1,0:0},None), + (70,{},[-1.65,.02,0,.85,0,0,0]), + (190,{4:0,3:.45},[-1.3,-.05,0,.6,0,0,0]), + (40,{3:0},None), + (80,{0:.12},None), + (100,{0:0,2:.55,4:.2},[-.85,-.05,0,.6,0,0,0]), + (300,{19:0,20:0},None)] + age=elapsed + for i,(n,updates,right) in enumerate(sequence): + if age H, S, V int arrays.""" + hsv = cv2.cvtColor(np.ascontiguousarray(im, dtype=np.uint8), cv2.COLOR_RGB2HSV) + return ( + hsv[:, :, 0].astype(np.int32), + hsv[:, :, 1].astype(np.int32), + hsv[:, :, 2].astype(np.int32), + ) + + +def _target_features(im): + """Features used while looking for the mug and the cutlery inside it. + + The mug is a neutral grey object and the cutlery is dark metal, both on a + pale yellow counter. A blank/self-occluded wrist view is rejected through + the colourfulness and counter terms. + """ + H, S, V = _hsv(im) + dark = (V < 100) & (S < 140) + mug = (V >= 75) & (V <= 205) & (S <= 70) + colour = (S >= 80) & (V >= 60) + counter = (H >= 10) & (H <= 45) & (V >= 180) & (S >= 10) & (S <= 90) + + dw = (dark.astype(np.float32) * _CENTRE_W).sum() + mw = (mug.astype(np.float32) * _CENTRE_W).sum() + colour_n = float(colour.sum()) + counter_n = float(counter.sum()) + dark_raw = float(dark.sum()) + mug_raw = float(mug.sum()) + dark_central = float(dark[8:76, 24:60].sum()) + + flat = max(0.0, (dark_raw + mug_raw - 0.75 * 84.0 * 84.0) / (84.0 * 84.0)) + score = ( + 0.90 * min(colour_n, 1600.0) / 1600.0 + + 0.90 * min(dw, 1400.0) / 1400.0 + + 0.35 * min(mw, 1800.0) / 1800.0 + - 2.0 * flat + ) + + if dw > 1.0: + ys, xs = np.nonzero(dark.astype(np.float32) * _CENTRE_W) + dx = float(xs.mean()) + dy = float(ys.mean()) + score -= 0.25 * abs(dx - 42.0) / 42.0 + 0.20 * abs(dy - 45.0) / 45.0 + else: + dx, dy = 99.0, 99.0 + + trigger = ( + colour_n > 700.0 + and dark_raw > 1400.0 + and dark_central > 280.0 + and mw > 500.0 + and counter_n > 40.0 + and abs(dx - 42.0) < 16.0 + and abs(dy - 45.0) < 16.0 + ) + return score, trigger, dark_raw + + +def _basket_features(im): + """Features used while looking for the white wire cutlery basket.""" + H, S, V = _hsv(im) + bright = (V >= 145) & (V <= 248) & (S <= 60) + lap = np.abs(cv2.Laplacian(V.astype(np.float32), cv2.CV_32F)) + tex = bright & (lap > 30.0) + colour = (S >= 80) & (V >= 60) + blue = (H >= 90) & (H <= 130) & (S >= 70) & (V >= 40) + + tw = (tex.astype(np.float32) * _CENTRE_W).sum() + bw = (bright.astype(np.float32) * _CENTRE_W).sum() + colour_n = float(colour.sum()) + blue_n = float(blue.sum()) + + score = ( + 0.90 * min(tw, 700.0) / 700.0 + + 0.40 * min(bw, 1400.0) / 1400.0 + + 0.20 * min(colour_n, 1500.0) / 1500.0 + ) + if tw > 1.0: + ys, xs = np.nonzero(tex.astype(np.float32) * _CENTRE_W) + dx = float(xs.mean()) + dy = float(ys.mean()) + score -= 0.25 * abs(dx - 42.0) / 42.0 + 0.20 * abs(dy - 45.0) / 45.0 + else: + dx, dy = 99.0, 99.0 + + trigger = ( + tw > 550.0 + and bw > 650.0 + and colour_n > 400.0 + and blue_n > 120.0 + and abs(dx - 42.0) < 18.0 + and abs(dy - 45.0) < 20.0 + ) + return score, trigger, tw + + +def _wrap(a): + return (a + np.pi) % (2.0 * np.pi) - np.pi + + +# G1 arm joint bounds (a little conservative). Order matches the action: +# shoulder pitch, roll, yaw, elbow, wrist roll, wrist pitch, wrist yaw. +_ARM_LIMITS = np.array( + [ + (-2.50, 2.50), + (-1.50, 1.50), + (-2.50, 2.50), + (-1.00, 2.00), + (-1.90, 1.90), + (-1.50, 1.50), + (-1.50, 1.50), + ], + dtype=np.float32, +) + + +class Policy: + """Deterministic visual-servo policy.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32).reshape(21) + self.home = self.hold.copy() + self.home_L = self.hold[5:12].copy() + self.home_R = self.hold[12:19].copy() + + lo = np.asarray(obs["low_dim_obs"], dtype=np.float32) + self.start_x = float(lo[21]) + self.start_y = float(lo[22]) + self.start_yaw = float(lo[24]) + self.time_limit = int(obs.get("time_limit") or 1200) + + self.state = "approach" + self.phase_t = 0 + self.settle = 0 + + # search bookkeeping + self.seq = [] + self.seq_idx = 0 + self.seq_hold = 0 + self.tgt_L = self.home_L.copy() + self.tgt_R = self.home_R.copy() + self.best_L = self.home_L.copy() + self.best_R = self.home_R.copy() + self.best_score_L = -9.0 + self.best_score_R = -9.0 + self.frozen_L = False + self.frozen_R = False + self.final_L = self.home_L.copy() + self.final_R = self.home_R.copy() + self.trig_count_L = 0 + self.trig_count_R = 0 + self.grip_cmd = 0.0 + self.carry_frac = 0.0 + self.rate_L = 0.10 + self.rate_R = 0.10 + self.search_hold = 3 + + # target for the walk-to-counter phase + self.approach_d = 0.30 + self.approach_x = self.start_x + self.approach_d * np.cos(self.start_yaw) + self.approach_y = self.start_y + self.approach_d * np.sin(self.start_yaw) + + # target yaw for the dishwasher phase (dishwasher is to our left) + self.dish_yaw = _wrap(self.start_yaw + 1.25) + + # ------------------------------------------------------------------ + # helpers + # ------------------------------------------------------------------ + def _pose(self, obs): + lo = np.asarray(obs["low_dim_obs"], dtype=np.float32) + return float(lo[21]), float(lo[22]), float(lo[24]) + + def _arm_pos(self, obs, side): + lo = np.asarray(obs["low_dim_obs"], dtype=np.float32) + if side == "L": + return lo[3:10].copy() + return lo[12:19].copy() + + def _command_arm(self, obs, side): + """Move one arm command target toward its current desired target.""" + home = self.home_L if side == "L" else self.home_R + final = self.final_L if side == "L" else self.final_R + cur = self.tgt_L if side == "L" else self.tgt_R + if (side == "L" and self.frozen_L) or (side == "R" and self.frozen_R): + return cur.copy() + + if self.state in ("grasp_search", "place_search"): + if self.seq_idx < len(self.seq): + v = np.asarray(self.seq[self.seq_idx], dtype=np.float32) + desired = np.clip( + home + v, _ARM_LIMITS[:, 0], _ARM_LIMITS[:, 1] + ) + else: + desired = cur + elif self.state in ("grasp_close", "turn", "release"): + desired = home + self.carry_frac * (final - home) + else: + desired = cur + rate = self.rate_L if side == "L" else self.rate_R + diff = np.clip(desired - cur, -rate, rate) + return cur + diff + + def _advance_seq(self, obs): + """Advance the current sweep after the arms have settled on a target.""" + if self.seq_idx >= len(self.seq): + return + v = np.asarray(self.seq[self.seq_idx], dtype=np.float32) + dL = 0.0 + dR = 0.0 + if not self.frozen_L: + dL = np.max( + np.abs( + np.clip(self.home_L + v, _ARM_LIMITS[:, 0], _ARM_LIMITS[:, 1]) + - self.tgt_L + ) + ) + if not self.frozen_R: + dR = np.max( + np.abs( + np.clip(self.home_R + v, _ARM_LIMITS[:, 0], _ARM_LIMITS[:, 1]) + - self.tgt_R + ) + ) + if dL < 0.025 and dR < 0.025: + self.seq_hold += 1 + else: + self.seq_hold = 0 + if self.seq_hold >= self.search_hold: + self.seq_idx += 1 + self.seq_hold = 0 + + def _build_grasp_seq(self): + seq = [] + # Primary sweep: moderate shoulder pitch with elbow flex/extend. + for sp in (0.0, -0.45, 0.45): + for el in (0.0, 0.50, -0.50): + seq.append((sp, 0.0, 0.0, el, 0.0, 0.0, 0.0)) + # Lateral variants early, in case the mug is not exactly centred. + for sr in (-0.50, -0.25, 0.25, 0.50): + seq.append((-0.55, sr, 0.0, 0.25, 0.0, 0.0, 0.0)) + for sr in (-0.50, 0.50): + seq.append((0.55, sr, 0.0, 0.25, 0.0, 0.0, 0.0)) + # Wrist orientation variants. + for wp in (-0.80, -0.50, 0.50, 0.80): + seq.append((-0.55, 0.0, 0.0, 0.25, 0.0, wp, 0.0)) + for wr in (-0.80, -0.50, 0.50, 0.80): + seq.append((-0.55, 0.0, 0.0, 0.25, wr, 0.0, 0.0)) + for sy in (-0.40, 0.40): + seq.append((-0.55, 0.0, sy, 0.25, 0.0, 0.0, 0.0)) + # Larger extensions only if the smaller sweep has not found it. + for sp in (-0.90, 0.90, -1.25, 1.25, -1.50, 1.50): + seq.append((sp, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)) + for sp in (-0.60, 0.60): + for el in (0.80, -0.80): + seq.append((sp, 0.0, 0.0, el, 0.0, 0.0, 0.0)) + for sr in (-0.80, 0.80): + seq.append((-0.55, sr, 0.0, 0.25, 0.0, 0.0, 0.0)) + for sr in (-0.50, 0.50): + for wp in (-0.50, 0.50): + seq.append((-0.55, sr, 0.0, 0.25, 0.0, wp, 0.0)) + return seq + + def _build_place_seq(self): + seq = [] + for sp in (0.0, -0.45, 0.45): + for el in (0.0, 0.50, -0.50): + seq.append((sp, 0.0, 0.0, el, 0.0, 0.0, 0.0)) + for sr in (-0.50, -0.25, 0.25, 0.50): + seq.append((-0.55, sr, 0.0, 0.25, 0.0, 0.0, 0.0)) + for sr in (-0.50, 0.50): + seq.append((0.55, sr, 0.0, 0.25, 0.0, 0.0, 0.0)) + for sy in (-0.40, 0.40): + seq.append((-0.55, 0.0, sy, 0.25, 0.0, 0.0, 0.0)) + for wp in (-0.50, 0.50): + seq.append((-0.55, 0.0, 0.0, 0.25, 0.0, wp, 0.0)) + for sp in (-0.90, 0.90, -1.25, 1.25): + seq.append((sp, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)) + for sp in (-0.70, -0.35, 0.35, 0.70): + for el in (0.20, -0.20): + seq.append((sp, 0.0, 0.0, el, 0.0, 0.0, 0.0)) + return seq + + def _update_search(self, obs, tools, features, slow_thresh=500.0): + """Run one step of a wrist-camera sweep.""" + if self.seq_idx < len(self.seq): + self._advance_seq(obs) + + fL = features.get("L") + fR = features.get("R") + if fL is not None and not self.frozen_L: + score, trig, prox = fL + self.rate_L = 0.06 if prox > slow_thresh else 0.10 + if score > self.best_score_L: + self.best_score_L = score + self.best_L = self._arm_pos(obs, "L") + if trig: + self.trig_count_L += 1 + else: + self.trig_count_L = 0 + if self.trig_count_L >= 3: + self.frozen_L = True + self.final_L = self._arm_pos(obs, "L") + self.tgt_L = self.final_L.copy() + if fR is not None and not self.frozen_R: + score, trig, prox = fR + self.rate_R = 0.06 if prox > slow_thresh else 0.10 + if score > self.best_score_R: + self.best_score_R = score + self.best_R = self._arm_pos(obs, "R") + if trig: + self.trig_count_R += 1 + else: + self.trig_count_R = 0 + if self.trig_count_R >= 3: + self.frozen_R = True + self.final_R = self._arm_pos(obs, "R") + self.tgt_R = self.final_R.copy() + + def _finish_search(self, obs): + if not self.frozen_L: + self.final_L = self.best_L.copy() + if not self.frozen_R: + self.final_R = self.best_R.copy() + # If one wrist found a clearly better view than the other, give the + # weaker hand the same reach configuration instead of leaving it home. + if self.best_score_L >= 0.70 and ( + self.best_score_R < 0.70 or self.best_score_L - self.best_score_R > 0.60 + ): + self.final_R = np.clip( + self.home_R + (self.final_L - self.home_L), + _ARM_LIMITS[:, 0], + _ARM_LIMITS[:, 1], + ) + elif self.best_score_R >= 0.70 and ( + self.best_score_L < 0.70 or self.best_score_R - self.best_score_L > 0.60 + ): + self.final_L = np.clip( + self.home_L + (self.final_R - self.home_R), + _ARM_LIMITS[:, 0], + _ARM_LIMITS[:, 1], + ) + self.tgt_L = self.final_L.copy() + self.tgt_R = self.final_R.copy() + + def _base_action(self, obs, vx=0.0, vy=0.0, wz=0.0, height=0.74, pitch=0.0): + raw = self.hold.copy() + raw[0] = float(np.clip(vx, -0.5, 0.5)) + raw[1] = float(np.clip(vy, -0.4, 0.4)) + raw[2] = float(np.clip(height, 0.40, 1.0)) + raw[3] = float(np.clip(wz, -0.7, 0.7)) + raw[4] = float(np.clip(pitch, -0.2, 0.8)) + raw[5:12] = self.tgt_L + raw[12:19] = self.tgt_R + raw[19] = float(np.clip(self.grip_cmd, 0.0, 1.0)) + raw[20] = float(np.clip(self.grip_cmd, 0.0, 1.0)) + return raw + + # ------------------------------------------------------------------ + # main loop + # ------------------------------------------------------------------ + def act(self, obs, tools): + self.phase_t += 1 + t = int(obs.get("t", 0)) + state = self.state + + # ---------------------------------------------------------- approach + if state == "approach": + x, y, yaw = self._pose(obs) + ex = self.approach_x - x + ey = self.approach_y - y + err = float(np.hypot(ex, ey)) + + near_counter = False + if self.phase_t > 10: + im = tools.image("head", 84, 84) + H, S, V = _hsv(im) + counter_n = float( + ((H >= 10) & (H <= 45) & (V >= 180) & (S >= 10) & (S <= 90)).sum() + ) + blue_n = float( + ((H >= 90) & (H <= 130) & (S >= 70) & (V >= 40)).sum() + ) + near_counter = counter_n > 1250.0 and counter_n > 2.0 * blue_n + + # stop if the counter is clearly reached or we have walked long + if err > 0.02 and self.phase_t < 75 and not near_counter: + vx = float(np.clip(1.4 * err, 0.07, 0.28)) + # body-frame direction to the target + vx = vx * float(np.cos(yaw) * ex + np.sin(yaw) * ey) / max(err, 1e-6) + if 0.0 < abs(vx) < 0.06: + vx = 0.06 * (1.0 if vx > 0 else -1.0) + vy = float(np.clip(1.0 * (-np.sin(yaw) * ex + np.cos(yaw) * ey), -0.15, 0.15)) + wz = float(np.clip(1.2 * _wrap(self.start_yaw - yaw), -0.12, 0.12)) + return self._base_action(obs, vx, vy, wz, 0.74, 0.12) + self.settle += 1 + if self.settle >= 8: + self.state = "grasp_search" + self.phase_t = 0 + self.seq = self._build_grasp_seq() + return self._base_action(obs, 0.0, 0.0, 0.0, 0.74, 0.18) + + # ------------------------------------------------------ grasp search + if state == "grasp_search": + imL = tools.image("left_wrist", 84, 84) + imR = tools.image("right_wrist", 84, 84) + featL = _target_features(imL) + featR = _target_features(imR) + self._update_search(obs, tools, {"L": featL, "R": featR}, slow_thresh=500.0) + self.tgt_L = self._command_arm(obs, "L") + self.tgt_R = self._command_arm(obs, "R") + + deadline = self.time_limit - 430 + if (self.frozen_L and self.frozen_R) or self.seq_idx >= len(self.seq) or t > deadline: + self._finish_search(obs) + self.frozen_L = False + self.frozen_R = False + self.state = "grasp_close" + self.phase_t = 0 + self.settle = 0 + creep = 0.07 if self.phase_t < 25 else 0.0 + return self._base_action(obs, creep, 0.0, 0.0, 0.72, 0.28) + + # ------------------------------------------------------- grasp close + if state == "grasp_close": + self.rate_L = 0.10 + self.rate_R = 0.10 + self.carry_frac = 1.05 if self.phase_t <= 5 else 1.0 + self.tgt_L = self._command_arm(obs, "L") + self.tgt_R = self._command_arm(obs, "R") + self.grip_cmd = min(1.0, self.grip_cmd + 0.16) + if self.phase_t > 14: + self.carry_frac = 0.72 + if self.phase_t > 26: + self.carry_frac = 0.40 + if self.phase_t > 38: + self.state = "turn" + self.phase_t = 0 + self.settle = 0 + self.carry_frac = 0.40 + return self._base_action(obs, 0.0, 0.0, 0.0, 0.74, 0.20) + + # -------------------------------------------------------------- turn + if state == "turn": + self.rate_L = 0.10 + self.rate_R = 0.10 + x, y, yaw = self._pose(obs) + err = _wrap(self.dish_yaw - yaw) + self.tgt_L = self._command_arm(obs, "L") + self.tgt_R = self._command_arm(obs, "R") + + if self.phase_t <= 10: + self.carry_frac = 0.25 + return self._base_action(obs, -0.15, 0.0, 0.0, 0.74, 0.15) + + if abs(err) > 0.06 and self.phase_t < 230: + self.settle = 0 + wz = float(np.clip(1.8 * err, -0.65, 0.65)) + return self._base_action(obs, 0.0, 0.0, wz, 0.74, 0.12) + + # reached the dishwasher heading; take a small step, then squat + self.settle += 1 + if self.settle <= 35 and self.phase_t < 230: + return self._base_action(obs, 0.15, 0.0, 0.0, 0.74, 0.15) + + self.carry_frac = 0.0 + sq = min(1.0, max(0.0, (self.settle - 35) / 26.0)) + h = 0.74 - 0.18 * sq + p = 0.12 + 0.38 * sq + if self.settle > 35 + 36 or self.phase_t > 300: + self.state = "place_search" + self.phase_t = 0 + self.seq = self._build_place_seq() + self.tgt_L = self.home_L.copy() + self.tgt_R = self.home_R.copy() + self.seq_idx = 0 + self.seq_hold = 0 + self.best_score_L = -9.0 + self.best_score_R = -9.0 + self.frozen_L = False + self.frozen_R = False + self.trig_count_L = 0 + self.trig_count_R = 0 + self.place_wait = 0 + self.final_L = self.home_L.copy() + self.final_R = self.home_R.copy() + return self._base_action(obs, 0.0, 0.0, 0.0, h, p) + + # ------------------------------------------------------ place search + if state == "place_search": + imL = tools.image("left_wrist", 84, 84) + imR = tools.image("right_wrist", 84, 84) + featL = _basket_features(imL) + featR = _basket_features(imR) + self._update_search(obs, tools, {"L": featL, "R": featR}, slow_thresh=120.0) + self.tgt_L = self._command_arm(obs, "L") + self.tgt_R = self._command_arm(obs, "R") + + deadline = self.time_limit - 150 + both = self.frozen_L and self.frozen_R + one = self.frozen_L or self.frozen_R + if one and not both: + self.place_wait += 1 + if both or (one and (self.place_wait > 70 or t > deadline)): + # Freeze both hands where they are and pour the cutlery in. + self.final_L = self._arm_pos(obs, "L") + self.final_R = self._arm_pos(obs, "R") + self.tgt_L = self.final_L.copy() + self.tgt_R = self.final_R.copy() + self.frozen_L = False + self.frozen_R = False + self.state = "release" + self.phase_t = 0 + self.settle = 0 + elif (not one) and (self.seq_idx >= len(self.seq) or t > deadline): + self._finish_search(obs) + self.frozen_L = False + self.frozen_R = False + self.state = "release" + self.phase_t = 0 + self.settle = 0 + return self._base_action(obs, 0.0, 0.0, 0.0, 0.56, 0.50) + + # ------------------------------------------------------------ release + if state == "release": + # Dip a little further while still holding, then open the grippers + # and finally retract so the basket is not disturbed. + self.rate_L = 0.10 + self.rate_R = 0.10 + if self.phase_t <= 10: + self.carry_frac = 1.08 + elif self.phase_t <= 24: + self.carry_frac = 1.0 + else: + self.carry_frac = 0.35 + self.tgt_L = self._command_arm(obs, "L") + self.tgt_R = self._command_arm(obs, "R") + if self.phase_t > 10: + self.grip_cmd = max(0.0, self.grip_cmd - 0.18) + return self._base_action(obs, 0.0, 0.0, 0.0, 0.56, 0.50) + + # --------------------------------------------------------------- done + return self._base_action(obs, 0.0, 0.0, 0.0, 0.56, 0.35) diff --git a/policies/dishwasher_load_cutlery/deepseek1017-s2/episodes.csv b/policies/dishwasher_load_cutlery/deepseek1017-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a2beb126e68975e5c1aedaf4b27bdf0b9cf7febd --- /dev/null +++ b/policies/dishwasher_load_cutlery/deepseek1017-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/deepseek1017-s2/policy.py b/policies/dishwasher_load_cutlery/deepseek1017-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a7b471720741e71ea1be48f38d8383fbe91ee36c --- /dev/null +++ b/policies/dishwasher_load_cutlery/deepseek1017-s2/policy.py @@ -0,0 +1,822 @@ +"""Hand-written control policy: load the knife and fork from the mug on the +counter into the dishwasher cutlery basket. + +The robot is a Unitree G1 whose walking/balance is handled by a frozen +whole-body controller; this policy commands the base and both 7-DoF arms. + +Deterministic state machine, classical image processing only. There is no +learned model and no data lookup table. + +Strategy +-------- +The robot starts facing the dishwasher with both hands bent in front of it. +The mug stands on the counter in front of/above the hands; the cutlery basket +is part of the open dishwasher below the counter. + +The gross vertical reach is done with the pelvis height, a reliable, +joint-agnostic motion: the body is raised until the hands are at counter +height and is lowered later to the basket. The arms then only need to aim +and to extend. + +* Raise the pelvis, pitch forward a little, raise the arms in a wide sweep + and scan the wrists until the mug is seen. The sweep covers both signs of + the shoulder convention, so no joint-sign convention is assumed. +* Centre the mug in each wrist camera with a visual servo on the wrist + joints whose image effect is measured online. +* Measure which arm joint moves the gripper towards the mug (from the + growing apparent size of the mug) and extend along it until the mug fills + the view; close both grippers. +* Lift the pelvis and pull the arms back to free the cutlery, step back, + squat and swing the wrists down towards the dishwasher. +* Find the white wire basket on the blue floor, centre it, lower until it + fills the view and release. + +Neither wall-clock time nor random numbers are used. +""" + +import os + +import numpy as np +import cv2 + +_DEBUG = bool(os.environ.get("POLICY_DEBUG")) + +# -------------------------------------------------------------------------- +# tuning +# -------------------------------------------------------------------------- +H0 = 0.74 # nominal pelvis height at reset +H_WORK = 0.90 # tall stance while working at the counter +H_LIFT = 0.95 # extra lift used to free the cutlery +H_WALK = 0.76 # height for stepping back +H_SQUAT = 0.55 # squat height at the basket + +PITCH_WORK = 0.16 +PITCH_DOWN = 0.55 + +RAISE_SEARCH = 0.55 # shoulder sweep amplitude while hunting the mug +SWEEP_STEP = 0.025 +BACK_SPEED = -0.12 +BACK_STEPS = 46 + +VISION_PERIOD = 3 +TGX, TGY = 41.5, 47.0 + +MUG_MIN_AREA = 90 +MUG_MAX_AREA = 4700 +MUG_CLOSE_H = 54 +MUG_CLOSE_AREA = 2000 +BASKET_CLOSE = 0.26 # white fraction meaning the basket fills the view + +# maximum joint excursion from the pose reported at reset +DLIM = np.array([0.95, 0.70, 0.70, 0.55, 0.60, 0.85, 0.85], np.float32) + +SIDE_CAM = ("left_wrist", "right_wrist") + + +def _dbg(*a): + if _DEBUG: + print(*a, flush=True) + + +# -------------------------------------------------------------------------- +def _planes(img): + rgb = img.astype(np.int16) + v = rgb.max(axis=2) + s = v - rgb.min(axis=2) + return rgb, v, s, rgb[..., 2] - rgb[..., 0] + + +def find_mug(img): + """Locate the mug in a wrist image. Returns ``(cx, cy, w, h, area)``.""" + rgb, v, s, bmr = _planes(img) + mug = ((bmr < 18) & (v > 62) & (v < 188) & (s < 70)).astype(np.uint8) + if int(mug.sum()) < 40: + return None + bright = ((v > 200) & (s < 70)).astype(np.uint8) + mug = cv2.morphologyEx(mug, cv2.MORPH_CLOSE, np.ones((3, 3), np.uint8)) + n, lab, stats, cent = cv2.connectedComponentsWithStats(mug, 8) + best = None + best_score = 0.0 + for j in range(1, n): + x = int(stats[j, 0]); y = int(stats[j, 1]) + w = int(stats[j, 2]); h = int(stats[j, 3]) + a = int(stats[j, 4]) + if a < MUG_MIN_AREA or a > MUG_MAX_AREA: + continue + if w < 10 or h < 10 or w > 64 or h > 76: + continue + ar = w / max(1.0, float(h)) + if ar < 0.45 or ar > 2.2: + continue + vals = v[lab == j] + if vals.size == 0 or float(vals.mean()) > 168.0: + continue + x0, y0 = max(0, x - 4), max(0, y - 4) + x1, y1 = min(84, x + w + 4), min(84, y + h + 4) + rb = bright[y0:y1, x0:x1] + ring = np.ones_like(rb) + iy0, ix0 = max(0, y - y0), max(0, x - x0) + ring[iy0:iy0 + h, ix0:ix0 + w] = 0 + nring = int(ring.sum()) + if nring < 8: + continue + bf = float((rb * ring).sum()) / float(nring) + if bf < 0.15: + continue + score = float(a) * (0.25 + bf) + if score > best_score: + best_score = score + best = (float(cent[j][0]), float(cent[j][1]), w, h, a) + return best + + +def find_basket(img): + """Locate the white wire cutlery basket over the blue floor. + + The basket is seen from above against the blue tiled floor: a sizeable + white (wire) fraction together with a large blue fraction. A bright + counter top has a large white fraction but almost no blue, and an empty + blue floor has blue but no white, so both are rejected. + + Returns ``(cx, cy, white_frac, blue_frac)`` or ``None``. + """ + rgb, v, s, bmr = _planes(img) + white = ((v > 176) & (s < 55)) + blue = (bmr > 28) & (v < 205) + wf = float(white.mean()) + bf = float(blue.mean()) + if bf < 0.30 or wf < 0.20 or wf > 0.55: + return None + edges = cv2.Canny(img, 40, 110) + if float((edges > 0).mean()) < 0.05: + return None + ys, xs = np.nonzero(white) + if xs.size < 120: + return None + return (float(xs.mean()), float(ys.mean()), wf, bf) + + +# -------------------------------------------------------------------------- +class _Side: + """Per-arm image servo state.""" + + __slots__ = ("state", "wait", "ref", "mug", "miss", "sgn_yaw", "sgn_pitch", + "sgn_ext", "ext_joint", "ext_gain", "sgn_sh", "probe", + "probe_applied", "align_t", "close_hits", "seen", "scan_dir", + "idle_t", "min_ex", "min_ey", "flip_wait", "h_ref", "push_t") + + def __init__(self): + self.state = "idle" + self.wait = 0 + self.ref = None + self.mug = None + self.miss = 0 + self.sgn_yaw = 1.0 + self.sgn_pitch = 1.0 + self.sgn_ext = 1.0 + self.ext_joint = 3 + self.ext_gain = 0.0 + self.sgn_sh = 0.0 + self.probe = 0.0 + self.probe_applied = 0.0 + self.align_t = 0 + self.close_hits = 0 + self.seen = False + self.scan_dir = 1.0 + self.idle_t = 0 + self.min_ex = 999.0 + self.min_ey = 999.0 + self.flip_wait = 0 + self.h_ref = None + self.push_t = 0 + + def restart(self): + self.__init__() + + +class Policy: + # ------------------------------------------------------------------ + def reset(self, obs, tools): + self.tools = tools + # safe defaults in case the environment hands back something unusual + self.hold = np.zeros(21, np.float32) + self.hold[2] = H0 + self.action_dim = 21 + self.time_limit = 1500 + try: + self.action_dim = int(getattr(tools, "info", {}).get("action_dim", 21)) + except Exception: + self.action_dim = 21 + try: + hold = np.asarray(tools.hold_action(), dtype=np.float32).reshape(-1) + if hold.size >= 21 and np.all(np.isfinite(hold)): + self.hold = hold[:21].copy() + elif hold.size > 0 and np.all(np.isfinite(hold)): + self.hold[:hold.size] = hold[:21] + except Exception as exc: + _dbg("hold_action failed", repr(exc)) + self.hold[2] = float(np.clip(self.hold[2], 0.42, 0.98)) + self.arm0 = [self.hold[5:12].copy(), self.hold[12:19].copy()] + self.delta = [np.zeros(7, np.float32), np.zeros(7, np.float32)] + self.grip = [0.0, 0.0] + + self.t = 0 + self.phase = "boot" + self.phase_t = 0 + try: + self.time_limit = int(obs.get("time_limit") or 1500) + except Exception: + self.time_limit = 1500 + if self.time_limit < 200: + self.time_limit = 1500 + self.attempt = 0 + + self.height = float(np.clip(self.hold[2], 0.42, 0.98)) + self.pitch = 0.0 + self.vx = 0.0 + self.wz = 0.0 + self.sh_up = 0.0 + self._ld = None + self.yaw0 = 0.0 + try: + ld = obs.get("low_dim_obs") + if ld is not None: + self._ld = np.asarray(ld, dtype=np.float32).reshape(-1) + if self._ld.size > 24: + self.yaw0 = float(self._ld[24]) + except Exception: + self._ld = None + self.sides = [_Side(), _Side()] + self.vision_fail = 0 + self.basket_found = 0 + self.basket_wf = 0.0 + self.f_open = None + self.f_closed = None + self.grasp_retry = 0 + _dbg("reset time_limit", self.time_limit, "hold", np.round(self.hold, 3)) + + # ------------------------------------------------------------------ + def _raw(self): + raw = self.hold.copy() + raw[0] = float(self.vx) + raw[1] = 0.0 + raw[2] = float(np.clip(self.height, 0.42, 0.99)) + raw[3] = float(np.clip(self.wz, -0.35, 0.35)) + raw[4] = float(np.clip(self.pitch, -0.18, 0.78)) + for s in range(2): + d = np.clip(self.delta[s], -DLIM, DLIM) + raw[5 + 7 * s:12 + 7 * s] = self.arm0[s] + d + raw[19] = float(np.clip(self.grip[0], 0.0, 1.0)) + raw[20] = float(np.clip(self.grip[1], 0.0, 1.0)) + if not np.all(np.isfinite(raw)): + raw = self.hold.copy() + ad = getattr(self, "action_dim", 21) + if ad < 21: + raw = raw[:ad] + elif ad > 21: + raw = np.concatenate([raw, np.zeros(ad - 21, np.float32)]) + return raw + + def _go(self, phase): + _dbg("phase", self.phase, "->", phase, "t", self.t) + self.phase = phase + self.phase_t = 0 + + def _set_shoulder(self, v): + v = float(np.clip(v, -1.05, 1.05)) + self.delta[0][0] = v + self.delta[1][0] = v + + def _push_shoulder(self, dv): + self._set_shoulder(float(self.delta[0][0]) + dv) + + def _grip_cmd(self, target, rate): + for s in range(2): + if self.grip[s] < target: + self.grip[s] = min(target, self.grip[s] + rate) + else: + self.grip[s] = max(target, self.grip[s] - rate) + + def _grab(self, cam): + try: + return self.tools.image(cam, 84, 84) + except Exception as exc: + self.vision_fail += 1 + _dbg("image fail", cam, repr(exc)) + return None + + # ------------------------------------------------------------------ + # per-arm visual servo + # ------------------------------------------------------------------ + def _bump(self, s, j, dv): + d = self.delta[s] + old = float(d[j]) + new = float(np.clip(old + dv, -DLIM[j], DLIM[j])) + d[j] = new + return new - old + + def _probe_apply(self, s, j, dv): + sd = self.sides[s] + sd.probe = float(dv) + sd.probe_applied = self._bump(s, j, dv) + + def _probe_revert(self, s, j): + sd = self.sides[s] + self._bump(s, j, -sd.probe_applied) + sd.probe_applied = 0.0 + + def _servo_side(self, s, img): + sd = self.sides[s] + mug = find_mug(img) + sd.wait += 1 + + if mug is None: + sd.miss += 1 + if sd.state in ("cal_yaw", "cal_pitch", "cal_ext", "cal_ext2"): + if sd.wait >= 6: + j = {"cal_yaw": 6, "cal_pitch": 5, + "cal_ext": 3, "cal_ext2": 0}[sd.state] + self._probe_revert(s, j) + sd.state = "idle" + sd.idle_t = 0 + elif sd.state == "idle": + sd.idle_t += 1 + if sd.idle_t % 2 == 0: + if abs(self.delta[s][5]) > 0.50: + sd.scan_dir = -sd.scan_dir + self._bump(s, 5, 0.035 * sd.scan_dir) + if sd.idle_t > 110: + sd.state = "done" + elif sd.state == "center": + if sd.miss >= 14: + sd.state = "cal_ext" + sd.wait = 0 + sd.ref = sd.mug + self._probe_apply(s, 3, 0.11) + elif sd.state == "push": + if sd.miss >= 10: + sd.state = "done" + return + + sd.miss = 0 + sd.seen = True + cx, cy, w, h, a = mug + sd.mug = mug + + if sd.state == "idle": + sd.state = "cal_yaw" + sd.wait = 0 + sd.ref = mug + self._probe_apply(s, 6, 0.12) + return + + if sd.state == "cal_yaw": + if sd.wait < 4: + return + dcx = cx - sd.ref[0] + if abs(dcx) > 1.0: + sd.sgn_yaw = 1.0 if dcx * sd.probe > 0 else -1.0 + self._probe_revert(s, 6) + sd.state = "cal_pitch" + sd.wait = 0 + sd.ref = mug + self._probe_apply(s, 5, 0.12) + _dbg("yaw sign", s, sd.sgn_yaw, "dcx", dcx) + return + + if sd.state == "cal_pitch": + if sd.wait < 4: + return + dcy = cy - sd.ref[1] + if abs(dcy) > 1.0: + sd.sgn_pitch = 1.0 if dcy * sd.probe > 0 else -1.0 + self._probe_revert(s, 5) + sd.state = "center" + sd.wait = 0 + sd.align_t = 0 + sd.min_ex = 999.0 + sd.min_ey = 999.0 + sd.flip_wait = 0 + _dbg("pitch sign", s, sd.sgn_pitch, "dcy", dcy) + return + + if sd.state == "center": + ex = cx - TGX + ey = cy - TGY + ae = abs(ex) + be = abs(ey) + if ae < sd.min_ex: + sd.min_ex = ae + if be < sd.min_ey: + sd.min_ey = be + if sd.flip_wait > 0: + sd.flip_wait -= 1 + elif ae > sd.min_ex + 7.0: + sd.sgn_yaw = -sd.sgn_yaw + sd.min_ex = ae + sd.flip_wait = 6 + elif be > sd.min_ey + 7.0: + sd.sgn_pitch = -sd.sgn_pitch + sd.min_ey = be + sd.flip_wait = 6 + self._bump(s, 6, float(np.clip(-0.0030 * ex * sd.sgn_yaw, -0.05, 0.05))) + self._bump(s, 5, float(np.clip(-0.0030 * ey * sd.sgn_pitch, -0.05, 0.05))) + if abs(ex) < 9.0 and abs(ey) < 11.0: + sd.align_t += 1 + else: + sd.align_t = 0 + if (sd.align_t >= 2 or a >= MUG_CLOSE_AREA + or (h >= MUG_CLOSE_H and abs(ex) < 16 and abs(ey) < 22) + or sd.wait > 34): + sd.state = "cal_ext" + sd.wait = 0 + sd.ref = mug + self._probe_apply(s, 3, 0.11) + _dbg("aligned", s, "ex", ex, "ey", ey, "h", h) + return + + if sd.state == "cal_ext": + if sd.wait < 4: + return + dh = h - sd.ref[3] + sd.ext_gain = 0.0 + if abs(dh) > 1.0: + sd.sgn_ext = 1.0 if dh * sd.probe > 0 else -1.0 + sd.ext_joint = 3 + sd.ext_gain = abs(dh) + self._probe_revert(s, 3) + sd.state = "cal_ext2" + sd.wait = 0 + sd.ref = mug + self._probe_apply(s, 0, 0.11) + _dbg("ext elbow", s, sd.sgn_ext, "dh", dh) + return + + if sd.state == "cal_ext2": + if sd.wait < 4: + return + dh = h - sd.ref[3] + if abs(dh) > 1.0: + sgn = 1.0 if dh * sd.probe > 0 else -1.0 + if abs(dh) > sd.ext_gain: + sd.sgn_ext = sgn + sd.ext_joint = 0 + sd.sgn_sh = sgn + self._probe_revert(s, 0) + if sd.sgn_sh == 0.0: + sd.sgn_sh = sd.sgn_ext + sd.state = "push" + sd.wait = 0 + sd.h_ref = None + sd.push_t = 0 + _dbg("ext shoulder", s, "sgn_sh", sd.sgn_sh, "dh", dh, + "joint", sd.ext_joint) + return + + if sd.state == "push": + if sd.h_ref is None: + sd.h_ref = float(h) + sd.push_t = 0 + sd.push_t += 1 + if sd.push_t == 18 and h < sd.h_ref - 3.0: + # the measured approach direction did not make the mug larger + sd.sgn_ext = -sd.sgn_ext + sd.h_ref = float(h) + ex = cx - TGX + ey = cy - TGY + self._bump(s, 6, float(np.clip(-0.0028 * ex * sd.sgn_yaw, -0.04, 0.04))) + self._bump(s, 5, float(np.clip(-0.0028 * ey * sd.sgn_pitch, -0.04, 0.04))) + if sd.wait % 2 == 0: + self._bump(s, sd.ext_joint, 0.030 * sd.sgn_ext) + if h >= MUG_CLOSE_H or a >= MUG_CLOSE_AREA: + sd.close_hits += 1 + if sd.close_hits >= 2 or sd.wait > 65: + sd.state = "done" + return + + # ------------------------------------------------------------------ + def _run_vision(self): + for s, cam in enumerate(SIDE_CAM): + img = self._grab(cam) + if img is not None: + self._servo_side(s, img) + + def _detect_all(self): + for s, cam in enumerate(SIDE_CAM): + img = self._grab(cam) + if img is None: + continue + mug = find_mug(img) + if mug is not None: + self.sides[s].seen = True + self.sides[s].mug = mug + + def _scan_done(self): + return sum(1 for sd in self.sides if sd.state == "done") + + # ------------------------------------------------------------------ + def _head_yaw_servo(self, obs): + """Turn the base a little so the mug is centred in the head camera.""" + ld = obs.get("low_dim_obs") + if ld is not None: + self._ld = np.asarray(ld, dtype=np.float32).reshape(-1) + img = self._grab("head") + if img is None: + return + mug = find_mug(img) + if mug is None: + return + cx, cy, w, h, a = mug + if cy > 40.0 or a < 150 or cx < 16 or cx > 66: + return + yaw = (float(self._ld[24]) + if (self._ld is not None and self._ld.size > 24) else self.yaw0) + if abs(yaw - self.yaw0) > 0.15: + return + self.wz = float(np.clip(-0.007 * (cx - 42.0), -0.22, 0.22)) + + # ------------------------------------------------------------------ + def _grasp_ok(self): + """True unless both grippers clearly closed on nothing. + + The finger joint positions are compared with the fully-closed + reference measured at the start of the episode. A missing + calibration conservatively counts as a successful grasp. + """ + if (self.f_open is None or self.f_closed is None + or self._ld is None or self._ld.size < 21): + return True + for s, sl in ((0, slice(10, 12)), (1, slice(19, 21))): + f = float(self._ld[sl].mean()) + span = self.f_open[s] - self.f_closed[s] + if abs(span) < 1e-3: + return True + frac = (f - self.f_closed[s]) / span + if frac > 0.07: + return True + return False + + # ------------------------------------------------------------------ + def act(self, obs, tools): + """Return the 21-float action; never let an internal error escape.""" + try: + return self._act(obs, tools) + except Exception as exc: # pragma: no cover - defensive + _dbg("act exception", repr(exc)) + self.err_count = getattr(self, "err_count", 0) + 1 + raw = self.hold.copy() + raw[0] = 0.0 + raw[1] = 0.0 + raw[2] = float(np.clip(getattr(self, "height", H0), 0.55, 0.90)) + raw[3] = 0.0 + raw[4] = 0.0 + for s in range(2): + d = np.clip(self.delta[s], -DLIM, DLIM) + raw[5 + 7 * s:12 + 7 * s] = self.arm0[s] + d + raw[19] = 0.0 + raw[20] = 0.0 + ad = getattr(self, "action_dim", 21) + if ad < 21: + raw = raw[:ad] + elif ad > 21: + raw = np.concatenate([raw, np.zeros(ad - 21, np.float32)]) + return raw + + # ------------------------------------------------------------------ + def _act(self, obs, tools): + self.t += 1 + self.phase_t += 1 + self.vx = 0.0 + self.wz = 0.0 + ld = obs.get("low_dim_obs") + if ld is not None: + self._ld = np.asarray(ld, dtype=np.float32).reshape(-1) + if self.t % 6 == 0 and self.phase in ("search", "sweepA", "sweepB", + "sweepC"): + self._head_yaw_servo(obs) + + if self.phase == "boot": + self.pitch = min(PITCH_WORK, self.pitch + 0.008) + # measure the fully-open and fully-closed finger positions so a + # later empty grasp can be detected + if self.phase_t == 1 and self._ld is not None and self._ld.size >= 21: + self.f_open = [float(self._ld[10:12].mean()), + float(self._ld[19:21].mean())] + if self.phase_t <= 14: + self.grip = [1.0, 1.0] + elif self.phase_t == 15: + if self._ld is not None and self._ld.size >= 21: + self.f_closed = [float(self._ld[10:12].mean()), + float(self._ld[19:21].mean())] + self.grip = [0.0, 0.0] + if self.phase_t >= 30: + self._go("rise") + + elif self.phase == "rise": + dh = H_WORK - self.height + if abs(dh) > 0.005: + self.height += float(np.clip(dh, -0.006, 0.009)) + self.pitch = min(PITCH_WORK, self.pitch + 0.004) + if abs(H_WORK - self.height) <= 0.005 or self.phase_t > 85: + self._go("search") + + elif self.phase == "search": + scan = 0.55 * np.sin(self.phase_t * 0.060) + self.delta[0][5] = scan + self.delta[1][5] = scan + if self.t % VISION_PERIOD == 0: + self._detect_all() + n = sum(1 for sd in self.sides if sd.seen) + if n >= 1 and self.phase_t > 25: + self._go("work") + elif self.phase_t > 65: + self._go("sweepA") + + elif self.phase == "sweepA": + self._push_shoulder(SWEEP_STEP) + scan = 0.55 * np.sin(self.phase_t * 0.075) + self.delta[0][5] = scan + self.delta[1][5] = scan + if self.t % VISION_PERIOD == 0: + self._detect_all() + n = sum(1 for sd in self.sides if sd.seen) + if n >= 1: + self.sh_up = 1.0 + self._go("work") + elif self.delta[0][0] >= RAISE_SEARCH - 1e-6 or self.phase_t > 30: + self._go("sweepB") + + elif self.phase == "sweepB": + self._push_shoulder(-SWEEP_STEP) + scan = 0.55 * np.sin(self.phase_t * 0.055) + self.delta[0][5] = scan + self.delta[1][5] = scan + if self.t % VISION_PERIOD == 0: + self._detect_all() + n = sum(1 for sd in self.sides if sd.seen) + if n >= 1: + self.sh_up = -1.0 + self._go("work") + elif self.delta[0][0] <= -RAISE_SEARCH + 1e-6 or self.phase_t > 55: + self._go("sweepC") + + elif self.phase == "sweepC": + self._push_shoulder(SWEEP_STEP) + scan = 0.40 * np.sin(self.phase_t * 0.080) + self.delta[0][5] = scan + self.delta[1][5] = scan + if self.t % VISION_PERIOD == 0: + self._detect_all() + n = sum(1 for sd in self.sides if sd.seen) + if n >= 1 or self.phase_t > 30: + self._go("work") + + elif self.phase == "work": + if self.t % VISION_PERIOD == 0: + self._run_vision() + done = self._scan_done() + if done >= 1 and self.phase_t > 40: + self._go("grasp") + elif self.phase_t > (120 if self.grasp_retry else 200): + self._go("grasp") + + elif self.phase == "grasp": + self._grip_cmd(1.0, 0.10) + if self.phase_t >= 15: + if (self.grasp_retry < 1 and not self._grasp_ok()): + self.grasp_retry = 1 + self._go("regrasp") + else: + self._go("lift") + + elif self.phase == "regrasp": + self._grip_cmd(0.0, 0.15) + if self.phase_t >= 14: + for sd in self.sides: + if sd.state == "done": + sd.state = "center" + sd.wait = 0 + sd.align_t = 0 + sd.close_hits = 0 + sd.min_ex = 999.0 + sd.min_ey = 999.0 + sd.flip_wait = 0 + sd.h_ref = None + self._go("work") + + elif self.phase == "lift": + self._grip_cmd(1.0, 0.05) + self.height = min(H_LIFT, self.height + 0.0032) + if self.phase_t > 16: + for s in range(2): + self._bump(s, self.sides[s].ext_joint, + -0.013 * self.sides[s].sgn_ext) + if self.phase_t > 55: + self._go("unrise") + + elif self.phase == "unrise": + self._grip_cmd(1.0, 0.05) + self.height = max(H_WALK, self.height - 0.0045) + if self.height <= H_WALK + 1e-6 or self.phase_t > 50: + self._go("walkback") + + elif self.phase == "walkback": + self._grip_cmd(1.0, 0.05) + self.height = H_WALK + self.vx = BACK_SPEED + if self.phase_t >= BACK_STEPS: + self.vx = 0.0 + self._go("squat") + + elif self.phase == "squat": + self._grip_cmd(1.0, 0.05) + self.height = max(H_SQUAT, self.height - 0.005) + self.pitch = min(PITCH_DOWN, self.pitch + 0.008) + for s in range(2): + sd = self.sides[s] + if sd.sgn_sh != 0.0: + self._bump(s, 0, -0.0045 * sd.sgn_sh) + if sd.ext_joint == 3: + self._bump(s, 3, -0.0040 * sd.sgn_ext) + self._bump(s, 5, -0.0080 * sd.sgn_pitch) + if self.phase_t > 80: + self._go("basket") + + elif self.phase == "basket": + if self.phase_t == 1: + self.basket_found = 0 + self.basket_wf = 0.0 + if self.t % VISION_PERIOD == 0: + for s, cam in enumerate(SIDE_CAM): + img = self._grab(cam) + if img is None: + continue + bk = find_basket(img) + if bk is None: + continue + cx, cy, wf, bf = bk + self.basket_found += 1 + self.basket_wf = max(self.basket_wf, wf) + sd = self.sides[s] + self._bump(s, 6, float(np.clip( + -0.0045 * (cx - TGX) * sd.sgn_yaw, -0.05, 0.05))) + self._bump(s, 5, float(np.clip( + -0.0045 * (cy - TGY) * sd.sgn_pitch, -0.05, 0.05))) + if self.basket_found and self.basket_wf < BASKET_CLOSE: + self.height = max(0.50, self.height - 0.0025) + if (self.basket_found >= 6 and self.basket_wf >= BASKET_CLOSE) \ + or self.phase_t > 55: + self._go("release") + + elif self.phase == "release": + self._grip_cmd(0.0, 0.12) + if self.phase_t >= 22: + if (self.attempt == 0 and self.time_limit >= 1700 + and self.t < 0.50 * self.time_limit): + self.attempt = 1 + self._go("return") + else: + self._go("done") + + elif self.phase == "return": + # stand back up from the squat, then walk back to the counter + self._grip_cmd(0.0, 0.08) + self.pitch = max(PITCH_WORK, self.pitch - 0.010) + self.height = min(H_WALK, self.height + 0.008) + if self.height >= H_WALK - 1e-6 and self.phase_t > 25: + self._go("return_walk") + + elif self.phase == "return_walk": + self._grip_cmd(0.0, 0.08) + self.height = H_WALK + self.pitch = max(PITCH_WORK, self.pitch - 0.008) + if self.phase_t > 8: + self.vx = -BACK_SPEED + if self.phase_t >= BACK_STEPS + 8: + self.vx = 0.0 + self._go("return_rise") + + elif self.phase == "return_rise": + self._grip_cmd(0.0, 0.08) + # a slightly different viewpoint for the second attempt + target_h = H_WORK - (0.04 if self.attempt > 0 else 0.0) + target_p = PITCH_WORK + (0.05 if self.attempt > 0 else 0.0) + self.pitch = min(target_p, self.pitch + 0.005) + if abs(target_h - self.height) > 0.005: + self.height += float(np.clip(target_h - self.height, -0.007, 0.009)) + if self.phase_t == 1: + for sd in self.sides: + sd.restart() + if self.sh_up != 0.0: + self._set_shoulder(0.35 * self.sh_up) + if abs(target_h - self.height) <= 0.005 and self.phase_t > 25: + self._go("search") + + elif self.phase == "done": + self._grip_cmd(0.0, 0.05) + self.height = max(H_WALK, self.height - 0.002) + self.pitch = max(0.0, self.pitch - 0.004) + + if self.t > self.time_limit - 8: + self.vx = 0.0 + return self._raw() diff --git a/policies/dishwasher_load_cutlery/deepseek1017-s3/episodes.csv b/policies/dishwasher_load_cutlery/deepseek1017-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a2beb126e68975e5c1aedaf4b27bdf0b9cf7febd --- /dev/null +++ b/policies/dishwasher_load_cutlery/deepseek1017-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/deepseek1017-s3/policy.py b/policies/dishwasher_load_cutlery/deepseek1017-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..254c5b51594b22f8c24d5c8d6810a322687d3fb8 --- /dev/null +++ b/policies/dishwasher_load_cutlery/deepseek1017-s3/policy.py @@ -0,0 +1,355 @@ +"""Hand-written control policy for the G1 cutlery-loading task. + +Task: move the knife and fork from the mug on the counter into the +dishwasher's cutlery basket. + +Only the robot's own cameras and the low-dimensional body state are used. +The controller is a small state machine: + + LOOK settle; squeeze the empty grippers once to learn their travel + REACH raise both hands in front of the chest + ALIGN servo the base so the head camera sees the mug exactly as in the + demonstration grasp pose (image position + apparent size) + LOWER drop the upper body into the mug + CLOSE close the grippers + CHECK did the fingers stop early (something between them)? + RETRY if not: change the reach guess and dip again (several tries) + LIFT raise the body again + TRANSFER squat / lean forward, bring the hands down to the basket + RELEASE open the grippers inside the basket + +Every number here is hand-set; there are no learned components. +""" + +import numpy as np +import cv2 + + +# -------------------------------------------------------------------------- +# image-space targets taken from the demonstration +# -------------------------------------------------------------------------- +MUG_TARGET_U = 45.0 # horizontal image position of the mug when grasping +MUG_TARGET_W = 19.0 # mug width (px) at the demonstration grasp pose +MUG_MIN_AREA = 28 + +# -------------------------------------------------------------------------- +# arm poses (shoulder_pitch, shoulder_roll, shoulder_yaw, elbow, +# wrist_roll, wrist_pitch, wrist_yaw) in radians +# -------------------------------------------------------------------------- +PRE_ELBOW = 0.15 +PRE_WRIST = 0.60 # flex the wrist so the fingers point into the mug +ROLL_ADDUCT = 0.28 # lateral (adduction) guess on the shoulder roll +# The sign conventions of the left/right shoulder roll axes are not known from +# the documentation, so the four possible sign combinations are attempted in +# turn. In every combination at least one hand ends up towards the centre. +# entries: (shoulder_pitch, left_roll_sign, right_roll_sign, body_dip) +ATTEMPTS = ( + (-1.45, +1.0, -1.0, 0.10), + (-1.45, -1.0, +1.0, 0.10), + (-1.45, +1.0, +1.0, 0.10), + (-1.45, -1.0, -1.0, 0.10), + (-1.55, +1.0, -1.0, 0.16), + (-1.30, +1.0, -1.0, 0.04), +) +DOWN_L = np.array([-1.18, 0.00, -0.08, 0.12, 0.00, 0.18, 0.00], np.float32) +DOWN_R = np.array([-1.18, 0.00, 0.08, 0.12, 0.00, 0.18, 0.00], np.float32) + +ARM_RATE = 0.08 # max joint change per step (rad) +GRASP_PITCH_OFF = 0.15 # torso pitch added to the reset value when grasping +PLACE_PITCH_OFF = 0.60 # torso pitch added to the reset value when placing +PLACE_HEIGHT_OFF = 0.26 # pelvis height drop when placing (m) +LIFT_HEIGHT_OFF = 0.04 # pelvis height rise while lifting (m) + + +def _clip(v, lo, hi): + return float(min(hi, max(lo, v))) + + +def _blobs(mask, min_area=20): + n, lab, stats, cents = cv2.connectedComponentsWithStats( + mask.astype(np.uint8), connectivity=8) + out = [] + for i in range(1, n): + x, y, w, h, area = stats[i] + if area < min_area: + continue + out.append({ + "x": int(x), "y": int(y), "w": int(w), "h": int(h), + "area": int(area), "cx": float(cents[i][0]), "cy": float(cents[i][1]), + }) + return out + + +def _mug_mask(im): + f = im.astype(np.float32) + r, g, b = f[..., 0], f[..., 1], f[..., 2] + v = f.mean(-1) + mx = f.max(-1) + mn = f.min(-1) + return (((mx - mn) < 22.0) & (v > 92.0) & (v < 172.0) + & (np.abs(r - b) < 16.0)) + + +def _cream_mask(im): + f = im.astype(np.float32) + r, g, b = f[..., 0], f[..., 1], f[..., 2] + return (r > 170.0) & (g > 160.0) & ((r - b) > 16.0) + + +def _toward(current, target, rate=ARM_RATE): + d = np.clip(np.asarray(target, np.float32) - current, -rate, rate) + return (current + d).astype(np.float32) + + +def _ramp(a, b, t, n): + s = min(1.0, max(0.0, t / float(max(1, n)))) + return float(a) + (float(b) - float(a)) * s + + +class Policy: + """State-machine policy for loading cutlery into the dishwasher basket.""" + + def __init__(self): + self.hold = None + self.step = 0 + self.phase = "look" + self.phase_t = 0 + self.mug = None + self.arm_l = None + self.arm_r = None + self.grip_l = 0.0 + self.grip_r = 0.0 + self.f_open_l = self.f_open_r = 0.0 + self.f_closed_l = self.f_closed_r = 0.0 + self.have_travel = False + self.grasp_l = False + self.grasp_r = False + self.attempt = 0 + + # -- helpers ----------------------------------------------------------- + @staticmethod + def _state(obs): + return np.asarray(obs["low_dim_obs"], dtype=np.float32) + + def _fingers(self, ld): + return float(ld[10:12].mean()), float(ld[19:21].mean()) + + def _find_mug(self, im): + cands = [] + cream = _cream_mask(im) + for bl in _blobs(_mug_mask(im), MUG_MIN_AREA): + x, y, w, h = bl["x"], bl["y"], bl["w"], bl["h"] + if h < 5 or w < 5 or y > 50 or w > 40: + continue + # the hands come in from the image borders, the mug does not + if x <= 1 or x + w >= im.shape[1] - 1: + continue + if h < 0.6 * w or h > 1.8 * w: + continue + x0, y0 = max(0, x - 4), max(0, y - 4) + x1, y1 = min(im.shape[1], x + w + 4), min(im.shape[0], y + h + 4) + surround = float(cream[y0:y1, x0:x1].mean()) + if surround < 0.12: + continue + cands.append((bl["area"] * (0.5 + surround), bl)) + if not cands: + return None + cands.sort(key=lambda t: -t[0]) + return cands[0][1] + + def _pre_poses(self): + pitch, sl, sr, _ = ATTEMPTS[min(self.attempt, len(ATTEMPTS) - 1)] + pl = np.array([pitch, ROLL_ADDUCT * sl, 0.00, PRE_ELBOW, 0.00, + PRE_WRIST, 0.00], np.float32) + pr = np.array([pitch, ROLL_ADDUCT * sr, 0.00, PRE_ELBOW, 0.00, + PRE_WRIST, 0.00], np.float32) + return pl, pr + + def _dip(self): + return ATTEMPTS[min(self.attempt, len(ATTEMPTS) - 1)][3] + + def _action(self, vx=0.0, vy=0.0, wz=0.0, height=None, pitch=None): + a = self.hold.copy() + a[0] = vx + a[1] = vy + a[2] = self.h_view if height is None else height + a[3] = wz + a[4] = self.p_view if pitch is None else pitch + a[5:12] = self.arm_l + a[12:19] = self.arm_r + a[19] = self.grip_l + a[20] = self.grip_r + return a + + def _goto(self, name): + self.phase = name + self.phase_t = 0 + + # -- episode ----------------------------------------------------------- + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + ld = self._state(obs) + self.arm_l = np.array(ld[3:10], dtype=np.float32) + self.arm_r = np.array(ld[12:19], dtype=np.float32) + # use the episode's own reset stance as the baseline + self.h_view = _clip(float(self.hold[2]), 0.4, 1.0) + self.p_view = _clip(float(self.hold[4]), -0.2, 0.8) + self.p_grasp = _clip(self.p_view + GRASP_PITCH_OFF, -0.2, 0.8) + self.p_place = _clip(self.p_view + PLACE_PITCH_OFF, -0.2, 0.8) + self.h_place = _clip(self.h_view - PLACE_HEIGHT_OFF, 0.4, 1.0) + self.h_lift = _clip(self.h_view + LIFT_HEIGHT_OFF, 0.4, 1.0) + self.mug = None + self.step = 0 + self.phase = "look" + self.phase_t = 0 + self.grip_l = 0.0 + self.grip_r = 0.0 + self.f_open_l, self.f_open_r = self._fingers(ld) + self.f_closed_l = self.f_closed_r = self.f_open_l + self.have_travel = False + self.grasp_l = self.grasp_r = False + self.attempt = 0 + # pace the grasp attempts so the transfer always happens in time + try: + self.tlimit = int(obs.get("time_limit") or 1000) + except (TypeError, ValueError): + self.tlimit = 1000 + room = (0.70 * self.tlimit - 200.0) / 73.0 + self.max_attempt = min(len(ATTEMPTS) - 1, max(0, int(room))) + self.align_max = int(max(25, min(80, 0.10 * self.tlimit))) + + def act(self, obs, tools): + self.step += 1 + self.phase_t += 1 + ld = self._state(obs) + self.arm_l = np.array(ld[3:10], dtype=np.float32) + self.arm_r = np.array(ld[12:19], dtype=np.float32) + head = tools.image("head") + self.mug = self._find_mug(head) + + if self.phase == "look": + return self._phase_look(ld) + if self.phase == "reach": + return self._phase_reach(ld) + if self.phase == "align": + return self._phase_align(ld) + if self.phase == "lower": + return self._phase_lower(ld) + if self.phase == "close": + return self._phase_close(ld) + if self.phase == "check": + return self._phase_check(ld) + if self.phase == "retry": + return self._phase_retry(ld) + if self.phase == "lift": + return self._phase_lift(ld) + if self.phase == "transfer": + return self._phase_transfer(ld) + if self.phase == "release": + return self._phase_release(ld) + return self._action() + + # -- phases ------------------------------------------------------------ + def _phase_look(self, ld): + """Settle; squeeze the empty grippers once to learn their travel.""" + if self.phase_t <= 18: + self.grip_l = min(1.0, self.grip_l + 0.15) + self.grip_r = min(1.0, self.grip_r + 0.15) + elif self.phase_t <= 34: + if not self.have_travel: + self.f_closed_l, self.f_closed_r = self._fingers(ld) + self.have_travel = True + self.grip_l = max(0.0, self.grip_l - 0.15) + self.grip_r = max(0.0, self.grip_r - 0.15) + else: + self._goto("reach") + return self._action() + + def _phase_reach(self, ld): + tl, tr = self._pre_poses() + self.arm_l = _toward(self.arm_l, tl) + self.arm_r = _toward(self.arm_r, tr) + pitch = min(self.p_grasp, self.p_view + 0.01 * self.phase_t) + reached = (np.abs(self.arm_l - tl).max() < 0.06 and + np.abs(self.arm_r - tr).max() < 0.06) + if reached or self.phase_t > 80: + self._goto("align") + return self._action(pitch=pitch) + + def _phase_align(self, ld): + """Servo the base so the head camera sees the mug as in the demo.""" + vx = 0.0 + wz = 0.0 + if self.mug is not None: + err_u = self.mug["cx"] - MUG_TARGET_U + err_w = MUG_TARGET_W - self.mug["w"] + wz = _clip(-0.012 * err_u, -0.28, 0.28) + if abs(err_u) < 7.0 and err_w > 3.0: + vx = _clip(0.010 * err_w, 0.06, 0.20) + ok = (self.mug is not None and + abs(self.mug["cx"] - MUG_TARGET_U) < 4.0 and + self.mug["w"] >= MUG_TARGET_W - 2.0) + if ok or self.phase_t > self.align_max: + self._goto("lower") + return self._action(vx=vx, wz=wz, pitch=self.p_grasp) + + def _phase_lower(self, ld): + tl, tr = self._pre_poses() + tl[0] -= 0.06 # pitch the arm a little further into the mug + tr[0] -= 0.06 + self.arm_l = _toward(self.arm_l, tl) + self.arm_r = _toward(self.arm_r, tr) + height = _ramp(self.h_view, self.h_view - self._dip(), + self.phase_t, 30) + if self.phase_t > 34: + self._goto("close") + return self._action(height=height, pitch=self.p_grasp) + + def _phase_close(self, ld): + self.grip_l = min(1.0, self.grip_l + 0.12) + self.grip_r = min(1.0, self.grip_r + 0.12) + if self.phase_t > 22: + self._goto("check") + return self._action(height=self.h_view - self._dip(), + pitch=self.p_grasp) + + def _phase_check(self, ld): + fl, fr = self._fingers(ld) + travel_l = abs(self.f_closed_l - self.f_open_l) + travel_r = abs(self.f_closed_r - self.f_open_r) + self.grasp_l = abs(self.f_closed_l - fl) > max(0.01, 0.12 * travel_l) + self.grasp_r = abs(self.f_closed_r - fr) > max(0.01, 0.12 * travel_r) + if self.grasp_l or self.grasp_r or self.attempt >= self.max_attempt: + self._goto("lift") + else: + self.attempt += 1 + self._goto("retry") + return self._action(height=self.h_view - self._dip(), + pitch=self.p_grasp) + + def _phase_retry(self, ld): + self.grip_l = max(0.0, self.grip_l - 0.14) + self.grip_r = max(0.0, self.grip_r - 0.14) + if self.phase_t > 16: + self._goto("lower") + return self._action(pitch=self.p_grasp) + + def _phase_lift(self, ld): + height = _ramp(self.h_view - self._dip(), self.h_lift, self.phase_t, 25) + if self.phase_t > 28: + self._goto("transfer") + return self._action(height=height, pitch=self.p_grasp) + + def _phase_transfer(self, ld): + self.arm_l = _toward(self.arm_l, DOWN_L, rate=0.05) + self.arm_r = _toward(self.arm_r, DOWN_R, rate=0.05) + pitch = min(self.p_place, self.p_grasp + 0.017 * self.phase_t) + height = max(self.h_place, self.h_lift - 0.005 * self.phase_t) + if self.phase_t > 100: + self._goto("release") + return self._action(height=height, pitch=pitch) + + def _phase_release(self, ld): + self.grip_l = max(0.0, self.grip_l - 0.12) + self.grip_r = max(0.0, self.grip_r - 0.12) + return self._action(height=self.h_place, pitch=self.p_place) diff --git a/policies/dishwasher_load_cutlery/gpt61sol-s1/episodes.csv b/policies/dishwasher_load_cutlery/gpt61sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a2beb126e68975e5c1aedaf4b27bdf0b9cf7febd --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/gpt61sol-s1/policy.py b/policies/dishwasher_load_cutlery/gpt61sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c8222e004af01e3ae6ad7de2e74ed318d866336b --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61sol-s1/policy.py @@ -0,0 +1,106 @@ +"""Deterministic upper-body manipulation and closed-loop base control.""" +import numpy as np + +class Policy: + + def reset(self, obs, tools): + self.initial = np.asarray(tools.hold_action(), float) + pl = [-1.7, 0.5, 0, 0.2, 0, 1.2, 0] + pr = [-1.7, -0.5, 0, 0.2, 0, 1.2, 0] + hl = [-1.85, 0, 0, 0.5, 0, 1.35, 0] + hr = [-1.85, -0.5, 0, 0.5, 0, 1.35, 0] + fl = [-1.3, 0, 0, 0.5, 0, 0.8, 0] + kr = [-1.3, 0, 0, 0.5, 0, 0.8, 0] + cl = [-1.85, 0.3, 0, 0.5, 0, 1.35, 0] + cr = [-1.85, 0, 0, 0.5, 0, 1.35, 0] + dl = [-0.6, 0, 0, 0, 0, 0.6, 0] + dr = [-0.6, 0, 0, 0, 0, 0.6, 0] + self.stages = [(0, -0.6, 0, 0.74, 0, pl, pr, 0, 0, 100), (0.14, -0.62, 0, 0.74, 0, hl, hr, 0, 0, 180), (0.14, -0.62, 0, 0.74, 0, fl, hr, 0, 0, 100), (0.14, -0.62, 0, 0.74, 0, fl, hr, 1, 0, 60), (0.14, -0.62, 0, 0.74, 0, cl, hr, 1, 0, 100), (0.15, -0.35, 0, 0.78, 0, cl, kr, 1, 0, 300), (0.15, -0.35, 0, 0.78, 0, cl, kr, 1, 1, 65), (-0.25, -0.5, 0, 0.74, 0, cl, cr, 1, 1, 170), (-0.25, -0.5, 1.57, 0.74, 0, cl, cr, 1, 1, 200), (0.18, -0.5, 1.57, 0.74, 0, cl, cr, 1, 1, 180), (0.18, -0.5, 1.57, 0.55, 0, dl, cr, 1, 1, 220), (0.18, -0.5, 1.57, 0.55, 0, dl, cr, 0, 1, 70), (0.18, -0.5, 1.57, 0.74, 0, hl, cr, 0, 1, 170), (0, -0.5, 1.57, 0.74, 0, hl, cr, 0, 1, 150), (0, -0.5, 1.57, 0.55, 0, hl, dr, 0, 1, 220), (0, -0.5, 1.57, 0.55, 0, hl, dr, 0, 0, 80), (0, -0.5, 1.57, 0.55, 0, hl, cr, 0, 0, 100)] + self.stage = 0 + self.start = 0 + self.previous = None + self.last_stage = -1 + self.blend_from = None + self.knife_y = -0.35 + self.knife_x = 0.15 + self.knife_locked = False + self.capture_count = 0 + self.pick_q = None + self.search_q = np.array([-1.85, -0.5, 0, 0.5, 0, 1.35, 0], float) + + def act(self, obs, tools): + t = obs['t'] + while self.stage < len(self.stages) - 1 and t - self.start >= self.stages[self.stage][-1]: + self.start += self.stages[self.stage][-1] + self.stage += 1 + x, y, yaw, h, pitch, ql, qr, gl, gr, n = self.stages[self.stage] + if self.stage == 5: + u = min((t - self.start) / 260.0, 1.0) + x = -0.12 + 0.22 * u + y = -0.3 - 0.42 * u + h = 0.74 + sp = -1.3 + 0.18 * np.sin(np.pi * 0.5 * ((t - self.start) // 60)) + desired_q = np.array([sp, 0, 0, 0.5, 0, -sp - 0.5, 0], float) + self.search_q += np.clip(desired_q - self.search_q, -0.015, 0.015) + qr = self.search_q.copy() + gr = 1 if (t - self.start) % 60 >= 30 else 0 + fingers = np.asarray(obs['low_dim_obs'])[19:21] + if gr and (t - self.start) % 60 >= 45 and (-0.033 < float(fingers.sum()) < -0.002): + im = tools.image('right_wrist').astype(np.int16) + metal = (im.max(2) - im.min(2) < 25) & (im.mean(2) > 30) & (im.mean(2) < 225) + if metal[:65, 25:60].sum() > 15: + self.capture_count += 1 + else: + self.capture_count = 0 + if self.capture_count >= 3 and (not self.knife_locked): + self.knife_locked = True + self.pick_q = qr.copy() + self.knife_x = float(obs['low_dim_obs'][21]) + self.knife_y = float(obs['low_dim_obs'][22]) + row = list(self.stages[5]) + row[-1] = t - self.start + 20 + self.stages[5] = tuple(row) + else: + self.capture_count = 0 + if self.knife_locked: + x = self.knife_x + y = self.knife_y + gr = 1 + qr = self.pick_q + if self.stage == 6: + if self.knife_locked: + x = self.knife_x + y = self.knife_y + qr = self.pick_q + else: + x = 0.1 + y = -0.72 + qr = self.search_q + h = 0.74 + a = self.initial.copy() + a[2] = h + a[4] = pitch + a[5:12] = ql + a[12:19] = qr + a[19] = gl + a[20] = gr + if self.stage != self.last_stage: + self.blend_from = self.previous.copy() if self.previous is not None else a.copy() + self.last_stage = self.stage + if self.stage >= 10: + f = min((t - self.start) / 150.0, 1.0) + a[2] = self.blend_from[2] * (1 - f) + a[2] * f + a[4:19] = self.blend_from[4:19] * (1 - f) + a[4:19] * f + self.previous = a.copy() + p = np.asarray(obs['low_dim_obs'])[21:25] + v = np.clip((np.array([x, y]) - p[:2]) * 2, -0.2, 0.2) + for z in range(2): + if abs(v[z]) < 0.065: + v[z] = np.sign(v[z]) * 0.065 if abs(v[z]) > 0.016 else 0 + co, si = (np.cos(p[3]), np.sin(p[3])) + a[0] = co * v[0] + si * v[1] + a[1] = -si * v[0] + co * v[1] + if self.stage < 8: + a[:2] = v + a[3] = np.clip(2 * (yaw - p[3]), -0.6, 0.6) + return a diff --git a/policies/dishwasher_load_cutlery/gpt61sol-s2/episodes.csv b/policies/dishwasher_load_cutlery/gpt61sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..438318bce576d2dce9d0c1f9d1cb8e02ad5d8862 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,787,terminated,0 +620003,0,2650,timeout,0 +620004,0,788,terminated,0 +620005,0,2650,timeout,0 +620006,0,986,terminated,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,1374,terminated,0 +620010,0,880,terminated,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,909,terminated,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,1256,terminated,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,1209,terminated,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,948,terminated,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,785,terminated,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,1221,terminated,0 +620057,0,779,terminated,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,1216,terminated,0 +620067,0,2650,timeout,0 +620068,0,786,terminated,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,868,terminated,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,941,terminated,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,1220,terminated,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/gpt61sol-s2/policy.py b/policies/dishwasher_load_cutlery/gpt61sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..729a3510ea51c85bc59c858dc1a59af9a9cbd5dc --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61sol-s2/policy.py @@ -0,0 +1,91 @@ +"""Hand-written deterministic cutlery transfer with camera alignment.""" +import cv2 +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.a=np.zeros(21,dtype=np.float32) + self.a[2]=.74;self.a[19:]=.5 + self.a[5]=-1.8;self.a[10]=.9 + self.phases=[] + def add(name,n,changes,xy=None,yaw=0,ramp=1): + self.phases.append((name,n,changes,xy,yaw,ramp)) + add('approach mug',100,{},(.1,-.55)) + for item in range(2): + if item: + # Retract the idle hand so it does not stop the return at the counter. + add('return to mug',230,{2:.74,4:0,5:-1.8,6:0,7:0,8:0,10:.9, + 12:.3,13:-.2,15:1.4,19:.5},(.06,-.565),ramp=80) + add('reach',100,{2:.74,4:.8,5:-1.9,6:0,7:0,8:0,10:.81,19:.5},ramp=70) + add('align',80 if not item else 120,{}) + add('grasp',50,{19:1}) + add('lift',100,{2:.74,4:0,5:-2,6:.2,10:.7},ramp=60) + add('face basket',190,{},(-.1,-.6),.75) + add('lower over basket',140,{2:.55,4:.4,5:-.8,6:0,7:0,8:0,10:.7},ramp=100) + add('release',150,{19:0},ramp=10) + add('settle',1000,{}) + self.i=0;self.k=0;self.phase='';self.second=False;self.retried=False + self.start=self.a.copy();self.goal=self.a.copy() + + @staticmethod + def mug_center(im): + im=im.astype(np.int16) + mask=((im.max(2)-im.min(2)<40)&(im.mean(2)>55)&(im.mean(2)<190)).astype(np.uint8) + mask[:18]=0;mask[:,:20]=0 + count,labels,stats,centers=cv2.connectedComponentsWithStats(mask) + choices=[i for i in range(1,count) if stats[i,4]>70 and stats[i,2]>7] + if not choices:return None + i=max(choices,key=lambda i:stats[i,4]) + ys,xs=np.where((labels==i)&(np.indices(labels.shape)[0]>50)) + return float(xs.mean()) if len(xs)>30 else float(centers[i,0]) + + @staticmethod + def navigate(a,obs,xy,yaw): + p=obs['low_dim_obs'][21:25];w=float(p[3]) + v=np.clip(2*(np.asarray(xy)-p[:2]),-.18,.18) + v=np.array([[np.cos(w),np.sin(w)],[-np.sin(w),np.cos(w)]])@v + speed=np.linalg.norm(v) + if speed<.035:v[:]=0 + elif speed<.065:v*=.065/speed + a[:2]=v + err=(yaw-w+np.pi)%(2*np.pi)-np.pi + a[3]=np.clip(2*err,-.5,.5) + return a + + def act(self,obs,tools): + name,n,changes,xy,yaw,ramp=self.phases[self.i] + if self.k==0: + self.phase=name + if name=='return to mug':self.second=True + self.start=self.a.copy();self.goal=self.a.copy() + for j,v in changes.items():self.goal[j]=v + self.k+=1 + if name in ('align','retry align') and self.k%10==1: + x=self.mug_center(tools.image('left_wrist')) + if x is not None: + center=42 if name=='retry align' else 37 + self.goal[6]=np.clip(self.goal[6]+np.clip(.002*(center-x),-.02,.02),-.12,.3) + a=self.start+(self.goal-self.start)*min(1,self.k/ramp) + a[:2]=0;a[3]=0 + if (self.second or name.startswith('retry')) and name in ( + 'reach','align','grasp','lift','retry reach','retry align','retry grasp','retry lift'): + a[3]=np.clip(-4*obs['low_dim_obs'][24],-.5,.5) + if xy is not None:a=self.navigate(a,obs,xy,yaw) + if self.k>=n: + self.a=self.goal.copy();self.k=0 + # Fully closed finger joints indicate an empty pinch. There is time + # for one alternate approach before the episode deadline. + fingers=np.asarray(obs['low_dim_obs'][10:12]) + if name=='lift' and not self.retried and np.all(fingers < -.018): + self.retried=True + recovery=[ + ('retry approach',100,{2:.74,4:0,5:-1.8,6:0,10:.9, + 12:.3,13:-.2,15:1.4,19:.5},(.08,-.565),0,70), + ('retry reach',100,{4:.8,5:-1.75,6:0,10:.81},None,0,70), + ('retry align',80,{},None,0,1), + ('retry grasp',50,{19:1},None,0,1), + ('retry lift',100,{4:0,5:-2,6:.2,10:.7},None,0,60), + ] + self.phases[self.i+1:self.i+1]=recovery + self.i=min(self.i+1,len(self.phases)-1) + return a diff --git a/policies/dishwasher_load_cutlery/gpt61sol-s3/episodes.csv b/policies/dishwasher_load_cutlery/gpt61sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..db5d0de0e4cccba9f2d36c0eb2a0214a45482862 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,1149,terminated,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,1186,terminated,0 +620019,0,1148,terminated,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,1151,terminated,0 +620025,0,1254,terminated,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,1145,terminated,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,1144,terminated,0 +620036,0,1152,terminated,0 +620037,0,1140,terminated,0 +620038,0,1151,terminated,0 +620039,0,2650,timeout,0 +620040,0,1159,terminated,0 +620041,0,2650,timeout,0 +620042,0,1246,terminated,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,1142,terminated,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,1153,terminated,0 +620051,0,909,terminated,0 +620052,0,2650,timeout,0 +620053,0,577,terminated,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,1142,terminated,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2274,terminated,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,1142,terminated,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,1149,terminated,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,1147,terminated,0 +620092,0,1142,terminated,0 +620093,0,1147,terminated,0 +620094,0,2650,timeout,0 +620095,0,1155,terminated,0 +620096,0,2650,timeout,0 +620097,0,1161,terminated,0 +620098,0,2650,timeout,0 +620099,0,1160,terminated,0 diff --git a/policies/dishwasher_load_cutlery/gpt61sol-s3/policy.py b/policies/dishwasher_load_cutlery/gpt61sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..2e79e635b8679250f03640b540ae987f2540e0a6 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61sol-s3/policy.py @@ -0,0 +1,58 @@ +"""Deterministic hand-written pick-and-place controller with base feedback.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.stage = 0 + self.start = int(obs['t']) + self.stages = self.trip(False) + self.trip(True) + self.hold = np.asarray(tools.hold_action(), dtype=float) + + def trip(self, second): + # Each tuple specifies a hand-written manipulation phase: + # duration, base x/y/yaw, shoulder, torso, wrist, fingers, height. + y = -.71 if second else -.66 + seq = [] + if second: + seq.append((170,-.08,-.66,0,-1.8,0,1.5,0,.74)) + seq += [ + (170 if second else 230,.25,y,0,-1.8,0,1.5,0,.74), + (80 if second else 110,.25,y,0,-1.1,.5,.8,0,.74), + (60 if second else 80,.25,y,0,-1.1,.5,.8,1,.74), + (80 if second else 100,.25,y,0,-1.35,.5,.8,1,.74), + (110 if second else 150,-.08,y,0,-1.8,0,1.5,1,.74), + (170 if second else 200,.30,-.45,1.57,-1.8,0,1.5,1,.74), + (130 if second else 150,.30,-.45,1.57,-.9,0,.5,1,.62), + (60 if second else 100,.30,-.45,1.57,-.9,.6,.5,1,.62), + (90 if second else 100,.30,-.45,1.57,-.9,.6,.5,0,.62), + ] + return seq + + def act(self, obs, tools): + t=int(obs['t']) + while self.stage=self.stages[self.stage][0]: + self.start+=self.stages[self.stage][0] + self.stage+=1 + a=self.hold.copy() + a[12:19]=[0,-.3,0,1.3,0,0,0] + a[20]=1 + if self.stage>=len(self.stages): + a[:5]=[0,0,.74,0,0] + a[5:12]=[-1.8,0,0,0,0,1.5,0] + a[19]=0 + return a.astype(np.float32) + _,x,y,goal,s,p,w,g,h=self.stages[self.stage] + a[2]=h;a[4]=p + a[5:12]=[s,-.1 if h<.7 else 0,-.45 if h<.7 else 0,0,0,w,0] + a[19]=g + body=np.asarray(obs['low_dim_obs']) + yaw=float(body[24]);d=np.array([x,y])-body[21:23] + c=np.cos(yaw);sn=np.sin(yaw) + vel=np.array([c*d[0]+sn*d[1],-sn*d[0]+c*d[1]])*2 + norm=float(np.linalg.norm(vel)) + if np.linalg.norm(d)<.008:vel*=0 + elif norm<.08 and norm>1e-8:vel*=.08/norm + a[:2]=np.clip(vel,-.18,.18) if h>.7 else 0 + err=(goal-yaw+np.pi)%(2*np.pi)-np.pi + a[3]=np.clip(2*err,-.8,.8) + return a.astype(np.float32) diff --git a/policies/dishwasher_load_cutlery/gpt61terra-s1/episodes.csv b/policies/dishwasher_load_cutlery/gpt61terra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..5c881318cb8cb4f2a0444d7156e2470c107b6197 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61terra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,1,1806,success,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,692,terminated,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,1783,terminated,0 +620017,0,2650,timeout,0 +620018,0,696,terminated,0 +620019,0,1336,terminated,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,693,terminated,0 +620032,0,2650,timeout,0 +620033,0,1343,terminated,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,1627,terminated,0 +620043,0,1338,terminated,0 +620044,0,1552,terminated,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,1744,terminated,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,785,terminated,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,1638,terminated,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,744,terminated,0 +620066,0,2650,timeout,0 +620067,0,1230,terminated,0 +620068,0,1235,terminated,0 +620069,0,1764,terminated,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,685,terminated,0 +620077,0,1353,terminated,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,789,terminated,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,1760,terminated,0 +620088,0,819,terminated,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,682,terminated,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,766,terminated,0 diff --git a/policies/dishwasher_load_cutlery/gpt61terra-s1/policy.py b/policies/dishwasher_load_cutlery/gpt61terra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a63e9a9af34b0e53db6153b5a1a67526baae932a --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61terra-s1/policy.py @@ -0,0 +1,71 @@ +"""A deterministic, staged controller for the cutlery transfer.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.default = np.asarray(tools.hold_action(), dtype=np.float32) + self.default[19:21] = 0 + self.stage = 0 + self.since = 0 + self.yaw0 = float(obs['low_dim_obs'][24]) + + def act(self, obs, tools): + t = int(obs['t']) + age = t - self.since + q = obs['low_dim_obs'] + a = self.default.copy() + a[2], a[4] = 1.0, -.2 + lup = [-1.3, 0, 0, 0, 0, 0, 0] + rup = [-1.3, 0, 0, 0, 0, 0, 0] + if self.stage <= 8: + if t >= 140: a[0] = .3 + if self.stage == 0: + a[5:12] = lup + duration = 100 + elif self.stage == 1: + a[5:12] = [-1.3,0,-.5,0,0,0,0]; duration = 100 + elif self.stage == 2: + a[5:12] = [-1.3,0,-.5,.5,0,0,0]; duration = 100 + elif self.stage == 3: + a[5:12] = [-1.3,0,-.5,1,0,0,0]; duration = 100 + elif self.stage == 4: + a[5:12] = [-1.,0,-.5,1,0,0,0]; duration = 90 + elif self.stage == 5: + a[5:12] = [-1.,0,-1.3,1,0,0,0]; duration = 90 + elif self.stage == 6: + a[5:12] = [-1.,0,-1.3,1,0,0,0]; a[19] = 1; duration = 70 + elif self.stage == 7: + a[5:12] = [-1.4,0,-.8,.4,0,0,0]; a[19] = 1; duration = 100 + else: + a[5:12] = lup; a[19] = 1; a[12:19] = rup; duration = 100 + elif self.stage <= 13: + a[0] = .3; a[5:12] = lup; a[19] = 1 + if self.stage == 9: + a[12:19] = [-1.3,0,.5,.5,0,0,0]; duration = 90 + elif self.stage == 10: + a[12:19] = [-1.3,0,.5,1,0,0,0]; duration = 90 + elif self.stage == 11: + a[12:19] = [-1.,0,1.1,1,0,0,0]; duration = 100 + elif self.stage == 12: + a[12:19] = [-1.,0,1.1,1,0,0,0]; a[20] = 1; duration = 70 + else: + a[12:19] = [-1.4,0,.8,.4,0,0,0]; a[20] = 1; duration = 100 + elif self.stage == 14: + a[2] = .74; a[4] = 0; a[5:12] = lup; a[12:19] = rup; a[19:21] = 1 + a[0] = -.2 if age < 75 else 0 + if age >= 120: + err = (self.yaw0 + 1.3 - float(q[24]) + np.pi) % (2*np.pi) - np.pi + if abs(err) > .08: a[3] = np.clip(err, -.5, .5) + else: self.stage, self.since = 15, t + if age > 380: self.stage, self.since = 15, t + duration = 10000 + else: + a[2] = .65; a[4] = .4 + a[5:12] = [-.9,.1,0,.7,0,.5,0] + a[12:19] = [-.9,-.1,0,.7,0,.5,0] + a[19:21] = 1 if age < 130 else 0 + duration = 10000 + if age >= duration: + self.stage += 1 + self.since = t + return a diff --git a/policies/dishwasher_load_cutlery/gpt61terra-s2/episodes.csv b/policies/dishwasher_load_cutlery/gpt61terra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a2beb126e68975e5c1aedaf4b27bdf0b9cf7febd --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61terra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/gpt61terra-s2/policy.py b/policies/dishwasher_load_cutlery/gpt61terra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..45da3ae5044ae3bce71d8611bc057f71a8378c64 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61terra-s2/policy.py @@ -0,0 +1,48 @@ +"""Deterministic upper-body sequence for loading the cutlery basket.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.start = np.asarray(obs['low_dim_obs'][21:25], dtype=float).copy() + + def act(self, obs, tools): + t = obs['t'] + p = obs['low_dim_obs'][21:25] + a = self.hold.copy() + a[2] = .74 + a[19:21] = 0 + # Move back to make space for the hands to rise above the counter. + if t < 55: + a[0] = -.3 + return a + a[5:12] = [-1.4, 0, 0, .2, 0, 1., 0] + a[12:19] = [-.8, 0, 0, 0, 0, 0, 0] + if t < 155: + return a + if t < 380: + a[0] = .15 + a[1] = np.clip(3 * (self.start[1] - p[1]), -.2, .2) + a[3] = np.clip(-2 * (p[3] - self.start[3]), -.3, .3) + return a + # Reach over the rim and close the fingers, then lift clear of the mug. + a[5:12] = [-1.4, -.15, 0, .2, 0, 1.5, 0] + if t >= 465: + a[19] = 1 + if t >= 530: + a[5:12] = [-1.7, -.15, 0, .2, 0, 1.5, 0] + if t >= 620: + a[12:19] = [-1.4, .15, 0, .2, 0, 1.5, 0] + if t >= 710: + a[20] = 1 + if t >= 780: + a[12:19] = [-1.7, .15, 0, .2, 0, 1.5, 0] + if 860 <= t < 1110: + error = 1.5 + self.start[3] - p[3] + a[3] = np.clip(error * 1.5, -.4, .4) if abs(error) > .04 else 0 + if t >= 1110: + a[5:12] = [-1.1, -.15, 0, .7, 0, 1.0, 0] + a[12:19] = [-1.1, .15, 0, .7, 0, 1.0, 0] + if t >= 1200: + a[19:21] = 0 + return a diff --git a/policies/dishwasher_load_cutlery/gpt61terra-s3/episodes.csv b/policies/dishwasher_load_cutlery/gpt61terra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..4049ba046c65c7e15724669985dec3967eaa929f --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61terra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,1493,terminated,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,1480,terminated,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,1483,terminated,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,1478,terminated,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,1490,terminated,0 +620079,0,2650,timeout,0 +620080,0,1486,terminated,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,1482,terminated,0 +620092,0,2650,timeout,0 +620093,0,1479,terminated,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,1480,terminated,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/gpt61terra-s3/policy.py b/policies/dishwasher_load_cutlery/gpt61terra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c0d5d6ed5adc8ef340b5a0d427e5e50ce8209f41 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt61terra-s3/policy.py @@ -0,0 +1,67 @@ +"""Deterministic upper-body and base controller for loading cutlery.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.base = np.asarray(tools.hold_action(), dtype=np.float32) + self.base[2] = .95 + self.base[19:21] = 0 + self.origin = np.asarray(obs['low_dim_obs'][21:25], dtype=float).copy() + + def move_to(self, a, obs, x, y, yaw, vmax=.45): + p = obs['low_dim_obs'][21:25] + angle = float(p[3]) + dx, dy = x-float(p[0]), y-float(p[1]) + vx, vy = np.clip(dx*2.5, -vmax, vmax), np.clip(dy*2.5, -vmax, vmax) + a[0] = vx*np.cos(angle)+vy*np.sin(angle) + a[1] = -vx*np.sin(angle)+vy*np.cos(angle) + if np.hypot(a[0],a[1]) < .06: + a[0:2] = 0 + err = (yaw-angle+np.pi)%(2*np.pi)-np.pi + a[3] = np.clip(2*err,-.5,.5) + + def act(self, obs, tools): + t = obs['t'] + a = self.base.copy() + a[5:12] = [-1.7,.3,0,1,0,0,0] + a[19] = 1 + if t < 80: + a[5:12] = [-1.5,0,0,0,0,0,0] + a[19] = 0 + elif t < 270: + a[0] = .7 + a[4] = .5 + a[5:12] = [-1,.3,0,1,0,-.7,0] + a[19] = float(t >= 210) + elif t < 340: + a[0] = -.3 + a[4] = .5 + elif t < 540: + a[4] = .5 + a[12] = -1.5 + self.move_to(a,obs,self.origin[0]-.05,self.origin[1],0,.3) + elif t < 800: + a[4] = .5 + a[12:19] = [-1,.06,0,1,0,-.7,0] + a[20] = float(t >= 740) + self.move_to(a,obs,self.origin[0]+.22,self.origin[1],0,.55) + elif t < 900: + a[4] = .35 + a[12:19] = [-1.7,.06,0,1,0,0,0] + a[20] = 1 + self.move_to(a,obs,self.origin[0]-.3,self.origin[1],0,.35) + elif t < 1130: + a[12:19] = [-1.7,.06,0,1,0,0,0] + a[20] = 1 + self.move_to(a,obs,self.origin[0]-.4,self.origin[1]+.1,.9,.3) + elif t < 1330: + a[12:19] = [-1.7,.06,0,1,0,0,0] + a[20] = 1 + self.move_to(a,obs,self.origin[0]-.2,self.origin[1]+.35,.9,.25) + else: + a[5:12] = [-.9,.1,0,1,0,-.4,0] + a[12:19] = [-.9,-.1,0,1,0,-.4,0] + a[4] = .25 + a[19:21] = 0 if t >= 1450 else 1 + return a diff --git a/policies/dishwasher_load_cutlery/gpt6sol-s1/episodes.csv b/policies/dishwasher_load_cutlery/gpt6sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..32f5d173aa19f2f64f26bddd129db7e421441789 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt6sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,1,1347,success,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,560,terminated,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,662,terminated,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,661,terminated,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,1383,terminated,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,609,terminated,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,593,terminated,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,593,terminated,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,479,terminated,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,813,terminated,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,667,terminated,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,659,terminated,0 +620081,0,1361,fell,1 +620082,0,2127,terminated,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,743,terminated,0 +620087,0,2650,timeout,0 +620088,0,487,terminated,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,1629,terminated,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,662,terminated,0 +620098,0,2650,timeout,0 +620099,0,663,terminated,0 diff --git a/policies/dishwasher_load_cutlery/gpt6sol-s1/policy.py b/policies/dishwasher_load_cutlery/gpt6sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..427e2904b50b525a98c0bbbeccefc87bcd5c2cd6 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt6sol-s1/policy.py @@ -0,0 +1,142 @@ +"""Deterministic joint and base controller for the cutlery task.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.a[5:19] = 0 + self.a[19:21] = 0 + self.a[2] = 0.74 + self.phases = [] + self._build() + self.labels = {p[1]: j for j, p in enumerate(self.phases) if p[0] == "mark"} + self.i = 0 + self.n = 0 + self.entered = False + self.yaw_control = False + + def hold(self, steps, **changes): + self.phases.append(("hold", steps, changes)) + + def move(self, axis, target, speed, cap=250): + self.phases.append(("move", (axis, target, speed, cap), {})) + + def mark(self, name): + self.phases.append(("mark", name, {})) + + def _build(self): + # Raise both hands clear of the counter, then pick up the fork. + for sp in (-0.5, -1.0, -1.5, -2.0): + self.hold(35, lp=sp, rp=sp, le=0, re=0) + self.hold(45, lp=-1.5, rp=-1.5, le=0.7, re=0.7) + self.hold(45, lp=-1.5, rp=-1.5, le=1.3, re=1.3) + self.move(0, 0.18, 0.20, 150) + self.hold(12) + self.hold(30, le=1.2) + self.hold(40, lg=1) + self.hold(45, lp=-1.8, le=1.0) + self.mark("yaw_on") + + # Carry the fork around the cabinet to the cutlery basket. + self.move(0, -0.50, -0.25, 200) + self.hold(12) + self.hold(70, rp=0, re=0) + self.move(1, -0.11, 0.25, 250) + self.hold(12) + self.move(0, -0.33, 0.16, 170) + self.hold(12) + self.mark("basket_y") + self.hold(15) + self.hold(50, lp=-1.5, le=1.2) + self.hold(50, lp=-1.2) + self.hold(50, lp=-1.0) + self.hold(50, lr=-0.4) + self.hold(30, lp=-0.8, lg=0) + self.hold(55, lp=-2.0, le=0, lr=0, rp=-2.0, re=0) + + # Return for the knife and grasp its exposed blade with the right hand. + self.move(0, -0.50, -0.25, 150) + self.hold(12) + self.move(1, -0.62, -0.25, 200) + self.hold(12) + self.hold(50, rp=-1.5, re=1.3) + self.move(0, 0.19, 0.20, 250) + self.hold(12) + self.hold(30) + self.hold(40, rg=1) + self.hold(45, rp=-1.8, re=1.0) + self.mark("knife_check") + self.hold(25, rg=0, rp=-1.5, re=1.1) + self.hold(35, rg=1) + self.hold(40, rp=-1.8, re=1.0) + self.mark("transfer") + + # Place the knife in the same basket. + self.move(0, -0.50, -0.30, 180) + self.hold(10) + self.hold(45, lp=0, le=0) + self.move(1, -0.11, 0.30, 220) + self.hold(10) + self.move(0, -0.33, 0.20, 170) + self.hold(10) + self.hold(25, rp=-1.5, re=1.2) + self.hold(25, rp=-1.2) + self.hold(25, rp=-1.0) + self.hold(20, rr=0.4) + self.hold(80, rp=-0.8, rg=0) + self.hold(100, rp=-1.8, re=1.0, rr=0) + + def _apply(self, changes): + mapping = {"lp": 5, "lr": 6, "le": 8, "rp": 12, "rr": 13, + "re": 15, "lg": 19, "rg": 20} + for key, value in changes.items(): + self.a[mapping[key]] = value + + def act(self, obs, tools): + l = obs["low_dim_obs"] + x, y, yaw = float(l[21]), float(l[22]), float(l[24]) + while self.i < len(self.phases): + kind, value, changes = self.phases[self.i] + if not self.entered: + self._apply(changes) + self.n = 0 + self.entered = True + if kind == "mark": + if value == "yaw_on": + self.yaw_control = True + elif value == "basket_y": + if y < -0.13 and self.n < 100: + self.a[1] = 0.15 + self.n += 1 + self.a[3] = np.clip(-2.0 * yaw, -0.25, 0.25) + return self.a.copy() + self.a[1] = 0 + elif value == "knife_check": + if float(l[19] + l[20]) > -0.034: + self.i = self.labels["transfer"] + self.entered = False + continue + self.i += 1 + self.entered = False + continue + if kind == "hold": + if self.n >= value: + self.i += 1 + self.entered = False + continue + else: + axis, target, speed, cap = value + measured = x if axis == 0 else y + if (measured - target) * speed >= 0 or self.n >= cap: + self.a[axis] = 0 + self.i += 1 + self.entered = False + continue + self.a[axis] = speed + self.n += 1 + self.a[3] = np.clip(-2.0 * yaw, -0.25, 0.25) if self.yaw_control else 0 + return self.a.copy() + self.a[0] = self.a[1] = self.a[3] = 0 + return self.a.copy() diff --git a/policies/dishwasher_load_cutlery/gpt6sol-s2/episodes.csv b/policies/dishwasher_load_cutlery/gpt6sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..668b4b686497c27d882af6771303718c4fc2c557 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt6sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,377,terminated,0 +620010,0,384,terminated,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,716,terminated,0 +620022,0,859,terminated,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,716,terminated,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,717,terminated,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,1244,terminated,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,385,terminated,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,408,terminated,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,758,terminated,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/gpt6sol-s2/policy.py b/policies/dishwasher_load_cutlery/gpt6sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..d13fc4ae811477943822052d8dd1ebe02581af4b --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt6sol-s2/policy.py @@ -0,0 +1,107 @@ +"""Deterministic image and proprioception based cutlery controller.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.left_has_cutlery = False + self.right_has_cutlery = False + self.initial = np.asarray(tools.hold_action(), dtype=np.float32) + + @staticmethod + def _base(raw, obs, x_goal=None, y_goal=None, yaw_goal=None): + x, y, _, yaw = obs['low_dim_obs'][21:25] + if yaw_goal is not None: + error = (yaw_goal - yaw + np.pi) % (2 * np.pi) - np.pi + raw[3] = np.clip(2.5 * error, -0.45, 0.45) if abs(error) > .025 else 0 + if x_goal is not None or y_goal is not None: + dx = (x_goal - x) if x_goal is not None else 0.0 + dy = (y_goal - y) if y_goal is not None else 0.0 + c, s = np.cos(yaw), np.sin(yaw) + forward, lateral = c * dx + s * dy, -s * dx + c * dy + v = np.array([forward, lateral], dtype=float) * 2.0 + norm = np.linalg.norm(v) + if norm > .22: + v *= .22 / norm + if norm < .065: + v[:] = 0 + raw[:2] = v + + @staticmethod + def _held(tools, camera): + im = np.asarray(tools.image(camera), dtype=np.int16) + mid = im[3:40, 36:49] + bright = np.mean(mid, axis=2) + chroma = np.max(mid, axis=2) - np.min(mid, axis=2) + return bool(np.count_nonzero((bright > 85) & (bright < 220) & (chroma < 27)) > 42) + + def act(self, obs, tools): + t = int(obs['t']) + raw = self.initial.copy() + raw[:5] = (0, 0, .74, 0, 0) + raw[5:19] = 0 + raw[19:] = (0, 0) + if t >= 20: + raw[5] = -2.1 + if t >= 720: + raw[12] = -2.1 + + if 80 <= t < 1220: + self._base(raw, obs, .035, -.64, 0) + if t >= 230: + raw[2], raw[4] = .9, -.2 + + left_poses = ( + (-1.4, .15, -.8, 1.1, 0, .3, 0), + (-1.2, .18, 0, .92, 0, 0, 0), + (-1.5, .1, -.5, 1.25, 0, .25, 0), + ) + for start, pose in zip((230, 400, 560), left_poses): + if start <= t < start + 110 and not self.left_has_cutlery: + raw[5:12] = pose + if t >= start + 70: + raw[19] = 1 + break + if 340 <= t < 400 or 510 <= t < 560 or 670 <= t < 720: + raw[5:12] = (-2.1, 0, 0, 0, 0, .1, 0) + raw[19] = 1 + if t in (399, 559, 719) and not self.left_has_cutlery: + self.left_has_cutlery = self._held(tools, 'left_wrist') + if self.left_has_cutlery: + raw[5:12] = (-2.1, 0, 0, 0, 0, .1, 0) + raw[19] = 1 + + right_poses = ( + (-1.2, .1, .8, 1.1, 0, .25, 0), + (-1.0, .15, .5, 1.25, 0, -.1, 0), + ) + for start, pose in zip((800, 1040), right_poses): + if start <= t < start + 180 and not self.right_has_cutlery: + raw[12:19] = pose + if t >= start + 105: + raw[20] = 1 + if t >= start + 155: + raw[12:19] = (-2.1, 0, 0, 0, 0, .1, 0) + break + if t in (979, 1219) and not self.right_has_cutlery: + self.right_has_cutlery = self._held(tools, 'right_wrist') + if self.right_has_cutlery: + raw[12:19] = (-2.1, 0, 0, 0, 0, .1, 0) + raw[20] = 1 + + if 1220 <= t < 1370: + self._base(raw, obs, -.045, -.62, 0) + raw[19], raw[20] = 1, 1 + if 1370 <= t < 1620: + self._base(raw, obs, -.045, -.62, 1.33) + raw[19], raw[20] = 1, 1 + if 1620 <= t < 1830: + self._base(raw, obs, .01, -.49, 1.33) + raw[19], raw[20] = 1, 1 + if t >= 1830: + raw[2], raw[4] = .62, .35 + raw[5:12] = (-1.1, -.2, -.4, 1.1, 0, -.45, 0) + raw[12:19] = (-1.1, .2, .4, 1.1, 0, -.45, 0) + raw[19], raw[20] = (1, 1) if t < 2030 else (0, 0) + return raw diff --git a/policies/dishwasher_load_cutlery/gpt6sol-s3/episodes.csv b/policies/dishwasher_load_cutlery/gpt6sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..d503614513fae3a1a745db0250d8da6e034007ab --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt6sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,881,terminated,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,849,terminated,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,1368,terminated,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,769,terminated,0 +620067,0,2650,timeout,0 +620068,0,909,terminated,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/gpt6sol-s3/policy.py b/policies/dishwasher_load_cutlery/gpt6sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..db16d6ed29ba5558e17aaa75ae9220fbbf55ce41 --- /dev/null +++ b/policies/dishwasher_load_cutlery/gpt6sol-s3/policy.py @@ -0,0 +1,97 @@ +"""Deterministic joint-space control for loading cutlery into the dishwasher.""" + +import math +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.initial = np.asarray(tools.hold_action(), dtype=np.float32) + + @staticmethod + def _arm(a, side, shoulder, elbow, roll=0.0, wrist_pitch=0.0): + i = 5 if side == 0 else 12 + a[i:i + 7] = (shoulder, roll, 0.0, elbow, 0.0, wrist_pitch, 0.0) + + @staticmethod + def _drive(a, obs, x, y, yaw): + state = obs["low_dim_obs"] + px, py, _, heading = (float(v) for v in state[21:25]) + dx, dy = x - px, y - py + forward = math.cos(heading) * dx + math.sin(heading) * dy + lateral = -math.sin(heading) * dx + math.cos(heading) * dy + a[0] = float(np.clip(2.5 * forward, -0.4, 0.4)) + a[1] = float(np.clip(2.5 * lateral, -0.3, 0.3)) + if abs(a[0]) < 0.06: + a[0] = 0.0 + if abs(a[1]) < 0.06: + a[1] = 0.0 + err = (yaw - heading + math.pi) % (2.0 * math.pi) - math.pi + a[3] = float(np.clip(2.0 * err, -0.8, 0.8)) + + def act(self, obs, tools): + t = int(obs["t"]) + a = self.initial.copy() + a[0] = a[1] = a[3] = 0.0 + a[2] = 0.74 + a[4] = 0.0 + a[19] = a[20] = 0.0 + + # Raise both hands clear of the countertop before extending them. + if t < 55: + self._arm(a, 0, -2.0, 0.0) + self._arm(a, 1, -2.0, 0.0) + elif t < 110: + self._arm(a, 0, -2.0, 1.0) + self._arm(a, 1, -2.0, 1.0) + else: + self._arm(a, 0, -1.7, 1.5) + self._arm(a, 1, -1.7, 1.5) + + if 165 <= t < 540: + self._drive(a, obs, 0.08, -0.52, 0.0) + elif 540 <= t < 785: + self._drive(a, obs, 0.08, -0.60, 0.0) + + # Fork: pass the open left gripper beside the fork stem and close. + if 320 <= t < 485: + a[4] = 0.25 + self._arm(a, 0, -1.30, 0.80) + if t >= 385: + a[19] = 1.0 + elif t >= 485: + a[19] = 1.0 + + # Knife: approach from the other side after the fork is lifted. + if 555 <= t < 720: + a[4] = 0.40 + self._arm(a, 1, -1.10, 0.40) + if t >= 620: + a[20] = 1.0 + elif t >= 720: + a[20] = 1.0 + + if 785 <= t < 925: + self._drive(a, obs, -0.08, -0.60, 0.0) + elif 925 <= t < 1105: + self._drive(a, obs, -0.08, -0.60, 1.65) + elif 1105 <= t < 1330: + self._drive(a, obs, -0.07, -0.40, 1.65) + + # Lower the utensils into the front of the open cutlery basket. + if 1330 <= t < 1400: + self._arm(a, 0, -1.2, 1.5) + self._arm(a, 1, -1.2, 1.5) + elif 1400 <= t < 1470: + a[2] = 0.60 + a[4] = 0.25 + self._arm(a, 0, -0.8, 1.0) + self._arm(a, 1, -0.8, 1.0) + elif t >= 1470: + a[2] = 0.60 + a[4] = 0.45 + self._arm(a, 0, -0.4, 0.6) + self._arm(a, 1, -0.4, 0.6) + if t >= 1530: + a[19] = a[20] = 0.0 + return a diff --git a/policies/dishwasher_load_cutlery/kimi31pro-s2/episodes.csv b/policies/dishwasher_load_cutlery/kimi31pro-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..255728865d79310dfdeffbb3127e32383aa4e4c7 --- /dev/null +++ b/policies/dishwasher_load_cutlery/kimi31pro-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,902,terminated,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,1,1566,success,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,974,terminated,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,872,terminated,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,1514,terminated,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,949,terminated,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/kimi31pro-s2/policy.py b/policies/dishwasher_load_cutlery/kimi31pro-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a69fa90ab0c58cd41458917cfac3bf83a7f89261 --- /dev/null +++ b/policies/dishwasher_load_cutlery/kimi31pro-s2/policy.py @@ -0,0 +1,147 @@ +"""Deterministic hand-written controller for the cutlery-loading task. + +The policy uses joint-space motions, pelvis feedback, and a contact-triggered +wrist descent. It does not use learned models, stored demonstrations, or +unseeded randomness. +""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.raw = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.raw[19:21] = 0.0 + self.base_target = np.array([0.23, -0.63, 0.02], dtype=np.float64) + + left_ready = [-1.0, 0.05, 0.0, 0.4, 0.0, 0.2, 0.0] + right_clear = [-0.8, -0.2, 0.0, 0.4, 0.0, 0.4, 0.0] + self.phases = [ + # Approach the counter with the right hand clear of the fork. + dict(n=220, move=True, pitch=0.0, L=left_ready, R=right_clear, + grip=(0.0, 0.0)), + dict(n=80, move=True, + L=[-1.1, 0.15, 0.0, 0.3, 0.0, 1.4, 0.0]), + # Compliant fork approach. Five contact readings end the descent. + dict(n=200, descend=True), + dict(n=60, grip=(1.0, None)), + dict(n=65, move=True, L=[-1.8, 0.15, 0.0, 0.0, 0.0, 1.6, 0.0]), + # High right-hand pose for the exposed knife handle. + dict(n=70, move=True, + R=[-1.45, 0.0, 0.0, 0.0, 0.0, 1.45, 0.0]), + dict(n=55, grip=(None, 1.0)), + # Spread the loaded hands before carrying them to the rack. + dict(n=65, move=True, + L=[-1.8, 0.40, 0.0, 0.0, 0.0, 1.6, 0.0], + R=[-1.8, -0.30, 0.0, 0.0, 0.0, 1.6, 0.0]), + dict(n=100, base=(-0.05, -0.73, 0.02)), + dict(n=130, move=True, base=(-0.05, -0.73, 1.0), pitch=0.8), + dict(n=80, move=True, + L=[-1.0, 0.15, 0.0, 0.8, 0.0, 0.05, 0.0]), + ] + # Let the base settle at the fork release stance. + for _ in range(6): + self.phases.append(dict(n=80, base=(0.10, -0.50, 1.03))) + self.phases.extend([ + dict(n=50, move=True, height=0.65), + dict(n=50, grip=(0.0, None)), + # Restore walking height and bring the knife over the same basket. + dict(n=80, move=True, height=0.74, + R=[-1.0, 0.0, 0.0, 0.8, 0.0, 0.05, 0.0]), + ]) + for _ in range(6): + self.phases.append(dict(n=80, base=(-0.228, -0.595, 1.03))) + self.phases.extend([ + dict(n=50, move=True, height=0.65), + dict(n=150, grip=(None, 0.0)), + ]) + + self.phase = 0 + self.contact_count = 0 + self._start_phase(0) + + def _start_phase(self, index): + self.spec = self.phases[index] + self.j = 0 + self.contact_count = 0 + spec = self.spec + + # Gripper changes are immediate; arm, pitch and height changes are + # interpolated by act(), just as in the development controller. + if spec.get("grip") is not None: + left, right = spec["grip"] + if left is not None: + self.raw[19] = left + if right is not None: + self.raw[20] = right + if spec.get("base") is not None: + self.base_target = np.asarray(spec["base"], dtype=np.float64) + + self.start = self.raw.copy() + self.target = self.raw.copy() + if spec.get("L") is not None: + self.target[5:12] = spec["L"] + if spec.get("R") is not None: + self.target[12:19] = spec["R"] + if spec.get("pitch") is not None: + self.target[4] = spec["pitch"] + if spec.get("height") is not None: + self.target[2] = spec["height"] + + def _base_hold(self, action, obs): + p = obs["low_dim_obs"] + x, y, _z, yaw = map(float, p[21:25]) + tx, ty, target_yaw = self.base_target + ex, ey = tx - x, ty - y + + wx = np.clip(ex * 1.2, -0.14, 0.14) if abs(ex) > 0.012 else 0.0 + wy = np.clip(ey, -0.08, 0.08) if abs(ey) > 0.015 else 0.0 + # The whole-body controller ignores planar speeds below 0.055 m/s. + if 0.0 < abs(wx) < 0.06: + wx = np.sign(wx) * 0.06 + if 0.0 < abs(wy) < 0.06: + wy = np.sign(wy) * 0.06 + c, s = np.cos(yaw), np.sin(yaw) + action[0] = c * wx + s * wy + action[1] = -s * wx + c * wy + + dy = (target_yaw - yaw + np.pi) % (2.0 * np.pi) - np.pi + action[3] = np.clip(dy * 1.5, -0.35, 0.35) if abs(dy) > 0.02 else 0.0 + + def act(self, obs, tools): + if self.phase >= len(self.phases): + action = self.raw.copy() + action[0:2] = 0.0 + action[3] = 0.0 + self.raw = action.copy() + return action + + spec = self.spec + j = self.j + if spec.get("descend"): + # Preserve hand orientation while lowering the left wrist. + elbow = 0.3 + 0.0025 * (j + 1) + self.raw[8] = elbow + self.raw[10] = 1.7 - elbow + elif spec.get("move"): + u = min(1.0, (j + 1) / max(1, spec["n"] - 15)) + self.raw = self.start * (1.0 - u) + self.target * u + + action = self.raw.copy() + self._base_hold(action, obs) + self.raw = action.copy() + + advance = False + if spec.get("descend"): + if abs(float(obs["low_dim_obs"][7])) > 0.035 and j > 15: + self.contact_count += 1 + else: + self.contact_count = 0 + advance = self.contact_count >= 5 + + self.j += 1 + if self.j >= spec["n"] or advance: + self.phase += 1 + if self.phase < len(self.phases): + self._start_phase(self.phase) + return action diff --git a/policies/dishwasher_load_cutlery/kimi31pro-s3/episodes.csv b/policies/dishwasher_load_cutlery/kimi31pro-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..0ea0cc084580310a4f1b62597b2bc51e2b29b9db --- /dev/null +++ b/policies/dishwasher_load_cutlery/kimi31pro-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,1,923,success,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,919,terminated,0 +620011,0,2650,timeout,0 +620012,1,959,success,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,1270,terminated,0 +620016,0,2650,timeout,0 +620017,0,1303,terminated,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,2650,timeout,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,2650,timeout,0 +620028,0,1019,terminated,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,1294,terminated,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,1040,terminated,0 +620060,0,1246,terminated,0 +620061,0,2650,timeout,0 +620062,0,1305,terminated,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2650,timeout,0 +620072,0,1246,terminated,0 +620073,0,727,terminated,0 +620074,0,2650,timeout,0 +620075,0,2650,timeout,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,0,2650,timeout,0 +620083,0,1298,terminated,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,892,terminated,0 +620093,0,2650,timeout,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/kimi31pro-s3/policy.py b/policies/dishwasher_load_cutlery/kimi31pro-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..531ab88fbff613a003e77b0204771c92e2c34daf --- /dev/null +++ b/policies/dishwasher_load_cutlery/kimi31pro-s3/policy.py @@ -0,0 +1,97 @@ +"""Deterministic hand-written controller for loading the knife and fork. + +The controller uses a raised two-hand pickup, keeps the grasped utensils fixed +relative to the body during a left turn, and makes separate placement corrections +for the knife and fork over the cutlery basket. Only proprioception is used; +all motion and timing constants were hand-tuned through the public interface. +""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + p = obs["low_dim_obs"] + self.target = np.array([p[21] + 0.18, p[22], p[24]], dtype=float) + self.action = np.asarray(tools.hold_action(), dtype=float).copy() + self.action[19:21] = 0.0 + # name, duration. The final stage is intentionally unbounded. + self.stages = [ + ("walk", 180), + ("top", 150), + ("close", 100), + ("lift", 120), + ("turn", 220), + ("place", 120), + ("right_shift", 120), + ("right_release", 80), + ("left_shift", 120), + ("left_release", 80), + ("settle", 10**9), + ] + self.stage_index = 0 + self.stage_step = 0 + self._enter_stage() + + def _enter_stage(self): + name, _ = self.stages[self.stage_index] + self.start = self.action.copy() + self.end = self.action.copy() + e = self.end + if name == "walk": + e[2] = 0.82 + elif name == "top": + e[5:12] = [-1.4, -0.05, 0, 1.3, 0, 0, 0] + e[12:19] = [-1.4, 0.05, 0, 1.3, 0, 0, 0] + elif name == "close": + e[19:21] = 1.0 + elif name == "lift": + e[5], e[8] = -1.8, 1.7 + e[12], e[15] = -1.8, 1.7 + elif name == "turn": + self.target[2] = 1.35 + e[2] = 0.74 + e[4] = 0.8 + elif name == "place": + e[5], e[8] = -0.8, 1.0 + e[12], e[15] = -0.8, 1.0 + elif name == "right_shift": + self.target[0] += 0.04 * np.sin(1.35) + self.target[1] -= 0.04 * np.cos(1.35) + elif name == "right_release": + e[20] = 0.0 + elif name == "left_shift": + self.target[0] += 0.12 * np.sin(1.35) + self.target[1] -= 0.12 * np.cos(1.35) + elif name == "left_release": + e[19] = 0.0 + self.stage_step = 0 + + def _base_command(self, obs): + p = obs["low_dim_obs"] + x, y, yaw = p[21], p[22], p[24] + ex, ey = self.target[0] - x, self.target[1] - y + c, s = np.cos(yaw), np.sin(yaw) + v = np.array([3 * (c * ex + s * ey), 3 * (-s * ex + c * ey)]) + speed = np.linalg.norm(v) + if speed < 0.02: + v[:] = 0.0 + elif speed < 0.06: + v *= 0.06 / speed + elif speed > 0.35: + v *= 0.35 / speed + yaw_error = (self.target[2] - yaw + np.pi) % (2 * np.pi) - np.pi + return v[0], v[1], np.clip(2 * yaw_error, -0.6, 0.6) + + def act(self, obs, tools): + name, duration = self.stages[self.stage_index] + if self.stage_step >= duration: + self.action = self.end.copy() + self.stage_index = min(self.stage_index + 1, len(self.stages) - 1) + self._enter_stage() + name, duration = self.stages[self.stage_index] + u = min(1.0, (self.stage_step + 1) / min(100, duration)) + raw = self.start * (1 - u) + self.end * u + raw[0], raw[1], raw[3] = self._base_command(obs) + self.stage_step += 1 + return raw diff --git a/policies/dishwasher_load_cutlery/opus-s1/episodes.csv b/policies/dishwasher_load_cutlery/opus-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..7a49236cacae11513542849aaf715cacb382906a --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,1,1757,success,0 +620003,0,2230,terminated,0 +620004,0,2650,timeout,0 +620005,1,1713,success,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2650,timeout,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,2650,timeout,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2030,terminated,0 +620022,0,1693,terminated,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,2650,timeout,0 +620027,0,519,terminated,0 +620028,0,2650,timeout,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,2650,timeout,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,1,1967,success,0 +620039,0,1488,terminated,0 +620040,0,2650,timeout,0 +620041,1,1754,success,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,1,1727,success,0 +620048,0,2650,timeout,0 +620049,1,1747,success,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,0,2650,timeout,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,1,1973,success,0 +620059,0,2650,timeout,0 +620060,0,1708,terminated,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,2650,timeout,0 +620067,0,2650,timeout,0 +620068,1,1977,success,0 +620069,0,2650,timeout,0 +620070,0,2650,timeout,0 +620071,0,2645,terminated,0 +620072,0,1477,terminated,0 +620073,0,964,terminated,0 +620074,0,2650,timeout,0 +620075,0,1753,terminated,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,1,1872,success,0 +620080,0,2650,timeout,0 +620081,0,2650,timeout,0 +620082,1,1975,success,0 +620083,0,1946,terminated,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,2650,timeout,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,0,2650,timeout,0 +620092,0,2650,timeout,0 +620093,1,1732,success,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,1,2022,success,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/opus-s1/policy.py b/policies/dishwasher_load_cutlery/opus-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..f4df65fb902a3d808eca0c02ee3e4ad4ece6a65e --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s1/policy.py @@ -0,0 +1,414 @@ +"""Scripted policy: carry the fork and knife from the mug to the dishwasher cutlery basket. + +Sequence (all hand-written, constants tuned by running episodes): + 1. walk up to the counter, find the mug in the head camera and step in front of it; + 2. left hand sweeps through the mug at rim height and closes (retries at other + offsets if the gripper closes on nothing), lifts and moves aside; the right + hand then does the same for the remaining utensil; + 3. walk back, turn left, walk to the open dishwasher and squat with the torso + pitched forward; + 4. lower both hands over the cutlery basket and open the grippers. +""" + +import cv2 +import numpy as np +from scipy.optimize import least_squares + +# ----------------------------------------------------------------------------- kinematics + + +def _rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def _ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def _rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +def _T(R=None, p=(0, 0, 0)): + M = np.eye(4) + if R is not None: + M[:3, :3] = R + M[:3, 3] = p + return M + + +_AX = {"x": _rx, "y": _ry, "z": _rz} + + +def _chain(side): + s = 1 if side == "l" else -1 + return [ + ((0.0039563, s * 0.10022, 0.23778), s * 0.27931, "y"), + ((0, s * 0.038, -0.013831), -s * 0.27925, "x"), + ((0, s * 0.00624, -0.1032), 0.0, "z"), + ((0.015783, 0, -0.080518), 0.0, "y"), + ((0.100, s * 0.00188791, -0.010), 0.0, "x"), + ((0.038, 0, 0), 0.0, "y"), + ((0.046, 0, 0), 0.0, "z"), + ] + + +_CHAINS = {"l": _chain("l"), "r": _chain("r")} + + +def torso_T(waist): + yaw, roll, pitch = waist + return _T(_rz(yaw)) @ _T(_rx(roll), (-0.0039635, 0, 0.044)) @ _T(_ry(pitch)) + + +def arm_fk(side, q, tool=0.0, waist=(0, 0, 0)): + M = torso_T(waist) + for (p, r, ax), qi in zip(_CHAINS[side], q): + M = M @ _T(_rx(r), p) @ _T(_AX[ax](qi)) + return M @ _T(p=(tool, 0, 0)) + + +LIM_L = np.array([[-3.0, 2.6], [-0.05, 2.2], [-2.6, 2.6], [-1.0, 2.0], + [-1.9, 1.9], [-1.55, 1.55], [-1.55, 1.55]]) +LIM_R = LIM_L.copy() +LIM_R[1] = [-2.2, 0.05] +TOOL = 0.135 # grasp point ahead of the wrist_yaw frame (m) + + +def ik(side, p, d, q0, waist, up=None, wd=0.5, wu=0.5, reg=0.02, tool=TOOL): + lim = LIM_L if side == "l" else LIM_R + q0 = np.clip(np.asarray(q0, float), lim[:, 0] + 1e-3, lim[:, 1] - 1e-3) + + def res(q): + M = arm_fk(side, q, tool, waist) + r = [M[:3, 3] - p, wd * (M[:3, 0] - d)] + if up is not None: + r.append(wu * (M[:3, 2] - up)) + r.append(reg * (q - q0)) + return np.concatenate(r) + + s = least_squares(res, q0, bounds=(lim[:, 0], lim[:, 1])) + M = arm_fk(side, s.x, tool, waist) + return s.x, float(np.linalg.norm(M[:3, 3] - p)) + + +# ----------------------------------------------------------------------------- head camera + +CAM_P = np.array([0.038322960926, 0.011581524055, 0.47646789608]) +CAM_PITCH = 0.99302964847 +CAM_FOVY = 49.887744047 +COUNTER_Z = 0.89 +MUG_R = 0.045 + + +def head_T(waist): + return torso_T(waist) @ _T(_ry(CAM_PITCH), CAM_P) + + +def world_T(lo, tilt=0.0): + x, y, z, yaw = lo[21:25] + return _T(_rz(yaw), (x, y, z)) @ _T(_ry(tilt)) + + +def pixel_to_plane(u, v, lo, zw): + f = 42 / np.tan(np.radians(CAM_FOVY) / 2) + C = world_T(lo) @ head_T(lo[0:3]) + d = C[:3, :3] @ np.array([1.0, (42 - u) / f, (42 - v) / f]) + o = C[:3, 3] + return o + (zw - o[2]) / d[2] * d, C + + +def find_mug(im, lo, vmax=40): + hsv = cv2.cvtColor(im, cv2.COLOR_RGB2HSV) + s, v = hsv[..., 1].astype(int), hsv[..., 2].astype(int) + m = ((s < 30) & (v > 70) & (v < 200)).astype(np.uint8) + m[vmax:] = 0 + n, lab, st, _ = cv2.connectedComponentsWithStats(m) + best = None + for i in range(1, n): + if st[i, 4] >= 15 and st[i, 2] >= 4 and (best is None or st[i, 4] > st[best, 4]): + best = i + if best is None: + return None + ys, xs = np.nonzero(lab == best) + vb = ys.max() + bottom = xs[ys >= vb - 1] + ub = (bottom.min() + bottom.max() + 1) / 2.0 + p, C = pixel_to_plane(ub, vb + 1.0, lo, COUNTER_Z) + dv = p[:2] - C[:2, 3] + dv /= np.linalg.norm(dv) + return p[:2] + MUG_R * dv + + +def detect_utensils(im): + """Utensils (S~14, flat grey) just above the mug rim in a wrist image. + + Returns lateral offsets (m, + = image left) of each utensil from the mug axis, + measured in units of the mug's apparent radius. + """ + hsv = cv2.cvtColor(im, cv2.COLOR_RGB2HSV) + s, v = hsv[..., 1].astype(int), hsv[..., 2].astype(int) + mug = ((s <= 6) & (v > 60) & (v < 250)).astype(np.uint8) + ut = (s >= 9) & (s <= 19) & (v > 50) & (v < 215) + n, lab, st, _ = cv2.connectedComponentsWithStats(mug) + if n <= 1: + return [] + i = 1 + int(np.argmax(st[1:, 4])) + if st[i, 4] < 80: + return [] + m = lab == i + r_top = int(np.nonzero(m.any(1))[0].min()) + r_w = int(np.argmax(m.sum(1))) + cols = np.nonzero(m[r_w])[0] + u_c = (cols.min() + cols.max() + 1) / 2.0 + half = (cols.max() - cols.min() + 1) / 2.0 + cand = [] + for r in range(max(0, r_top - 6), r_top + 2): + cand += list(np.nonzero(ut[r])[0] + 0.5) + clusters = [] + for u in sorted(cand): + if clusters and u - clusters[-1][-1] <= 3: + clusters[-1].append(u) + else: + clusters.append([u]) + return [float((u_c - np.mean(c)) / half * MUG_R) for c in clusters if len(c) >= 3] + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +RAISED = np.array([0, 0, 0, -1.0, 0, 0, 0.0]) + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + # tunables + GRASP_DX_L = (-0.01, 0.045, -0.035) + GRASP_DX_R = (-0.01, 0.045, -0.035) + DROP_L = (0.10, -0.17, 0.50) + DROP_R = (0.28, -0.17, 0.50) + TILT = 0.15 + STAND = (0.20, -0.42) + TUCK = (0.30, 0.17, 0.42) # pelvis frame, y mirrored for the right hand + debug = False + + def reset(self, obs, tools): + self.obs = obs + self.tools = tools + self.a = np.asarray(tools.hold_action(), dtype=np.float64).copy() + self.gen = self._main() + self.log = [] + self.dbg = [] + + def act(self, obs, tools): + self.obs = obs + try: + a = next(self.gen) + except StopIteration: + a = self.a + return np.asarray(a, dtype=np.float32) + + # ------------------------------------------------------------------ helpers + def lo(self): + return np.asarray(self.obs["low_dim_obs"], dtype=np.float64) + + def hold(self, n): + for _ in range(n): + yield self.a.copy() + + def walk_to(self, x, y, yaw, tol=0.02, maxn=400, vmax=0.25): + a = self.a + for _ in range(maxn): + L = self.lo() + ex, ey = x - L[21], y - L[22] + c, s = np.cos(L[24]), np.sin(L[24]) + bx, by = c * ex + s * ey, -s * ex + c * ey + eyaw = wrap(yaw - L[24]) + if abs(bx) < tol and abs(by) < tol and abs(eyaw) < 0.05: + break + vx, vy = np.clip(1.5 * bx, -vmax, vmax), np.clip(1.5 * by, -vmax, vmax) + sp = np.hypot(vx, vy) + if abs(bx) < tol and abs(by) < tol: + vx = vy = 0.0 + elif sp < 0.06: + vx, vy = vx / sp * 0.06, vy / sp * 0.06 + a[0], a[1] = vx, vy + a[3] = np.clip(2.0 * eyaw, -0.6, 0.6) + yield a.copy() + a[0] = a[1] = a[3] = 0.0 + yield a.copy() + + def move_arm(self, side, q, n=40): + off = 5 if side == "l" else 12 + q0 = self.a[off:off + 7].copy() + for i in range(1, n + 1): + self.a[off:off + 7] = q0 + (q - q0) * i / n + yield self.a.copy() + + def hand_ik(self, side, pw, d=(1, 0, 0), q0=None, wd=0.5, tilt=0.0): + L = self.lo() + Wi = np.linalg.inv(world_T(L, tilt)) + p = (Wi @ np.append(pw, 1))[:3] + dd = Wi[:3, :3] @ np.asarray(d, float) + up = Wi[:3, :3] @ np.array([0, 0, 1.0]) + s = 1 if side == "l" else -1 + if q0 is None: + q0 = np.array([-0.8, s * 0.3, 0, 0.3, 0, 0, 0]) + return ik(side, p, dd, q0, L[0:3], up=up, wd=wd) + + def grip_state(self, side): + return self.lo()[50 if side == "l" else 51] + + def hand_pos(self, side): + L = self.lo() + q = L[3:10] if side == "l" else L[12:19] + return (world_T(L) @ arm_fk(side, q, TOOL, L[0:3]))[:3, 3] + + def reach(self, side, pw, q, n=40, fix=1): + """Move the tool point to pw; then correct for tracking error using measured joints.""" + pw = np.asarray(pw, float) + q, _ = self.hand_ik(side, pw, q0=q) + yield from self.move_arm(side, q, n) + tgt = pw.copy() + for _ in range(fix): + yield from self.hold(12) + tgt = tgt + (pw - self.hand_pos(side)) + q, _ = self.hand_ik(side, tgt, q0=q) + yield from self.move_arm(side, q, 10) + return q + + def grasp(self, side, pick): + """Sweep the open hand into the mug at rim height and close; retry offsets.""" + mug, Z = self.mug, COUNTER_Z + 0.125 + gi = 19 if side == "l" else 20 + cam = "left_wrist" if side == "l" else "right_wrist" + self.a[gi] = 0.0 + q = yield from self.reach(side, [mug[0] - 0.16, mug[1], Z + 0.04], None, 40, fix=0) + yield from self.hold(10) + im = self.tools.image(cam) + if self.debug: + self.dbg.append((side, im, self.lo().copy())) + dys = detect_utensils(im) + if side == "r" and not dys and self.left_load > 0.0: + # the left hand already took both utensils (gripper held wide open) + self.log.append(("r", "mug empty")) + return q, False + dy = pick(dys) if dys else 0.0 + dy = float(np.clip(dy, -0.04, 0.04)) + tries = [(0.03, dy), (-0.01, 0.0), (0.0, 0.5 * dy), (0.03, dy + 0.02), (0.03, dy - 0.02)] + for k, (dx, ddy) in enumerate(tries): + if k > 0 and self.obs["t"] > 1500: + break + self.a[gi] = 0.0 + if k > 0: + yield from self.hold(10) + q = yield from self.reach(side, [mug[0] - 0.15, y, Z + 0.08], q, 30, fix=0) + y = mug[1] + ddy + q = yield from self.reach(side, [mug[0] - 0.15, y, Z], q, 25 if k == 0 else 35, fix=1) + q = yield from self.reach(side, [mug[0] + dx, y, Z], q, 50, fix=1) + self.a[gi] = 1.0 + yield from self.hold(35) + st = self.grip_state(side) + L = self.lo() + fing = L[10:12] if side == "l" else L[19:21] + m0 = self.ut_mask(self.tools.image(cam)) + q = yield from self.reach(side, [mug[0] + dx, y, Z + 0.08], q, 25, fix=0) + yield from self.hold(10) + m1 = self.ut_mask(self.tools.image(cam)) + iou = float((m0 & m1).sum() / max(1, (m0 | m1).sum())) + # a thin knife blade keeps the gripper state at 1.0, but the fingers stop + # just short of fully closed and the blade moves with the camera + held = st < 0.95 or (float(np.mean(fing)) > -0.0194 and iou > 0.4) + self.log.append((side, round(ddy, 3), float(st), np.round(fing, 4).tolist(), round(iou, 2), + int(m0.sum()), int(m1.sum()), [round(d, 3) for d in dys])) + if self.debug: + self.dbg.append((side + "c", self.tools.image(cam), self.lo().copy())) + if held: + return q, True + self.a[gi] = 0.0 + return q, False + + @staticmethod + def ut_mask(im): + hsv = cv2.cvtColor(im, cv2.COLOR_RGB2HSV) + s, v = hsv[..., 1].astype(int), hsv[..., 2].astype(int) + return (s >= 9) & (s <= 19) & (v > 50) & (v < 215) + + # ------------------------------------------------------------------ script + def _main(self): + a = self.a + a[5:12] = RAISED + a[12:19] = RAISED + yield from self.hold(30) + yield from self.walk_to(0.19, self.lo()[22], 0.0) + a[4] = -0.2 + yield from self.hold(40) + mug = find_mug(self.tools.image("head"), self.lo()) + if mug is None or not (0.5 < mug[0] < 0.8 and -0.8 < mug[1] < -0.4): + mug = np.array([0.65, -0.61]) + self.mug = mug + a[4] = 0.0 + yield from self.hold(30) + Z = COUNTER_Z + 0.125 + + # left hand: first utensil + self.left_load = 0.0 + q, okl = yield from self.grasp("l", max) + self.left_load = 1.0 if okl else 0.0 + q, _ = self.hand_ik("l", [mug[0] - 0.05, mug[1], Z + 0.22], q0=q) + yield from self.move_arm("l", q, 50) + q, _ = self.hand_ik("l", [mug[0] - 0.10, mug[1] + 0.20, Z + 0.20], q0=q) + yield from self.move_arm("l", q, 40) + # right hand: second utensil + q, okr = yield from self.grasp("r", min) + q, _ = self.hand_ik("r", [mug[0] - 0.05, mug[1], Z + 0.22], q0=q) + yield from self.move_arm("r", q, 50) + yield from self.hold(10) + # tuck both hands (utensils held up, close to the body) for the walk + L = self.lo() + for side, s in (("l", 1), ("r", -1)): + q0 = L[3:10] if side == "l" else L[12:19] + qt, _ = ik(side, np.array(self.TUCK) * [1, s, 1], np.array([1.0, 0, 0]), q0, + L[0:3], up=np.array([0, 0, 1.0])) + yield from self.move_arm(side, qt, 40) + self.log.append(("tuck", np.round(self.lo()[50:52], 2).tolist())) + + # go to the dishwasher + L = self.lo() + yield from self.walk_to(-0.05, L[22], 0.0) + yield from self.walk_to(-0.05, -0.6, 0.8) + yield from self.walk_to(self.STAND[0], -0.6, np.pi / 2) + a[2] = 0.72 + yield from self.walk_to(self.STAND[0], self.STAND[1], np.pi / 2, vmax=0.12, maxn=150) + yield from self.hold(20) + self.log.append(("arrive", int(self.obs["t"]), np.round(self.lo()[50:52], 2).tolist())) + for h, p in ((0.62, 0.4), (0.55, 0.6), (0.5, 0.75)): + a[2], a[4] = h, p + for _ in range(50): + a[3] = np.clip(2 * wrap(np.pi / 2 - self.lo()[24]), -0.3, 0.3) + yield a.copy() + a[3] = 0.0 + yield from self.hold(20) + self.log.append(("squat", int(self.obs["t"]), np.round(self.lo()[50:52], 2).tolist())) + + # lower both hands over the basket + ql, qr = self.lo()[3:10].copy(), self.lo()[12:19].copy() + for dz in (0.14, 0.06, 0.0): + ql, _ = self.hand_ik("l", np.array(self.DROP_L) + [0, 0, dz], d=(0, 1, 0), q0=ql, tilt=self.TILT) + qr, _ = self.hand_ik("r", np.array(self.DROP_R) + [0, 0, dz], d=(0, 1, 0), q0=qr, tilt=self.TILT) + l0, r0 = a[5:12].copy(), a[12:19].copy() + for i in range(1, 31): + a[5:12] = l0 + (ql - l0) * i / 30 + a[12:19] = r0 + (qr - r0) * i / 30 + yield a.copy() + yield from self.hold(15) + self.log.append(("drop", int(self.obs["t"]), np.round(self.hand_pos("l"), 3).tolist(), + np.round(self.hand_pos("r"), 3).tolist(), np.round(self.lo()[50:52], 2).tolist())) + a[19] = a[20] = 0.0 + while True: + yield a.copy() diff --git a/policies/dishwasher_load_cutlery/opus-s2/episodes.csv b/policies/dishwasher_load_cutlery/opus-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..09098ef27589aa5922d071d55e54e2c71634f1cc --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,1,2247,success,0 +620002,0,774,terminated,0 +620003,0,2650,timeout,0 +620004,0,886,terminated,0 +620005,0,2650,timeout,0 +620006,0,818,terminated,0 +620007,0,881,terminated,0 +620008,0,878,terminated,0 +620009,0,2067,terminated,0 +620010,0,866,terminated,0 +620011,1,2266,success,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,819,terminated,0 +620015,0,2650,timeout,0 +620016,0,833,terminated,0 +620017,0,2650,timeout,0 +620018,0,840,terminated,0 +620019,0,2650,timeout,0 +620020,0,2612,terminated,0 +620021,0,904,terminated,0 +620022,0,2316,terminated,0 +620023,0,912,terminated,0 +620024,0,1339,terminated,0 +620025,0,1971,terminated,0 +620026,0,812,terminated,0 +620027,0,2650,timeout,0 +620028,0,2220,terminated,0 +620029,1,2004,success,0 +620030,0,882,terminated,0 +620031,0,2650,timeout,0 +620032,0,2650,timeout,0 +620033,0,1985,terminated,0 +620034,0,2650,timeout,0 +620035,0,2650,timeout,0 +620036,0,2155,terminated,0 +620037,0,2650,timeout,0 +620038,0,784,terminated,0 +620039,1,2092,success,0 +620040,0,2650,timeout,0 +620041,1,2249,success,0 +620042,0,1031,terminated,0 +620043,0,2650,timeout,0 +620044,0,2650,timeout,0 +620045,0,2650,timeout,0 +620046,0,2650,timeout,0 +620047,0,2650,timeout,0 +620048,1,2373,success,0 +620049,0,2250,terminated,0 +620050,0,2650,timeout,0 +620051,0,1255,terminated,0 +620052,0,2650,timeout,0 +620053,1,2281,success,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,2650,timeout,0 +620060,0,2255,terminated,0 +620061,0,2650,timeout,0 +620062,0,2650,timeout,0 +620063,0,871,terminated,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,917,terminated,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2271,terminated,0 +620070,0,2650,timeout,0 +620071,0,1964,terminated,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,1,2287,success,0 +620075,0,891,terminated,0 +620076,0,2023,terminated,0 +620077,1,2430,success,0 +620078,0,864,terminated,0 +620079,0,2650,timeout,0 +620080,0,2650,timeout,0 +620081,0,1892,terminated,0 +620082,0,2650,timeout,0 +620083,0,1089,terminated,0 +620084,0,1951,terminated,0 +620085,0,913,terminated,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,1,1993,success,0 +620089,0,2650,timeout,0 +620090,0,2650,timeout,0 +620091,1,1943,success,0 +620092,0,2650,timeout,0 +620093,1,1947,success,0 +620094,0,2650,timeout,0 +620095,0,2650,timeout,0 +620096,0,2650,timeout,0 +620097,0,2650,timeout,0 +620098,0,1026,terminated,0 +620099,0,2427,terminated,0 diff --git a/policies/dishwasher_load_cutlery/opus-s2/g1kin.py b/policies/dishwasher_load_cutlery/opus-s2/g1kin.py new file mode 100644 index 0000000000000000000000000000000000000000..f1c55d3713f6ab0ba624cfd5163e9b9d12b95473 --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s2/g1kin.py @@ -0,0 +1,149 @@ +"""Hand-written forward kinematics of the G1 arm (URDF numbers) and a small IK.""" +import numpy as np +from scipy.optimize import least_squares + + +def rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +def rpy(r, p, y): + return rz(y) @ ry(p) @ rx(r) + + +AX = {'x': rx, 'y': ry, 'z': rz} + + +def _chain(side): + s = 1.0 if side == 'L' else -1.0 + return [ + # (xyz, rpy, axis) + ((0.0039563, s * 0.10022, 0.24778), (s * 0.27931, 5.4949e-05, -s * 0.00019159), 'y'), + ((0.0, s * 0.038, -0.013831), (-s * 0.27925, 0, 0), 'x'), + ((0.0, s * 0.00624, -0.1032), (0, 0, 0), 'z'), + ((0.015783, 0.0, -0.080518), (0, 0, 0), 'y'), + ((0.100, s * 0.00188791, -0.010), (0, 0, 0), 'x'), + ((0.038, 0, 0), (0, 0, 0), 'y'), + ((0.046, 0, 0), (0, 0, 0), 'z'), + ] + + +CHAINS = {'L': _chain('L'), 'R': _chain('R')} +WAIST_Z = 0.044 +WAIST_X = -0.0039635 +LO = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443]) +HI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443]) +LIM = {'L': (LO, HI), 'R': (np.array([-3.0892, -2.2515, -2.618, -1.0472, -1.97222, -1.61443, -1.61443]), + np.array([2.6704, 1.5882, 2.618, 2.0944, 1.97222, 1.61443, 1.61443]))} + + +def torso_frame(waist): + """Pose of torso_link in the pelvis frame for waist (yaw, roll, pitch).""" + R = rz(waist[0]) @ rx(waist[1]) @ ry(waist[2]) + p = np.array([WAIST_X, 0.0, WAIST_Z]) + return p, R + + +def arm_fk(q, side, waist=(0, 0, 0), tool=(0.0, 0, 0), beta=0.0): + """Return (pos, R) of the tool frame in the pelvis frame. + + The tool frame is the wrist-yaw link pitched down by beta; tool is an offset in it. + """ + p, R = torso_frame(waist) + for (xyz, r, ax), qi in zip(CHAINS[side], q): + p = p + R @ np.array(xyz) + R = R @ rpy(*r) @ AX[ax](qi) + if beta: + R = R @ ry(beta) + p = p + R @ np.array(tool) + return p, R + + +# head camera: URDF d435 mount position, pitch fitted from the counter edge +HEAD_CAM_POS = np.array([0.0576235, 0.01753, 0.42987]) +HEAD_CAM_PITCH = 1.068 +HEAD_CAM_YAW = -0.055 +HEAD_F = 78.4 +CX = CY = 41.5 + + +def head_cam(waist): + """Head camera position and rotation (x fwd, y left, z up) in pelvis frame.""" + p, R = torso_frame(waist) + pc = p + R @ HEAD_CAM_POS + Rc = R @ rz(HEAD_CAM_YAW) @ ry(HEAD_CAM_PITCH) + return pc, Rc + + +def project(pt, waist): + pc, Rc = head_cam(waist) + d = Rc.T @ (np.asarray(pt) - pc) + return np.array([CX - HEAD_F * d[1] / d[0], CY - HEAD_F * d[2] / d[0]]) + + +def pixel_ray(u, v, waist): + pc, Rc = head_cam(waist) + d = Rc @ np.array([1.0, -(u - CX) / HEAD_F, -(v - CY) / HEAD_F]) + return pc, d / np.linalg.norm(d) + + +def pixel_to_plane(u, v, waist, z): + """Intersect the pixel ray with the horizontal plane z (pelvis frame).""" + pc, d = pixel_ray(u, v, waist) + t = (z - pc[2]) / d[2] + return pc + t * d + + +WRIST_BETA = 0.4 +WRIST_CAM_OFF = np.array([0.02, 0.0, 0.0]) # camera position in the tool frame (from wrist-yaw origin) +WRIST_F = 78.0 + + +def wrist_cam(q, side, waist): + """Wrist camera position and rotation (x along view, y left, z up) in the pelvis frame.""" + return arm_fk(q, side, waist, WRIST_CAM_OFF, WRIST_BETA) + + +def wrist_pixel_to_plane(u, v, q, side, waist, z): + pc, Rc = wrist_cam(q, side, waist) + d = Rc @ np.array([1.0, -(u - CX) / WRIST_F, -(v - CY) / WRIST_F]) + t = (z - pc[2]) / d[2] + return pc + t * d + + +def ik(side, target, q0, waist=(0, 0, 0), tool=(0.12, 0, 0), axis=None, axis_w=0.3, + yaw_dir=None, yaw_w=0.1, q_nom=None, reg=0.02, beta=0.0): + """Solve for arm joints placing the tool point at target (pelvis frame). + + axis: desired direction of the tool x axis (pelvis frame). + yaw_dir: desired direction of the tool y axis (finger closing axis). + """ + lo, hi = LIM[side] + q_nom = q0 if q_nom is None else q_nom + target = np.asarray(target, float) + + def res(q): + p, R = arm_fk(q, side, waist, tool, beta) + r = [p - target] + if axis is not None: + r.append(axis_w * (R[:, 0] - axis)) + if yaw_dir is not None: + r.append(yaw_w * (R[:, 1] - yaw_dir)) + r.append(reg * (q - q_nom)) + return np.concatenate(r) + + q0 = np.clip(q0, lo + 1e-3, hi - 1e-3) + sol = least_squares(res, q0, bounds=(lo, hi), xtol=1e-8, ftol=1e-8, max_nfev=200) + p, R = arm_fk(sol.x, side, waist, tool, beta) + return sol.x, np.linalg.norm(p - target) diff --git a/policies/dishwasher_load_cutlery/opus-s2/policy.py b/policies/dishwasher_load_cutlery/opus-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..aa2984c79c9cd45833b9c6ebe7342f0dc8692eb1 --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s2/policy.py @@ -0,0 +1,503 @@ +"""Hand-written policy: load the knife and fork from the mug into the dishwasher basket. + +Phases (done twice, once per utensil, with the left hand only): walk to the counter, +find the mug with the head camera, grasp a utensil above the rim by visual servoing +on the left wrist camera (depth from a small sideways parallax move, then close-and- +check probing), walk to the side of the pulled-out rack facing +x, squat, lean and +release the utensil over the cutlery basket. Arm targets come from a hand-written +forward-kinematics model (g1kin.py) and a small least-squares IK. +""" + +import numpy as np +from scipy import ndimage + +from g1kin import arm_fk, ik, pixel_to_plane, wrist_cam + +BETA = 0.4 # wrist camera / gripper axis is pitched down this much vs the wrist link +TOOL = (0.10, 0.0, 0.0) +F_WRIST = 78.0 +G_GRASP = 0.09 # distance from wrist camera to the grasp centre between the fingertips +COUNTER_Z = 0.83 # world height of the counter top +RIM_Z = 0.935 # world height of the mug rim +GRASP_DZ = 0.035 # grasp this much above the rim + +QL_CARRY = np.array([-0.219, 0.387, 0.448, -0.848, -0.522, 1.045, 0.015]) +QR_CARRY = np.array([-0.187, -0.4, -0.452, -0.817, 0.562, 0.989, -0.028]) +QL_NOM = np.array([-0.575, -0.056, -0.302, -0.252, 0.027, 0.33, 0.481]) +QR_NOM = np.array([-0.575, 0.056, 0.302, -0.252, -0.027, 0.33, -0.481]) +DEBUG = False +SIDE_OFF = 0.10 # stand this far to the side of the mug for each hand's grasp +STAND_DX = 0.42 # stand this far (world x) behind the mug +STAND_XMAX = 0.19 # the counter blocks the robot at about x = 0.20 +GRASP_PITCH = 0.25 +PROBE_BEFORE = -0.01 # first close this much beyond the estimated utensil depth +PROBE_BEYOND = 0.035 # and stop this much beyond it +RETRY_UNTIL = (900, 1950) # retry a failed grasp only before these control steps +PROBE_STEP = 0.012 +PARALLAX_DY = 0.03 +PROBE_ALL = False # debugging: keep probing after a catch +DROP_PEL = (0.13, -0.63) # world pelvis position for dropping, facing +y (x > 0.15 hits the cabinet) +SQUAT_H = 0.64 +SIDE_PEL = (-0.15, -0.45) # beside the rack, facing +x (the rack stops the robot at y ~ -0.44) +SIDE_H = 0.62 +DROP_PITCH = 0.35 +DROP_TILT = np.radians(45) +DROP_Z = 0.52 # world height of the grasp point when releasing +DROP_X = (0.12, 0.17) # world x of the release points (the lower end trails ~0.09 behind) +BASKET_X = 0.18 # world x, y of the middle of the cutlery basket +BASKET_Y = -0.245 +SIDE_YAW = 0.3 +X_AXIS = np.array([1.0, 0.0, 0.0]) +Y_AXIS = np.array([0.0, 1.0, 0.0]) + + +def gray_mask(im): + im = im.astype(int) + mx, mn = im.max(2), im.min(2) + return (mx - mn < 30) & (mx > 40) & (mx < 215) + + +def metal_mask(im): + """Neutral (metal / ceramic) pixels; excludes the blue floor and the cream counter. + + Thin utensils seen edge-on blend with the blue background, so the blue-minus-red + margin is generous.""" + im = im.astype(int) + d = im[..., 2] - im[..., 0] + mx = im.max(2) + dbg = np.median(d, axis=1, keepdims=True) + return (d > -25) & (d < 50) & (np.abs(d - dbg) > 12) & (mx > 45) & (mx < 230) + + +def utensil_columns(im, r0=34, r1=48): + """Column clusters of grey (metal) pixels in a band of rows of a wrist image.""" + m = gray_mask(im)[r0:r1] + cols = m.sum(0) + cols[:4] = 0 + cols[80:] = 0 + lab, n = ndimage.label(cols > (r1 - r0) * 0.3) + out = [] + for k in range(1, n + 1): + xs = np.where(lab == k)[0] + wts = cols[xs] + out.append((float((xs * wts).sum() / wts.sum()), int(xs.min()), int(xs.max()))) + return out + + +def utensil_lines(im, r0=22, r1=56, vc=41.5): + """Thin grey structures crossing the band of rows r0..r1 of a wrist image. + + Each connected component is fitted with a line u = a v + b; returns + (u at row vc, lo, hi) like utensil_columns so the same merging applies. + """ + m = metal_mask(im) + # stop above the mug rim: the first row (below the band top) with a wide grey run + for r in range(r0 + 6, r1): + row = np.concatenate([[0], m[r].astype(np.int8), [0]]) + d = np.diff(row) + starts, ends = np.where(d == 1)[0], np.where(d == -1)[0] + if len(starts) and (ends - starts).max() > 12: + r1 = r - 1 + break + m[:r0] = False + m[r1:] = False + lab, n = ndimage.label(m, structure=np.ones((3, 3))) + out = [] + for k in range(1, n + 1): + ys, xs = np.where(lab == k) + if len(ys) < 4 or ys.max() - ys.min() < 5: + continue + if xs.mean() < 5 or xs.mean() > 78: # the open fingertips at the image edges + continue + if len(ys) > 0.5 * (ys.max() - ys.min() + 1) * 14: # too wide: mug body / arm + continue + A = np.stack([ys, np.ones_like(ys)], 1).astype(float) + (sl, b), *_ = np.linalg.lstsq(A, xs.astype(float), rcond=None) + uc = sl * vc + b + if not (-5 < uc < 89): + continue + hw = 0.5 * len(ys) / (ys.max() - ys.min() + 1) + out.append((float(uc), float(uc - hw), float(uc + hw))) + return out + + +def merge_clusters(cl, gap=4): + """Merge clusters closer than gap px (fork tines) -> list of (centre, lo, hi).""" + cl = sorted(cl, key=lambda c: c[1]) + out = [] + for c in cl: + if out and c[1] - out[-1][2] <= gap: + lo, hi = out[-1][1], max(out[-1][2], c[2]) + out[-1] = ((lo + hi) / 2.0, lo, hi) + else: + out.append(((c[1] + c[2]) / 2.0, c[1], c[2])) + return out + + +def find_mug(im): + """Return (u_bottom_centre, v_bottom, width) of the mug in the head image, or None.""" + m = gray_mask(im) + c = im[:, 20:64].astype(int).mean(1) + brown = np.where((c[:, 0] - c[:, 2] > 25) & (c[:, 0] < 200) & (c[:, 1] < 150))[0] + edge = int(brown.min()) if len(brown) else 45 + m[max(0, edge - 2):, :] = False + lab, n = ndimage.label(m) + if n == 0: + return None + sizes = ndimage.sum(m, lab, range(1, n + 1)) + k = int(np.argmax(sizes)) + 1 + if sizes[k - 1] < 15: + return None + ys, xs = np.where(lab == k) + vb = ys.max() + # body columns: rows in the lower half of the blob + sel = ys >= vb - 4 + return float(np.median(xs[sel])), float(vb) + 0.5, float(xs[sel].max() - xs[sel].min() + 1) + + +class Policy: + def reset(self, obs, tools): + self.tools = tools + self.hold = np.asarray(tools.hold_action(), dtype=np.float64) + self.a = self.hold.copy() + self.obs = obs + self.log = [] + self.imlog = [] + self.gen = self.script() + + # ------------------------------------------------------------------ helpers + def lo(self): + return np.asarray(self.obs['low_dim_obs'], dtype=np.float64) + + def pel(self): + lo = self.lo() + return lo[21], lo[22], lo[23], lo[24] + + def waist(self): + return self.lo()[0:3] + + def qarm(self, side): + lo = self.lo() + return lo[3:10].copy() if side == 'L' else lo[12:19].copy() + + def set_arm(self, side, q): + if side == 'L': + self.a[5:12] = q + else: + self.a[12:19] = q + + def world_to_pel(self, p): + x, y, z, yaw = self.pel() + c, s = np.cos(yaw), np.sin(yaw) + dx, dy = p[0] - x, p[1] - y + return np.array([c * dx + s * dy, -s * dx + c * dy, p[2] - z]) + + def pel_to_world(self, p): + x, y, z, yaw = self.pel() + c, s = np.cos(yaw), np.sin(yaw) + return np.array([x + c * p[0] - s * p[1], y + s * p[0] + c * p[1], z + p[2]]) + + def wait(self, n): + for _ in range(n): + yield self.a.copy() + + def goto(self, tx, ty, tyaw, tol=0.02, maxn=600, vmax=0.25): + for _ in range(maxn): + x, y, _, yaw = self.pel() + ex, ey = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + bx, by = c * ex + s * ey, -s * ex + c * ey + eyaw = (tyaw - yaw + np.pi) % (2 * np.pi) - np.pi + d = np.hypot(bx, by) + if d < tol and abs(eyaw) < 0.03: + break + if d >= tol: + v = max(min(vmax, 1.5 * d), 0.08) + self.a[0], self.a[1] = v * bx / d, v * by / d + else: + self.a[0] = self.a[1] = 0.0 + self.a[3] = np.clip(2.0 * eyaw, -0.5, 0.5) if abs(eyaw) > 0.02 else 0.0 + yield self.a.copy() + self.a[0] = self.a[1] = self.a[3] = 0.0 + + def solve(self, side, tgt, axis=X_AXIS, axis_w=1.0, q0=None): + qn = QL_NOM if side == 'L' else QR_NOM + qc = QL_CARRY if side == 'L' else QR_CARRY + inits = [self.qarm(side) if q0 is None else q0, qn, qc] + best = None + for qi in inits: + q, err = ik(side, tgt, qi, self.waist(), tool=TOOL, beta=BETA, axis=axis, axis_w=axis_w, + yaw_dir=Y_AXIS, yaw_w=0.3, q_nom=qn, reg=0.02) + if best is None or err < best[1] - 1e-3: + best = (q, err) + if err < 0.01: + break + return best + + def tool_pos(self, side): + p, R = arm_fk(self.qarm(side), side, self.waist(), TOOL, BETA) + return p, R + + def move_tool(self, side, tgt, n=30, axis=X_AXIS, axis_w=1.0, q0=None): + q, err = self.solve(side, tgt, axis, axis_w, q0) + self.set_arm(side, q) + yield from self.wait(n) + if DEBUG: + self.log.append(('move', side, np.round(tgt, 3).tolist(), round(float(err), 3), + np.round(self.tool_pos(side)[0], 3).tolist(), np.round(q, 2).tolist(), + np.round(self.qarm(side), 2).tolist())) + return err + + # ------------------------------------------------------------------ phases + def locate_mug(self): + im = self.tools.image('head') + r = find_mug(im) + if r is None: + return None + u, v, wpx = r + zc = COUNTER_Z - self.pel()[2] + p = pixel_to_plane(u, v, self.waist(), zc) + # bottom silhouette point is the front of the base; centre is ~one radius further + d = p[:2] / np.linalg.norm(p[:2]) + p[:2] += 0.045 * d + self.log.append(('mug_px', r, p.tolist())) + return self.pel_to_world(p) + + def wrist_u(self, side, pick, u_ref=41.5): + im = self.tools.image('left_wrist' if side == 'L' else 'right_wrist') + if DEBUG: + self.imlog.append((side, pick, u_ref, getattr(self, 'u_mug', None), im)) + cl = merge_clusters(utensil_lines(im)) + if not cl: + cl = merge_clusters(utensil_columns(im)) + if pick in ('left', 'right'): + cl = [c for c in cl if abs(c[0] - self.u_mug) < 30] + if not cl: + return None, cl + if pick == 'left': + c = cl[0] + elif pick == 'right': + c = cl[-1] + else: + c = min(cl, key=lambda c: abs(c[0] - u_ref)) + return c[0], cl + + def grasp(self, side, mug_w, pick): + """Grasp one utensil above the rim of the mug with one hand.""" + mug = self.world_to_pel(mug_w) + zg = RIM_Z + GRASP_DZ - self.pel()[2] + ys = 0.04 if side == 'L' else -0.04 + tgt = np.array([max(0.31, mug[0] - 0.25), mug[1] + ys, zg + 0.10]) + self.set_arm(side, self.solve(side, tgt, q0=QL_NOM if side == 'L' else QR_NOM)[0]) + self.a[19 if side == 'L' else 20] = 0.0 + yield from self.wait(25) + tgt[2] = zg + yield from self.move_tool(side, tgt, 20) + # expected column of the mug centre in the wrist image + pc, Rc = wrist_cam(self.qarm(side), side, self.waist()) + dm = Rc.T @ (np.array([mug[0], mug[1], zg]) - pc) + self.u_mug = 41.5 - F_WRIST * dm[1] / max(dm[0], 0.05) + self.log.append(('u_mug', side, float(self.u_mug))) + # 1) centre the utensil horizontally + u = None + for it in range(4): + u, cl = self.wrist_u(side, pick if it == 0 else 'centre') + self.log.append(('servo', side, it, u, cl)) + if u is None: + break + p, _ = self.tool_pos(side) + d = max(0.08, mug[0] - p[0] + 0.07) + tgt[1] = p[1] - (u - 41.5) * d / F_WRIST * 0.9 + tgt[1] = np.clip(tgt[1], mug[1] - 0.09, mug[1] + 0.09) + yield from self.move_tool(side, tgt, 18) + if abs(u - 41.5) < 2.5: + break + if u is None: + return False + # 2) parallax: step sideways and measure the image shift + pc0, _ = self.tool_pos(side) + uc, _ = self.wrist_u(side, 'centre') + uc = 41.5 if uc is None else uc + d_est = mug[0] - pc0[0] + 0.07 + obs_pu = [] + for dy in (-PARALLAX_DY, PARALLAX_DY): + t2 = tgt.copy() + t2[1] += dy + yield from self.move_tool(side, t2, 18) + p, _ = self.tool_pos(side) + u_pred = uc + F_WRIST * (p[1] - pc0[1]) / d_est + u, _ = self.wrist_u(side, 'centre', u_pred) + obs_pu.append((p[1], u)) + depth = None + (ya, ua), (yb, ub) = obs_pu + if ua is not None and ub is not None and ub - ua > 4: + depth = F_WRIST * (yb - ya) / (ub - ua) + self.log.append(('parallax', side, uc, obs_pu, round(d_est, 3), depth)) + if depth is None or not (0.08 < depth < 0.45): + depth = d_est + # back to the centred position, then advance along the axis + yield from self.move_tool(side, tgt, 15) + gi = 19 if side == 'L' else 20 + x_end = tgt[0] + depth - G_GRASP + PROBE_BEYOND + adv = depth - G_GRASP - PROBE_BEFORE + t3 = tgt.copy() + n_sub = max(1, int(np.ceil(adv / 0.04))) + for k in range(n_sub): + t3[0] = tgt[0] + adv * (k + 1) / n_sub + yield from self.move_tool(side, t3, 12) + # probe: close, check the fingers, open and advance a little if empty + held = False + while True: + u, _ = self.wrist_u(side, 'centre') + if u is not None and 3 < abs(u - 41.5) < 10: + p, _ = self.tool_pos(side) + dr = max(0.06, x_end + G_GRASP - PROBE_BEYOND - p[0]) + t3[1] = np.clip(p[1] - (u - 41.5) * dr / F_WRIST * 0.7, mug[1] - 0.09, mug[1] + 0.09) + yield from self.move_tool(side, t3, 10) + self.a[gi] = 1.0 + yield from self.wait(18) + held = self.holding(side) + self.log.append(('probe', side, round(float(t3[0]), 3), u, held, + np.round(self.lo()[10:12] if side == 'L' else self.lo()[19:21], 4).tolist())) + if PROBE_ALL and t3[0] < x_end - 1e-3: + held = False + if held or t3[0] >= x_end - 1e-3: + break + self.a[gi] = 0.0 + yield from self.wait(8) + t3[0] = min(x_end, t3[0] + PROBE_STEP) + yield from self.move_tool(side, t3, 10) + # lift straight up + t4 = t3.copy() + for k in range(3): + t4[2] += 0.05 + yield from self.move_tool(side, t4, 12) + held = self.holding(side) + self.log.append(('grip', side, float(self.lo()[50 if side == 'L' else 51]), held)) + return held + + def holding(self, side): + lo = self.lo() + f = lo[10:12] if side == 'L' else lo[19:21] + return bool(f.sum() > -0.0385) + + def approach(self, tx, ty): + """Walk upright to a grasping stance, lean forward and correct the drift.""" + self.a[4] = 0.0 + yield from self.goto(tx, ty, 0.0, tol=0.025, maxn=250, vmax=0.35) + self.a[4] = GRASP_PITCH + yield from self.wait(20) + yield from self.goto(tx, ty, 0.0, tol=0.03, maxn=50) + yield from self.wait(5) + self.log.append(('stance', np.round(self.pel(), 3).tolist(), round(float(self.waist()[2]), 3), int(self.obs['t']))) + + def script(self): + a = self.a + a[5:12] = QL_CARRY + a[12:19] = QR_CARRY + yield from self.wait(10) + yield from self.goto(0.08, -0.60, 0.0, tol=0.04, maxn=300, vmax=0.4) + a[4] = -0.2 + yield from self.wait(40) + mug = self.locate_mug() + if mug is None: + mug = np.array([0.62, -0.60, 0.0]) + self.mug = mug + # only the left hand can reach the cutlery basket from the side of the rack, + # so it carries the two utensils one after the other + for k in range(2): + a[4] = 0.0 + tx = float(np.clip(mug[0] - STAND_DX, -0.05, STAND_XMAX)) + yield from self.approach(tx, float(mug[1]) - SIDE_OFF) + for attempt in range(3): + ok = yield from self.grasp('L', mug, 'left' if k == 0 and attempt == 0 else 'centre') + if ok or int(self.obs['t']) > RETRY_UNTIL[k]: + break + q_park, _ = self.solve('L', np.array([0.30, 0.15, 0.40])) + yield from self.ramp_arm('L', q_park, 40) + self.log.append(('grasped', k, ok, int(self.obs['t']))) + if ok: + yield from self.place_left(DROP_X[k]) + if k == 0: + # walk back and look for the mug again (the grasp may have moved it) + a[2] = 0.74 + a[4] = 0.0 + yield from self.goto(-0.20, -0.60, 0.0, tol=0.08, maxn=150, vmax=0.4) + self.log.append(('t_back', int(self.obs['t']))) + yield from self.goto(tx, float(mug[1]) - SIDE_OFF, 0.0, tol=0.04, maxn=250, vmax=0.4) + a[4] = -0.2 + yield from self.wait(30) + self.log.append(('t_look', int(self.obs['t']))) + mug2 = self.locate_mug() + self.log.append(('mug2', None if mug2 is None else np.round(mug2, 3).tolist())) + if mug2 is not None and np.linalg.norm(mug2[:2] - mug[:2]) < 0.12: + mug = mug2 + while True: + yield from self.wait(10) + + def ramp_arm(self, side, q, n): + """Move the arm target linearly to q over n steps (keeps a held utensil from swinging).""" + sl = slice(5, 12) if side == 'L' else slice(12, 19) + q0 = self.a[sl].copy() + for i in range(n): + self.a[sl] = q0 + (q - q0) * (i + 1) / n + yield self.a.copy() + + def place_left(self, drop_x): + """Walk to the side of the rack (facing +x) and release over the basket.""" + a = self.a + a[2] = 0.74 + a[4] = 0.0 + yield from self.goto(-0.20, -0.60, 0.0, tol=0.06, maxn=200, vmax=0.3) + yield from self.goto(SIDE_PEL[0], SIDE_PEL[1], SIDE_YAW, tol=0.03, maxn=110) + a[0] = a[1] = a[3] = 0.0 + a[2] = SIDE_H + a[4] = DROP_PITCH + yield from self.wait(40) + ax = np.array([np.cos(DROP_TILT), 0.0, -np.sin(DROP_TILT)]) + t_hi = self.world_to_pel(np.array([drop_x, BASKET_Y, DROP_Z + 0.08])) + t_up = self.world_to_pel(np.array([drop_x - 0.05, BASKET_Y, DROP_Z + 0.25])) + q_up, _ = self.solve('L', t_up, axis=ax, q0=QL_NOM) + yield from self.ramp_arm('L', q_up, 40) + yield from self.move_tool('L', t_hi, 30, axis=ax) + t_lo = self.world_to_pel(np.array([drop_x, BASKET_Y, DROP_Z])) + yield from self.move_tool('L', t_lo, 30, axis=ax) + self.log.append(('drop', np.round(self.pel_to_world(self.tool_pos('L')[0]), 3).tolist(), + np.round(self.pel(), 3).tolist(), int(self.obs['t']))) + a[19] = 0.0 + yield from self.wait(30) + yield from self.move_tool('L', t_hi + [-0.05, 0, 0.05], 25, axis=ax) + yield from self.move_tool('L', np.array([0.25, 0.18, 0.40]), 30, q0=QL_CARRY) + a[2] = 0.74 + a[4] = 0.0 + yield from self.wait(30) + + def place(self): + a = self.a + a[4] = 0.0 + # back away from the counter and turn to face the dishwasher rack + yield from self.goto(-0.02, -0.62, 0.0, maxn=200) + yield from self.goto(-0.02, -0.62, np.pi / 2, maxn=400) + yield from self.goto(DROP_PEL[0], DROP_PEL[1], np.pi / 2, maxn=300) + yield from self.wait(20) + a[2] = SQUAT_H + a[4] = DROP_PITCH + yield from self.wait(40) + tl = self.world_to_pel(np.array([BASKET_X - 0.06, BASKET_Y, DROP_Z])) + tr = self.world_to_pel(np.array([BASKET_X + 0.06, BASKET_Y, DROP_Z])) + for dz, n in ((0.08, 40), (0.0, 30)): + yield from self.move_tool('L', tl + [0, 0, dz], 0, axis_w=0.3, q0=QL_NOM) + yield from self.move_tool('R', tr + [0, 0, dz], n, axis_w=0.3, q0=QR_NOM) + self.log.append(('drop_pose', self.tool_pos('L')[0].tolist(), self.tool_pos('R')[0].tolist(), self.pel())) + a[19] = 0.0 + a[20] = 0.0 + yield from self.wait(40) + yield from self.move_tool('L', tl + [-0.1, 0.08, 0.15], 0, q0=QL_NOM) + yield from self.move_tool('R', tr + [-0.1, -0.08, 0.15], 40, q0=QR_NOM) + + def act(self, obs, tools): + self.obs = obs + try: + return next(self.gen) + except StopIteration: + return self.a.copy() diff --git a/policies/dishwasher_load_cutlery/opus-s3/episodes.csv b/policies/dishwasher_load_cutlery/opus-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..f84e1531193fc0b9a11b05b883bd7bd3316deccd --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,2650,timeout,0 +620001,0,2650,timeout,0 +620002,0,2650,timeout,0 +620003,0,2650,timeout,0 +620004,0,2650,timeout,0 +620005,0,2650,timeout,0 +620006,0,2650,timeout,0 +620007,0,2650,timeout,0 +620008,0,2650,timeout,0 +620009,0,2650,timeout,0 +620010,0,2230,terminated,0 +620011,0,2650,timeout,0 +620012,0,2650,timeout,0 +620013,0,2650,timeout,0 +620014,0,2650,timeout,0 +620015,0,2650,timeout,0 +620016,0,2650,timeout,0 +620017,0,2650,timeout,0 +620018,0,1162,terminated,0 +620019,0,2650,timeout,0 +620020,0,2650,timeout,0 +620021,0,2650,timeout,0 +620022,0,1611,terminated,0 +620023,0,2650,timeout,0 +620024,0,2650,timeout,0 +620025,0,2650,timeout,0 +620026,0,1665,terminated,0 +620027,0,2650,timeout,0 +620028,1,2458,success,0 +620029,0,2650,timeout,0 +620030,0,2650,timeout,0 +620031,0,2650,timeout,0 +620032,0,2413,terminated,0 +620033,0,1681,terminated,0 +620034,0,931,terminated,0 +620035,0,2650,timeout,0 +620036,0,2650,timeout,0 +620037,0,2650,timeout,0 +620038,0,2650,timeout,0 +620039,0,2650,timeout,0 +620040,0,2650,timeout,0 +620041,0,2650,timeout,0 +620042,0,2650,timeout,0 +620043,0,2650,timeout,0 +620044,0,1576,terminated,0 +620045,0,2650,timeout,0 +620046,0,1876,terminated,0 +620047,0,2650,timeout,0 +620048,0,2650,timeout,0 +620049,0,2650,timeout,0 +620050,0,2650,timeout,0 +620051,0,2650,timeout,0 +620052,0,2650,timeout,0 +620053,1,2137,success,0 +620054,0,2650,timeout,0 +620055,0,2650,timeout,0 +620056,0,2650,timeout,0 +620057,0,2650,timeout,0 +620058,0,2650,timeout,0 +620059,0,1091,terminated,0 +620060,0,2650,timeout,0 +620061,0,2650,timeout,0 +620062,0,1947,terminated,0 +620063,0,2650,timeout,0 +620064,0,2650,timeout,0 +620065,0,2650,timeout,0 +620066,0,1853,terminated,0 +620067,0,2650,timeout,0 +620068,0,2650,timeout,0 +620069,0,2650,timeout,0 +620070,1,1963,success,0 +620071,0,2650,timeout,0 +620072,0,2650,timeout,0 +620073,0,2650,timeout,0 +620074,0,2650,timeout,0 +620075,0,2079,terminated,0 +620076,0,2650,timeout,0 +620077,0,2650,timeout,0 +620078,0,2650,timeout,0 +620079,0,1916,terminated,0 +620080,0,2650,timeout,0 +620081,1,2040,success,0 +620082,0,2650,timeout,0 +620083,0,2650,timeout,0 +620084,0,2650,timeout,0 +620085,0,2650,timeout,0 +620086,0,2650,timeout,0 +620087,0,2650,timeout,0 +620088,0,1578,terminated,0 +620089,1,1880,success,0 +620090,0,2650,timeout,0 +620091,0,1307,terminated,0 +620092,0,1885,terminated,0 +620093,0,2650,timeout,0 +620094,0,1204,terminated,0 +620095,0,2650,timeout,0 +620096,0,1549,terminated,0 +620097,0,2650,timeout,0 +620098,0,2650,timeout,0 +620099,0,2650,timeout,0 diff --git a/policies/dishwasher_load_cutlery/opus-s3/kin.py b/policies/dishwasher_load_cutlery/opus-s3/kin.py new file mode 100644 index 0000000000000000000000000000000000000000..9bb88b93c72ef788906a11aa069e678c0013f2f4 --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s3/kin.py @@ -0,0 +1,161 @@ +"""G1 arm kinematics (hand-written from the G1 URDF geometry) and a small IK solver. + +Frames: everything is expressed in the pelvis frame (x forward, y left, z up, +origin at the pelvis), using the waist joint angles from the observation. +""" + +import numpy as np +from scipy.optimize import least_squares + + +def rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +def rpy(r, p, y): + return rz(y) @ ry(p) @ rx(r) + + +AXES = {"x": rx, "y": ry, "z": rz} + +# (origin xyz, origin rpy, axis) per arm joint, left arm; the right arm mirrors y. +ARM = [ + ((0.0039563, 0.10022, 0.23778), (0.27931, 5.4949e-05, -0.00019159), "y"), + ((0.0, 0.038, -0.013831), (-0.27925, 0.0, 0.0), "x"), + ((0.0, 0.00624, -0.1032), (0, 0, 0), "z"), + ((0.015783, 0.0, -0.080518), (0, 0, 0), "y"), + ((0.100, 0.00188791, -0.010), (0, 0, 0), "x"), + ((0.038, 0.0, 0.0), (0, 0, 0), "y"), + ((0.046, 0.0, 0.0), (0, 0, 0), "z"), +] +# grasp point (between the finger tips) in the wrist_yaw frame +TIP = np.array([0.13, 0.0, 0.0]) + +LIM_LO = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443]) +LIM_HI = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443]) + + +def torso_T(waist): + """Pose (R, p) of torso_link in the pelvis frame from waist yaw, roll, pitch.""" + yaw, roll, pitch = waist + R = rz(yaw) + p = R @ np.array([-0.0039635, 0.0, 0.035]) + R = R @ rx(roll) + p = p + R @ np.array([0.0, 0.0, 0.019]) + R = R @ ry(pitch) + return R, p + + +def arm_fk(q, side, waist=(0.0, 0.0, 0.0), tip=TIP): + """Return (R, p) of the grasp point in the pelvis frame. + + side: +1 left, -1 right. + """ + R, p = torso_T(waist) + for (xyz, r, ax), a in zip(ARM, q): + xyz = np.array([xyz[0], side * xyz[1], xyz[2]]) + r = (side * r[0], r[1], side * r[2]) + p = p + R @ xyz + R = R @ rpy(*r) @ AXES[ax](a) + return R, p + R @ tip + + +def arm_points(q, side, waist=(0.0, 0.0, 0.0)): + """Positions (pelvis frame) of the elbow joint and the wrist roll joint.""" + R, p = torso_T(waist) + pts = [] + for i, ((xyz, r, ax), a) in enumerate(zip(ARM, q)): + xyz = np.array([xyz[0], side * xyz[1], xyz[2]]) + r = (side * r[0], r[1], side * r[2]) + p = p + R @ xyz + if i in (3, 4): + pts.append(p.copy()) + R = R @ rpy(*r) @ AXES[ax](a) + return pts + + +def rot_err(Ra, Rb): + """Rotation vector of Ra^T Rb (small-angle).""" + M = Ra.T @ Rb + return 0.5 * np.array([M[2, 1] - M[1, 2], M[0, 2] - M[2, 0], M[1, 0] - M[0, 1]]) + + +def arm_ik(p_target, R_target, side, q0, waist=(0.0, 0.0, 0.0), w_rot=0.3, + q_nom=None, w_nom=0.02, tip=TIP, free_axis=None, w_q=None, elbow_above=None): + """Least-squares IK for one arm. + + free_axis: optional unit vector (in the hand frame) about which rotation is + free (e.g. allow any roll about the finger axis). + """ + q0 = np.clip(np.asarray(q0, float), LIM_LO + 1e-3, LIM_HI - 1e-3) + if q_nom is None: + q_nom = q0 + q_nom = np.asarray(q_nom, float) + + def res(q): + R, p = arm_fk(q, side, waist, tip) + if free_axis is not None: + # only the free axis direction (hand frame) is constrained + e = R @ free_axis - R_target @ free_axis + else: + e = 0.5 * (R - R_target).T.reshape(-1) + out = [(p - p_target), w_rot * e, w_nom * (q - q_nom)] + if w_q is not None: + out.append(w_q * q) + if elbow_above is not None: + el, wr = arm_points(q, side, waist) + out.append([3.0 * max(0.0, wr[2] + elbow_above - el[2])]) + return np.concatenate(out) + + lo = LIM_LO.copy() + hi = LIM_HI.copy() + if side < 0: + # mirror: roll and yaw joints flip sign + lo, hi = lo.copy(), hi.copy() + for i in (1, 2, 4, 6): + lo[i], hi[i] = -LIM_HI[i], -LIM_LO[i] + sol = least_squares(res, q0, bounds=(lo, hi), xtol=1e-6, ftol=1e-8, max_nfev=200) + R, p = arm_fk(sol.x, side, waist, tip) + return sol.x, float(np.linalg.norm(p - p_target)) + + +SEEDS = [ + np.array([-0.5, 0.2, 0.0, 0.3, 0.0, 0.0, 0.0]), + np.array([-1.0, 0.3, 0.3, 0.8, 0.0, 0.5, 0.0]), + np.array([-0.3, 0.3, -1.0, 0.5, -1.5, 0.0, 0.0]), + np.array([-0.3, 0.3, 1.0, 0.5, 1.5, 0.0, 0.0]), + np.array([-1.2, 0.5, -1.5, 0.5, -1.0, 0.8, 0.5]), + np.array([-1.2, 0.5, 1.5, 0.5, 1.0, 0.8, -0.5]), + np.array([0.0, 0.2, 0.0, 1.2, -1.5, 0.0, 0.0]), + np.array([0.0, 0.2, 0.0, 1.2, 1.5, 0.0, 0.0]), +] + + +def arm_ik_multi(p_target, R_target, side, waist=(0.0, 0.0, 0.0), w_rot=1.0, extra=(), + free_axis=None): + """Multi-start IK; returns the solution with the smallest pose error.""" + best = None + mir = np.array([1, -1, -1, 1, -1, 1, -1]) if side < 0 else np.ones(7) + seeds = [np.asarray(s, float) * mir for s in SEEDS] + [np.asarray(s, float) for s in extra] + for s in seeds: + q, e = arm_ik(p_target, R_target, side, s, waist, w_rot=w_rot, q_nom=s, w_nom=0.005, + free_axis=free_axis) + R, _ = arm_fk(q, side, waist) + if free_axis is not None: + score = e + 0.1 * np.linalg.norm(R @ free_axis - R_target @ free_axis) + else: + score = e + 0.1 * np.linalg.norm(R - R_target) + if best is None or score < best[2]: + best = (q, e, score) + return best[0], best[1] diff --git a/policies/dishwasher_load_cutlery/opus-s3/policy.py b/policies/dishwasher_load_cutlery/opus-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..6f770290badc191ac1cd9bc3bb4801525df00560 --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s3/policy.py @@ -0,0 +1,378 @@ +"""Dishwasher cutlery loading policy for the G1 (hand-written state machine). + +The knife and fork stand in a mug on the counter in front of the robot; the +open dishwasher with its cutlery basket is to the robot's left. + +Pipeline + 1. raise the arms, walk to the counter, locate the mug with the head camera; + 2. for the left hand, then the right hand: stand so the mug is in front of + that hand, sweep the open gripper (fingers level) over the top of the mug + just above the rim, steering sideways with the wrist camera, close it on + the protruding cutlery and pull it out; + 3. turn to the dishwasher, squat and open both grippers above the basket. +""" + +import os +import sys + +import numpy as np + +sys.path.append(os.path.dirname(os.path.abspath(__file__))) +from kin import arm_fk, arm_ik, ry, rz # noqa: E402 +from vision import find_mug, pixel_on_plane, wrist_mug # noqa: E402 + +MIR = np.array([1, -1, -1, 1, -1, 1, -1]) +Q_ELBOW_OUT = np.array([-1.29, 1.41, -1.37, -0.61, -1.59, -0.22, 1.02]) +FLIP_Y = np.array([1.0, -1.0, 1.0]) + +COUNTER_Z = 0.838 # counter top height (world), consistent with the head camera model +LOOK_X = 0.10 # pelvis x for the first mug detection (world) +LOOK_PITCH = -0.2 # lean back while looking for the mug +REACH = 0.47 # forward distance pelvis -> mug centre for the sweep grasp +SIDE_OFF = 0.12 # mug lateral offset (pelvis frame) toward the grasping hand +SWEEP_Z = 0.985 # world height of the level fingers (above the rim) +SWEEP_BACK = 0.13 # pre-grasp distance behind the grasp point +SWEEP_FWD = 0.02 # grasp point relative to the mug centre (along the heading) +PULL = (-0.08, 0.20) # pull-out motion (forward, up) +PULL_PITCH = -0.15 # lean back while pulling (counters the forward sag) +MUG_R = 0.04 # mug radius: the base pixel is the front of the mug +MUG_D = 0.08 # mug diameter (for the wrist-camera lateral correction) +U_STAR = 42.0 # wrist image column of the gripper mid-plane +CARRY = np.array([0.33, 0.15, 0.30]) # level carry pose of the left tip (pelvis frame) +HOLD_L = np.array([0.33, 0.22, 0.30]) # left tip holding cutlery during the right grasp +CARRY_LOW = np.array([0.30, 0.15, 0.15]) # tips while turning away from the counter +BACK_D = 0.15 # step back from the counter before turning +TURN_WZ = 0.25 # yaw rate while carrying the cutlery +BASKET = np.array([0.20, -0.23]) # cutlery basket centre (world xy; top z ~0.3, x ~0..0.4) +STAND_Y = -0.475 # pelvis y in front of the dishwasher before squatting +DROP_HI = np.array([0.40, 0.06, 0.08]) # left tip while walking to the dishwasher +DROP = np.array([0.50, 0.06, -0.10]) # left tip above the basket (pelvis frame; x set from the pose) +DROP_MAX_FWD = 0.57 # reach limit for the drop (level fingers, 0.7 rad lean) +SQUAT = 0.65 # pelvis height for the drop (the pelvis also moves back ~0.17) +DROP_PITCH = 0.7 # lean forward for the drop +DROP_PITCH_R = 1.3 # right fingers pitched down for the drop +DW_YAW = np.pi / 2 +EMPTY_GRIP = 0.95 # gripper state above this after closing = nothing grasped +RETRY_OFFS = (0.05, -0.05) # lateral offsets for repeated sweeps (a lone knife leans) +RETRY_DZ = 0.02 # repeated sweeps go a bit lower +RETRY_T_MAX = 1550 # no new grasp attempt after this step (time to reach the dishwasher) +MAX_DQ = 0.04 # max arm joint command change per step (rad) + + +def lerp(a, b, s): + s = min(max(s, 0.0), 1.0) + return a + (b - a) * s + + +def mirror(p, side): + return p if side > 0 else p * FLIP_Y + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.t = 0 + self.phase = "lift" + self.t_phase = 0 + lo = obs["low_dim_obs"] + self.start = lo[21:25].copy() + self.q = {1: Q_ELBOW_OUT.copy(), -1: Q_ELBOW_OUT * MIR} + for s in (1, -1): + self.q[s], _ = self.ik(s, mirror(CARRY, s), np.eye(3), self.q[s], lo[0:3]) + self.grip = {1: 0.6, -1: 0.6} + self.pitch = 0.0 + self.height = 0.74 + self.mug_obs = [] + self.mug = None + self.base_target = None + self.q_cmd = None + self.side = 1 + self.y_corr = 0.0 + self.z_corr = 0.0 + self.y_bias = 0.0 + self.tries = 0 + self.held = {1: False, -1: False} + self.hand_from = {} + + # ----- helpers + @staticmethod + def ik(side, p, R, q0, waist, elbow=0.02): + return arm_ik(p, R, side, q0, waist, w_rot=1.0, elbow_above=elbow) + + def w2p(self, lo, pw): + x, y, z, yaw = lo[21], lo[22], lo[23], lo[24] + return rz(-yaw) @ (np.asarray(pw) - np.array([x, y, z])) + + def p2w(self, lo, pp): + x, y, z, yaw = lo[21], lo[22], lo[23], lo[24] + return rz(yaw) @ np.asarray(pp) + np.array([x, y, z]) + + def base_cmd(self, lo, target, vmax=0.2): + """Velocity command to reach a world (x, y, yaw) target.""" + x, y, yaw = lo[21], lo[22], lo[24] + tx, ty, tyaw = target + ex, ey = tx - x, ty - y + c, s = np.cos(yaw), np.sin(yaw) + bx, by = c * ex + s * ey, -s * ex + c * ey + vx = np.clip(1.5 * bx, -vmax, vmax) + vy = np.clip(1.5 * by, -vmax, vmax) + sp = np.hypot(vx, vy) + dist = np.hypot(bx, by) + if dist < 0.01: + vx = vy = 0.0 + elif sp < 0.08: + vx, vy = vx / sp * 0.08, vy / sp * 0.08 + eyaw = (tyaw - yaw + np.pi) % (2 * np.pi) - np.pi + wz = np.clip(1.2 * eyaw, -0.4, 0.4) + return vx, vy, wz, dist, abs(eyaw) + + def drive(self, a, lo, target, vmax=0.2): + vx, vy, wz, dist, eyaw = self.base_cmd(lo, target, vmax) + a[0], a[1], a[3] = vx, vy, wz + return dist, eyaw + + def arm_p(self, lo, side, p, R=np.eye(3), elbow=0.02): + """Move one tip to a pelvis-frame position (fingers level by default).""" + self.q[side], e = self.ik(side, p, R, self.q[side], lo[0:3], elbow) + return e + + def arm_w(self, lo, side, p_world, R_world): + return self.arm_p(lo, side, self.w2p(lo, p_world), rz(-lo[24]) @ R_world) + + def tip_p(self, lo, side): + q = lo[3:10] if side > 0 else lo[12:19] + return arm_fk(q, side, lo[0:3])[1] + + def tip_w(self, lo, side): + return self.p2w(lo, self.tip_p(lo, side)) + + def grip_state(self, lo, side): + return float(lo[50] if side > 0 else lo[51]) + + def goto(self, ph): + self.phase = ph + self.t_phase = 0 + + def detect_mug(self, lo, tools): + im = tools.image("head") + r = find_mug(im) + if r is None: + return + P = pixel_on_plane(lo[0:3], r[0], r[1], COUNTER_Z - lo[23]) + Pw = self.p2w(lo, P) + # the base pixel is the front of the mug: push back along the viewing ray + d = Pw[:2] - lo[21:23] + d /= np.linalg.norm(d) + self.mug_obs.append(Pw[:2] + MUG_R * d) + + def mug_stand(self, side): + return (self.mug[0] - REACH, self.mug[1] - side * SIDE_OFF, 0.0) + + # ----- main + def act(self, obs, tools): + a = self.hold.copy() + lo = obs["low_dim_obs"] + self.t += 1 + tp = self.t_phase + self.t_phase += 1 + ph = self.phase + s = self.side + other = -s + + if ph == "lift": + if tp >= 50: + self.goto("walk") + elif ph == "walk": + dist, _ = self.drive(a, lo, (LOOK_X, self.start[1], 0.0)) + if dist < 0.02 and tp > 50: + self.goto("look") + elif ph == "look": + self.pitch = LOOK_PITCH + if tp >= 30 and tp % 4 == 0: + self.detect_mug(lo, tools) + if tp >= 50: + self.pitch = 0.0 + if not self.mug_obs: + # fall back to the typical mug position + self.mug_obs = [np.array([0.60, -0.62])] + m = np.median(np.array(self.mug_obs), axis=0) + self.mug = np.array([m[0], m[1], COUNTER_Z]) + print("mug1", np.round(self.mug, 3), "n", len(self.mug_obs)) + self.goto("approach") + elif ph == "approach": + dist, eyaw = self.drive(a, lo, self.mug_stand(s), vmax=0.12) + if s < 0: + self.arm_p(lo, 1, lerp(self.hand_from[1], HOLD_L, tp / 40)) + if (dist < 0.015 and eyaw < 0.03 and tp > 30) or tp > 300: + self.mug_obs = [] + self.goto("look2" if s > 0 else "pre") + if s < 0: + self.start_pre(lo) + elif ph == "look2": + self.pitch = LOOK_PITCH + if tp >= 30 and tp % 4 == 0: + self.detect_mug(lo, tools) + if tp >= 50: + self.pitch = 0.0 + if self.mug_obs: + m = np.median(np.array(self.mug_obs), axis=0) + self.mug = np.array([m[0], m[1], COUNTER_Z]) + print("mug2", np.round(self.mug, 3), "pelvis", np.round(lo[21:25], 3), "n", len(self.mug_obs)) + self.start_pre(lo) + self.goto("pre") + elif ph == "pre": + g = self.grasp_point() + pre = g - SWEEP_BACK * self.R_s[:, 0] + self.grip[s] = 0.0 + e = self.arm_w(lo, s, lerp(self.hand_from[s], pre, tp / 45), self.R_s) + if tp >= 60: + print("side", s, "pre ik err", round(e, 4), "tip", np.round(self.tip_w(lo, s), 3)) + self.goto("sweep") + elif ph == "sweep": + if tp % 4 == 0: + self.servo(lo, tools) + g = self.grasp_point() + pre = g - SWEEP_BACK * self.R_s[:, 0] + e = self.arm_w(lo, s, lerp(pre, g, tp / 60), self.R_s) + if tp >= 75: + print("side", s, "sweep ik err", round(e, 4), "tip", np.round(self.tip_w(lo, s), 3), + "corr", round(self.y_corr, 3), round(self.z_corr, 3)) + self.goto("close") + elif ph == "close": + self.grip[s] = 1.0 + if tp >= 30: + gs = self.grip_state(lo, s) + print("side", s, "grip state", round(gs, 3), "try", self.tries) + if gs >= EMPTY_GRIP and self.tries < len(RETRY_OFFS) and self.t < RETRY_T_MAX: + # closed on nothing: open, back off and sweep again shifted sideways + self.y_bias = RETRY_OFFS[self.tries] + self.tries += 1 + self.grip[s] = 0.0 + self.hand_from[s] = self.tip_w(lo, s) + self.goto("pre") + else: + self.goto("pull") + elif ph == "pull": + g = self.grasp_point() + self.pitch = PULL_PITCH + v = PULL[0] * self.R_s[:, 0] + np.array([0, 0, PULL[1]]) + self.arm_w(lo, s, lerp(g, g + v, tp / 100), self.R_s) + if tp >= 120: + gs = self.grip_state(lo, s) + self.held[s] = gs < 0.95 + print("side", s, "grip after pull", round(gs, 3), "tip", np.round(self.tip_w(lo, s), 3), + "waist", np.round(lo[0:3], 3)) + self.pitch = 0.0 + if gs >= EMPTY_GRIP and self.tries < len(RETRY_OFFS) and self.t < RETRY_T_MAX: + # lost it while pulling: sweep again + self.y_bias = RETRY_OFFS[self.tries] + self.tries += 1 + self.grip[s] = 0.0 + self.hand_from[s] = self.tip_w(lo, s) + self.goto("pre") + return self.finish(a) + self.hand_from = {1: self.tip_p(lo, 1), -1: self.tip_p(lo, -1)} + if s > 0: + self.side = -1 + self.y_corr = self.z_corr = self.y_bias = 0.0 + self.tries = 0 + self.goto("approach") + else: + self.goto("back") + elif ph == "back": + # step back from the counter slowly, bringing the hands in and down + if tp == 0: + self.back_xy = (lo[21] - BACK_D, lo[22]) + dist, _ = self.drive(a, lo, (self.back_xy[0], self.back_xy[1], 0.0), vmax=0.08) + for sd in (1, -1): + self.arm_p(lo, sd, lerp(self.hand_from[sd], mirror(CARRY_LOW, sd), tp / 80)) + if (tp > 80 and dist < 0.02) or tp > 250: + self.hand_from = {1: self.tip_p(lo, 1), -1: self.tip_p(lo, -1)} + print("backed t", self.t, "grip", np.round(lo[50:52], 2), "pelvis", np.round(lo[21:25], 3)) + self.goto("turn") + elif ph == "turn": + # turn toward the dishwasher in place, slowly + if tp == 0: + self.base_target = (BASKET[0], STAND_Y, DW_YAW) + a[3] = float(np.clip(1.0 * (DW_YAW - lo[24]), -TURN_WZ, TURN_WZ)) + for sd in (1, -1): + self.arm_p(lo, sd, mirror(CARRY_LOW, sd)) + if lo[24] > DW_YAW - 0.15 or tp > 400: + self.hand_from = {1: self.tip_p(lo, 1), -1: self.tip_p(lo, -1)} + print("turned t", self.t, "grip", np.round(lo[50:52], 2), "pelvis", np.round(lo[21:25], 3)) + self.goto("to_dw") + elif ph == "to_dw": + dist, eyaw = self.drive(a, lo, self.base_target, vmax=0.12) + for sd in (1, -1): + self.arm_p(lo, sd, lerp(self.hand_from[sd], mirror(DROP_HI, sd), tp / 60)) + if (dist < 0.015 and eyaw < 0.04 and tp > 60) or tp > 250: + print("at dw", np.round(lo[21:25], 3), "t", self.t, "grip", np.round(lo[50:52], 2)) + self.goto("squat") + elif ph == "squat": + self.height = lerp(0.74, SQUAT, tp / 80) + self.pitch = lerp(0.0, DROP_PITCH, tp / 80) + for sd in (1, -1): + self.arm_p(lo, sd, mirror(lerp(DROP_HI, self.drop_target(lo), tp / 80), sd), + R=self.drop_R(sd, tp / 80), elbow=None) + if tp >= 120: + print("squat tips", np.round(self.tip_w(lo, 1), 3), np.round(self.tip_w(lo, -1), 3), + "pelvis", np.round(lo[21:25], 3), "grip", np.round(lo[50:52], 2)) + self.drop_fixed = self.drop_target(lo) + self.goto("release") + elif ph == "release": + self.grip[1] = self.grip[-1] = 0.0 + for sd in (1, -1): + self.arm_p(lo, sd, mirror(self.drop_fixed, sd), R=self.drop_R(sd, 1.0), elbow=None) + if tp >= 60: + self.goto("done") + elif ph == "done": + # lift the hands straight up, clear of the cutlery + for sd in (1, -1): + self.arm_p(lo, sd, mirror(self.drop_fixed, sd) + np.array([0.0, 0.0, 0.12 * min(1.0, tp / 60)]), + R=self.drop_R(sd, 1.0), elbow=None) + return self.finish(a) + + def drop_R(self, side, s): + """Hand orientation for the drop: left level (holds its piece upright), right + pitched down (its piece lies along the fingers and is turned upright).""" + return np.eye(3) if side > 0 else ry(lerp(0.0, DROP_PITCH_R, s)) + + def drop_target(self, lo): + """Left tip target (pelvis frame) above the basket, from the measured pelvis pose.""" + rel = rz(-lo[24]) @ np.array([BASKET[0] - lo[21], BASKET[1] - lo[22], 0.0]) + fwd = float(np.clip(rel[0], 0.30, DROP_MAX_FWD)) + return np.array([fwd, DROP[1], DROP[2]]) + + def start_pre(self, lo): + self.hand_from[self.side] = self.tip_w(lo, self.side) + self.R_s = rz(lo[24]) + + def servo(self, lo, tools): + """Wrist-camera lateral correction and FK height correction during the sweep.""" + s = self.side + r = wrist_mug(tools.image("left_wrist" if s > 0 else "right_wrist")) + if r is not None: + u, w, top = r + if 12 <= w <= 70 and 8 < u < 76: + dy = -(u - U_STAR) * MUG_D / w + self.y_corr = float(np.clip(self.y_corr + 0.5 * dy, -0.06, 0.06)) + z = self.tip_w(lo, s)[2] + self.z_corr = float(np.clip(self.z_corr + 0.3 * (SWEEP_Z - z), -0.03, 0.03)) + + def grasp_point(self): + lat = self.R_s[:, 1] + return (np.array([self.mug[0], self.mug[1], SWEEP_Z + self.z_corr - (RETRY_DZ if self.tries else 0.0)]) + + SWEEP_FWD * self.R_s[:, 0] + (self.y_corr + self.y_bias) * lat) + + def finish(self, a): + """Fill in the posture and arm commands, rate-limiting the arm joints.""" + a[2] = self.height + a[4] = self.pitch + tgt = np.concatenate([self.q[1], self.q[-1]]) + if self.q_cmd is None: + self.q_cmd = np.asarray(self.hold[5:19], float).copy() + self.q_cmd = self.q_cmd + np.clip(tgt - self.q_cmd, -MAX_DQ, MAX_DQ) + a[5:19] = self.q_cmd + a[19] = self.grip[1] + a[20] = self.grip[-1] + return a diff --git a/policies/dishwasher_load_cutlery/opus-s3/vision.py b/policies/dishwasher_load_cutlery/opus-s3/vision.py new file mode 100644 index 0000000000000000000000000000000000000000..221b8d3b077ffdb8a7c2c3bcf6c785f736b0ee44 --- /dev/null +++ b/policies/dishwasher_load_cutlery/opus-s3/vision.py @@ -0,0 +1,178 @@ +"""Head-camera model and simple detectors.""" + +import numpy as np +from scipy import ndimage + +from kin import torso_T, rx, ry, rz + +# head camera in the torso frame: x, y, z, pitch, yaw, roll, focal(px) (fitted) +HEAD = [0.0477, 0.0219, 0.2466, 0.7933, -0.067, -0.0401, 73.1622] + + +def head_ray(waist, u, v, cam=HEAD): + """Ray (origin, unit dir) in the pelvis frame for pixel (u, v) (pixel centres at +0.5).""" + x, y, zc, pitch, yaw, roll, f = cam + Rt, pt = torso_T(waist) + Rc = Rt @ rz(yaw) @ ry(pitch) @ rx(roll) + pc = pt + Rt @ np.array([x, y, zc]) + d = Rc @ np.array([1.0, (42 - u) / f, (42 - v) / f]) + return pc, d / np.linalg.norm(d) + + +def head_project(waist, P, cam=HEAD): + x, y, zc, pitch, yaw, roll, f = cam + Rt, pt = torso_T(waist) + Rc = Rt @ rz(yaw) @ ry(pitch) @ rx(roll) + pc = pt + Rt @ np.array([x, y, zc]) + v = Rc.T @ (P - pc) + return np.array([42 - f * v[1] / v[0], 42 - f * v[2] / v[0]]) + + +def pixel_on_plane(waist, u, v, z_plane): + """Intersect the pixel ray with the horizontal plane z = z_plane (pelvis frame).""" + pc, d = head_ray(waist, u, v) + s = (z_plane - pc[2]) / d[2] + return pc + s * d + + +def counter_edge_row(im): + col = im[:, 30:55].astype(int).mean(1) + brown = (col[:, 0] - col[:, 2] > 35) & (col[:, 0] < 200) + rows = np.nonzero(brown)[0] + return int(rows.min()) if len(rows) else None + + +def wrist_mug(im): + """Mug body in a wrist image (level hand): (u_centre, width, top_row) or None. + + The mug renders pure gray (saturation ~0); the counter is yellowish or + saturated white, the wall blue. + """ + a = im.astype(int) + sat = a.max(2) - a.min(2) + val = a.max(2) + m = (sat <= 8) & (val >= 90) & (val <= 240) + lab, n = ndimage.label(m) + if n == 0: + return None + sizes = ndimage.sum(m, lab, range(1, n + 1)) + l = 1 + int(np.argmax(sizes)) + if sizes[l - 1] < 60: + return None + blob = lab == l + cols = blob.sum(0) + body = np.nonzero(cols >= 0.5 * cols.max())[0] + w = float(body.max() - body.min() + 1) + rows = blob[:, body.min():body.max() + 1].sum(1) + top = np.nonzero(rows >= 0.6 * w)[0] + top = int(top.min()) if len(top) else 0 + return (body.min() + body.max() + 1) / 2.0, w, top + + +def wrist_stick(im, mug, dz_rows, u_ref=42.0): + """Column where a stick protruding from the mug crosses the grasp height. + + im: level wrist image; mug: (u, w, top) from wrist_mug; dz_rows: grasp + height above the rim in pixels. Picks the stick closest to u_ref. + Returns (u_at_grasp_row, n_pixels) or None. + """ + u_m, w, top = mug + if top < 6: + return None + a = im.astype(int) + sat = a.max(2) - a.min(2) + val = a.max(2) + m = (sat <= 14) & (val >= 60) & (val <= 235) + m[top - 1:, :] = False + ys, xs = np.nonzero(m) + if len(ys) < 6: + return None + # group columns near the rim into segments, one per stick + band = ys >= top - 8 + if band.sum() < 3: + band = np.ones_like(ys, bool) + cols = np.zeros(84, int) + np.add.at(cols, xs[band], 1) + segs = [] + c = 0 + while c < 84: + if cols[c] > 0: + c0 = c + while c < 84 and cols[c] > 0: + c += 1 + segs.append((c0, c - 1)) + c += 1 + best = None + for c0, c1 in segs: + cen = (c0 + c1 + 1) / 2.0 + if best is None or abs(cen - u_ref) < abs(best[0] - u_ref): + best = (cen, c0, c1) + cen, c0, c1 = best + # follow that stick upward: pixels within a widening window around its line + sel = (xs >= c0 - 3) & (xs <= c1 + 3) & (ys >= top - 8) + xs_s, ys_s = xs[sel], ys[sel] + for _ in range(3): + if len(ys_s) >= 4 and ys_s.max() - ys_s.min() >= 3: + A = np.stack([np.ones_like(ys_s), ys_s], 1).astype(float) + k = np.linalg.lstsq(A, xs_s.astype(float), rcond=None)[0] + else: + k = np.array([cen, 0.0]) + pred = k[0] + k[1] * ys + sel = np.abs(xs - pred) <= 3 + xs_s, ys_s = xs[sel], ys[sel] + y_g = max(0.0, top - dz_rows) + return float(k[0] + k[1] * y_g), int(len(ys_s)) + + +def stick_lean(im, row_max=45): + """Lean of a gray stick above the mug in a level wrist image. + + Returns the lateral slope (image columns per row, + = top leans to the + image right) of the gray pixels in the upper part of the image, or None. + """ + a = im[:row_max].astype(int) + sat = a.max(2) - a.min(2) + val = a.max(2) + m = (sat <= 14) & (val >= 70) & (val <= 230) + ys, xs = np.nonzero(m) + if len(ys) < 25: + return None + # robust line fit x = c0 + c1 * y + A = np.stack([np.ones_like(ys), ys], 1).astype(float) + c = np.linalg.lstsq(A, xs.astype(float), rcond=None)[0] + for _ in range(2): + r = np.abs(A @ c - xs) + keep = r < max(3.0, np.percentile(r, 70)) + c = np.linalg.lstsq(A[keep], xs[keep].astype(float), rcond=None)[0] + return -float(c[1]) + + +def find_mug(im): + """Return (u_center, v_bottom, mask) of the mug (gray, unsaturated blob above the counter edge).""" + a = im.astype(int) + edge = counter_edge_row(im) + if edge is None: + return None + sat = a.max(2) - a.min(2) + val = a.max(2) + m = (sat < 22) & (val > 60) & (val < 215) + m[edge - 1:, :] = False + lab, n = ndimage.label(m) + best = None + for l in range(1, n + 1): + ys, xs = np.nonzero(lab == l) + if len(ys) < 12: + continue + cx = xs.mean() + # skip the wrists in the top corners + if cx < 12 or cx > 72: + continue + score = len(ys) + if best is None or score > best[0]: + best = (score, ys, xs) + if best is None: + return None + _, ys, xs = best + vb = ys.max() + sel = ys >= vb - 2 + return float(xs[sel].mean() + 0.5), float(vb + 1.0), (ys, xs) diff --git a/policies/dishwasher_load_plates/astra-s1/episodes.csv b/policies/dishwasher_load_plates/astra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..047bcf68000eb2fe409bddbada3a02f739fe8b69 --- /dev/null +++ b/policies/dishwasher_load_plates/astra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,657,terminated,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,1,1484,success,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,676,terminated,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,701,terminated,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,668,terminated,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,677,terminated,0 +620071,0,705,terminated,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,658,terminated,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,775,terminated,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,1,1494,success,0 diff --git a/policies/dishwasher_load_plates/astra-s1/policy.py b/policies/dishwasher_load_plates/astra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..deb18ec1b44607c589f7e9c50d11c45e18955eb2 --- /dev/null +++ b/policies/dishwasher_load_plates/astra-s1/policy.py @@ -0,0 +1,76 @@ +"""Deterministic two-handed dish transfer with closed-loop base positioning.""" +import numpy as np +from scipy.spatial.transform import Rotation + + +def arm_pose(shoulder, yaw, orientation=-0.5, elbow=0.): + wrist = (Rotation.from_euler('Y', -elbow) + * Rotation.from_euler('Z', -yaw) + * Rotation.from_euler('Y', orientation - shoulder)) + roll, pitch, turn = wrist.as_euler('XYZ') + return [shoulder, 0., yaw, elbow, roll, pitch, turn] + + +class Policy: + place_y = .1 + place_shoulder = -1.2 + place_elbow = 1.2 + place_orientation = 1.0 + + def reset(self, obs, tools): + self.action = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.action[19:] = 0. + self.action[5:12] = arm_pose(-.5, -.3) + self.action[12:19] = arm_pose(-.4, .5) + + def navigate(self, a, obs, target, speed=.12): + p = obs['low_dim_obs'][21:25] + error = np.asarray(target) - p[:2] + v = np.clip(error * 2., -speed, speed) + v = np.where(abs(error) < .008, 0., np.sign(error) * np.maximum(abs(v), .065)) + c, s = np.cos(p[3]), np.sin(p[3]) + a[:2] = [c*v[0] + s*v[1], -s*v[0] + c*v[1]] + a[3] = np.clip(-2.*p[3], -.15, .15) + + def act(self, obs, tools): + t = int(obs['t']) + a = self.action.copy() + a[:2] = 0. + a[3] = 0. + # Approach with open fingers; use measured pelvis pose to reject drift. + if t < 280: + self.navigate(a, obs, [.16, -.64]) + elif t < 310: + pass + # Clamp, then lift and separate the hands with wrist compensation. + elif t < 370: + a[19:] = 1. + elif t < 490: + f = min(1., (t-370)/100.) + a[5:12] = arm_pose(-.5-.4*f, -.3*(1.-f)) + a[12:19] = arm_pose(-.4-.4*f, .5*(1.-f)) + # Clear the counter before moving across the open dishwasher door. + elif t < 810: + self.navigate(a, obs, [-.45, -.64]) + elif t < 1210: + self.navigate(a, obs, [-.45, self.place_y], .18) + elif t < 1211: + pass + # Lower slowly into the basket, rotating the grips down during insertion. + elif t < 1431: + f = min(1., (t-1211)/180.) + a[2] = .74-.34*f + a[4] = .8*f + a[5:12] = arm_pose(-.9+(self.place_shoulder+.9)*f, 0., -.5+(self.place_orientation-.3)*f, self.place_elbow*f) + a[12:19] = arm_pose(-.8+(self.place_shoulder+.8)*f, 0., -.5+(self.place_orientation-.3)*f, self.place_elbow*f) + # Allow the plates to settle before withdrawing the open hands. + elif t < 1571: + a[19:] = 0. + elif t < 1771: + f = min(1., (t-1571)/150.) + a[2] = .4+.34*f + a[4] = .8*(1.-f) + a[5:12] = arm_pose(self.place_shoulder+(-.9-self.place_shoulder)*f, 0., (self.place_orientation-.8)+(-.5-self.place_orientation+.8)*f, self.place_elbow*(1.-f)) + a[12:19] = arm_pose(self.place_shoulder+(-.8-self.place_shoulder)*f, 0., (self.place_orientation-.8)+(-.5-self.place_orientation+.8)*f, self.place_elbow*(1.-f)) + self.action = a.copy() + return a diff --git a/policies/dishwasher_load_plates/astra-s2/episodes.csv b/policies/dishwasher_load_plates/astra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..91775bab2cd6092b6bc715426823ac715c3fce0d --- /dev/null +++ b/policies/dishwasher_load_plates/astra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,1547,terminated,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,1,1969,success,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,967,terminated,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,948,terminated,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,783,terminated,0 +620028,0,856,terminated,0 +620029,1,1509,success,0 +620030,0,1027,terminated,0 +620031,0,1585,terminated,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,1153,terminated,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,906,terminated,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,1012,terminated,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,851,terminated,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,1,1449,success,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,847,terminated,0 +620073,0,1214,terminated,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,1549,terminated,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,943,terminated,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/astra-s2/policy.py b/policies/dishwasher_load_plates/astra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..5ff9cfa1abe6827e025e6e40a431e280a5ed1dbc --- /dev/null +++ b/policies/dishwasher_load_plates/astra-s2/policy.py @@ -0,0 +1,141 @@ +"""Deterministic, camera-guided two-handed plate transfer. + +The controller uses wrist-image segmentation to align each grasp, pelvis +feedback for navigation, and a staged squat and release into the lower rack. +All gains and joint poses are hand-tuned constants; there are no fitted models. +""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.a = np.array(tools.hold_action(), dtype=float) + self.phase = 0 + self.start = 0 + self.y0 = float(obs['low_dim_obs'][22]) + self.target_y = self.y0 + 0.04 + self.qleft = np.array([-.5, -.04, 0, 0, 0, 0, 0.]) + self.qright = np.array([-.5, .08, 0, 0, 0, 0, 0.]) + self.err = [0., 0.] + + @staticmethod + def plate(im, side): + # Neutral ceramic pixels stand out from the blue wall and wood rack. + rgb = im.astype(float) + mask = (rgb.max(2) - rgb.min(2) < 27) & (rgb[:, :, 0] > 100) + centers = [] + for y in (5, 10, 15, 20, 25, 30, 35): + edges = np.diff(np.r_[False, mask[y], False].astype(int)) + starts = np.where(edges == 1)[0] + ends = np.where(edges == -1)[0] + runs = [(s, e) for s, e in zip(starts, ends) + if e - s >= 2 and s < 80 and e > 4] + if runs: + s, e = runs[0 if side == 0 else -1] + centers.append((s + e - 1) * .5) + return np.median(centers) if centers else None + + def align(self, tools): + for side, q in enumerate((self.qleft, self.qright)): + camera = ('left_wrist', 'right_wrist')[side] + x = self.plate(tools.image(camera), side) + if x is not None: + error = 42 - x + self.err[side] = float(error) + q[1] = np.clip(q[1] + np.clip(error * .0002, -.004, .004), + -.12, .12) + q[2] = np.clip(q[2] + np.clip(error * .0006, -.012, .012), + -.45, .45) + + def walk(self, obs, x, y, yaw=0., speed=.18): + pose = obs['low_dim_obs'][21:25] + error = np.array([x, y]) - pose[:2] + c, s = np.cos(pose[3]), np.sin(pose[3]) + velocity = np.clip(1.8 * error, -speed, speed) + if np.linalg.norm(error) < .01: + velocity *= 0 + elif np.linalg.norm(velocity) < .065: + velocity *= .065 / (np.linalg.norm(velocity) + 1e-8) + self.a[0] = c * velocity[0] + s * velocity[1] + self.a[1] = -s * velocity[0] + c * velocity[1] + self.a[3] = np.clip(2 * (yaw - pose[3]), -.25, .25) + return np.linalg.norm(error) < .018 and abs(yaw - pose[3]) < .04 + + def act(self, obs, tools): + t = obs['t'] + elapsed = t - self.start + self.a[[0, 1, 3]] = 0 + height, pitch, grip = .74, 0., 0. + advance = False + + if self.phase == 0: + advance = elapsed > 80 + elif self.phase == 1: + advance = self.walk(obs, .025, self.target_y) and elapsed > 70 + elif self.phase == 2: + if elapsed % 5 == 0: + self.align(tools) + advance = elapsed > 100 + elif self.phase == 3: + if elapsed % 5 == 0: + self.align(tools) + advance = elapsed > 240 or ( + self.walk(obs, .15, self.target_y, speed=.075) and elapsed > 75) + elif self.phase == 4: + if elapsed < 80 and elapsed % 5 == 0: + self.align(tools) + advance = elapsed > 100 + elif self.phase == 5: + grip = 1. + advance = elapsed > 55 + elif self.phase == 6: + grip = 1. + advance = elapsed > 80 + elif self.phase == 7: + grip = 1. + advance = elapsed > 280 or ( + self.walk(obs, -.48, self.target_y, speed=.20) and elapsed > 80) + elif self.phase == 8: + grip = 1. + advance = elapsed > 340 or ( + self.walk(obs, -.48, 0, speed=.22) and elapsed > 80) + elif self.phase == 9: + grip = 1. + advance = elapsed > 180 or ( + self.walk(obs, -.35, 0, speed=.14) and elapsed > 80) + elif self.phase == 10: + grip, height, pitch = 1., .4, .5 + advance = elapsed > 140 + elif self.phase == 11: + height, pitch = .4, .5 + advance = elapsed > 45 + + left, right = self.qleft.copy(), self.qright.copy() + if self.phase >= 6: + # Lift clear of the dish-rack tines while keeping the wrists level. + left[0] = right[0] = -1.1 + left[5] = right[5] = .6 + if 10 <= self.phase <= 11: + left[0] = right[0] = -.5 + left[5] = right[5] = -.5 + # Bring the plates to separated insertion positions, compensating + # wrist roll and yaw for the lateral repositioning of each arm. + for q, roll, yaw in ((left, -.10, -.19), (right, .12, .19)): + q[4] = np.clip(q[1] - roll, -.25, .25) + yaw_change = q[2] - yaw + q[6] = np.clip(yaw_change, -.4, .4) if abs(yaw_change) < .3 else 0. + q[1], q[2] = roll, yaw + if self.phase >= 12: + left[:] = 0 + right[:] = 0 + + target = self.a.copy() + target[2], target[4] = height, pitch + target[5:12], target[12:19] = left, right + self.a[2:3] += np.clip(target[2:3] - self.a[2:3], -.003, .003) + self.a[4:19] += np.clip(target[4:19] - self.a[4:19], -.012, .012) + self.a[19:21] = grip + if advance: + self.phase += 1 + self.start = t + return self.a.copy() diff --git a/policies/dishwasher_load_plates/astra-s3/episodes.csv b/policies/dishwasher_load_plates/astra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..62a2708b15d77cdf3d2f56773b2334ffc6cee400 --- /dev/null +++ b/policies/dishwasher_load_plates/astra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,1,2080,success,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,1039,terminated,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,1,2080,success,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,1916,terminated,0 +620025,0,3150,timeout,0 +620026,0,851,terminated,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,895,terminated,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,1926,terminated,0 +620038,0,3150,timeout,0 +620039,0,1338,terminated,0 +620040,1,2085,success,0 +620041,1,2062,success,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,1190,terminated,0 +620066,0,781,terminated,0 +620067,1,1940,success,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,2031,terminated,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,1093,terminated,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,1,2075,success,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,787,terminated,0 +620093,0,3150,timeout,0 +620094,0,1039,terminated,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,784,terminated,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/astra-s3/policy.py b/policies/dishwasher_load_plates/astra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..9ea3c8a923375f35212bc9ea3122a7057bc41bdd --- /dev/null +++ b/policies/dishwasher_load_plates/astra-s3/policy.py @@ -0,0 +1,72 @@ +"""Deterministic, hand-written plate-loading controller. + +Pose targets are manually tuned physical joint angles. Smooth interpolation +handles reaching, lifting clear of the dish rack, lowering, and release. +Base motion is closed-loop on the observed pelvis position and yaw. +No demonstration files, fitted models, or external state are used at runtime. +""" +import numpy as np + +class Policy: + """Reach, grasp, lift, navigate, lower, and release each plate.""" + + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=float) + self.phase = 0 + self.tick = 0 + self.start = self.a.copy() + self.stable = 0 + self.stages = [ + ('pose', 150, {5: -0.8, 12: -0.8, 8: 0.3, 15: 0.3, 6: -0.08, 13: 0.06, 19: 0, 20: 0}), + ('nav', 240, (0.075, -0.62, 0.05)), + ('pose', 100, {4: 0.35, 5: -0.97, 12: -0.97}), + ('pose', 70, {19: 1, 20: 1}), + ('pose', 130, {5: -1.65, 12: -1.65, 10: 0.68, 17: 0.68}), + ('pose', 90, {4: 0, 5: -1.48, 12: -1.48}), + ('nav', 320, (-0.62, -0.605, 0)), + ('nav', 350, (-0.62, 0.0, 0)), + ('nav', 260, (-0.33, 0.0, 0)), + ('pose', 180, {2: 0.5, 4: 0.6, 5: -1.8, 12: -1.8, 8: 1.2, 15: 1.2, 10: -0.278019, 17: -0.266509, 6: 0.35, 13: 0.35, 9: -0.178048, 16: -0.391801, 11: 0.408403, 18: -0.760477}), + ('pose', 240, {2: 0.4, 4: 0.8, 8: 1.6, 15: 1.6, 10: -0.870109, 17: -0.825871, 9: -0.210772, 16: -0.515978, 11: 0.335992, 18: -1.004926}), + ('pose', 140, {19: 0.25}), + ('pose', 140, {20: 0.25}), + ('pose', 120, {}), + ('pose', 100, {19: 0, 20: 0}), + ('pose', 100, {}), + ('pose', 160, {2: 0.6, 5: -0.8, 12: -0.8, 8: 0.6, 15: 0.6, 10: -1.1, 17: -1.1}), + ('pose', 160, {6: 0, 13: 0, 9: 0, 16: 0, 11: 0, 18: 0, 19: 0, 20: 0, 2: 0.65, 4: 0.2, 5: 0, 12: 0, 8: 0, 15: 0, 10: 0, 17: 0}), + ] + + def act(self, obs, tools): + if self.phase >= len(self.stages): + return self.a + kind, duration, target = self.stages[self.phase] + self.tick += 1 + self.a[[0, 1, 3]] = 0 + if kind == 'pose': + f = min(1, self.tick / (duration * 0.75)) + f = f * f * (3 - 2 * f) + for k, v in target.items(): + self.a[k] = self.start[k] + (v - self.start[k]) * f + else: + pos = obs['low_dim_obs'][21:25] + err = np.asarray(target[:2]) - pos[:2] + yaw = pos[3] + rot = np.array([[np.cos(yaw), np.sin(yaw)], [-np.sin(yaw), np.cos(yaw)]]) + vel = rot @ err * 1.6 + speed = np.linalg.norm(vel) + if np.linalg.norm(err) > 0.018: + vel = vel / max(speed, 1e-06) * np.clip(speed, 0.065, 0.16) + self.a[:2] = vel + self.a[3] = np.clip((target[2] - yaw) * 2, -0.3, 0.3) + if np.linalg.norm(err) < 0.025 and abs(yaw - target[2]) < 0.04: + self.stable += 1 + else: + self.stable = 0 + if self.tick >= duration or (kind == 'nav' and self.stable >= 20): + self.phase += 1 + self.tick = 0 + self.stable = 0 + self.a[[0, 1, 3]] = 0 + self.start = self.a.copy() + return self.a.copy() diff --git a/policies/dishwasher_load_plates/deepseek1017-s1/episodes.csv b/policies/dishwasher_load_plates/deepseek1017-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2870178ebb17fedea06418a056bd8ec94f2f3b5c --- /dev/null +++ b/policies/dishwasher_load_plates/deepseek1017-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/deepseek1017-s1/policy.py b/policies/dishwasher_load_plates/deepseek1017-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..5faf0edd9bd3f47cc384b19c6ef93ccf78f65dbd --- /dev/null +++ b/policies/dishwasher_load_plates/deepseek1017-s1/policy.py @@ -0,0 +1,405 @@ +"""Hand-written control policy for the G1 "load plates into the dishwasher" task. + +Deterministic staged controller using only the robot's own cameras and +proprioception: + + 1. lean back a little so the wooden dish rack above the dishwasher is in view + 2. slowly sweep the left arm through the rack's workspace while scoring the + left wrist image for a bright plate surrounded by the brown rack + 3. local coordinate-descent on the arm joints to centre / approach the plate + 4. close the gripper, verify something is held, pull the plate out + 5. lower the plate to the dishwasher's lower rack, open, retreat + +No learned components: the image score and the search are hand written. +""" + +import os +import numpy as np +import cv2 + +# --------------------------------------------------------------------------- +LEFT = slice(5, 12) + +DEFAULT_HEIGHT = 0.74 +LOOK_PITCH = -0.15 + +# sweep over (elbow, shoulder yaw) while shoulder pitch moves through its range +SWEEP_EL = (0.10, 0.80, 1.50) +SWEEP_SY = (-0.30, 0.30) +SWEEP_ROLL = 0.15 +SWEEP_SP_LO = 0.35 +SWEEP_SP_HI = -1.70 +SWEEP_STEPS = 64 +SWEEP_TRANS = 12 +ARM_RATE = 0.065 + +# coordinate descent +LOCAL_STEPS = (0.09, 0.045) +LOCAL_COORDS = (0, 2, 3, 1) # shoulder pitch, shoulder yaw, elbow, roll +LOCAL_SETTLE = 7 + +# low insertion posture +LOW_HEIGHT = 0.55 +LOW_PITCH = 0.52 +LOW_ARM = (-0.20, 0.10, 0.00, 0.20, 0.0, 0.35, 0.0) +INSERT_ARM = (0.02, 0.10, 0.00, 0.05, 0.0, 0.45, 0.0) + + +def _masks(img): + hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV) + h, s, v = hsv[:, :, 0], hsv[:, :, 1], hsv[:, :, 2] + plate = (v > 140) & (s < 75) + wood = (h >= 5) & (h <= 30) & (s >= 60) & (v >= 45) & (v <= 225) + blue = (h >= 90) & (h <= 130) & (s >= 80) & (v >= 35) + return plate, wood, blue + + +def _score(img): + """Plate evidence near the brown wooden rack. + + The white dishwasher door / walls also pass the bright-colour test, so the + plate is only counted when it is close to detected wood. This biases the + arm search towards poses where the rack and the plate are both in view. + """ + plate, wood, _ = _masks(img) + h, w = plate.shape + pu = plate.astype(np.uint8) + wu = wood.astype(np.uint8) + kern = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (9, 9)) + near = float((pu & cv2.dilate(wu, kern)).mean()) + wa = float(wood.mean()) + central = float(plate[int(h * 0.20):int(h * 0.82), + int(w * 0.20):int(w * 0.82)].mean()) + return near + 0.50 * wa + 0.30 * central + + +def _visible(img): + plate, _, _ = _masks(img) + h, w = plate.shape + central = plate[int(h * 0.25):int(h * 0.80), int(w * 0.25):int(w * 0.80)] + return float(central.mean()), float(plate.mean()) + + +class Policy: + def __init__(self): + self.debug = bool(int(os.environ.get("POLICY_DEBUG", "0"))) + + # ------------------------------------------------------------------ + def reset(self, obs, tools): + self.t = 0 + self.phase = "calib_close" + self.phase_t = 0 + self.hold = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.arm = self.hold[LEFT].copy().astype(np.float64) + self.arm_target = self.arm.copy() + self.gripper = float(self.hold[19]) + self.height = float(self.hold[2]) + self.pitch = float(self.hold[4]) + self.best_score = -1e9 + self.best_arm = self.arm.copy() + self.grasp_arm = self.arm.copy() + self.sweep_i = 0 + self.sweep_dir = 1 + self.sweep_t = 0 + self.local_i = 0 + self.local_coord_i = 0 + self.local_dir = 1 + self.local_ref = None + self.local_target = None + self.retries = 0 + self.local_started = False + self._img_logged = False + ld = np.asarray(obs.get("low_dim_obs"), dtype=np.float64) + self.finger0 = ld[10:12].copy() if ld.size >= 12 else None + self.finger_closed = None + self.finger_open = None + self.pull_ref = None + + # ------------------------------------------------------------------ + def _rate(self, cur, tgt, rate): + return cur + np.clip(np.asarray(tgt) - cur, -rate, rate) + + def _set_arm(self, raw, vals=None): + if vals is not None: + self.arm_target = np.asarray(vals, dtype=np.float64).copy() + self.arm_target = np.clip(self.arm_target, -2.8, 2.8) + self.arm = self._rate(self.arm, self.arm_target, ARM_RATE) + raw[5:12] = self.arm + + def _save(self, img, tag): + if not self.debug: + return + try: + d = "/work/viz/live" + os.makedirs(d, exist_ok=True) + cv2.imwrite(os.path.join(d, f"{self.t:04d}_{tag}.png"), + cv2.cvtColor(img, cv2.COLOR_RGB2BGR)) + except Exception: + pass + + def _goto(self, phase): + self.phase = phase + self.phase_t = 0 + + # ------------------------------------------------------------------ + def act(self, obs, tools): + self.t += 1 + self.phase_t += 1 + + raw = self.hold.copy() + if bool(obs.get("fell", False)): + # already fallen: do not make anything worse + raw[0] = raw[1] = raw[3] = 0.0 + return raw + raw[0] = 0.0 + raw[1] = 0.0 + raw[3] = 0.0 + raw[20] = float(self.hold[20]) + + low_phase = self.phase in ("lower", "insert", "release", "retreat") + ht = LOW_HEIGHT if low_phase else DEFAULT_HEIGHT + pt = LOW_PITCH if low_phase else LOOK_PITCH + self.height = float(self._rate(self.height, ht, 0.006)) + self.pitch = float(self._rate(self.pitch, pt, 0.005)) + raw[2] = self.height + raw[4] = self.pitch + + try: + img = tools.image("left_wrist") + except Exception: + img = np.zeros((84, 84, 3), dtype=np.uint8) + + if self.phase == "calib_close": + self._set_arm(raw) + self.gripper = 1.0 + if self.phase_t >= 25 and self.finger_closed is None: + ld = np.asarray(obs.get("low_dim_obs"), dtype=np.float64) + if ld.size >= 12: + self.finger_closed = ld[10:12].copy() + self._goto("calib_open") + elif self.phase == "calib_open": + self._set_arm(raw) + self.gripper = 0.0 + if self.phase_t >= 20: + ld = np.asarray(obs.get("low_dim_obs"), dtype=np.float64) + if ld.size >= 12: + self.finger_open = ld[10:12].copy() + self._goto("look_up") + + elif self.phase == "look_up": + self._set_arm(raw) + if self.phase_t >= 30: + self._goto("sweep") + self.sweep_i = 0 + self.sweep_dir = 1 + self.sweep_t = 0 + self.best_score = -1e9 + self._set_arm(raw, self._sweep_vals(0.0, True)) + + elif self.phase == "sweep": + self.sweep_t += 1 + el = SWEEP_EL[self.sweep_i // len(SWEEP_SY)] + sy = SWEEP_SY[self.sweep_i % len(SWEEP_SY)] + if self.sweep_t == 1: + # move to the start of this sweep and to the new el/sy + sp = SWEEP_SP_LO if self.sweep_dir > 0 else SWEEP_SP_HI + self._set_arm(raw, self._sweep_vals(sp, True, el, sy)) + elif self.sweep_t <= SWEEP_TRANS + 10: + self._set_arm(raw) + # also nudge sp to the sweep start + sp = SWEEP_SP_LO if self.sweep_dir > 0 else SWEEP_SP_HI + self.arm_target[0] = sp + else: + n = self.sweep_t - (SWEEP_TRANS + 10) + frac = n / float(SWEEP_STEPS) + sp = SWEEP_SP_LO + (SWEEP_SP_HI - SWEEP_SP_LO) * frac + if self.sweep_dir < 0: + sp = SWEEP_SP_HI - (SWEEP_SP_HI - SWEEP_SP_LO) * frac + self._set_arm(raw, self._sweep_vals(sp, True, el, sy)) + if n % 2 == 0: + sc = _score(img) + if sc > self.best_score: + self.best_score = sc + self.best_arm = self.arm_target.copy() + if n >= SWEEP_STEPS: + self.sweep_i += 1 + self.sweep_t = 0 + self.sweep_dir *= -1 + if self.sweep_i >= len(SWEEP_EL) * len(SWEEP_SY): + self._goto("local") + if self.best_score < 0.12: + # nothing convincing found: start from a pose that + # points the left hand at the rack region seen in + # the demonstration + self.best_arm = np.array( + (-1.00, 0.15, 0.00, 0.60, 0.0, 0.0, 0.0), + dtype=np.float64) + self.arm = self.best_arm.copy() + self.arm_target = self.best_arm.copy() + self.local_i = 0 + self.local_coord_i = 0 + self.local_dir = 1 + self.local_ref = self.arm.copy() + self.local_target = self.arm.copy() + self.local_started = False + + elif self.phase == "local": + if not self.local_started: + # first settle at the best sweep pose so the reference score is + # measured at the pose the search starts from + self.arm_target = self.best_arm.copy() + self._set_arm(raw) + if self.phase_t >= 10: + self.arm = self.best_arm.copy() + self.arm_target = self.best_arm.copy() + self.local_ref = self.best_arm.copy() + self.local_coord_i = 0 + self.local_dir = 1 + self.local_i = 0 + self.best_score = _score(img) + self.local_target = self._local_candidate() + self.local_started = True + self.phase_t = 0 + else: + self._set_arm(raw, self.local_target) + if self.phase_t >= LOCAL_SETTLE + 6: + sc = _score(img) + if sc > self.best_score + 1e-5: + self.best_score = sc + self.local_ref = self.arm_target.copy() + # next coordinate, positive direction + self.local_coord_i += 1 + self.local_dir = 1 + if self.local_coord_i >= len(LOCAL_COORDS): + self.local_coord_i = 0 + self.local_i += 1 + if self.local_i >= len(LOCAL_STEPS): + self.best_arm = self.local_ref.copy() + self.arm = self.local_ref.copy() + self.arm_target = self.local_ref.copy() + self._goto("grasp") + else: + self.local_target = self._local_candidate() + else: + if self.local_dir > 0: + self.local_dir = -1 + self.local_target = self._local_candidate() + else: + self.local_dir = 1 + self.local_coord_i += 1 + if self.local_coord_i >= len(LOCAL_COORDS): + self.local_coord_i = 0 + self.local_i += 1 + if self.local_i >= len(LOCAL_STEPS): + self.best_arm = self.local_ref.copy() + self.arm = self.local_ref.copy() + self.arm_target = self.local_ref.copy() + self._goto("grasp") + else: + self.local_target = self._local_candidate() + self.phase_t = 0 + + elif self.phase == "grasp": + if self.phase_t == 1: + self.grasp_arm = self.arm_target.copy() + self._set_arm(raw) + self.gripper = min(1.0, self.gripper + 0.10) + if self.phase_t >= 22: + self._goto("pull") + + elif self.phase == "pull": + # extract the plate from the slot while keeping the grip shut + self.gripper = 1.0 + if self.phase_t == 1: + self.pull_ref = _visible(img) + a = self.grasp_arm.copy() + a[0] += 0.12 + a[3] -= 0.10 + self.arm_target = a.copy() + self._set_arm(raw) + if self.phase_t >= 18: + self._goto("verify") + + elif self.phase == "verify": + self._set_arm(raw) + self.gripper = 1.0 + if self.phase_t >= 10: + pc, pa = _visible(img) + held = False + if self.pull_ref is not None: + pc0, pa0 = self.pull_ref + if pa0 > 0.05: + held = (pa > 0.55 * pa0) or (pc > 0.60 * pc0 and pc > 0.10) + else: + held = pa > 0.10 + elif pc > 0.10 or pa > 0.25: + held = True + ld = np.asarray(obs.get("low_dim_obs"), dtype=np.float64) + if self.finger_closed is not None and ld.size >= 12: + dev = float(np.linalg.norm(ld[10:12] - self.finger_closed)) + if dev > 0.025: + held = True + if held or self.retries >= 2: + self._goto("retract") + else: + self.retries += 1 + self.gripper = 0.0 + # reopen and try a small perturbation of the best pose + a = self.grasp_arm.copy() + a[0] += 0.06 * self.retries + a[3] -= 0.06 * self.retries + self.arm = a + self.arm_target = a.copy() + self._goto("grasp") + + elif self.phase == "retract": + self.gripper = 1.0 + a = self.grasp_arm.copy() + a[0] += 0.22 + a[3] -= 0.18 + self._set_arm(raw, a) + if self.phase_t >= 50: + self._goto("lower") + + elif self.phase == "lower": + self.gripper = 1.0 + self._set_arm(raw, np.array(LOW_ARM, dtype=np.float64)) + if self.phase_t >= 150: + self._goto("insert") + + elif self.phase == "insert": + self.gripper = 1.0 + self._set_arm(raw, np.array(INSERT_ARM, dtype=np.float64)) + if self.phase_t >= 70: + self._goto("release") + + elif self.phase == "release": + self.gripper = max(0.0, self.gripper - 0.08) + self._set_arm(raw) + if self.phase_t >= 35: + self._goto("retreat") + + else: # retreat + self.gripper = 0.0 + self._set_arm(raw, np.array((-0.55, 0.10, 0.0, 0.45, 0.0, 0.15, 0.0))) + + raw[19] = float(np.clip(self.gripper, 0.0, 1.0)) + raw[5:12] = np.clip(self.arm, -2.8, 2.8) + raw[2] = float(np.clip(self.height, 0.40, 1.0)) + raw[4] = float(np.clip(self.pitch, -0.2, 0.8)) + return raw + + # ------------------------------------------------------------------ + def _sweep_vals(self, sp, reset=False, el=None, sy=None): + if reset or el is None: + el = SWEEP_EL[0] if self.sweep_i == 0 else SWEEP_EL[min(self.sweep_i // len(SWEEP_SY), len(SWEEP_EL) - 1)] + if reset or sy is None: + sy = SWEEP_SY[self.sweep_i % len(SWEEP_SY)] + return np.array((sp, SWEEP_ROLL, sy, el, 0.0, 0.0, 0.0), dtype=np.float64) + + def _local_candidate(self): + c = LOCAL_COORDS[self.local_coord_i] + step = LOCAL_STEPS[min(self.local_i, len(LOCAL_STEPS) - 1)] + a = self.local_ref.copy() + a[c] += self.local_dir * step + return np.clip(a, -2.8, 2.8) diff --git a/policies/dishwasher_load_plates/deepseek1017-s2/episodes.csv b/policies/dishwasher_load_plates/deepseek1017-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2870178ebb17fedea06418a056bd8ec94f2f3b5c --- /dev/null +++ b/policies/dishwasher_load_plates/deepseek1017-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/deepseek1017-s2/policy.py b/policies/dishwasher_load_plates/deepseek1017-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..3aef31e5f7200525b19c1b197f22918d369a8bbc --- /dev/null +++ b/policies/dishwasher_load_plates/deepseek1017-s2/policy.py @@ -0,0 +1,664 @@ +"""Hand-written control policy for the G1 dishwasher-load-plates task. + +Strategy (no learned components): + * lean the torso back a little (as in the demonstration) to bring the high + plate rack into the head/wrist views; + * find, for each arm, a joint-space direction that raises the hand toward the + rack by maximising a wrist-camera colour score (the rack/counter is warm, + the dishwasher door is neutral grey); + * perform a small haptic scan with the grippers (finger joint positions tell + us when the fingers close on an object) over hand height and lateral offset; + * lift, move back over the (nearby) dishwasher lower rack, squat and release. + +Everything is deterministic and uses only the robot's own cameras and body +state. All motion is deliberately slow and clamped. +""" + +import numpy as np +from scipy import ndimage as ndi + + +# --------------------------------------------------------------------------- +# small utilities + + +def _clip(x, lo, hi): + return max(lo, min(hi, x)) + + +def _img_feats(im): + """Colour statistics of one 84x84 RGB image (float32 in 0..255).""" + if im is None or im.size < 3: + return dict(warm=0.0, blue=0.0, white=0.0, dark=0.0, bright=0.0, score=0.0) + a = im.astype(np.float32) + r, g, b = a[..., 0], a[..., 1], a[..., 2] + br = (r + g + b) / 3.0 + warm = float((((r - b) > 25.0) & (br > 110.0) & (g > 90.0)).mean()) + blue = float(((b > r + 15.0) & (br > 45.0)).mean()) + white = float(((br > 145.0) & (np.abs(r - b) < 32.0)).mean()) + dark = float((br < 65.0).mean()) + bright = float(br.mean()) + score = white + dark + 0.5 * blue - 0.8 * warm + return dict(warm=warm, blue=blue, white=white, dark=dark, + bright=bright, score=float(score)) + + +# --------------------------------------------------------------------------- +# policy + + +class Policy: + def reset(self, obs, tools): + self.tools = tools + ld = np.asarray(obs["low_dim_obs"], dtype=np.float32).reshape(-1) + self.ld = ld + self.t = 0 + self.limit = int(obs.get("time_limit") or 1250) + hold = np.asarray(tools.hold_action(), dtype=np.float32).reshape(-1) + self.hold0 = hold.copy() + self.height0 = float(hold[2]) + self.pitch0 = float(hold[4]) + + # arm reference posture + self.qL0 = ld[3:10].astype(np.float32).copy() + self.qR0 = ld[12:19].astype(np.float32).copy() + self.qL = self.qL0.copy() + self.qR = self.qR0.copy() + + # finite joint safety windows (relative to reset posture) + self.sp_lo = np.maximum(self.qL0[0] - 1.9, -3.0) + self.sp_hi = np.minimum(self.qL0[0] + 1.9, 2.7) + self.el_lo = np.maximum(self.qL0[3] - 1.5, -1.2) + self.el_hi = np.minimum(self.qL0[3] + 1.5, 2.2) + + # pose reference in the world + self.x0 = float(ld[21]) + self.y0 = float(ld[22]) + self.yaw0 = float(ld[23]) + # reference pose used by base servoing (updated after the approach walk) + self.ax = self.x0 + self.ay = self.y0 + self.ayaw = self.yaw0 + + # gripper references (calibrated in the first few steps) + self.fp_open = ld[10:12].astype(np.float32).copy() + self.fp_closed = ld[10:12].astype(np.float32).copy() + self.g_open = 0.0 + self.g_close = 1.0 + self.calib_done = False + self.calib_close_t = 0 + self.fp_bad = False + + # phase machine + self.pitch_ref = _clip(self.pitch0 - 0.15, -0.2, 0.6) + self.phase = "calib" + self.k = 0 + self.phase_t = 0 + self.attempts = 0 + self.retry = False + self.got_contact = False + self.dir_attempt = 0 + + # approach + self.approach_done = False + self.good_warm = 0 + + # probing / raising + self.cands = [ + (1.0, -0.4, -0.6), + (-1.0, 0.4, 0.6), + (1.0, 0.4, -1.4), + (-1.0, -0.4, 1.4), + (1.0, -0.4, 0.0), + (-1.0, 0.4, 0.0), + ] + self.probe_i = 0 + self.probe_best = {0: (-1e9, 0), 1: (-1e9, 1)} # arm -> (score, cand) + self.probe_scores = {0: [0.0] * len(self.cands), 1: [0.0] * len(self.cands)} + self.probe_hold = 0 + self.dL = np.array([1.0, 0.0, 0.0, -0.4, 0.0, 0.0, 0.0], np.float32) + self.dR = np.array([1.0, 0.0, 0.0, -0.4, 0.0, 0.0, 0.0], np.float32) + self.s = 0.0 + self.s_best = 0.6 + self.warm_best = -1.0 + self.raise_t = 0 + + # scan + self.scan_points = [] # (ds, dpitch, dy) + self.scan_i = 0 + self.scan_state = "move" # move | open | close | wait + self.scan_sub_t = 0 + self.scan_contact = False + self.best_scan = None # (score, ds, dpitch, dy) + self.pitch_cmd = self.pitch0 + self.height_cmd = self.height0 + self.dy_cmd = 0.0 + self.dx_cmd = 0.0 + self.g_cmd = 0.0 + self.last_img = {"head": None, "left_wrist": None, "right_wrist": None} + self.img_t = -10 + + # transfer / place + self.wobble = 0.0 + + self._snap_images(force=True) + + # -- helpers ----------------------------------------------------------- + def _image(self, cam): + try: + return self.tools.image(cam) + except Exception: + return None + + def _snap_images(self, force=False): + if force or self.t - self.img_t >= 3: + for cam in self.last_img: + self.last_img[cam] = self._image(cam) + self.img_t = self.t + + def _get_ld(self, obs): + try: + return np.asarray(obs["low_dim_obs"], dtype=np.float32).reshape(-1) + except Exception: + return self.ld + + def _set_arm_targets(self, s_l, s_r): + dL, dR = self.dL, self.dR + ql = self.qL0 + dL * float(s_l) + qr = self.qR0 + dR * float(s_r) + ql[0] = _clip(ql[0], self.sp_lo, self.sp_hi) + qr[0] = _clip(qr[0], self.sp_lo, self.sp_hi) + ql[3] = _clip(ql[3], self.el_lo, self.el_hi) + qr[3] = _clip(qr[3], self.el_lo, self.el_hi) + # leave roll/yaw/wrist roll/yaw alone, clamp compensating wrist pitch + ql[1] = self.qL0[1] + ql[2] = self.qL0[2] + qr[1] = self.qR0[1] + qr[2] = self.qR0[2] + ql[5] = _clip(ql[5], self.qL0[5] - 1.10, self.qL0[5] + 1.10) + qr[5] = _clip(qr[5], self.qR0[5] - 1.10, self.qR0[5] + 1.10) + self.qL = ql.astype(np.float32) + self.qR = qr.astype(np.float32) + + def _finger_ratio(self, ld): + """1 = fingers fully open, 0 = closed (relative to calibration).""" + out = [] + for lo in (10, 19): + fp = ld[lo:lo + 2].astype(np.float32) + a = self.fp_open + b = self.fp_closed + denom = float(np.mean(np.abs(a - b))) + 1e-3 + r = float(np.mean(np.abs(fp - b))) / denom + out.append(_clip(r, -0.5, 2.0)) + return out + + def _move_base(self, raw, ld, dy=0.0, dx=0.0, speed=0.11): + """P-control in the world frame toward the reset pose + body offset.""" + yaw = float(ld[23]) + # desired world point = start + R(yaw0) * [dx, dy] + c, s = np.cos(self.ayaw), np.sin(self.ayaw) + tx = self.ax + c * dx - s * dy + ty = self.ay + s * dx + c * dy + ex = tx - float(ld[21]) + ey = ty - float(ld[22]) + # world error -> body frame + cy, sy = np.cos(yaw), np.sin(yaw) + vx = cy * ex + sy * ey + vy = -sy * ex + cy * ey + n = float(np.hypot(vx, vy)) + if n < 0.015: + vx = vy = 0.0 + else: + scale = min(speed, max(0.06, 0.75 * n)) / max(n, 1e-6) + vx *= scale + vy *= scale + raw[0] = _clip(vx, -0.2, 0.2) + raw[1] = _clip(vy, -0.2, 0.2) + # gently hold heading + raw[3] = _clip(-0.8 * (yaw - self.ayaw), -0.18, 0.18) + return float(np.hypot(ex, ey)) + + def _wrist_scores(self): + # "warm" = the cream/yellow counter and wooden rack; the neutral grey + # dishwasher door and blue floor score zero. This is the most reliable + # cue for pointing the wrist camera at the plate rack. + lf = _img_feats(self.last_img["left_wrist"]) + rf = _img_feats(self.last_img["right_wrist"]) + return (lf["warm"] + 0.25 * lf["white"], + rf["warm"] + 0.25 * rf["white"]) + + # -- act --------------------------------------------------------------- + def act(self, obs, tools): + self.t += 1 + self.phase_t += 1 + self.k += 1 + ld = self._get_ld(obs) + self.ld = ld + raw = np.asarray(tools.hold_action(), dtype=np.float32).reshape(-1).copy() + if raw.size < 21: + raw = np.resize(raw, 21) + if self.phase not in ("done", "retry_reset"): + self._snap_images() + + # default: hold height/pitch/arms, grippers open/closed as set + raw[2] = float(self.height_cmd) + raw[4] = float(self.pitch_cmd) + raw[5:12] = self.qL + raw[12:19] = self.qR + raw[19] = float(self.g_cmd) + raw[20] = float(self.g_cmd) + + # ---------------- calibration of grippers ------------------------- + if self.phase == "calib": + self.g_cmd = 0.0 + if self.phase_t == 4: + self.fp_open = ld[10:12].astype(np.float32).copy() + self._set_arm_targets(0.0, 0.0) + elif self.phase_t >= 5 and self.phase_t <= 16: + self.g_cmd = 1.0 + if self.phase_t == 15: + self.fp_closed = ld[10:12].astype(np.float32).copy() + if float(np.mean(np.abs(self.fp_open - self.fp_closed))) < 0.02: + self.fp_bad = True + elif self.phase_t > 16: + self.g_cmd = 0.0 + if self.phase_t >= 22: + self.phase = "approach" + self.phase_t = 0 + return raw + + # ---------------- walk up to the counter -------------------------- + if self.phase == "approach": + self.g_cmd = 0.0 + # Lean back slightly: this raises the hands and brings the high + # plate rack into the head/wrist views (as in the demonstration). + self.pitch_cmd = self.pitch_ref + raw[3] = _clip(-0.8 * (float(ld[23]) - self.ayaw), -0.15, 0.15) + if self.phase_t >= 18: + self.approach_done = True + self.ax = float(ld[21]) + self.ay = float(ld[22]) + self.ayaw = float(ld[23]) + self.phase = "probe" + self.phase_t = 0 + self.probe_i = 0 + self.probe_hold = 0 + self._set_arm_targets(0.0, 0.0) + return raw + + # ---------------- probe arm directions ---------------------------- + if self.phase == "probe": + self.g_cmd = 0.0 + ci = self.probe_i + if ci >= len(self.cands): + # pick the best direction for each arm + self.rankL = list(np.argsort(self.probe_scores[0])[::-1]) + self.rankR = list(np.argsort(self.probe_scores[1])[::-1]) + for arm in (0, 1): + ranks = self.rankL if arm == 0 else self.rankR + bi = int(ranks[0]) + dsp, delb, dwp = self.cands[bi] + d = np.zeros(7, np.float32) + d[0] = dsp + d[3] = delb + d[5] = dwp + if arm == 0: + self.dL = d + else: + self.dR = d + self.phase = "raise" + self.phase_t = 0 + self.raise_t = 0 + self.s = 0.0 + self.warm_best = -1.0 + self.s_best = 0.5 + self._set_arm_targets(0.0, 0.0) + return raw + + dsp, delb, dwp = self.cands[ci] + d = np.zeros(7, np.float32) + d[0] = dsp + d[3] = delb + d[5] = dwp + self.dL = d.copy() + self.dR = d.copy() + # move out for ~8 steps, hold 6, score, move back + if self.probe_hold == 0: + self.probe_hold = 1 + self.probe_sub = 0 + self.probe_sub = getattr(self, "probe_sub", 0) + 1 + if self.probe_sub <= 8: + ss = 0.30 * (self.probe_sub / 8.0) + elif self.probe_sub <= 14: + ss = 0.30 + elif self.probe_sub <= 20: + ss = 0.30 * (1.0 - (self.probe_sub - 14) / 6.0) + else: + ss = 0.0 + self._set_arm_targets(ss, ss) + if self.probe_sub == 13: + sl, sr = self._wrist_scores() + self.probe_scores[0][ci] = max(self.probe_scores[0][ci], sl) + self.probe_scores[1][ci] = max(self.probe_scores[1][ci], sr) + if self.probe_sub >= 22: + self.probe_i += 1 + self.probe_sub = 0 + self._set_arm_targets(0.0, 0.0) + return raw + + # ---------------- raise toward the rack --------------------------- + if self.phase == "raise": + self.g_cmd = 0.0 + self.raise_t += 1 + # ramp s, then settle at best value + ramp_steps = 36 if getattr(self, "retry", False) else 55 + if self.raise_t <= ramp_steps: + self.s = 1.15 * (self.raise_t / float(ramp_steps)) + else: + # choose best s observed + if self.warm_best > 0.10: + self.s = _clip(self.s_best, 0.25, 1.15) + else: + self.s = 0.95 + self._set_arm_targets(self.s, self.s) + if self.raise_t <= ramp_steps and self.raise_t % 3 == 0: + lf = _img_feats(self.last_img["left_wrist"]) + rf = _img_feats(self.last_img["right_wrist"]) + w = lf["warm"] + rf["warm"] + if w > self.warm_best: + self.warm_best = w + self.s_best = self.s + if self.raise_t >= ramp_steps + 8: + self.phase = "scan" + self.phase_t = 0 + self._build_scan() + self.scan_i = 0 + self.scan_state = "move" + self.scan_sub_t = 0 + self.ds_cmd = 0.0 + self.pitch_cmd = self.pitch_ref + self.height_cmd = self.height0 + self.dy_cmd = 0.0 + self.dx_cmd = 0.0 + self.g_cmd = 0.0 + return raw + + # ---------------- haptic scan ------------------------------------- + if self.phase == "scan": + return self._scan_step(raw, ld) + + # ---------------- lift / transfer / place ------------------------- + if self.phase == "lift": + self.phase_t += 1 + # retreat from the rack and lift + self._move_base(raw, ld, dy=float(getattr(self, "fb_dy", 0.0)), + dx=-0.06 + float(getattr(self, "fb_dx", 0.0)), + speed=0.10) + self.pitch_cmd = getattr(self, "fb_pitch", self.pitch_ref) - 0.10 * min(1.0, self.phase_t / 18.0) + self.s = _clip(getattr(self, "s_grab", self.s) + 0.16 * + min(1.0, self.phase_t / 20.0), 0.0, 1.3) + self._set_arm_targets(self.s, self.s) + self.g_cmd = 1.0 + if self.phase_t >= 26: + self.phase = "transfer" + self.phase_t = 0 + self.tx = _clip(self.ax - 0.03, self.ax - 0.12, self.ax + 0.12) + self.ty = self.ay + 0.06 + return raw + + if self.phase == "transfer": + self.phase_t += 1 + self.g_cmd = 1.0 + err = self._move_base(raw, ld, + dy=float(self.ty - self.ay), + dx=float(self.tx - self.ax), speed=0.18) + self.pitch_cmd = self.pitch_ref + self._set_arm_targets(self.s, self.s) + if err < 0.035 or self.phase_t >= 55: + self.phase = "aim" + self.phase_t = 0 + self.pitch_cmd = _clip(self.pitch_ref + 0.35, -0.2, 0.6) + return raw + + if self.phase == "aim": + self.phase_t += 1 + self.g_cmd = 1.0 + self.pitch_cmd = _clip(self.pitch_ref + 0.35, -0.2, 0.6) + self._set_arm_targets(self.s, self.s) + raw[0] = 0.0 + raw[1] = 0.0 + raw[3] = _clip(-0.8 * (float(ld[23]) - self.ayaw), -0.15, 0.15) + cx = self._rack_cx() + if cx is not None and self.phase_t > 8: + raw[1] = _clip(0.80 * (0.5 - cx), -0.18, 0.18) + if self.phase_t >= 55 or (cx is not None and self.phase_t > 16 and abs(cx - 0.5) < 0.05): + self.phase = "lower" + self.phase_t = 0 + self.hx = float(ld[21]) + self.hy = float(ld[22]) + self.low_s = None + return raw + + if self.phase == "lower": + self.phase_t += 1 + self.g_cmd = 1.0 + f = min(1.0, self.phase_t / 55.0) + self.height_cmd = self.height0 * (1.0 - f) + 0.48 * f + self.pitch_cmd = self.pitch_ref * (1.0 - f) + 0.46 * f + self.s = _clip(getattr(self, "s_grab", self.s) - 0.55 * f, -0.2, 1.3) + self._set_arm_targets(self.s, self.s) + # small forward shift to bring the hands over the pulled-out rack + self._move_base(raw, ld, + dy=float(getattr(self, "hy", self.ty) - self.ay), + dx=float(getattr(self, "hx", self.tx) - self.ax) + 0.03, + speed=0.08) + wl = _img_feats(self.last_img["left_wrist"]) + wr = _img_feats(self.last_img["right_wrist"]) + blue = 0.5 * (wl["blue"] + wr["blue"]) + if self.phase_t >= 58 or (self.phase_t > 50 and blue > 0.28): + self.phase = "release" + self.phase_t = 0 + return raw + + if self.phase == "release": + self.phase_t += 1 + self.g_cmd = 0.0 + self._set_arm_targets(self.s, self.s) + # hold low and still while the task condition latches + if self.phase_t > 60: + f = min(1.0, (self.phase_t - 60) / 40.0) + self.height_cmd = 0.48 * (1.0 - f) + max(0.62, self.height0) * f + self.pitch_cmd = 0.46 * (1.0 - f) + self.pitch_ref * f + self.s = _clip(self.s - 0.25 * f, -0.2, 1.3) + self._set_arm_targets(self.s, self.s) + if self.phase_t > 112: + self.phase = "done" + self.phase_t = 0 + return raw + + if self.phase == "retry_reset": + self.phase_t += 1 + self.g_cmd = 0.0 + self.height_cmd = self.height0 + self.pitch_cmd = self.pitch_ref + self._set_arm_targets(0.0, 0.0) + self._move_base(raw, ld, dy=0.0, dx=0.0, speed=0.12) + if self.phase_t >= 26: + if self.dir_attempt < 3: + self.dir_attempt += 1 + for arm in (0, 1): + ranks = self.rankL if arm == 0 else self.rankR + bi = int(ranks[min(self.dir_attempt, len(ranks) - 1)]) + dsp, delb, dwp = self.cands[bi] + d = np.zeros(7, np.float32) + d[0] = dsp + d[3] = delb + d[5] = dwp + if arm == 0: + self.dL = d + else: + self.dR = d + self.best_scan = None + self.warm_best = -1.0 + self.retry = True + self.phase = "raise" + self.phase_t = 0 + self.raise_t = 0 + self.s = 0.0 + self.warm_best = -1.0 + if hasattr(self, "s_best"): + self.s_best = _clip(self.s_best, 0.25, 1.15) + return raw + + # done: hold a safe standing pose + self.g_cmd = 0.0 + self.height_cmd = max(0.68, self.height0) + self.pitch_cmd = self.pitch_ref + if self.phase == "done": + self.phase_t += 1 + if (self.attempts < 1 and self.t < self.limit - 360 + and self.phase_t > 12): + self.attempts += 1 + self.phase = "retry_reset" + self.phase_t = 0 + return raw + + # -- scan helpers ------------------------------------------------------ + def _build_scan(self): + # (arm raise delta, torso pitch delta, lateral base offset, fwd offset) + pts = [(0.0, 0.0, 0.0, 0.0)] + pts.append((0.22, 0.0, 0.0, 0.0)) + pts.append((-0.22, 0.0, 0.0, 0.0)) + pts.append((0.0, 0.20, 0.0, 0.0)) + pts.append((0.0, -0.18, 0.0, 0.0)) + pts.append((0.0, 0.0, 0.0, 0.07)) + pts.append((0.0, 0.0, 0.0, -0.07)) + pts.append((0.0, 0.0, 0.12, 0.0)) + pts.append((0.0, 0.0, -0.12, 0.0)) + pts.append((0.36, 0.24, 0.0, 0.04)) + pts.append((-0.36, -0.12, 0.0, 0.0)) + pts.append((0.20, 0.18, 0.12, 0.0)) + pts.append((-0.55, 0.15, 0.0, 0.0)) + pts.append((0.55, -0.10, 0.0, 0.0)) + if getattr(self, "retry", False): + pts = [pts[0], pts[2], pts[4], pts[12], pts[13], pts[5]] + self.scan_points = pts + + def _rack_cx(self): + """Head-image x of the white dishwasher rack over the blue floor.""" + im = self.last_img.get("head") + if im is None: + return None + a = im.astype(np.float32) + r, g, b = a[..., 0], a[..., 1], a[..., 2] + br = (r + g + b) / 3.0 + blue = ((b > r + 15.0) & (br > 45.0)).astype(np.uint8) + white = (br > 140.0) & (np.abs(r - b) < 35.0) + if blue.sum() < 30: + return None + bd = ndi.binary_dilation(blue.astype(bool), iterations=3) + near = white & (bd > 0) + ys, xs = np.nonzero(near) + if len(xs) < 40: + return None + h, w = br.shape + cy = float(ys.mean()) / max(h - 1, 1) + if cy < 0.40: + return None + return float(xs.mean()) / max(w - 1, 1) + + def _scan_step(self, raw, ld): + n = len(self.scan_points) + if self.scan_i >= n: + # no contact: fall back to the visually best pose, try a blind grab + if getattr(self, "best_scan", None) is not None: + _, ds, dp, dy, dx = self.best_scan + self.s_grab = _clip(self.s + ds, 0.0, 1.2) + self.fb_dy = dy + self.fb_dx = dx + self.fb_pitch = _clip(self.pitch_ref + dp, -0.2, 0.6) + self._set_arm_targets(self.s_grab, self.s_grab) + self.pitch_cmd = self.fb_pitch + self.g_cmd = 1.0 + self.phase = "lift" + self.phase_t = 0 + return raw + self.phase = "lift" + self.phase_t = 0 + self.s_grab = self.s + self.fb_dy = 0.0 + self.fb_dx = 0.0 + self.fb_pitch = self.pitch_ref + return raw + + ds, dp, dy, dx = self.scan_points[self.scan_i] + if self.scan_state == "move": + self.scan_sub_t += 1 + self.g_cmd = 0.0 + self.pitch_cmd = _clip(self.pitch_ref + dp, -0.2, 0.6) + self.height_cmd = self.height0 + err = self._move_base(raw, ld, dy=dy, dx=dx, speed=0.18) + moving = abs(dy) > 1e-6 or abs(dx) > 1e-6 + need = 6 if not moving else 34 + if (moving and err < 0.025) or self.scan_sub_t >= need: + self.scan_state = "open" + self.scan_sub_t = 0 + self._set_arm_targets(_clip(self.s + ds, 0.0, 1.25), + _clip(self.s + ds, 0.0, 1.25)) + return raw + + if self.scan_state == "open": + self.scan_sub_t += 1 + self.g_cmd = 0.0 + self._set_arm_targets(_clip(self.s + ds, 0.0, 1.25), + _clip(self.s + ds, 0.0, 1.25)) + if self.scan_sub_t >= 4: + self.scan_state = "close" + self.scan_sub_t = 0 + return raw + + if self.scan_state == "close": + self.scan_sub_t += 1 + self.g_cmd = 1.0 + self._set_arm_targets(_clip(self.s + ds, 0.0, 1.25), + _clip(self.s + ds, 0.0, 1.25)) + if self.scan_sub_t == 9: + lf = _img_feats(self.last_img["left_wrist"]) + rf = _img_feats(self.last_img["right_wrist"]) + sc = lf["score"] + rf["score"] + if getattr(self, "best_scan", None) is None or sc > self.best_scan[0]: + self.best_scan = (sc, ds, dp, dy, dx) + if self.scan_sub_t == 10: + if self.fp_bad: + rl = rr = 0.0 + else: + rl, rr = self._finger_ratio(ld) + self.scan_contact = (not self.fp_bad) and ( + max(rl, rr) > 0.13 or min(rl, rr) > 0.22) + if self.scan_sub_t >= 11: + if self.scan_contact: + self.got_contact = True + self.s_grab = _clip(self.s + ds, 0.0, 1.25) + self.fb_dy = dy + self.fb_dx = dx + self.fb_pitch = _clip(self.pitch_ref + dp, -0.2, 0.6) + self.phase = "lift" + self.phase_t = 0 + return raw + self.scan_state = "open2" + self.scan_sub_t = 0 + return raw + + if self.scan_state == "open2": + self.scan_sub_t += 1 + self.g_cmd = 0.0 + self._set_arm_targets(_clip(self.s + ds, 0.0, 1.25), + _clip(self.s + ds, 0.0, 1.25)) + if self.scan_sub_t >= 3: + self.scan_i += 1 + self.scan_state = "move" + self.scan_sub_t = 0 + return raw + + self.scan_state = "move" + return raw diff --git a/policies/dishwasher_load_plates/deepseek1017-s3/episodes.csv b/policies/dishwasher_load_plates/deepseek1017-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2870178ebb17fedea06418a056bd8ec94f2f3b5c --- /dev/null +++ b/policies/dishwasher_load_plates/deepseek1017-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/deepseek1017-s3/policy.py b/policies/dishwasher_load_plates/deepseek1017-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..72876d24ee530a858a8df6d8a6ee3355a504b96d --- /dev/null +++ b/policies/dishwasher_load_plates/deepseek1017-s3/policy.py @@ -0,0 +1,308 @@ +"""Hand-written control policy for loading plates into a dishwasher. + +The policy is a deterministic state machine. Its motion primitives come from +the supplied human demonstration: the robot stands at the counter with both +arms forward, raises both hands to the wooden plate rack, pinches the plates, +pulls them in, pitches the torso forward while squatting so that the hands +travel down into the pulled-out lower rack of the dishwasher, releases, and +withdraws. + +Two hand-written feedback mechanisms make the open-loop motion adaptive: + +* Before the first reach the grippers are closed once on empty air and the + finger joint readings are recorded. When the plates are pinched later the + fingers stop short of that "closed on air" position; comparing the two + readings tells the policy whether a grasp actually happened. +* If no grasp is detected the robot opens the grippers, steps a few + centimetres to the side (closed loop on the pelvis position from the + proprioceptive observation) and tries again, sampling the width of the + rack. After a few tries it performs the placement motion anyway. + +Nothing here is learned from data: every constant is a hand-chosen joint +offset or a timing. +""" + +import numpy as np + +# Conservative boxed ranges for the G1 arm joints (rad). The action is +# clamped into these so a bad offset can never produce an out-of-limit +# command that the simulator would reject. +_ARM_LIMITS = np.array( + [ + (-3.00, 2.60), # shoulder pitch + (-1.55, 2.20), # shoulder roll + (-2.60, 2.60), # shoulder yaw + (-0.08, 2.60), # elbow + (-1.90, 1.90), # wrist roll + (-1.90, 1.90), # wrist pitch + (-1.90, 1.90), # wrist yaw + ], + dtype=np.float32, +) + +# Arm poses as (shoulder pitch, elbow, wrist pitch) deltas from the reset pose. +_RAISE = (0.55, -0.20, 0.25) +_LIFT = (0.62, 0.10, 0.10) +_LOWER = (0.15, 0.05, -0.10) +_INSERT = (-0.05, -0.10, -0.30) +_WITHDRAW = (0.30, 0.30, 0.00) +_FINAL = (0.30, 0.10, 0.10) + + +def _smooth(u): + """Smoothstep on [0, 1].""" + u = min(1.0, max(0.0, float(u))) + return u * u * (3.0 - 2.0 * u) + + +def _lerp(a, b, u): + """Interpolate two 3-vectors.""" + return tuple(a[i] + (b[i] - a[i]) * u for i in range(3)) + + +class Policy: + """Deterministic state-machine controller for the plate-loading task.""" + + def reset(self, obs, tools): + """Record the reset pose and start the calibration phase.""" + self.hold = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.start_arm = self.hold[5:19].copy() + self.start_h = float(self.hold[2]) + self.start_p = float(self.hold[4]) + + ld = np.asarray(obs["low_dim_obs"], dtype=np.float32) + self.fp_open = ld[[10, 11, 19, 20]].copy() + self.fp_air = None + + self.state = "CAL" + self.ts = 0 # steps spent in the current state + self.t = 0 # total steps + self.attempt = 0 # lateral grasp attempts so far + self.pose = (0.0, 0.0, 0.0) # current arm deltas + self.pose0 = (0.0, 0.0, 0.0) # pose at state entry + self.height = self.start_h + self.pitch = self.start_p + self.grip = 0.0 + self.vy = 0.0 + self.y0 = float(ld[22]) + self.y_target = self.y0 + + # Per-arm sign of "forward" for the pitch-family joints. At reset the + # forearms are flexed forward (the demonstration starts with both hands + # in front of the belly), so the sign of the observed elbow angle tells + # us which sign of a pitch command swings the limb forward. Shoulder + # pitch, elbow and wrist pitch axes are parallel in the G1 arm, so the + # same sign applies to all of them. This makes the raise/lower motion + # independent of whether the simulator mirrors the left/right axes. + e_l = float(self.start_arm[3]) + e_r = float(self.start_arm[10]) + self.sign_l = 1.0 if e_l >= 0.0 else -1.0 + self.sign_r = 1.0 if e_r >= 0.0 else -1.0 + if abs(e_l) < 0.10: + self.sign_l = 1.0 + if abs(e_r) < 0.10: + self.sign_r = self.sign_l + + # Sign of an outward (abduction) shoulder roll. At reset the hands are + # held close together in front of the belly, i.e. the arms are + # adducted, so the opposite of the observed roll sign abducts them. + # To pinch the plates the hands have to separate, which the + # demonstration does as the arms come up. + r_l = float(self.start_arm[1]) + r_r = float(self.start_arm[8]) + self.out_l = -1.0 if r_l > 0.05 else 1.0 + self.out_r = (-1.0 if r_r > 0.05 else 1.0) + if abs(r_l) <= 0.05 and abs(r_r) <= 0.05: + self.out_r = -self.out_l if self.sign_r != self.sign_l else self.out_l + + # -- helpers ----------------------------------------------------------- + def _go(self, state): + """Switch to a new state, resetting the per-state step counter.""" + self.state = state + self.ts = 0 + self.pose0 = self.pose + + def _finger_grasp(self, ld): + """True when either gripper is blocked well before the empty close.""" + if self.fp_air is None: + return False + now = ld[[10, 11, 19, 20]].astype(np.float64) + open_ = self.fp_open.astype(np.float64) + air = self.fp_air.astype(np.float64) + blocked = 0 + valid = 0 + for i in range(4): + span = air[i] - open_[i] + if abs(span) < 0.01: + continue + valid += 1 + # Fraction of the way from open to the empty-closed position. + frac = (now[i] - open_[i]) / span + if frac < 0.85: + blocked += 1 + if valid == 0: + # The finger joints do not move (or are not reported) so the test + # carries no information; assume the grasp worked rather than + # opening the grippers on a plate that is already held. + return True + # Biased towards "grasped": a false positive only wastes the trip, + # a false negative would drop a plate that was actually held. + return blocked >= 1 + + def _apply_pose(self, raw, pose): + """Write an arm pose (deltas from reset) into ``raw``. + + ``sp`` raises the hand forward/up, ``el`` extends the elbow, ``wp`` + pitches the hand up. Both are expressed in the physical "forward" + direction and then multiplied by each arm's own pitch sign. + """ + arm = self.start_arm.copy() + sp, el, wp = pose + for base, sg, og in ((0, self.sign_l, self.out_l), + (7, self.sign_r, self.out_r)): + arm[base + 0] += sg * sp + arm[base + 1] += og * 0.20 + arm[base + 3] += sg * el + arm[base + 5] += sg * wp + arm = arm.reshape(2, 7) + arm = np.clip(arm, _ARM_LIMITS[:, 0], _ARM_LIMITS[:, 1]) + raw[5:19] = arm.reshape(-1) + + # -- main -------------------------------------------------------------- + def act(self, obs, tools): + """Return the 21-float action for this control step.""" + raw = self.hold.copy() + try: + ld = np.asarray(obs["low_dim_obs"], dtype=np.float32) + self.t += 1 + self.ts += 1 + st = self.state + + if st == "CAL": + # Close both empty grippers, then reopen: baseline for the + # finger joints when nothing is held. + self.grip = _smooth(self.ts / 22.0) + if self.ts == 22: + self.fp_air = ld[[10, 11, 19, 20]].copy() + if self.ts >= 24: + self.grip = 1.0 - _smooth((self.ts - 24) / 14.0) + if self.ts >= 40: + self.grip = 0.0 + self.y_target = self.y0 + self._go("SHIFT") + + elif st == "SHIFT": + # Lateral sampling step, closed loop on the pelvis y. + err = self.y_target - float(ld[22]) + if abs(err) > 0.02 and self.ts < 90: + v = 1.4 * err + self.vy = 0.0 if abs(v) < 0.065 else float( + np.clip(v, -0.16, 0.16)) + else: + self.vy = 0.0 + self._go("RAISE") + self.pose = (0.0, 0.0, 0.0) + + elif st in ("RAISE", "CLOSE", "CHECK", "OPEN", "LIFT", "LOWER", + "INSERT", "RELEASE", "WITHDRAW", "FINAL", "RETRACT"): + if st == "RAISE": + dur = 45 + self.pose = _lerp(self.pose0, _RAISE, + _smooth(self.ts / float(dur))) + self.grip = 0.0 + if self.ts >= dur: + self._go("CLOSE") + elif st == "CLOSE": + dur = 22 + self.pose = _RAISE + self.grip = _smooth(min(1.0, self.ts / 16.0)) + if self.ts >= dur: + self._go("CHECK") + elif st == "CHECK": + self._go("LIFT" if self._finger_grasp(ld) else "OPEN") + elif st == "OPEN": + dur = 20 + self.pose = _RAISE + self.grip = 1.0 - _smooth(self.ts / 12.0) + if self.ts >= dur: + self.grip = 0.0 + self.attempt += 1 + if self.attempt >= 3: + # Sensor says nothing was caught; try the + # placement anyway in case the reading is wrong. + self._go("LIFT") + else: + self._go("RETRACT") + elif st == "RETRACT": + dur = 35 + self.pose = _lerp(self.pose0, (0.0, 0.0, 0.0), + _smooth(self.ts / float(dur))) + self.grip = 0.0 + if self.ts >= dur: + shift = 0.085 if self.attempt == 1 else -0.085 + self.y_target = self.y0 + shift + self._go("SHIFT") + elif st == "LIFT": + dur = 50 + self.pose = _lerp(self.pose0, _LIFT, + _smooth(self.ts / float(dur))) + self.pitch = self.start_p + 0.10 * _smooth(self.ts / dur) + self.grip = 1.0 + if self.ts >= dur: + self._go("LOWER") + elif st == "LOWER": + dur = 160 + u = _smooth(self.ts / float(dur)) + self.pose = _lerp(self.pose0, _LOWER, u) + self.height = self.start_h + (0.66 - self.start_h) * u + self.pitch = (self.start_p + 0.10) + ( + 0.50 - 0.10) * u + self.grip = 1.0 + if self.ts >= dur: + self._go("INSERT") + elif st == "INSERT": + dur = 150 + u = _smooth(self.ts / float(dur)) + self.pose = _lerp(self.pose0, _INSERT, u) + self.height = 0.66 + (0.55 - 0.66) * u + self.pitch = 0.50 + (0.66 - 0.50) * u + self.grip = 1.0 + if self.ts >= dur: + self._go("RELEASE") + elif st == "RELEASE": + dur = 60 + self.pose = _INSERT + self.grip = 1.0 - _smooth(self.ts / 20.0) + if self.ts >= dur: + self.grip = 0.0 + self._go("WITHDRAW") + elif st == "WITHDRAW": + dur = 80 + u = _smooth(self.ts / float(dur)) + self.pose = _lerp(self.pose0, _WITHDRAW, u) + self.height = 0.55 + (0.68 - 0.55) * u + self.pitch = 0.66 + (0.35 - 0.66) * u + self.grip = 0.0 + if self.ts >= dur: + self._go("FINAL") + elif st == "FINAL": + dur = 100 + u = _smooth(self.ts / float(dur)) + self.pose = _lerp(self.pose0, _FINAL, u) + self.height = 0.68 + (0.72 - 0.68) * u + self.pitch = 0.35 + (0.10 - 0.35) * u + self.grip = 0.0 + + self._apply_pose(raw, self.pose) + raw[0] = 0.0 + raw[1] = float(self.vy) + raw[3] = 0.0 + raw[2] = float(np.clip(self.height, 0.40, 1.00)) + raw[4] = float(np.clip(self.pitch, -0.20, 0.80)) + g = float(np.clip(self.grip, 0.0, 1.0)) + raw[19] = g + raw[20] = g + except Exception: + # A controller bug must never abort the episode. + return self.hold + return raw diff --git a/policies/dishwasher_load_plates/gpt61sol-s1/episodes.csv b/policies/dishwasher_load_plates/gpt61sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..5e55756b011727096d4c4c3a713dc87577340c30 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,2519,terminated,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,2531,terminated,0 +620009,0,2522,terminated,0 +620010,0,2521,terminated,0 +620011,0,1529,terminated,0 +620012,0,1507,terminated,0 +620013,0,2520,terminated,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,1649,terminated,0 +620020,0,2526,terminated,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,1498,terminated,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,2534,terminated,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,1597,terminated,0 +620039,0,3150,timeout,0 +620040,0,1586,terminated,0 +620041,0,2505,terminated,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,1729,terminated,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,2518,terminated,0 +620049,0,2657,terminated,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,1497,terminated,0 +620053,0,3150,timeout,0 +620054,0,2523,terminated,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,1592,terminated,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,1501,terminated,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,2525,terminated,0 +620073,0,2526,terminated,0 +620074,0,3150,timeout,0 +620075,0,1498,terminated,0 +620076,0,2528,terminated,0 +620077,0,3150,timeout,0 +620078,0,2522,terminated,0 +620079,0,2583,terminated,0 +620080,0,2254,terminated,0 +620081,0,3150,timeout,0 +620082,0,1500,terminated,0 +620083,0,1702,terminated,0 +620084,0,3150,timeout,0 +620085,0,1548,terminated,0 +620086,0,1448,terminated,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,1494,terminated,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,1480,terminated,0 diff --git a/policies/dishwasher_load_plates/gpt61sol-s1/policy.py b/policies/dishwasher_load_plates/gpt61sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..2628030f4f4705ce0d518eb86b8781b1de841ffe --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61sol-s1/policy.py @@ -0,0 +1,98 @@ +"""Hand-written, deterministic visual plate-transfer control.""" +import numpy as np +import cv2 + +class Policy: + def reset(self,obs,tools): + self.a=np.array(tools.hold_action(),dtype=float) + self.a[19:]=0 + self.phase=0;self.n=0 + self.lower=np.array([-1,-1,.4,-1,-.2]+[-3.089,-1.588,-2.618,-1.047,-1.972,-1.614,-1.614]*2+[0,0]) + self.upper=np.array([1,1,1,1,.8]+[2.670,2.251,2.618,2.094,1.972,1.614,1.614]*2+[1,1]) + self.roll=np.zeros(2) + self.held=np.zeros(2,dtype=bool) + self.grasp_global=-1.25 + + @staticmethod + def plate(im): + c=im.astype(np.int16) + mask=((c.max(2)-c.min(2)<18)&(c.min(2)>190)).astype(np.uint8) + mask[:,:5]=0;mask[:,79:]=0 + _,_,stats,centers=cv2.connectedComponentsWithStats(mask) + items=[] + for (x,y,w,h,area),(cx,cy) in zip(stats[1:],centers[1:]): + if area>25 and h>18 and w<24 and y<60: + items.append((abs(cx-42)-.003*area,cx)) + return min(items)[1] if items else None + + def act(self,obs,tools): + s=obs['low_dim_obs'];p=self.phase;n=self.n + duration=[75,75,100,460,230,160,180,200,450,120,200,240,120,120,10000][p] + target=self.a.copy();target[:2]=0;target[3]=0 + h=.78;pitch=0.;grip=0.;x=.035;y=-.60 + sp=-1.9;el=.3;wp=1.6 + if p<3: + sp,el=[(0,2),(-1,2),(-2,2)][p];wp=0 + elif p==3: + f=min(1.,n/280.) + pitch=.5*f;sp=-2+.35*f;el=2-1.7*f + wp=-sp-el-s[2] + if n>170 and n%10==0: + for i,cam in enumerate(('left_wrist','right_wrist')): + cx=self.plate(tools.image(cam)) + if cx is not None: + self.roll[i]=np.clip(self.roll[i]-.0015*(cx-42),-.15,.3) + elif p==4: + if n==0: + self.grasp_global=-1.65+float(s[2]) + if n==65: + self.held=np.array([s[10]+s[11]>-.036,s[19]+s[20]>-.036]) + pitch=.5+.2*np.clip((n-70)/70.,0,1) + grip=1.;sp=self.grasp_global-s[2];wp=-self.grasp_global-el + elif p==5: + pitch=.7;grip=1.;sp=-1.65-.6*min(1,n/150.);wp=-sp-el-s[2] + elif p==6: + pitch=.7*(1-min(1,n/170.));grip=1. + sp=-1.85-s[2];wp=1.55 + else: + grip=1.;sp=-1.85-s[2];wp=1.55;x=-.42 + if p>=8:y=.05 + if p>=10: + f=min(1,n/190.) if p==10 else 1. + h=.78-.38*f;pitch=.25*f + if p>=11: + f=min(1,n/230.) if p==11 else 1. + global_sp=-1.85+.8*f + sp=global_sp-s[2];wp=-global_sp-el + if p>=12:grip=0. + if p>=13: + sp=-1.75-s[2];el=.6;wp=1.15 + target[2]=h;target[4]=pitch + for i,start in enumerate((5,12)): + target[start:start+7]=[sp,self.roll[i],0,el,0,wp,0] + target[19:]=grip + if p==4: + for i,start in enumerate((5,12)): + if self.held[i]: + target[start]-=.20 + target[start+5]+=.20 + elif 70<=n<120: + target[19+i]=0. + rate=np.full(21,.012);rate[2]=.0025;rate[4]=.004;rate[19:]=.035 + self.a += np.clip(target-self.a,-rate,rate) + if p<10: + err=np.array([x-s[21],y-s[22]]) + cap=.18 if p<7 else .24 + v=np.clip(err*4.,-cap,cap) + if np.linalg.norm(v)<.055: + norm=np.linalg.norm(err) + v=err*.065/norm if norm>.012 else np.zeros(2) + cy,sy=np.cos(s[24]),np.sin(s[24]) + self.a[:2]=[cy*v[0]+sy*v[1],-sy*v[0]+cy*v[1]] + self.a[3]=np.clip(-s[24]*3,-.25,.25) + else:self.a[:2]=0;self.a[3]=0 + self.n+=1 + if self.n>=duration: + self.phase=min(14,p+1);self.n=0 + self.a=np.clip(self.a,self.lower,self.upper) + return self.a.copy() diff --git a/policies/dishwasher_load_plates/gpt61sol-s2/episodes.csv b/policies/dishwasher_load_plates/gpt61sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..d5240ca4ab2dd496ee3be6202b5f8fa683a84750 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,784,terminated,0 +620002,0,3150,timeout,0 +620003,0,769,terminated,0 +620004,0,1628,terminated,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,1744,terminated,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,777,terminated,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,764,terminated,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,824,terminated,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,774,terminated,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,770,terminated,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,1063,terminated,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,884,terminated,0 +620060,0,1498,terminated,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,994,terminated,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,1100,terminated,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,781,terminated,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,843,terminated,0 +620081,0,3150,timeout,0 +620082,0,809,terminated,0 +620083,0,3150,timeout,0 +620084,0,1988,terminated,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,804,terminated,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,1101,terminated,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/gpt61sol-s2/policy.py b/policies/dishwasher_load_plates/gpt61sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..2e8a00182ef1728420e714f988b02e5b83c3bd75 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61sol-s2/policy.py @@ -0,0 +1,132 @@ +"""Hand-written plate handling controller using cameras and body state.""" +import numpy as np + +class Policy: + + def reset(self, obs, tools): + self.a = np.array(tools.hold_action(), float) + self.phase = 0 + self.k = 0 + self.start = self.a.copy() + self.orient = None + self.grasp_roll = [0.0, 0.0] + self.grasp_pitch = [0.0, 0.0] + self.retry = [False, False] + + def nav(self, obs, x, y, yaw=0): + p = obs['low_dim_obs'][21:25] + err = np.array([x, y]) - p[:2] + v = np.clip(3 * err, -0.3, 0.3) + if np.linalg.norm(v) < 0.1: + v = v / max(np.linalg.norm(v), 1e-09) * 0.1 if np.linalg.norm(err) > 0.012 else v * 0 + c, s = (np.cos(p[3]), np.sin(p[3])) + self.a[0] = c * v[0] + s * v[1] + self.a[1] = -s * v[0] + c * v[1] + self.a[3] = np.clip(2 * (yaw - p[3]), -0.6, 0.6) + + def act(self, obs, tools): + a = self.a + q = obs['low_dim_obs'] + p = self.phase + k = self.k + a[0] = a[1] = a[3] = 0 + durations = [90, 150, 140, 50, 280, 170, 50, 450, 60, 60, 160, 150, 120, 140, 200] + if p == 0: + a[5] = a[12] = -2 + a[10] = a[17] = 1.6 + a[19:] = 0.5 + elif p == 1: + self.nav(obs, 0, -0.6) + elif p == 2: + if k == 80: + for j, cam in enumerate(('left_wrist', 'right_wrist')): + im = np.asarray(tools.image(cam), dtype=np.int16) + mask = (im.min(2) > 170) & (im.max(2) - im.min(2) < 35) + mask[45:] = False + mask[:, :5] = False + mask[:, 78:] = False + yy, xx = np.where(mask) + if len(xx) > 100: + refx = (58.0, 46.0)[j] + refy = (13.0, 19.0)[j] + self.grasp_roll[j] = float(np.clip(0.007 * (refx - np.mean(xx)), -0.12, 0.12)) + self.grasp_pitch[j] = float(np.clip(-0.018 * (refy - np.mean(yy)), -0.08, 0.08)) + target = self.start.copy() + target[0] = target[1] = target[3] = 0 + target[5] = -1.3 + self.grasp_pitch[0] + target[12] = -1.3 + self.grasp_pitch[1] + target[6] = self.grasp_roll[0] + target[13] = self.grasp_roll[1] + target[8] = target[15] = 1 + target[10] = target[17] = 0.3 + self.a = a = self.start + (target - self.start) * min(1, (k + 1) / 60) + a[0] = a[1] = a[3] = 0 + elif p == 3: + a[19:] = 1 + elif p == 4: + a[5] = a[12] = -1.7 + if k == 0: + a[10] += 0.4 + a[17] += 0.4 + if k == 99: + self.retry = [bool(np.mean(q[10:12]) < -0.019), bool(np.mean(q[19:21]) < -0.019)] + if not any(self.retry): + self.k = 279 + for j, (sp, el, wp, g) in enumerate(((5, 8, 10, 19), (12, 15, 17, 20))): + if self.retry[j] and k >= 100: + if k < 180: + a[sp] = -1.25 + a[el] = 0.8 + a[wp] = 0.45 + a[g] = 0.5 + elif k < 220: + a[g] = 1 + else: + a[sp] = -1.7 + a[g] = 1 + elif p == 5: + self.nav(obs, -0.3, -0.6) + elif p == 7: + self.nav(obs, -0.3, 0.1) + elif p == 8: + self.nav(obs, -0.3, 0.1) + elif p == 9: + self.nav(obs, -0.3, 0.1) + f = min(1, (k + 1) / 120) + a[2] = 0.74 + a[4] = 0 + elif p == 10: + f = min(1, (k + 1) / 100) + a[2] = 0.74 + (0.42 - 0.74) * f + a[4] = 0.75 * f + a[5] = a[12] = -1.7 - 0.4 * f + a[8] = a[15] = 1 - 0.95 * f + elif p == 11: + a[19:] = max(0, 1 - (k + 1) / 60) + elif p == 12: + f = min(1, (k + 1) / 100) + a[5] = a[12] = -2.1 - 0.1 * f + a[8] = a[15] = 0.05 * (1 - f) + a[10] = a[17] = 0 + elif p == 13: + f = min(1, (k + 1) / 100) + a[2] = 0.42 + 0.32 * f + a[4] = 0.75 * (1 - f) + a[5] = a[12] = -1.8 + 1.5 * f + a[8] = a[15] = 0.8 * f + if p == 3 and k == durations[p] - 1: + self.orient = [q[2] + q[3] + q[6] + q[8], q[2] + q[12] + q[15] + q[17]] + if 4 <= p <= 10 and self.orient is not None: + for j, (sp, el, wp, ai) in enumerate([(3, 6, 8, 10), (12, 15, 17, 17)]): + error = self.orient[j] - (q[2] + q[sp] + q[el] + q[wp]) + a[ai] = np.clip(a[ai] + 0.12 * error, -1.6, 1.6) + self.k += 1 + if p in (7, 8, 9) and k > 40: + goals = {7: (-0.3, 0.1), 8: (-0.3, 0.1), 9: (-0.3, 0.1)} + if np.linalg.norm(q[21:23] - np.array(goals[p])) < 0.035: + self.k = durations[p] + if p < len(durations) and self.k >= durations[p]: + self.phase += 1 + self.k = 0 + self.start = a.copy() + return a.copy() diff --git a/policies/dishwasher_load_plates/gpt61sol-s3/episodes.csv b/policies/dishwasher_load_plates/gpt61sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..acfb53cabe1022c68cae0466d2cd8faf6929e520 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,1721,terminated,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,896,terminated,0 +620025,1,1590,success,0 +620026,0,3150,timeout,0 +620027,0,970,terminated,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,608,terminated,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,998,terminated,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,445,terminated,0 +620074,0,3150,timeout,0 +620075,0,1934,terminated,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,1492,terminated,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,851,terminated,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,1,1597,success,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,784,terminated,0 diff --git a/policies/dishwasher_load_plates/gpt61sol-s3/policy.py b/policies/dishwasher_load_plates/gpt61sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..96b6e0dc60abd2c358434b0ad110f541e226bce6 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61sol-s3/policy.py @@ -0,0 +1,94 @@ +"""Deterministic two-hand plate transfer with feedback-controlled walking.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float64) + self.a[:5] = [0, 0, .74, 0, -.15] + self.a[5:12] = [-.8, 0, 0, .4, 0, 0, 0] + self.a[12:19] = self.a[5:12] + self.a[19:21] = 0 + self.lower_start = None + self.delay = 0 + self.retried = False + self.retry_count = None + + def walk(self, obs, target): + p = np.asarray(obs['low_dim_obs'][21:25]) + v = np.asarray(target, dtype=float) - p[:2] + distance = np.linalg.norm(v) + if distance > .02: + v *= min(.23 / distance, 2.5) + speed = np.linalg.norm(v) + if speed < .06: + v *= .06 / speed + else: + v[:] = 0 + yaw = p[3] + self.a[0] = np.cos(yaw)*v[0] + np.sin(yaw)*v[1] + self.a[1] = -np.sin(yaw)*v[0] + np.cos(yaw)*v[1] + self.a[3] = np.clip(-2*yaw, -.2, .2) + + def sequence(self, obs, tools): + t = int(obs['t']) + self.a[0:2] = 0 + self.a[3] = 0 + if t < 70: + pass + elif t < 330: + self.walk(obs, [.18, -.6]) + elif t < 370: + self.a[19] = 1 + elif t < 440: + self.a[5:12] = [-1.6, 0, 0, 1.2, 0, 0, 0] + elif t < 520: + self.a[12:19] = [-.8, .35, 0, .4, 0, 0, 0] + elif t < 560: + self.a[20] = 1 + elif t < 630: + self.a[12:19] = [-1.6, .25, 0, 1.2, 0, 0, 0] + elif t < 890: + self.walk(obs, [-.66, -.6]) + elif t < 1110: + self.walk(obs, [-.66, 0]) + elif t < 1310: + self.walk(obs, [-.35, 0]) + elif t < 1430: + if self.lower_start is None: + self.lower_start = self.a.copy() + target = self.lower_start.copy() + target[2] = .52 + target[4] = .8 + target[5:12] = [-1.8, 0, 0, -.3, 0, .75, 0] + target[12:19] = [-1.8, .25, 0, -.3, 0, .75, 0] + self.a = self.lower_start + (target-self.lower_start)*min(1, (t-1310+1)/90) + elif t < 1530: + self.a[19:21] = 0 + elif t < 1650: + self.a[5:12] = [-1, 0, 0, 0, 0, -.15, 0] + self.a[12:19] = [-1, .25, 0, 0, 0, -.15, 0] + else: + self.a[2] = .74 + self.a[4] = 0 + self.a[5:19] = 0 + return self.a.copy() + + def act(self, obs, tools): + local = dict(obs) + local['t'] = int(obs['t']) - self.delay + if local['t'] == 560 and not self.retried: + self.retried = True + if float(obs['low_dim_obs'][51]) > .9: + self.retry_count = 0 + if self.retry_count is not None and self.retry_count < 240: + k = self.retry_count + self.a[12:19] = [-.8, .35, 0, .4, 0, 0, 0] + self.a[20] = 0 if k < 200 else 1 + self.a[:2] = 0 + self.a[3] = 0 + if k < 200: + self.walk(obs, [.16, -.4]) + self.retry_count += 1 + self.delay += 1 + return self.a.copy() + return self.sequence(local, tools) diff --git a/policies/dishwasher_load_plates/gpt61terra-s1/episodes.csv b/policies/dishwasher_load_plates/gpt61terra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..4a16becf9bceeeb6539ac136996e21df7f722bcb --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61terra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,2891,terminated,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,1039,terminated,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,1443,terminated,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,2320,terminated,0 +620034,0,3150,timeout,0 +620035,0,1376,terminated,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,2772,terminated,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,2885,terminated,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,2281,terminated,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,1538,terminated,0 +620068,0,1536,terminated,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,1567,terminated,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,1371,terminated,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,1544,terminated,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/gpt61terra-s1/policy.py b/policies/dishwasher_load_plates/gpt61terra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..96488779f6a55a5d2bc513db60584bdb2cf0f8b0 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61terra-s1/policy.py @@ -0,0 +1,44 @@ +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32) + self.a[19:21] = 0 + + def act(self, obs, tools): + t = obs['t']; p = obs['low_dim_obs']; a = self.a.copy() + a[0:2] = 0; a[3] = 0 + if t < 45: + a[0] = -.25 + elif t < 100: + a[5:12] = [0,0,0,1.8,0,0,0]; a[12:19] = [0,0,0,1.8,0,0,0] + elif t < 200: + a[5:12] = [-2.2,0,0,1.8,0,0,0]; a[12:19] = [-2.2,0,0,1.8,0,0,0] + elif t < 300: + a[5:12] = [-2.2,0,0,.5,0,0,0]; a[12:19] = [-2.2,0,0,.5,0,0,0] + else: + a[5:12] = [-1.2,0,0,.5,0,.3,0]; a[12:19] = [-1.2,0,0,.5,0,.3,0] + if t >= 700: a[6]=.25; a[13]=.2 + if t >= 900: a[5]=a[12]=-.9; a[10]=a[17]=.5 + if t >= 1100: a[19:21]=1 + if t >= 1300: a[5]=a[12]=-1.7 + if t < 1300: + x = -.07 if t < 700 else .04 + if t>=400: + a[0] = (.1 if t < 700 else .08) if p[21]=.06 else 0 + a[3] = np.clip(-2*p[24],-.3,.3) + elif t >= 1450 and t < 2250: + target = (-.35,-.60) if t < 1700 else ((-.35,-.10) if t < 2050 else (-.22,-.10)) + dx,dy=target[0]-p[21],target[1]-p[22] + vx=np.clip(dx*1.5,-.22,.22); vy=np.clip(dy*1.5,-.22,.22) + yaw=p[24]; a[0]=vx*np.cos(yaw)+vy*np.sin(yaw); a[1]=-vx*np.sin(yaw)+vy*np.cos(yaw) + if np.hypot(a[0],a[1])<.06: a[0:2]=0 + a[3]=np.clip(-2*yaw,-.3,.3) + elif t>=2250: + a[2]=.60; a[4]=.20 + a[5]=a[12]=-1.2 + if t>=2750: a[19:21]=0 + if t>=2850: a[5]=a[12]=-1.7 + return a diff --git a/policies/dishwasher_load_plates/gpt61terra-s2/episodes.csv b/policies/dishwasher_load_plates/gpt61terra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..400dad39c815a016933095e48528a1de09c1a59a --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61terra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,1234,terminated,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,566,terminated,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,1459,terminated,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,889,terminated,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,1472,terminated,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/gpt61terra-s2/policy.py b/policies/dishwasher_load_plates/gpt61terra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..1048078196f76310a45827ba762686de88ae019f --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61terra-s2/policy.py @@ -0,0 +1,71 @@ +"""Deterministic open-loop manipulation with closed-loop base positioning.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.stage = 0 + self.stage_start = int(obs['t']) + self.origin = np.asarray(obs['low_dim_obs'][21:25], dtype=float).copy() + + def act(self, obs, tools): + t = int(obs['t']) + q = obs['low_dim_obs'] + dt = t - self.stage_start + a = self.hold.copy() + a[19:21] = 0 + # Raise each arm over the counter before bending the elbows. + if self.stage == 0: + a[5] = -1.0 + if dt >= 100: self._next(t) + elif self.stage == 1: + a[5] = -1.2; a[8] = .8; a[12] = -1.0 + if dt >= 100: self._next(t) + elif self.stage <= 4: + a[5] = -1.2; a[8] = .8 + a[12] = -1.2; a[15] = .8 + if self.stage == 2: + if dt >= 100: self._next(t) + elif self.stage == 3: + a[0] = .16 if q[21] < self.origin[0] + .05 and dt < 80 else 0 + a[4] = .2 + if dt >= 120: self._next(t) + else: + a[4] = .2 + a[19:21] = 1 + if dt >= 80: self._next(t) + else: + a[19:21] = 1 + a[5] = -1.6; a[8] = 1.2 + a[12] = -1.6; a[15] = 1.2 + if self.stage == 5: + if dt >= 100: self._next(t) + elif self.stage == 6: + a[0] = -.2 if q[21] > self.origin[0] - .25 and dt < 140 else 0 + if dt >= 150: self._next(t) + elif self.stage == 7: + err = 1.56 - float(q[24]) + a[3] = np.clip(err * 1.2, -.5, .5) if abs(err) > .05 else 0 + if abs(err) < .05 or dt >= 240: self._next(t) + elif self.stage == 8: + a[1] = -.16 if dt < 105 else 0; a[0] = .16 if 105 <= dt < 215 else 0 + if dt >= 235: self._next(t) + elif self.stage == 9: + a[2] = .43; a[4] = .25 + a[5] = -.85; a[8] = .75 + a[12] = -.85; a[15] = .75 + if dt >= 220: self._next(t) + elif self.stage == 10: + a[2] = .43; a[4] = .25 + a[5] = -.85; a[8] = .75 + a[12] = -.85; a[15] = .75 + a[19:21] = 0 + if dt >= 100: self._next(t) + else: + a[2] = .74 + a[19:21] = 0 + return a + + def _next(self, t): + self.stage += 1 + self.stage_start = t diff --git a/policies/dishwasher_load_plates/gpt61terra-s3/episodes.csv b/policies/dishwasher_load_plates/gpt61terra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..15521d0c12bc446e6828cd0abc206c87d1325dc6 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61terra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,901,terminated,0 +620002,0,1112,terminated,0 +620003,0,1115,terminated,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,1098,terminated,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,1216,terminated,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,1194,terminated,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,778,terminated,0 +620033,0,3150,timeout,0 +620034,0,947,terminated,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,1022,terminated,0 +620041,0,918,terminated,0 +620042,0,1040,terminated,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,1000,terminated,0 +620046,0,3150,timeout,0 +620047,0,934,terminated,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,803,terminated,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,1095,terminated,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,1099,terminated,0 +620081,0,3150,timeout,0 +620082,0,1002,terminated,0 +620083,0,1013,terminated,0 +620084,0,1858,terminated,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/gpt61terra-s3/policy.py b/policies/dishwasher_load_plates/gpt61terra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..901c8c6193644a4e5da01acee999a6e6c83c0f7f --- /dev/null +++ b/policies/dishwasher_load_plates/gpt61terra-s3/policy.py @@ -0,0 +1,56 @@ +import numpy as np +class Policy: + def reset(self,obs,tools): + self.a=np.asarray(tools.hold_action(),dtype=np.float32); self.phase=0; self.start=0 + def act(self,obs,tools): + t=obs['t']; q=obs['low_dim_obs']; x,y,_,yaw=q[21:25] + a=self.a.copy();a[19:21]=0;a[5]=a[12]=-1.2 + p=self.phase; dt=t-self.start + def advance(): self.phase+=1;self.start=t + if p==0: + if dt>=120:advance() + elif p==1: + a[0]=.12 + if x>=-.005 or dt>260:advance() + elif p==2: + if dt>=80:advance() + elif p==3: + a[5]=a[12]=-1.4;a[8]=a[15]=1;a[10]=a[17]=.3 + if dt>=120:advance() + elif p==4: + a[5]=a[12]=-1.4;a[8]=a[15]=1;a[10]=a[17]=.3;a[19:21]=1 + if dt>=120:advance() + else: + a[5]=a[12]=-1.8;a[8]=a[15]=1;a[10]=a[17]=.3;a[19:21]=1 + if p==5: a[5]=a[12]=-1.4-.4*min(dt/120,1) + if p==5: + if dt>=120:advance() + elif p==6: + a[0]=-.12 + if dt>=1:advance() + elif p==7: + if dt>=60:advance() + elif p==8: + a[3]=.15 + if yaw>=1.25 or dt>=500:advance() + elif p==9: + if dt>=60:advance() + elif p==10: + a[0]=.15 + if y>=-.53 or dt>=200:advance() + elif p==11: + if dt>=70:advance() + elif p>=12: + a[2]=.55 + if p==12: + if dt>=180:advance() + else: + a[5]=a[12]=-1.4;a[8]=a[15]=.8 + if p==13: + if dt>=160:advance() + else: + a[19:21]=0 + if p==14: + if dt>=100:advance() + else:a[5]=a[12]=-1.2 + return a diff --git a/policies/dishwasher_load_plates/gpt6sol-s1/episodes.csv b/policies/dishwasher_load_plates/gpt6sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..e95d9698b7363f8538b90fe04de750122e9218a7 --- /dev/null +++ b/policies/dishwasher_load_plates/gpt6sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,547,terminated,0 +620003,0,3150,timeout,0 +620004,0,464,terminated,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,2033,terminated,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,545,terminated,0 +620019,0,3150,timeout,0 +620020,0,2314,terminated,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,509,terminated,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,483,terminated,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,637,terminated,0 +620042,0,3150,timeout,0 +620043,0,576,terminated,0 +620044,0,3150,timeout,0 +620045,0,2594,terminated,0 +620046,0,1346,terminated,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,1056,terminated,0 +620051,0,2858,terminated,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,2120,terminated,0 +620058,0,3150,timeout,0 +620059,0,570,terminated,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,414,terminated,0 +620064,0,626,terminated,0 +620065,0,3150,timeout,0 +620066,0,525,terminated,0 +620067,0,359,terminated,0 +620068,0,3150,timeout,0 +620069,0,556,terminated,0 +620070,0,3150,timeout,0 +620071,0,519,terminated,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,387,terminated,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,355,terminated,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,695,terminated,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,541,terminated,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,2057,fell,1 +620096,0,3150,timeout,0 +620097,0,544,terminated,0 +620098,0,3150,timeout,0 +620099,0,497,terminated,0 diff --git a/policies/dishwasher_load_plates/gpt6sol-s1/policy.py b/policies/dishwasher_load_plates/gpt6sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..89e1dd52fe693b56aa6bca9179960997d829c7cb --- /dev/null +++ b/policies/dishwasher_load_plates/gpt6sol-s1/policy.py @@ -0,0 +1,115 @@ +"""Hand-written, deterministic plate transfer controller.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32) + self.a[19:21] = 0.0 + self.stages = [ + ("reach1", 95), ("close1", 50), ("lift1", 100), + ("back1", 250), ("turn1", 100), ("dish1", 230), + ("settle1", 30), ("inward1", 80), ("squat1", 100), + ("lower1", 100), ("release1", 100), ("stand2", 100), + ("back2", 160), ("turn2", 115), ("recenter2", 80), + ("counter2", 110), ("reach2", 95), ("close2", 50), + ("lift2", 100), ("back3", 250), ("turn3", 100), + ("dish2", 160), ("inward2", 80), ("squat2", 100), + ("lower2", 100), ("release2", 100), ("wait", 1000), + ] + self.index = 0 + self.elapsed = 0 + self.entered = False + self.retried = False + + def _enter(self, name): + a = self.a + a[0] = a[1] = a[3] = 0.0 + if name == "reach1": + a[0] = 0.4 + a[5] = -0.6 + a[10] = 0.4 + a[19] = 0.0 + elif name == "close1": + a[0] = 0.4 + a[19] = 1.0 + elif name in ("lift1", "lift2"): + a[2] = 0.74 + a[4] = 0.0 + a[5] = -1.4 + a[7] = 0.0 + a[8] = 0.5 + a[10] = 0.8 + a[11] = 0.0 + a[19] = 1.0 + elif name in ("back1", "back2", "back3"): + a[0] = -0.1 + elif name in ("turn1", "turn3"): + a[3] = 0.4 + elif name == "turn2": + a[3] = -0.4 + elif name in ("dish1", "dish2"): + a[0] = 0.1 + elif name in ("inward1", "inward2"): + a[7] = -0.7 if name == "inward1" else -0.6 + a[11] = -a[7] + elif name in ("squat1", "squat2"): + a[2] = 0.5 if name == "squat1" else 0.55 + a[4] = 0.5 if name == "squat1" else 0.4 + elif name in ("lower1", "lower2"): + a[5] = -1.2 if name == "lower1" else -0.9 + a[8] = 0.1 if name == "lower1" else 0.2 + a[10] = 0.7 if name == "lower1" else 0.6 + elif name in ("release1", "release2"): + a[19] = 0.0 + elif name == "stand2": + a[2] = 0.74 + a[4] = 0.0 + a[5] = -1.4 + a[7] = 0.0 + a[8] = 0.5 + a[10] = 0.8 + a[11] = 0.0 + elif name == "recenter2": + a[1] = 0.2 + elif name == "counter2": + a[0] = 0.2 + elif name in ("reach2", "retry_open"): + a[0] = 0.8 if name == "reach2" else 0.4 + a[5] = -0.6 + a[7] = -0.25 if name == "reach2" else -0.5 + a[8] = 0.0 + a[10] = 0.4 + a[11] = -a[7] + a[19] = 0.0 + elif name in ("close2", "retry_close"): + a[0] = 0.8 if name == "close2" else 0.4 + a[19] = 1.0 + elif name == "wait": + a[0] = a[1] = a[3] = 0.0 + + def act(self, obs, tools): + if self.index >= len(self.stages): + return self.a.copy() + name, duration = self.stages[self.index] + if not self.entered: + self._enter(name) + self.entered = True + result = self.a.copy() + if name in ("counter2", "reach2", "close2"): + yaw = float(np.asarray(obs["low_dim_obs"])[24]) + result[3] = np.clip(-1.5 * yaw, -0.25, 0.25) + self.elapsed += 1 + if self.elapsed >= duration: + if name == "close2" and not self.retried: + fingers = np.asarray(obs["low_dim_obs"])[10:12] + if np.max(fingers + 0.020) < 0.002: + self.stages[self.index + 1:self.index + 1] = [ + ("retry_open", 60), ("retry_close", 70) + ] + self.retried = True + self.index += 1 + self.elapsed = 0 + self.entered = False + return result diff --git a/policies/dishwasher_load_plates/gpt6sol-s2/episodes.csv b/policies/dishwasher_load_plates/gpt6sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..33e77e163b58182663217892a96048c200a4f90e --- /dev/null +++ b/policies/dishwasher_load_plates/gpt6sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1852,terminated,0 +620001,0,1038,terminated,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,1858,terminated,0 +620005,0,742,terminated,0 +620006,0,874,terminated,0 +620007,0,1851,terminated,0 +620008,0,980,terminated,0 +620009,0,3150,timeout,0 +620010,0,1242,terminated,0 +620011,0,1850,terminated,0 +620012,0,1964,terminated,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,147,terminated,0 +620016,0,1307,terminated,0 +620017,0,3150,timeout,0 +620018,0,1851,terminated,0 +620019,0,3150,timeout,0 +620020,0,1850,terminated,0 +620021,0,749,terminated,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,940,terminated,0 +620025,0,1169,terminated,0 +620026,0,1115,terminated,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,987,terminated,0 +620030,0,890,terminated,0 +620031,0,3150,timeout,0 +620032,0,1026,terminated,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,1851,terminated,0 +620036,0,1008,terminated,0 +620037,0,1851,terminated,0 +620038,0,3150,timeout,0 +620039,0,1850,terminated,0 +620040,0,793,terminated,0 +620041,0,3150,timeout,0 +620042,0,1858,terminated,0 +620043,0,1851,terminated,0 +620044,0,3150,timeout,0 +620045,0,678,terminated,0 +620046,0,732,terminated,0 +620047,0,715,terminated,0 +620048,0,3150,timeout,0 +620049,0,1850,terminated,0 +620050,0,1045,terminated,0 +620051,0,1627,terminated,0 +620052,0,1007,terminated,0 +620053,0,965,terminated,0 +620054,0,3150,timeout,0 +620055,0,1851,terminated,0 +620056,0,1863,terminated,0 +620057,0,1137,terminated,0 +620058,0,1852,terminated,0 +620059,0,3150,timeout,0 +620060,0,1860,terminated,0 +620061,0,3150,timeout,0 +620062,0,1025,terminated,0 +620063,0,946,terminated,0 +620064,0,1850,terminated,0 +620065,0,1039,terminated,0 +620066,0,1985,terminated,0 +620067,0,1850,terminated,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,1012,terminated,0 +620071,0,3150,timeout,0 +620072,0,1260,terminated,0 +620073,0,1249,terminated,0 +620074,0,1850,terminated,0 +620075,0,3150,timeout,0 +620076,0,1851,terminated,0 +620077,0,1850,terminated,0 +620078,0,1879,terminated,0 +620079,0,3150,timeout,0 +620080,0,876,terminated,0 +620081,0,995,terminated,0 +620082,0,1851,terminated,0 +620083,0,754,terminated,0 +620084,0,979,terminated,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,1043,terminated,0 +620089,0,1264,terminated,0 +620090,0,3150,timeout,0 +620091,0,1010,terminated,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,1851,terminated,0 +620095,0,3150,timeout,0 +620096,0,951,terminated,0 +620097,0,3150,timeout,0 +620098,0,1283,terminated,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/gpt6sol-s2/policy.py b/policies/dishwasher_load_plates/gpt6sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..2af0e4387693c9a40abb24d6bb9cd48098b22d3e --- /dev/null +++ b/policies/dishwasher_load_plates/gpt6sol-s2/policy.py @@ -0,0 +1,63 @@ +"""Hand-written two-plate dishwasher loading policy.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + a = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.segments = [] + self.end = 0 + + def add(n, updates=None, smooth=False): + nonlocal a + b = a.copy() + for key, value in (updates or {}).items(): + b[key] = value + self.segments.append((self.end, self.end + n, a.copy(), b.copy(), smooth)) + self.end += n + a = b + + # Approach the counter and raise the body so the dishes are visible. + add(40, {0: .3, 19: 0., 20: 0.}) + add(50, {0: 0., 2: .9, 4: -.2}) + + # Raise both hands clear of the counter, then approach the plate rims. + for sp, el in ((-.4, 0.), (-.8, 0.), (-1.2, 0.), (-.8, .5)): + add(45, {5: sp, 8: el, 12: sp, 15: el}) + a[6] = .15 + add(60, {4: .6, 5: -1.2, 8: .5, + 12: -1.2, 13: 0., 15: .5}, True) + add(50, {19: 1., 20: 1.}) + + # Lift the plates out before leaning back. + for p, sp, el in ((.6, -1.35, .5), (.6, -1.45, .5), + (.6, -1.45, .3), (.4, -1.45, .3), + (.2, -1.45, .3), (0., -1.45, .3), + (0., -1.2, 0.), (-.2, -1.2, 0.)): + add(50, {4: p, 5: sp, 8: el, 12: sp, 15: el}, True) + + # Move back from the counter, then sideways to the dishwasher. + add(140, {0: -.25}) + add(360, {0: 0., 1: .2, 2: .74}) + add(80, {1: 0.}) + + # Lower the plates over the rack, squat, then open the grippers. + for p, sp, el in ((0., -1., .2), (.2, -.8, .5), (.4, -.6, .7)): + add(80, {4: p, 5: sp, 8: el, 12: sp, 15: el}, True) + for height in (.65, .55, .5): + add(80, {2: height}) + add(100, {19: 0., 20: 0.}) + add(100, {4: 0., 5: -1.1, 8: 0., 12: -1.1, 15: 0.}, True) + add(150) + add(80, {2: .74}) + self.last_action = a.copy() + + def act(self, obs, tools): + t = int(obs["t"]) + for lo, hi, start, target, smooth in self.segments: + if t < hi: + if smooth: + return start + (target - start) * ((t - lo + 1) / (hi - lo)) + return target.copy() + return self.last_action.copy() diff --git a/policies/dishwasher_load_plates/gpt6sol-s3/episodes.csv b/policies/dishwasher_load_plates/gpt6sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2be8dbe13df4fca8f28b0bb695e25c3d9ccbfcba --- /dev/null +++ b/policies/dishwasher_load_plates/gpt6sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,534,terminated,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,542,terminated,0 +620020,0,531,terminated,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,1909,terminated,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,760,terminated,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,636,terminated,0 +620058,0,643,terminated,0 +620059,0,293,terminated,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,2092,terminated,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,497,terminated,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,558,terminated,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,377,terminated,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,682,terminated,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,2006,terminated,0 +620086,0,3150,fell,1 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,3150,timeout,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,3150,timeout,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,331,terminated,0 diff --git a/policies/dishwasher_load_plates/gpt6sol-s3/policy.py b/policies/dishwasher_load_plates/gpt6sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..e40e0de0c1e3e68360c5df76579ba6ab48af84ee --- /dev/null +++ b/policies/dishwasher_load_plates/gpt6sol-s3/policy.py @@ -0,0 +1,116 @@ +"""Deterministic two trip plate loading controller for the G1.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self.a[19:] = 0.0 + self.phase = 0 + self.start = int(obs["t"]) + self.retry = False + self._enter(0) + + def _enter(self, p): + a = self.a + if p == 0: + a[5], a[10] = -1.5, .9 + elif p in (2, 18): + a[2], a[4], a[5], a[7], a[8], a[10] = .74, .4, -1.0, -.2, 0, .5 + elif p in (3, 19): + a[19] = 1.0 + self.retry = False + elif p in (4, 20): + a[5], a[10] = -1.5, .9 + elif p in (5, 21): + a[2], a[4], a[5], a[7], a[10] = .82, .1, -1.7, -.2, 1.1 + elif p in (6, 22): + a[2], a[4] = .74, 0.0 + elif p in (9, 25): + a[2], a[4], a[5], a[8], a[10] = .45, .6, -1.3, 0, .7 + elif p in (10, 26): + a[19] = 0.0 + elif p == 11: + a[2], a[4], a[5], a[10] = .74, 0.0, -1.5, .9 + + def _finished(self, p, age, s): + x, y, yaw = float(s[21]), float(s[22]), float(s[24]) + if p in (3, 19): + if age >= 40 and float(s[50]) > .97: + self.retry = True + if not self.retry: + return age >= 50 + return age >= 190 or (age >= 115 and float(s[50]) < .97) + fixed = {0: 60, 2: 70, 4: 70, 5: 80, 6: 50, + 9: 160, 10: 100, 11: 80, 18: 70, + 20: 70, 21: 80, 22: 50, 25: 160, 26: 100, + 15: 120} + if p in fixed: + return age >= fixed[p] + rules = { + 1: (x >= .015, 160), + 7: (x <= -.34, 180), + 8: (y >= -.015, 230), + 12: (x >= -.38, 150), + 13: (y <= -.59, 240), + 14: (x >= -.005, 230), + 16: (abs(y + .63) < .02, 120), + 17: (x >= .015 and yaw >= .08, 150), + 23: (x <= -.34, 180), + 24: (y >= -.015, 230), + } + if p not in rules: + return False + reached, maximum = rules[p] + return (age >= 25 and reached) or age >= maximum + + def act(self, obs, tools): + t = int(obs["t"]) + s = obs["low_dim_obs"] + while self.phase < 27 and self._finished(self.phase, t - self.start, s): + self.phase += 1 + self.start = t + self._enter(self.phase) + a = self.a + a[0] = a[1] = a[3] = 0.0 + x, y, yaw = float(s[21]), float(s[22]), float(s[24]) + p = self.phase + if p == 1: + a[0] = .16 if x < .02 else 0.0 + elif p == 7: + a[0] = -.18 if x > -.35 else 0.0 + elif p == 8: + a[1] = .30 if y < 0.0 else 0.0 + elif p == 12: + a[0] = .18 if x < -.38 else 0.0 + elif p == 13: + a[1] = -.30 if y > -.60 else 0.0 + elif p == 14: + a[0] = .18 if x < .01 else 0.0 + elif p == 15: + a[3] = -.25 if yaw > .025 else .25 if yaw < -.025 else 0.0 + elif p == 16: + a[1] = -.18 if y > -.63 else .18 if y < -.63 else 0.0 + elif p == 17: + if x < .02: + a[0] = .15 + a[3] = -.18 if yaw > .03 else .18 if yaw < -.03 else 0.0 + else: + a[3] = .25 if yaw < .10 else 0.0 + a[1] = -.10 if y > -.62 else 0.0 + elif p == 23: + a[0] = -.18 if x > -.35 else 0.0 + elif p == 24: + a[1] = .30 if y < 0.0 else 0.0 + if p in (3, 19) and self.retry: + age = t - self.start + if age < 75: + a[19], a[7], a[4] = 0.0, -.1, .45 + elif age < 115: + a[19] = 1.0 + elif float(s[50]) > .97 and age < 150: + a[19], a[7], a[4] = 0.0, -.3, .5 + else: + a[19] = 1.0 + return a.copy() diff --git a/policies/dishwasher_load_plates/kimi31pro-s1/episodes.csv b/policies/dishwasher_load_plates/kimi31pro-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..3d98d2c59ec1f17cb0f49db8045e9c7d85c6bf32 --- /dev/null +++ b/policies/dishwasher_load_plates/kimi31pro-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,3150,timeout,0 +620003,0,781,terminated,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,542,terminated,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,3150,timeout,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,562,terminated,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,1446,terminated,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,3150,timeout,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,3150,timeout,0 +620054,0,1333,terminated,0 +620055,0,3150,timeout,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,3150,timeout,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,3150,timeout,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,3150,timeout,0 +620083,0,3150,timeout,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,1340,terminated,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,1343,terminated,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,3150,timeout,0 +620098,0,3150,timeout,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/kimi31pro-s1/policy.py b/policies/dishwasher_load_plates/kimi31pro-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..673a4ad04f05bc4d0470cbbb9497bfda76857440 --- /dev/null +++ b/policies/dishwasher_load_plates/kimi31pro-s1/policy.py @@ -0,0 +1,147 @@ +"""Deterministic hand-written control for loading two plates into the lower rack.""" + +import numpy as np + + +ZERO = np.zeros(7, dtype=np.float32) +PRE = np.array([-1.2, -0.15, 0.0, 0.4, 0.0, 0.0, 0.0], dtype=np.float32) +GRASP = np.array([-1.5, -0.15, 0.0, 1.0, 0.0, 0.0, 0.0], dtype=np.float32) +LIFT = np.array([-1.9, -0.15, 0.0, 1.2, 0.0, 0.0, 0.0], dtype=np.float32) +ALIGN = np.array([-1.9, 0.0, 0.0, 1.2, 0.0, 0.0, 0.0], dtype=np.float32) +LEFT_INSERT = np.array([-1.3, 0.0, 0.0, 1.2, 0.0, 0.0, 0.0], dtype=np.float32) + + +class Policy: + """Acquire both plates before carrying them to the dishwasher.""" + + PHASES = ( + "left_pre", "left_pose", "left_close", + "right_pre", "right_pose", "right_close", "both_lift", + "back", "left", "turn", "left_align", "approach", "crouch", "lower", + "left_insert", "left_release", "left_settle", "right_align", "right_release", + "final_settle", "finished", + ) + DURATIONS = { + "left_pre": 70, "left_pose": 80, "left_close": 60, + "right_pre": 70, "right_pose": 80, "right_close": 60, + "both_lift": 90, "back": 100, "left": 180, "turn": 100, + "left_align": 80, "approach": 90, "crouch": 90, "lower": 90, "left_insert": 70, + "left_release": 40, + "left_settle": 60, "right_align": 80, "right_release": 40, + "final_settle": 100, "finished": 10**9, + } + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.cycle = 0 + self.phase_index = 0 + self.phase = self.PHASES[0] + self.phase_step = 0 + self.left = ZERO.copy() + self.right = ZERO.copy() + self.pitch = 0.0 + self.start_left = self.left.copy() + self.start_right = self.right.copy() + self.start_pitch = 0.0 + + def _advance(self): + self.phase_index = min(self.phase_index + 1, len(self.PHASES) - 1) + self.phase = self.PHASES[self.phase_index] + self.phase_step = 0 + self.start_left = self.left.copy() + self.start_right = self.right.copy() + self.start_pitch = self.pitch + + @staticmethod + def _navigation(obs, target): + d = obs["low_dim_obs"] + yaw = float(d[24]) + ex, ey = target[0] - float(d[21]), target[1] - float(d[22]) + wx = float(np.clip(1.5 * ex, -0.15, 0.15)) + wy = float(np.clip(1.5 * ey, -0.15, 0.15)) + c, s = np.cos(yaw), np.sin(yaw) + vx, vy = c * wx + s * wy, -s * wx + c * wy + if abs(ex) < 0.012 and abs(ey) < 0.012: + vx = vy = 0.0 + yaw_error = (target[2] - yaw + np.pi) % (2.0 * np.pi) - np.pi + wz = float(np.clip(1.2 * yaw_error, -0.25, 0.25)) + if abs(yaw_error) < 0.01: + wz = 0.0 + return vx, vy, wz + + def act(self, obs, tools): + if self.phase_step >= self.DURATIONS[self.phase]: + self._advance() + phase = self.phase + step = self.phase_step + + left = right = LIFT + pitch = 0.1 + grip_left = grip_right = 1.0 + if phase in ("left_pre", "left_pose", "left_close"): + left = {"left_pre": PRE}.get(phase, GRASP) + right = ZERO + pitch = 0.3 if phase != "left_pre" else 0.0 + grip_left = 1.0 if phase == "left_close" else 0.0 + grip_right = 0.6 + elif phase in ("right_pre", "right_pose", "right_close"): + left = GRASP + right = {"right_pre": PRE}.get(phase, GRASP) + pitch = 0.3 + grip_left = 1.0 + grip_right = 1.0 if phase == "right_close" else 0.0 + elif phase == "left_align": + left, right = ALIGN, LIFT + elif phase in ("approach", "crouch", "lower"): + left, right = ALIGN, LIFT + elif phase == "left_insert": + left, right = LEFT_INSERT, ALIGN + elif phase in ("left_release", "left_settle", "right_align"): + left, right = LEFT_INSERT, ALIGN + grip_left = 0.0 + elif phase in ("right_release", "final_settle", "finished"): + left, right = LEFT_INSERT, ALIGN + grip_left = grip_right = 0.0 + + moving_arms = phase in ( + "left_pre", "left_pose", "right_pre", "right_pose", "both_lift", + "left_align", "right_align", "left_insert", + ) + u = min(1.0, (step + 1) / 60.0) if moving_arms else 1.0 + self.left = self.start_left * (1.0 - u) + left * u + self.right = self.start_right * (1.0 - u) + right * u + self.pitch = self.start_pitch * (1.0 - u) + pitch * u + + raw = self.hold.copy() + height = 0.74 + if phase == "crouch": + h = min(1.0, (step + 1) / 75.0) + height = 0.74 * (1.0 - h) + 0.62 * h + elif phase == "lower": + h = min(1.0, (step + 1) / 75.0) + height = 0.62 * (1.0 - h) + 0.40 * h + elif phase in ("left_insert", "left_release", "left_settle", "right_align", "right_release", "final_settle", "finished"): + height = 0.40 + raw[0:2] = 0.0 + raw[2] = height + raw[3] = 0.0 + raw[4] = self.pitch + raw[5:12] = self.left + raw[12:19] = self.right + raw[19] = grip_left + raw[20] = grip_right + + nav_targets = { + "back": (-0.42, -0.60, 0.0), + "left": (-0.42, -0.35, 0.0), + "turn": (-0.42, -0.35, 0.45), + "approach": (-0.28, -0.15, 0.45), + } + if phase in nav_targets: + raw[0], raw[1], raw[3] = self._navigation(obs, nav_targets[phase]) + elif phase in ("left_align", "right_align"): + yaw = float(obs["low_dim_obs"][24]) + raw[3] = float(np.clip(1.2 * (0.45 - yaw), -0.25, 0.25)) + + self.phase_step += 1 + return raw diff --git a/policies/dishwasher_load_plates/kimi31pro-s2/episodes.csv b/policies/dishwasher_load_plates/kimi31pro-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..bb8615aaba66e08554099fc8bf1aa3c6cf854015 --- /dev/null +++ b/policies/dishwasher_load_plates/kimi31pro-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1016,terminated,0 +620001,0,3150,timeout,0 +620002,0,1695,terminated,0 +620003,0,1188,terminated,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,1143,terminated,0 +620007,0,1002,terminated,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,1136,terminated,0 +620011,0,1296,terminated,0 +620012,0,3150,timeout,0 +620013,0,3150,timeout,0 +620014,0,1126,terminated,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,1083,terminated,0 +620019,0,1008,terminated,0 +620020,0,1669,terminated,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,1190,terminated,0 +620024,0,3150,timeout,0 +620025,0,1361,terminated,0 +620026,0,3150,timeout,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,1131,terminated,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,3150,timeout,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,1195,terminated,0 +620038,0,1173,terminated,0 +620039,0,1236,terminated,0 +620040,0,3150,timeout,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,975,terminated,0 +620044,0,1152,terminated,0 +620045,0,3150,timeout,0 +620046,0,1179,terminated,0 +620047,0,3150,timeout,0 +620048,0,1121,terminated,0 +620049,0,3150,timeout,0 +620050,0,1225,terminated,0 +620051,0,3150,timeout,0 +620052,0,3150,timeout,0 +620053,0,1092,terminated,0 +620054,0,3150,timeout,0 +620055,0,951,terminated,0 +620056,0,3150,timeout,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,1112,terminated,0 +620060,0,3150,timeout,0 +620061,0,3150,timeout,0 +620062,0,1514,terminated,0 +620063,0,3150,timeout,0 +620064,0,1169,terminated,0 +620065,0,1033,terminated,0 +620066,0,1695,terminated,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,1152,terminated,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,1309,terminated,0 +620073,0,1287,terminated,0 +620074,0,3150,timeout,0 +620075,0,1018,terminated,0 +620076,0,1130,terminated,0 +620077,0,3150,timeout,0 +620078,0,1148,terminated,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,1011,terminated,0 +620083,0,1022,terminated,0 +620084,0,3150,timeout,0 +620085,0,1196,terminated,0 +620086,0,1695,terminated,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,1361,terminated,0 +620090,0,3150,timeout,0 +620091,0,3150,timeout,0 +620092,0,1067,terminated,0 +620093,0,3150,timeout,0 +620094,0,1691,terminated,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,1695,terminated,0 +620098,0,1184,terminated,0 +620099,0,1135,terminated,0 diff --git a/policies/dishwasher_load_plates/kimi31pro-s2/policy.py b/policies/dishwasher_load_plates/kimi31pro-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..d1c4de204755411bae2c60b2add837925580ac4d --- /dev/null +++ b/policies/dishwasher_load_plates/kimi31pro-s2/policy.py @@ -0,0 +1,159 @@ +"""Deterministic joint-space controller for loading two plates. + +The policy uses only proprioception and the physical action interface. Arm +motions are interpolated between measured joint positions; base motions are +closed-loop velocity commands using the pelvis pose and velocity. +""" + +import numpy as np + + +def arm(sp, roll, yaw, elbow, wrist_roll=0.0, wrist_pitch=0.0, wrist_yaw=0.0): + return np.array( + [sp, roll, yaw, elbow, wrist_roll, wrist_pitch, wrist_yaw], + dtype=np.float64, + ) + + +PARK_LEFT = arm(-1.35, 0.55, 0.0, 1.1) +PARK_RIGHT = arm(-1.35, -0.55, 0.0, 1.1) +LEFT_APPROACH_0 = arm(-1.35, 0.0, 0.0, 1.1) +LEFT_APPROACH_1 = arm(-1.35, 0.0, 0.4, 1.1) +LEFT_GRASP = arm(-1.35, 0.0, 0.45, 1.1) +LEFT_CLEAR = arm(-1.35, 0.45, 0.45, 1.1) +RIGHT_GRASP = arm(-1.35, 0.0, -0.45, 1.1) +LEFT_CARRY = arm(-0.9, 0.0, 0.45, 0.8, 0.0, -0.3) +RIGHT_CARRY = arm(-0.9, 0.0, -0.45, 0.8, 0.0, -0.3) +LEFT_INSERT = arm(-0.9, 0.0, 1.2, 0.8, 0.8, -0.3) +LEFT_RETREAT = arm(-0.35, 0.0, 1.2, 0.8, 0.8, -0.3) +RIGHT_INSERT = arm(-0.9, 0.0, 0.3, 0.8, -0.8, -0.3) +RIGHT_RETREAT = arm(-0.35, 0.0, 0.3, 0.8, -0.8, -0.3) + + +class Policy: + def reset(self, obs, tools): + self.raw = np.asarray(tools.hold_action(), dtype=np.float64).copy() + self.raw[2] = 0.74 + self.raw[4] = -0.2 + self.raw[19:21] = 0.0 + self.grip_right = 0.0 + + # kind, duration, left target, right target, height, pitch, left grip, + # optional base target. A base target of None means stand still. + self.phases = [ + ("move", 100, LEFT_APPROACH_0, PARK_RIGHT, 0.74, -0.2, 0.0, None), + ("move", 60, LEFT_APPROACH_1, PARK_RIGHT, 0.74, -0.2, 0.0, None), + ("move", 70, LEFT_GRASP, PARK_RIGHT, 0.74, -0.2, 0.0, None), + ("approach", 140, None, None, 0.74, -0.2, 0.0, (0.08, -0.60, 0.0)), + ("move", 50, LEFT_GRASP, PARK_RIGHT, 0.74, -0.2, 1.0, None), + ("move", 100, LEFT_GRASP, PARK_RIGHT, 0.82, -0.2, 1.0, None), + ("move", 100, LEFT_CLEAR, RIGHT_GRASP, 0.82, -0.2, 1.0, None), + ("approach", 140, None, None, 0.82, -0.2, 1.0, (0.14, -0.60, 0.10)), + ("move_right_close", 60, LEFT_CLEAR, RIGHT_GRASP, 0.82, -0.2, 1.0, None), + ("servo", 240, None, None, 0.82, -0.2, 1.0, (-0.28, -0.60, 0.0)), + ("move", 90, LEFT_CARRY, RIGHT_CARRY, 0.74, 0.2, 1.0, (-0.28, -0.60, 0.0)), + ("servo", 80, None, None, 0.74, 0.2, 1.0, (-0.28, -0.60, 0.0)), + ("move", 110, LEFT_INSERT, RIGHT_CARRY, 0.54, 0.65, 1.0, None), + ("move", 100, LEFT_INSERT, RIGHT_CARRY, 0.54, 0.65, 0.0, None), + ("move", 110, LEFT_RETREAT, RIGHT_CARRY, 0.54, 0.65, 0.0, None), + ("move", 130, LEFT_RETREAT, RIGHT_INSERT, 0.54, 0.65, 0.0, None), + ("move_right_open", 100, LEFT_RETREAT, RIGHT_INSERT, 0.54, 0.65, 0.0, None), + ("move", 110, LEFT_RETREAT, RIGHT_RETREAT, 0.54, 0.65, 0.0, None), + ("hold", 10**9, None, None, 0.54, 0.65, 0.0, None), + ] + self.phase = -1 + self.phase_t = 0 + self._enter(0, obs) + + def _enter(self, index, obs): + self.phase = index + self.phase_t = 0 + spec = self.phases[index] + kind = spec[0] + if kind == "move_right_close": + self.grip_right = 1.0 + elif kind == "move_right_open": + self.grip_right = 0.0 + if kind.startswith("move"): + q = obs["low_dim_obs"] + self.left_start = q[3:10].copy() + self.right_start = q[12:19].copy() + self.height_start = self.raw[2] + self.pitch_start = self.raw[4] + + @staticmethod + def _servo_command(obs, target): + q = obs["low_dim_obs"] + tx, ty, target_yaw = target + yaw = q[24] + c, s = np.cos(yaw), np.sin(yaw) + error = np.array([tx - q[21], ty - q[22]]) + desired = np.clip(2.2 * error, -0.14, 0.14) + command = desired + 1.2 * (desired - q[46:48]) + vx = c * command[0] + s * command[1] + vy = -s * command[0] + c * command[1] + desired_yaw_rate = np.clip(2.5 * (target_yaw - yaw), -0.25, 0.25) + wz = desired_yaw_rate + (desired_yaw_rate - q[49]) + return ( + np.clip(vx, -0.2, 0.2), + np.clip(vy, -0.16, 0.16), + np.clip(wz, -0.3, 0.3), + ) + + @staticmethod + def _servo_settled(obs, target): + q = obs["low_dim_obs"] + return ( + abs(target[0] - q[21]) < 0.018 + and abs(target[1] - q[22]) < 0.018 + and abs(target[2] - q[24]) < 0.04 + and np.linalg.norm(q[46:48]) < 0.025 + and abs(q[49]) < 0.04 + ) + + def _approach_command(self, obs, target): + q = obs["low_dim_obs"] + yaw = q[24] + dx, dy = target[0] - q[21], target[1] - q[22] + c, s = np.cos(yaw), np.sin(yaw) + vx = np.clip(3.5 * (c * dx + s * dy), -0.18, 0.18) if abs(dx) > 0.005 else 0.0 + vy = np.clip(3.5 * (-s * dx + c * dy), -0.12, 0.12) if abs(dy) > 0.006 else 0.0 + if target[2] == 0.0: + wz = np.clip(-2.0 * yaw, -0.2, 0.2) + else: + wz = np.clip(2.0 * (target[2] - yaw), -0.25, 0.25) + return vx, vy, wz + + def act(self, obs, tools): + spec = self.phases[self.phase] + kind, duration, base_target = spec[0], spec[1], spec[7] + + if self.phase_t >= duration or ( + kind == "servo" and self.phase_t > 50 and self._servo_settled(obs, base_target) + ): + self._enter(self.phase + 1, obs) + spec = self.phases[self.phase] + kind, duration, base_target = spec[0], spec[1], spec[7] + + if kind.startswith("move"): + _, _, left, right, height, pitch, grip_left, base_target = spec + s = min(1.0, (self.phase_t + 1) / (duration - 25)) + self.raw[5:12] = (1.0 - s) * self.left_start + s * left + self.raw[12:19] = (1.0 - s) * self.right_start + s * right + self.raw[2] = self.height_start + (height - self.height_start) * s + self.raw[4] = self.pitch_start + (pitch - self.pitch_start) * s + self.raw[19] = grip_left + self.raw[20] = self.grip_right + else: + self.raw[19] = spec[6] + self.raw[20] = self.grip_right + + if kind == "approach": + self.raw[0], self.raw[1], self.raw[3] = self._approach_command(obs, base_target) + elif base_target is not None: + self.raw[0], self.raw[1], self.raw[3] = self._servo_command(obs, base_target) + else: + self.raw[0] = self.raw[1] = self.raw[3] = 0.0 + + self.phase_t += 1 + return np.asarray(self.raw, dtype=np.float32) diff --git a/policies/dishwasher_load_plates/kimi31pro-s3/episodes.csv b/policies/dishwasher_load_plates/kimi31pro-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..4b66e4aaf35a69f95b3ac51f12866fbfe13fab3b --- /dev/null +++ b/policies/dishwasher_load_plates/kimi31pro-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,3150,timeout,0 +620001,0,3150,timeout,0 +620002,0,655,terminated,0 +620003,0,3150,timeout,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,3150,timeout,0 +620007,0,3150,timeout,0 +620008,0,3150,timeout,0 +620009,0,3150,timeout,0 +620010,0,3150,timeout,0 +620011,0,3150,timeout,0 +620012,0,923,terminated,0 +620013,0,3150,timeout,0 +620014,0,3150,timeout,0 +620015,0,3150,timeout,0 +620016,0,3150,timeout,0 +620017,0,3150,timeout,0 +620018,0,3150,timeout,0 +620019,0,529,terminated,0 +620020,0,3150,timeout,0 +620021,0,3150,timeout,0 +620022,0,3150,timeout,0 +620023,0,3150,timeout,0 +620024,0,3150,timeout,0 +620025,0,2327,terminated,0 +620026,0,706,terminated,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,0,3150,timeout,0 +620030,0,3150,timeout,0 +620031,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620034,0,2269,terminated,0 +620035,0,3150,timeout,0 +620036,0,3150,timeout,0 +620037,0,3150,timeout,0 +620038,0,3150,timeout,0 +620039,0,3150,timeout,0 +620040,0,466,terminated,0 +620041,0,3150,timeout,0 +620042,0,3150,timeout,0 +620043,0,3150,timeout,0 +620044,0,3150,timeout,0 +620045,0,3150,timeout,0 +620046,0,3150,timeout,0 +620047,0,3150,timeout,0 +620048,0,3150,timeout,0 +620049,0,3150,timeout,0 +620050,0,1155,terminated,0 +620051,0,2252,terminated,0 +620052,0,3150,timeout,0 +620053,0,984,terminated,0 +620054,0,3150,timeout,0 +620055,0,583,terminated,0 +620056,0,895,terminated,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,2669,terminated,0 +620061,0,3150,timeout,0 +620062,0,3150,timeout,0 +620063,0,3150,timeout,0 +620064,0,3150,timeout,0 +620065,0,3150,timeout,0 +620066,0,590,terminated,0 +620067,0,3150,timeout,0 +620068,0,3150,timeout,0 +620069,0,3150,timeout,0 +620070,0,3150,timeout,0 +620071,0,3150,timeout,0 +620072,0,3150,timeout,0 +620073,0,3150,timeout,0 +620074,0,3150,timeout,0 +620075,0,558,terminated,0 +620076,0,3150,timeout,0 +620077,0,3150,timeout,0 +620078,0,3150,timeout,0 +620079,0,3150,timeout,0 +620080,0,3150,timeout,0 +620081,0,3150,timeout,0 +620082,0,800,terminated,0 +620083,0,849,terminated,0 +620084,0,3150,timeout,0 +620085,0,635,terminated,0 +620086,0,3150,timeout,0 +620087,0,3150,timeout,0 +620088,0,3150,timeout,0 +620089,0,2180,terminated,0 +620090,0,3150,timeout,0 +620091,0,706,terminated,0 +620092,0,3150,timeout,0 +620093,0,3150,timeout,0 +620094,0,2163,terminated,0 +620095,0,3150,timeout,0 +620096,0,3150,timeout,0 +620097,0,536,terminated,0 +620098,0,513,terminated,0 +620099,0,3150,timeout,0 diff --git a/policies/dishwasher_load_plates/kimi31pro-s3/policy.py b/policies/dishwasher_load_plates/kimi31pro-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..472eead7c36fb5e768bd2704768ad0e7c840cfbc --- /dev/null +++ b/policies/dishwasher_load_plates/kimi31pro-s3/policy.py @@ -0,0 +1,182 @@ +"""Deterministic hand-written control for loading two plates into the dishwasher. + +Arm motions are joint-space primitives. Base motion is closed-loop on the +pelvis pose in ``low_dim_obs``. No task state or demonstration data is read. +""" + +import numpy as np + + +class Policy: + """Pick, carry, and deposit both plates with measured arm primitives.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + zero = np.zeros(7, dtype=np.float32) + pitch = 0.45 + self.plan = [] + + first_grasp = np.array([-0.60, 0.40, -0.23, -0.10, 0.0, -0.45, 0.0]) + first_carry = np.array([0.50, 0.40, -0.23, -1.00, 0.0, -0.65, 0.0]) + self._pick("first", "left", first_grasp, first_carry, 20) + + self._arms("stow", 50, zero, zero, 0.6, 0.6, pitch) + self._nav("return_to_sink_side", -0.40, -0.60, pitch=pitch, + speed=0.22, timeout=400) + self._nav("return_to_sink_front", -0.07, -0.60, pitch=pitch, + speed=0.22, timeout=250) + + second_grasp = np.array([-0.60, 0.40, -0.30, -0.10, 0.0, -0.45, 0.0]) + second_carry = np.array([0.50, 0.40, -0.30, -1.00, 0.0, -0.65, 0.0]) + self._pick("second", "left", second_grasp, second_carry, 70, + pregrasp_y=-0.64) + + self.stage_index = 0 + self.command = self.hold.copy() + self.command[:2] = self.command[3] = 0.0 + self.command[2] = 0.74 + self.stage_name = "reset" + self._start_stage() + + def _pick(self, name, hand, grasp, carry, final_hold, pregrasp_y=-0.60): + zero = np.zeros(7, dtype=np.float32) + left = hand == "left" + pitch = 0.45 + approach_left, approach_right = (grasp, zero) if left else (zero, grasp) + carry_left, carry_right = (carry, zero) if left else (zero, carry) + open_left, open_right = (0.0, 0.6) if left else (0.6, 0.0) + shut_left, shut_right = (1.0, 0.6) if left else (0.6, 1.0) + self._arms(name + "_approach", 80, approach_left, approach_right, + open_left, open_right, pitch) + self._nav(name + "_pregrasp", 0.10, pregrasp_y, pitch=pitch, timeout=200) + self._arms(name + "_close", 35, approach_left, approach_right, + shut_left, shut_right, pitch) + self._arms(name + "_grip_settle", 20, approach_left, approach_right, + shut_left, shut_right, pitch) + self.plan.append({"kind": "check", "name": name + "_grip_check", + "hand": hand, "retry_yaw": grasp[2] + 0.18}) + self._arms(name + "_extract", 80, carry_left, carry_right, + shut_left, shut_right, pitch) + self._nav(name + "_retreat", -0.40, -0.60, pitch=pitch, timeout=450) + self._nav(name + "_to_dishwasher", -0.40, 0.00, pitch=pitch, timeout=500) + self._arms(name + "_insert", 100, approach_left, approach_right, + shut_left, shut_right, pitch, height=0.55) + self._arms(name + "_release", 35, approach_left, approach_right, + open_left, open_right, pitch, height=0.55) + self._arms(name + "_released", final_hold, approach_left, approach_right, + open_left, open_right, pitch, height=0.55) + + def _arms(self, name, duration, left, right, left_grip, right_grip, pitch, + height=0.74): + goal = self.hold.copy() + goal[5:12] = left + goal[12:19] = right + goal[19] = left_grip + goal[20] = right_grip + goal[:2] = goal[3] = 0.0 + goal[2] = height + goal[4] = pitch + self.plan.append({"kind": "arms", "name": name, "duration": duration, + "goal": goal}) + + def _nav(self, name, x, y, pitch, speed=0.12, timeout=300): + self.plan.append({"kind": "nav", "name": name, "duration": timeout, + "xy": np.array([x, y], dtype=np.float32), + "pitch": pitch, "speed": speed}) + + def _start_stage(self): + self.stage = self.plan[self.stage_index] + self.stage_name = self.stage["name"] + self.stage_step = 0 + self.settle_steps = 0 + self.nav_finished = False + self.phase_start = self.command.copy() + + def _advance(self): + if self.stage["kind"] == "arms": + self.command = self.stage["goal"].copy() + self.stage_index += 1 + if self.stage_index < len(self.plan): + self._start_stage() + else: + self.stage_name = "done" + self.command[:2] = self.command[3] = 0.0 + + def act(self, obs, tools): + if self.stage_index >= len(self.plan): + raw = self.command.copy() + raw[:2] = raw[3] = 0.0 + return raw + + stage = self.stage + if stage["kind"] == "check": + raw = self.command.copy() + left = stage["hand"] == "left" + fingers = obs["low_dim_obs"][10:12] if left else obs["low_dim_obs"][19:21] + empty = bool(np.all(fingers < -0.018)) + if empty and not stage.get("retried", False): + yaw_index = 7 if left else 14 + grip_index = 19 if left else 20 + retry_yaw = stage["retry_yaw"] + prefix = stage["name"].split("_grip_check")[0] + for later in self.plan[self.stage_index + 1:]: + if later["name"].startswith(prefix + "_") and later["kind"] == "arms": + later["goal"][yaw_index] = retry_yaw + adjust = raw.copy() + adjust[yaw_index] = retry_yaw + adjust[grip_index] = 0.0 + closed = adjust.copy() + closed[grip_index] = 1.0 + retry_check = {"kind": "check", "name": prefix + "_retry_check", + "hand": stage["hand"], "retry_yaw": retry_yaw, + "retried": True} + self.plan[self.stage_index + 1:self.stage_index + 1] = [ + {"kind": "arms", "name": prefix + "_retry_adjust", + "duration": 50, "goal": adjust}, + {"kind": "arms", "name": prefix + "_retry_close", + "duration": 35, "goal": closed}, + {"kind": "arms", "name": prefix + "_retry_settle", + "duration": 20, "goal": closed}, + retry_check, + ] + self._advance() + return raw + + if stage["kind"] == "arms": + u = min(1.0, (self.stage_step + 1) / stage["duration"]) + s = u * u * (3.0 - 2.0 * u) + raw = self.phase_start + s * (stage["goal"] - self.phase_start) + raw[:2] = raw[3] = 0.0 + self.stage_step += 1 + if self.stage_step >= stage["duration"]: + self._advance() + return raw + + low = obs["low_dim_obs"] + position = low[21:23] + yaw = float(low[24]) + error = stage["xy"] - position + distance = float(np.linalg.norm(error)) + raw = self.command.copy() + raw[2] = 0.74 + raw[4] = stage["pitch"] + if not self.nav_finished: + if distance < 0.025 or self.stage_step >= stage["duration"]: + self.nav_finished = True + else: + speed_limit = stage["speed"] + velocity = np.clip(1.2 * error, -speed_limit, speed_limit) + if np.linalg.norm(velocity) < min(0.065, speed_limit): + velocity = min(0.065, speed_limit) * error / max(distance, 1e-6) + c, s = np.cos(yaw), np.sin(yaw) + raw[0] = c * velocity[0] + s * velocity[1] + raw[1] = -s * velocity[0] + c * velocity[1] + raw[3] = float(np.clip(-0.8 * yaw, -0.25, 0.25)) + self.stage_step += 1 + if self.nav_finished: + raw[:2] = raw[3] = 0.0 + self.settle_steps += 1 + if self.settle_steps >= 25: + self.command = raw.copy() + self._advance() + return raw diff --git a/policies/dishwasher_load_plates/opus-s1/episodes.csv b/policies/dishwasher_load_plates/opus-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..9766b08dd7490907f5fb209b89286d2497e43a86 --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1419,terminated,0 +620001,0,3150,timeout,0 +620002,1,2348,success,0 +620003,1,2385,success,0 +620004,0,3150,timeout,0 +620005,0,3150,timeout,0 +620006,0,1333,terminated,0 +620007,0,1262,terminated,0 +620008,1,2506,success,0 +620009,1,2406,success,0 +620010,1,2375,success,0 +620011,0,1429,terminated,0 +620012,0,1632,terminated,0 +620013,1,2502,success,0 +620014,0,1549,terminated,0 +620015,1,2494,success,0 +620016,0,3150,timeout,0 +620017,1,2384,success,0 +620018,0,3150,timeout,0 +620019,0,3150,timeout,0 +620020,0,3150,timeout,0 +620021,1,2335,success,0 +620022,1,2492,success,0 +620023,0,3150,timeout,0 +620024,0,1382,terminated,0 +620025,0,3150,timeout,0 +620026,0,2084,terminated,0 +620027,0,3150,timeout,0 +620028,0,3150,timeout,0 +620029,1,2328,success,0 +620030,0,1422,terminated,0 +620031,1,2717,success,0 +620032,0,3150,timeout,0 +620033,0,1257,terminated,0 +620034,1,2410,success,0 +620035,0,1319,terminated,0 +620036,1,2542,success,0 +620037,0,1643,terminated,0 +620038,0,3150,timeout,0 +620039,0,1362,terminated,0 +620040,1,2371,success,0 +620041,0,3150,timeout,0 +620042,1,2412,success,0 +620043,0,1258,terminated,0 +620044,0,1387,terminated,0 +620045,1,2380,success,0 +620046,1,2340,success,0 +620047,0,3150,timeout,0 +620048,1,2370,success,0 +620049,0,1409,terminated,0 +620050,1,2357,success,0 +620051,1,2479,success,0 +620052,0,1892,terminated,0 +620053,1,2381,success,0 +620054,0,3150,timeout,0 +620055,0,3150,timeout,0 +620056,1,2524,success,0 +620057,0,3150,timeout,0 +620058,0,3150,timeout,0 +620059,0,3150,timeout,0 +620060,0,3150,timeout,0 +620061,0,1687,terminated,0 +620062,0,1801,terminated,0 +620063,0,3150,timeout,0 +620064,1,2550,success,0 +620065,0,1677,terminated,0 +620066,1,2334,success,0 +620067,0,1713,terminated,0 +620068,0,1643,terminated,0 +620069,0,1802,terminated,0 +620070,0,1402,terminated,0 +620071,0,1389,terminated,0 +620072,0,3150,timeout,0 +620073,1,2488,success,0 +620074,0,1414,terminated,0 +620075,1,2235,success,0 +620076,0,1213,terminated,0 +620077,0,3150,timeout,0 +620078,0,1222,terminated,0 +620079,1,2497,success,0 +620080,0,1806,terminated,0 +620081,1,2384,success,0 +620082,1,2351,success,0 +620083,1,2385,success,0 +620084,0,3150,timeout,0 +620085,0,3150,timeout,0 +620086,1,2386,success,0 +620087,0,1520,terminated,0 +620088,0,1366,terminated,0 +620089,0,3150,timeout,0 +620090,1,2546,success,0 +620091,0,1765,terminated,0 +620092,0,1815,terminated,0 +620093,0,1394,terminated,0 +620094,1,2340,success,0 +620095,1,2348,success,0 +620096,1,2500,success,0 +620097,0,1795,terminated,0 +620098,1,2491,success,0 +620099,1,2448,success,0 diff --git a/policies/dishwasher_load_plates/opus-s1/g1lib.py b/policies/dishwasher_load_plates/opus-s1/g1lib.py new file mode 100644 index 0000000000000000000000000000000000000000..49102de879fce31be62ae78f41662732764569cd --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s1/g1lib.py @@ -0,0 +1,234 @@ +"""Kinematics, camera model and plate perception for the G1 dish task (all hand-written).""" +import numpy as np +from scipy import ndimage + +# ---------------------------------------------------------------- rotations +def rotx(a): + c,s=np.cos(a),np.sin(a); return np.array([[1,0,0],[0,c,-s],[0,s,c]]) +def roty(a): + c,s=np.cos(a),np.sin(a); return np.array([[c,0,s],[0,1,0],[-s,0,c]]) +def rotz(a): + c,s=np.cos(a),np.sin(a); return np.array([[c,-s,0],[s,c,0],[0,0,1]]) +_AX=(roty,rotx,rotz,roty,rotx,roty,rotz) + +# ---------------------------------------------------------------- arm kinematics (torso frame, G1 URDF) +def _chain(side): + m=1 if side=='L' else -1 + P=[(0.0039563,m*0.10022,0.24778),(0,m*0.038,-0.013831),(0,m*0.00624,-0.1032), + (0.015783,0,-0.080518),(0.100,m*0.00188791,-0.010),(0.038,0,0),(0.046,0,0)] + Rs=[rotx(m*0.27931),rotx(-m*0.27925),np.eye(3),np.eye(3),np.eye(3),np.eye(3),np.eye(3)] + return [np.array(p) for p in P],Rs +CH={s:_chain(s) for s in 'LR'} + +def fk(q,side,tool=(0,0,0),elbow=False): + P,Rs=CH[side] + R=np.eye(3); p=np.zeros(3); pe=None + for i in range(7): + p=p+R@P[i]; R=R@Rs[i]@_AX[i](q[i]) + if i==3: pe=p.copy() + if elbow: return p+R@np.asarray(tool),R,pe + return p+R@np.asarray(tool),R + +LO=np.array([-3.0892,-1.5882,-2.618,-1.0472,-1.97222,-1.61443,-1.61443]) +HI=np.array([2.6704,2.2515,2.618,2.0944,1.97222,1.61443,1.61443]) +def _limits(side): + if side=='L': return LO.copy(),HI.copy() + lo=LO.copy(); hi=HI.copy() + for i in (1,2,4,6): lo[i],hi[i]=-HI[i],-LO[i] + return lo,hi +LIM={s:_limits(s) for s in 'LR'} +ELBOW_Y=0.17; ELBOW_W=2.0 + +def _res(q,p_t,R_t,side,wrot): + p,R,pe=fk(q,side,(0,0,0),True) + sg=1 if side=='L' else -1 + eb=ELBOW_W*max(0.0,ELBOW_Y-sg*pe[1]) + return np.r_[p_t-p, wrot*(R_t-R).ravel(), eb] + +def ik(p_t,R_t,side,q0,wrot=0.15,iters=40): + """Levenberg-Marquardt with joint limits; wrist position + orientation + elbow clearance.""" + lo,hi=LIM[side] + q=np.clip(np.array(q0,float),lo,hi) + e=_res(q,p_t,R_t,side,wrot); c=e@e; lam=1e-3; h=1e-6 + for it in range(iters): + if c<1e-10: break + J=np.zeros((len(e),7)) + for i in range(7): + dq=q.copy(); dq[i]+=h + J[:,i]=-(_res(dq,p_t,R_t,side,wrot)-e)/h + A=J.T@J; g=J.T@e + improved=False + for _ in range(6): + dq=np.linalg.solve(A+lam*np.diag(np.diag(A)+1e-6),g) + qn=np.clip(q+dq,lo,hi) + en=_res(qn,p_t,R_t,side,wrot); cn=en@en + if cn60) + +def top_peaks(im,maxrow=60,border=3): + m=gray_mask(im) + lab,n=ndimage.label(m) + if n==0: return [] + sizes=ndimage.sum(m,lab,range(1,n+1)) + keep=np.isin(lab,1+np.nonzero(sizes>=25)[0]) + top=np.full(84,np.inf) + for c in range(84): + r=np.nonzero(keep[:maxrow,c])[0] + if len(r): top[c]=r[0] + peaks=[]; c=0 + while c<84: + if np.isfinite(top[c]): + lo_=max(0,c-4); hi_=min(84,c+5) + if top[c]<=top[lo_:hi_].min() and top[c]>0: + e=c + while e+1<84 and top[e+1]==top[c]: e+=1 + cc=(c+e)/2 + if border<=cc<=83-border: peaks.append((cc,float(top[c]))) + c=e+1; continue + c+=1 + return peaks + +def stripe_fit(im,u0,v0,nrows=14,maxw=9,gate=4): + g=gray_mask(im); pts=[]; u=u0 + for v in range(int(v0)+1,min(84,int(v0)+1+nrows)): + xs=np.nonzero(g[v])[0] + if len(xs)==0: continue + br=np.nonzero(np.diff(xs)>1)[0] + st=np.r_[xs[0],xs[br+1]]; en=np.r_[xs[br],xs[-1]] + c=(st+en)/2.0; w=en-st+1 + j=np.argmin(np.abs(c-u)) + if abs(c[j]-u)>gate: continue + if w[j]<=maxw: pts.append((v,c[j])); u=c[j] + if len(pts)<5: return None + P=np.array(pts); A=np.c_[np.ones(len(P)),P[:,0]] + return np.linalg.lstsq(A,P[:,1],rcond=None)[0] + +def locate_plates(ims,lo,zlim,xlim): + """plate tops in world: returns list of (P_top(3), k=dy/dz tilt)""" + cams={s:cam_world(lo,s) for s in 'LR'} + pk={'L':top_peaks(ims['L']),'R':top_peaks(ims['R'])} + cands=[] + for a in pk['L']: + oL,RL=cams['L']; d1=ray(RL,*a) + for b in pk['R']: + oR,RR=cams['R']; d2=ray(RR,*b) + A=np.c_[d1,-d2]; t=np.linalg.lstsq(A,oR-oL,rcond=None)[0] + if t[0]<=0 or t[1]<=0: continue + P1=oL+t[0]*d1; P2=oR+t[1]*d2; P=(P1+P2)/2 + if np.linalg.norm(P1-P2)<0.012 and zlim[0]0 and abs(Q[2]-zr)<0.03: ys.append((Q[1],s,p)) + ys.sort(key=lambda r:r[0]) + clusters=[] + for r in ys: + if clusters and r[0]-clusters[-1][-1][0]<0.02: clusters[-1].append(r) + else: clusters.append([r]) + out=[] + for cl in clusters: + y=float(np.mean([r[0] for r in cl])); T=np.array([xr,y,zr]) + ks=[] + for _,s,p in cl: + o,Rc=cams[s] + coef=stripe_fit(ims[s],p[0],p[1]) + if coef is None: continue + a,b=coef; v1,v2=p[1]+2,p[1]+12 + n=np.cross(ray(Rc,a+b*v1,v1),ray(Rc,a+b*v2,v2)); n/=np.linalg.norm(n) + if abs(n[1])<0.2: continue + k=-n[2]/n[1] + if abs(k)<0.6: ks.append(k) + out.append((T,float(np.mean(ks)) if ks else 0.0,len(cl))) + return out,pk + +def edge_line(im,u_pred,gate=10,rows=(2,50)): + """plate edge stripe near u_pred in a wrist image: (u at row 4, slope, n) or None""" + g=gray_mask(im); pts=[] + for v in range(rows[0],rows[1]): + xs=np.nonzero(g[v])[0] + if len(xs)==0: continue + br=np.nonzero(np.diff(xs)>1)[0] + starts=np.r_[xs[0],xs[br+1]]; ends=np.r_[xs[br],xs[-1]] + best=None + for a,b in zip(starts,ends): + if b-a>14: continue + c=(a+b)/2.0 + if abs(c-u_pred)<=gate and (best is None or abs(c-u_pred)0.01 or er>0.05): + q2,ep2,er2=G.ik_multi(np.asarray(p,float),R,self.side,self.q) + if ep2+0.05*er20.02: vx,vy=vx/sp*0.06,vy/sp*0.06 + else: vx=vy=0.0 + wz=np.clip(2.0*wrap(tyaw-yaw),-0.4,0.4) + if abs(wz)<0.03: wz=0.0 + # acceleration limit (smooth walking while carrying) + acc=ACC*0.02 + pvx,pvy=self.vprev + vx=float(np.clip(vx,pvx-acc,pvx+acc)); vy=float(np.clip(vy,pvy-acc,pvy+acc)) + self.vprev=(vx,vy) + if np.hypot(vx,vy)<0.055: vx_c,vy_c=0.0,0.0 + else: vx_c,vy_c=vx,vy + self.base[0]=vx_c; self.base[1]=vy_c; self.base[3]=wz + return np.hypot(dx,dy) + def stop_base(self): self.base[0]=self.base[1]=self.base[3]=0.0; self.vprev=(0.0,0.0) + def hand_w(self,lo,side,P,Rw): + """command the wrist of `side` to world position P with world orientation Rw""" + R,o=G.torso_world(lo) + self.q[side]=self.arm[side].solve(R.T@(np.asarray(P,float)-o),R.T@Rw) + self.wpose[side]=(np.asarray(P,float),Rw) + def meas_w(self,lo,side,tool=(0,0,0)): + q=lo[3:10] if side=='L' else lo[12:19] + p,R=G.fk(q,side,tool); return G.t2w(lo,p) + def lerp_w(self,lo,side,P_end,Rw,n,pt): + key='_ls_'+side + if pt==0: setattr(self,key,self.wpose[side][0] if side in self.wpose else self.meas_w(lo,side)) + ps=getattr(self,key) + s=min(1.0,(pt+1)/n); s=s*s*(3-2*s) + self.hand_w(lo,side,ps+(np.asarray(P_end)-ps)*s,Rw) + return pt+1>=n + def Ryaw(self,extra=np.eye(3)): return rotz(self.yaw0)@extra + # ---------- main + def act(self,obs,tools): + lo=np.asarray(obs['low_dim_obs'],float); t=self.t; self.t+=1 + pt=self.pt; self.pt+=1 + ph=self.phase + def nxt(p): + self.phase=p; self.pt=0 + for a_ in self.arm.values(): a_.allow_jump=(p=='pre') + if DBG: print(t,'->',p,'pelvis',lo[21:25]) + if ph=='raise': + s=min(1,pt/40) + for sd in 'LR': self.q[sd]=self.qlook[sd]*s + if pt>=70: + ims={'L':tools.image('left_wrist'),'R':tools.image('right_wrist')} + pl,_=G.locate_plates(ims,lo,(0.95,1.15),(0.35,0.80)) + if DBG: print('plates',[(np.round(T,3),round(k,3),n) for T,k,n in pl]) + pl=sorted(pl,key=lambda p:p[0][1]) + self.plate={} + if len(pl)>=2: self.plate={'L':pl[-1],'R':pl[0]} + elif len(pl)==1: self.plate={('L' if pl[0][0][1]>lo[22] else 'R'):pl[0]} + self.order=[s for s in 'LR' if s in self.plate] + snap(tools,self.tag,'look') + for sd in 'LR': self.arm[sd].q=self.q[sd].copy() + for sd in 'LR': self.wpose[sd]=(self.meas_w(lo,sd),None) + nxt('next') + elif ph=='next': + if not self.order: nxt('retreat'); return self.out() + self.side=self.order.pop(0); nxt('align') + elif ph=='align': + sd=self.side; sg=1 if sd=='L' else -1 + T,k,_=self.plate[sd] + c,s_=np.cos(self.yaw0),np.sin(self.yaw0) + tx=T[0]-c*STAND_OFF_X+s_*sg*GRASP_Y; ty=T[1]-s_*STAND_OFF_X-c*sg*GRASP_Y + d=self.goto_base(lo,tx,ty,self.yaw0,vmax=0.15) + if (d<0.02 and pt>20) or pt>180: + self.stop_base(); nxt('align2') + elif ph=='align2': + if pt>=20: nxt('ready') + elif ph=='ready': + sd=self.side; sg=1 if sd=='L' else -1 + if pt==0: + self.q_from=self.q[sd].copy() + self.q_to,_,_=G.ik_multi(np.array([0.22,sg*0.15,0.27]),np.eye(3),sd) + k=min(1.0,(pt+1)/50); k=k*k*(3-2*k) + self.q[sd]=self.q_from+(self.q_to-self.q_from)*k; self.arm[sd].q=self.q[sd].copy() + if pt>=55: + q=lo[3:10] if sd=='L' else lo[12:19] + p,R=G.fk(self.q[sd],sd); Rt,o=G.torso_world(lo) + self.wpose[sd]=(o+Rt@p,Rt@R); nxt('pre') + elif ph=='pre': + sd=self.side + T,k,_=self.plate[sd] + if pt==0: + zg=T[2]-GRIP_DROP + xf=T[0]-np.sqrt(PLATE_R**2-(PLATE_R-GRIP_DROP)**2) + self.gy=T[1]-GRIP_DROP*k; self.gy0=self.gy + self.roll=-float(np.arctan(k)); self.roll0=self.roll + self.xf=xf; self.zg=zg + self.wx_end=xf-GDEPTH; self.wx=self.wx_end-0.07 + if DBG: print('grasp',sd,'xf',round(xf,3),'y',round(self.gy,3),'z',round(zg,3),'k',round(k,3)) + self.lerp_w(lo,sd,[self.wx,self.gy,self.zg+0.03],self.Ryaw(rotx(self.roll)),60,pt) + if pt>=75: snap(tools,self.tag,'pre'+sd); nxt('in') + elif ph=='in': + sd=self.side + if pt%4==0 and self.wx=8 and n>=15: + self.roll=float(np.clip(self.roll-0.4*np.radians(slope/0.0145),self.roll0-0.2,self.roll0+0.2)) + self.wx=min(self.wx_end,self.wx+0.001) + self.hand_w(lo,sd,[self.wx,self.gy,self.zg+0.03*max(0,1-pt/40)],self.Ryaw(rotx(self.roll))) + if self.wx>=self.wx_end and pt>45: + snap(tools,self.tag,'in'+sd); nxt('close') + elif ph=='close': + sd=self.side + self.g[sd]=min(1.0,pt/20) + if pt==45: + gs=lo[50] if sd=='L' else lo[51] + self.held[sd]=gs<0.97 + if DBG: print('grip state',sd,gs,'held',self.held[sd]) + nxt('lift') + elif ph=='lift': + sd=self.side + if self.lerp_w(lo,sd,[self.wx,self.gy,self.zg+0.20],self.Ryaw(rotx(self.roll)),70,pt) and pt>=75: + snap(tools,self.tag,'lift'+sd); nxt('stow') + elif ph=='stow': + sd=self.side; sg=1 if sd=='L' else -1 + if pt==0: + P0,R0=self.wpose[sd]; self.rim0=P0+R0@np.array([GDEPTH,0,0]) + self.rim1=G.t2w(lo,[0.30,sg*0.27,0.42]) + n=90; k=min(1.0,(pt+1)/n); k=k*k*(3-2*k) + Rw=self.Ryaw(rotx(self.roll*(1-k))@roty(CARRY_PITCH*k)) + rim=self.rim0+(self.rim1-self.rim0)*k + self.hand_w(lo,sd,rim-Rw@np.array([GDEPTH,0,0]),Rw) + if pt>=n+5: snap(tools,self.tag,'stow'+sd); nxt('next') + # ---------------- transport + elif ph=='retreat': + if pt==0: self.rt=(lo[21]-0.10*np.cos(self.yaw0),lo[22]-0.10*np.sin(self.yaw0)) + d=self.goto_base(lo,self.rt[0],self.rt[1],self.yaw0,vmax=WALK_V) + if (d<0.04 and pt>20) or pt>150: nxt('todw') + elif ph=='todw': + d=self.goto_base(lo,DW_BASE[0],DW_BASE[1],self.yaw0,vmax=WALK_V) + self.hold_arms(lo) + if (d<0.02 and pt>40) or pt>750: + self.stop_base(); snap(tools,self.tag,'atdw'); nxt('squat') + elif ph=='squat': + nxt('over') + elif ph=='over': + n=150; k=min(1.0,(pt+1)/n); k=k*k*(3-2*k) + self.base[2]=0.74+(SQH-0.74)*k; self.base[4]=SQP*k + yaw=lo[24] + for sd in 'LR': + sg=1 if sd=='L' else -1 + if pt==0: + q=lo[3:10] if sd=='L' else lo[12:19] + p,R=G.fk(q,sd); Rt,o=G.torso_world(lo); Rm=Rt@R + if not hasattr(self,'ov'): self.ov={} + xa=rotz(-self.yaw0)@Rm[:,0] + a0=float(np.arctan2(-xa[2],xa[0])) + rim0=o+Rt@p+Rm@np.array([GDEPTH,0,0]) + tgt=np.array([lo[21]+np.cos(yaw)*PL_FWD-np.sin(yaw)*sg*PL_Y, lo[22]+np.sin(yaw)*PL_FWD+np.cos(yaw)*sg*PL_Y, PL_Z0]) + self.ov[sd]=(rim0,a0,tgt) + rim0,a0,tgt=self.ov[sd] + Rw=self.Ryaw(roty(a0+(PLACE_PITCH-a0)*k)) + rim=rim0+(tgt-rim0)*k + self.hand_w(lo,sd,rim-Rw@np.array([GDEPTH,0,0]),Rw) + if pt%30==0: snap(tools,self.tag,f'ov{pt}') + if pt>=n+30: + snap(tools,self.tag,'over'); self.zl=PL_Z0; self.contact={'L':False,'R':False}; nxt('lower') + elif ph=='lower': + self.zl-=0.0008 + for sd in 'LR': + if self.contact[sd]: continue + P=self.ov[sd][2].copy(); P[2]=self.zl + Rw=self.Ryaw(roty(PLACE_PITCH)) + self.hand_w(lo,sd,P-Rw@np.array([GDEPTH,0,0]),Rw) + if pt>20: + pm=self.meas_w(lo,sd)+Rw@np.array([GDEPTH,0,0]) + if P[2]=50: nxt('back') + elif ph=='back': + for sd in 'LR': + P0=self.wpose[sd][0] + if pt==0: setattr(self,'_bk'+sd,P0.copy()) + B=getattr(self,'_bk'+sd) + k=min(1,pt/60) + self.hand_w(lo,sd,B+np.array([-0.12*k*np.cos(self.yaw0),-0.12*k*np.sin(self.yaw0),0.10*k]),self.Ryaw()) + if pt>=70: + k=min(1.0,(pt-70)/100) + self.base[2]=SQH+(0.74-SQH)*k; self.base[4]=SQP*(1-k) + if pt%50==0: snap(tools,self.tag,f'back{pt}') + if pt>=200: nxt('wait') + elif ph=='wait': + if pt==100: snap(tools,self.tag,'final') + return self.out() + def hold_arms(self,lo): + pass + def out(self): + if not hasattr(self,'qprev'): self.qprev={sd:self.q[sd].copy() for sd in 'LR'} + for sd in 'LR': + d=np.clip(self.q[sd]-self.qprev[sd],-0.035,0.035); self.q[sd]=self.qprev[sd]+d; self.qprev[sd]=self.q[sd].copy() + a=self.h.copy() + a[:5]=self.base + a[5:12]=self.q['L']; a[12:19]=self.q['R']; a[19]=self.g['L']; a[20]=self.g['R'] + return a diff --git a/policies/dishwasher_load_plates/opus-s2/camgeo.py b/policies/dishwasher_load_plates/opus-s2/camgeo.py new file mode 100644 index 0000000000000000000000000000000000000000..c7768901ce05e70ea32cdb918d78697b6c7e8b9d --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s2/camgeo.py @@ -0,0 +1,63 @@ +"""Wrist camera model (hand-eye calibration from a bundle adjustment on the dev seeds).""" +import numpy as np +from scipy.spatial.transform import Rotation as Rot + +from g1fk import arm_fk, _rot + +F = 77.4 # focal length in pixels for the 84x84 image +_R0 = np.array([[0, 0, -1], [-1, 0, 0], [0, 1, 0]], float) +_MOUNT_R = (np.array([-0.00088, 0.39788, -0.00577]), np.array([0.10390, -0.00187, 0.05483])) + + +def mount(side): + r, t = _MOUNT_R + if side == 'l': # mirror about the x-z plane + r = np.array([-r[0], r[1], -r[2]]) + t = np.array([t[0], -t[1], t[2]]) + Rm = Rot.from_rotvec(r).as_matrix() @ _rot('y', 0.3) @ _R0 + return Rm, t + + +def hand_world(low, side, q=None): + """Hand (wrist_yaw frame) pose in world given the observation vector.""" + if q is None: + q = low[3:10] if side == 'l' else low[12:19] + p, R = arm_fk(q, side, low[0:3]) + Rw = _rot('z', low[24]) + return np.asarray(low[21:24], float) + Rw @ p, Rw @ R + + +def cam_world(low, side, q=None): + ph, Rh = hand_world(low, side, q) + Rm, t = mount(side) + return ph + Rh @ t, Rh @ Rm + + +def ray(C, Rc, u, v): + d = Rc @ np.array([(u - 42) / F, -(v - 42) / F, -1.0]) + return d / np.linalg.norm(d) + + +def project(C, Rc, X): + Xc = (np.asarray(X) - C) @ Rc + z = -Xc[..., 2] + return np.stack([42 + F * Xc[..., 0] / z, 42 - F * Xc[..., 1] / z], -1), z + + +def triangulate(rays): + A = np.zeros((3, 3)) + b = np.zeros(3) + for C, d in rays: + P = np.eye(3) - np.outer(d, d) + A += P + b += P @ C + return np.linalg.solve(A + 1e-9 * np.eye(3), b) + + +def world_to_pelvis(low, X): + yaw = low[24] + return _rot('z', -yaw) @ (np.asarray(X) - np.asarray(low[21:24])) + + +def pelvis_to_world(low, X): + return np.asarray(low[21:24]) + _rot('z', low[24]) @ np.asarray(X) diff --git a/policies/dishwasher_load_plates/opus-s2/episodes.csv b/policies/dishwasher_load_plates/opus-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..06b36e437202ea9154030e284c8e35e9ef3c9d11 --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s2/episodes.csv @@ -0,0 +1,99 @@ +seed,success,length,termination,fell +620008,0,993,terminated,0 +620003,0,1024,terminated,0 +620000,0,1031,terminated,0 +620010,0,1023,terminated,0 +620005,0,1076,terminated,0 +620009,0,1090,terminated,0 +620017,0,1058,terminated,0 +620020,0,3150,timeout,0 +620001,0,3150,timeout,0 +620004,0,3150,timeout,0 +620007,0,2940,terminated,0 +620022,0,3150,timeout,0 +620006,0,3150,timeout,0 +620019,0,1239,terminated,0 +620029,0,3150,timeout,0 +620034,0,1081,terminated,0 +620002,0,3150,timeout,0 +620011,0,3150,timeout,0 +620015,0,3150,timeout,0 +620046,0,992,terminated,0 +620041,0,1140,terminated,0 +620023,0,1027,terminated,0 +620012,0,3150,timeout,0 +620021,0,3150,timeout,0 +620027,0,1038,terminated,0 +620053,0,1026,terminated,0 +620058,0,3150,timeout,0 +620013,0,2759,terminated,0 +620018,0,3150,timeout,0 +620032,0,3150,timeout,0 +620033,0,3150,timeout,0 +620016,0,3150,timeout,0 +620014,0,3150,timeout,0 +620045,0,1054,terminated,0 +620035,0,3150,timeout,0 +620047,0,1036,terminated,0 +620031,0,3150,timeout,0 +620039,0,3150,timeout,0 +620043,0,1191,terminated,0 +620024,0,3150,timeout,0 +620065,0,3150,timeout,0 +620036,0,1022,terminated,0 +620048,0,1038,terminated,0 +620059,0,2099,terminated,0 +620060,0,1071,terminated,0 +620028,0,3150,timeout,0 +620071,0,1112,terminated,0 +620030,0,3150,timeout,0 +620040,0,1172,terminated,0 +620057,0,3150,timeout,0 +620083,0,1027,terminated,0 +620026,0,3150,timeout,0 +620070,0,3150,timeout,0 +620095,0,1005,terminated,0 +620044,0,3150,timeout,0 +620025,0,3150,timeout,0 +620051,0,3150,timeout,0 +620042,0,1717,terminated,0 +620054,0,993,terminated,0 +620072,0,3150,timeout,0 +620055,0,3150,timeout,0 +620077,0,3150,timeout,0 +620089,0,1028,terminated,0 +620082,0,3150,timeout,0 +620063,0,3150,timeout,0 +620094,0,1040,terminated,0 +620069,0,3150,timeout,0 +620052,0,3150,timeout,0 +620038,0,3052,fell,1 +620056,0,3150,timeout,0 +620081,0,1044,terminated,0 +620037,0,3150,timeout,0 +620093,0,1071,terminated,0 +620067,0,3150,timeout,0 +620084,0,3150,timeout,0 +620066,0,3150,timeout,0 +620064,0,3150,timeout,0 +620078,0,1710,terminated,0 +620050,0,3150,timeout,0 +620075,0,3150,timeout,0 +620068,0,3150,timeout,0 +620049,0,3150,timeout,0 +620079,0,3150,timeout,0 +620076,0,2073,terminated,0 +620061,0,1161,terminated,0 +620090,0,3150,timeout,0 +620062,0,3150,timeout,0 +620087,0,3150,timeout,0 +620080,0,3150,timeout,0 +620073,0,3150,timeout,0 +620091,0,3150,timeout,0 +620088,0,3150,timeout,0 +620074,0,3150,timeout,0 +620086,0,1128,terminated,0 +620099,0,3150,timeout,0 +620092,0,3150,timeout,0 +620085,0,3150,timeout,0 +620098,0,1885,terminated,0 diff --git a/policies/dishwasher_load_plates/opus-s2/g1fk.py b/policies/dishwasher_load_plates/opus-s2/g1fk.py new file mode 100644 index 0000000000000000000000000000000000000000..646f873325b57c5be1a6b52a2211381df6540311 --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s2/g1fk.py @@ -0,0 +1,99 @@ +"""Approximate forward kinematics of the G1 arms (Unitree model constants).""" +import numpy as np + + +def _quat(w, x, y, z): + w, x, y, z = np.array([w, x, y, z]) / np.linalg.norm([w, x, y, z]) + return np.array([ + [1 - 2 * (y * y + z * z), 2 * (x * y - z * w), 2 * (x * z + y * w)], + [2 * (x * y + z * w), 1 - 2 * (x * x + z * z), 2 * (y * z - x * w)], + [2 * (x * z - y * w), 2 * (y * z + x * w), 1 - 2 * (x * x + y * y)], + ]) + + +def _rot(axis, q): + c, s = np.cos(q), np.sin(q) + if axis == 'x': + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + if axis == 'y': + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +def _chain(side): + sg = 1.0 if side == 'l' else -1.0 + return [ + # (pos, quat or None, axis) + ((0.0039563, sg * 0.10022, 0.23778), (0.990264, sg * 0.139201, 0, 0), 'y'), + ((0, sg * 0.038, -0.013831), (0.990268, -sg * 0.139172, 0, 0), 'x'), + ((0, sg * 0.00624, -0.1032), None, 'z'), + ((0.015783, 0, -0.080518), None, 'y'), + ((0.100, sg * 0.00188791, -0.010), None, 'x'), + ((0.038, 0, 0), None, 'y'), + ((0.046, 0, 0), None, 'z'), + ] + + +def torso_frame(waist): + """pelvis->torso transform given waist yaw, roll, pitch.""" + R = _rot('z', waist[0]) + p = np.zeros(3) + p = p + R @ np.array([-0.0039635, 0, 0.035]) + R = R @ _rot('x', waist[1]) + p = p + R @ np.array([0, 0, 0.019]) + R = R @ _rot('y', waist[2]) + return p, R + + +def arm_fk(q, side, waist=(0, 0, 0), tip=0.0, all_frames=False): + """Return position, rotation of the wrist_yaw frame (+tip along x), in pelvis frame.""" + p, R = torso_frame(waist) + frames = [] + for (pos, quat, ax), qi in zip(_chain(side), q): + p = p + R @ np.array(pos) + if quat is not None: + R = R @ _quat(*quat) + R = R @ _rot(ax, qi) + frames.append((p.copy(), R.copy())) + p = p + R @ np.array([tip, 0, 0]) + if all_frames: + return p, R, frames + return p, R + + +def ik(target, side, q0, waist=(0, 0, 0), tip=0.0, rot_target=None, w_rot=0.3, + iters=100, lims=None, q_ref=None, w_ref=0.0): + """Damped least squares IK on the 7 joints. rot_target: 3x3 desired hand rotation.""" + q = np.array(q0, dtype=float) + for _ in range(iters): + p, R = arm_fk(q, side, waist, tip) + e = target - p + err = [e] + if rot_target is not None: + Re = rot_target @ R.T + ang = 0.5 * np.array([Re[2, 1] - Re[1, 2], Re[0, 2] - Re[2, 0], Re[1, 0] - Re[0, 1]]) + err.append(w_rot * ang) + err = np.concatenate(err) + if np.linalg.norm(err) < 1e-4: + break + J = np.zeros((len(err), 7)) + h = 1e-5 + for j in range(7): + dq = q.copy() + dq[j] += h + p2, R2 = arm_fk(dq, side, waist, tip) + col = [(p2 - p) / h] + if rot_target is not None: + dR = R2 @ R.T + w = 0.5 * np.array([dR[2, 1] - dR[1, 2], dR[0, 2] - dR[2, 0], dR[1, 0] - dR[0, 1]]) / h + col.append(w_rot * w) + J[:, j] = np.concatenate(col) + lam = 1e-3 + dq = J.T @ np.linalg.solve(J @ J.T + lam * np.eye(len(err)), err) + if q_ref is not None and w_ref > 0: + N = np.eye(7) - np.linalg.pinv(J) @ J + dq += N @ (w_ref * (np.asarray(q_ref) - q)) + q += np.clip(dq, -0.2, 0.2) + if lims is not None: + q = np.clip(q, lims[0], lims[1]) + return q diff --git a/policies/dishwasher_load_plates/opus-s2/policy.py b/policies/dishwasher_load_plates/opus-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38a02b2c34edb60441afa714bdcb7adcd11a9c --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s2/policy.py @@ -0,0 +1,680 @@ +"""Scripted policy for dishwasher_load_plates on the Unitree G1. + +Pipeline: raise the arms, localise the two plate tops by stereo from the two wrist +cameras, walk up to each plate, grasp it by its upper rim (camera-centred approach), +walk to the dishwasher, lower the plates into the lower rack and release. +""" + +import os +import sys + +import cv2 # noqa: F401 +import numpy as np +from scipy import ndimage +from scipy.spatial.transform import Rotation as Rot, Slerp + +sys.path.append(os.path.dirname(os.path.abspath(__file__))) +import camgeo # noqa: E402 +from g1fk import arm_fk, ik, _rot # noqa: E402 + +# comfortable joint ranges (the full limits let the IK fold the arm into the torso) +LIM_R = (np.array([-2.6, -1.5, -1.3, -1.0, -1.3, -1.4, -1.4]), np.array([1.0, 0.2, 1.3, 2.0, 1.3, 1.4, 1.4])) +LIM_L = (np.array([-2.6, -0.2, -1.3, -1.0, -1.3, -1.4, -1.4]), np.array([1.0, 1.5, 1.3, 2.0, 1.3, 1.4, 1.4])) +Q0 = {'l': np.array([-0.5, 0.3, 0.0, 0.5, 0.0, 0.0, 0.0]), + 'r': np.array([-0.5, -0.3, 0.0, 0.5, 0.0, 0.0, 0.0])} +_SEEDS = [[-0.5, 0.3, 0.0, 0.5, 0.0, 0.0, 0.0], [-1.0, 0.3, 0.0, 0.0, 0.0, 0.0, 0.0], + [-1.5, 0.3, 0.3, -0.5, 0.0, 0.0, 0.0], [-0.3, 0.6, -0.5, 0.0, 0.0, 0.0, 0.0], + [-1.0, 0.0, 0.5, -0.8, 0.0, 0.0, 0.0]] +SEEDS = {'l': [np.array(s) for s in _SEEDS], + 'r': [np.array(s) * np.array([1, -1, -1, 1, -1, 1, -1]) for s in _SEEDS]} +SL = {'l': slice(5, 12), 'r': slice(12, 19)} +OL = {'l': slice(3, 10), 'r': slice(12, 19)} +GI = {'l': 19, 'r': 20} +GS = {'l': 50, 'r': 51} +SGN = {'l': 1.0, 'r': -1.0} + +TIP = 0.20 # fingertip distance along the hand x axis (m) +APPROACH_X = 0.52 # pelvis to plate-top distance (x) when grasping +SHOULDER_Y = 0.13 # plate sits this far to the side of the pelvis (in front of the hand) +TORSO_GRASP = 0.0 +BACK_PITCH = 0.0 +BACK_PRE = 0.12 +BACK_DEPTH = 0.05 +BACK_GAIN = 0.6 +BACK_ITERS = 25 +BACK_STEP = 0.01 +BACK_MAX = 0.16 +BACK_LAG = 0.012 +LOOK_DY = (-0.06, -0.02, 0.02, 0.06) +LOOK_Z = 0.33 +LOOK_PITCH = -0.35 +TOP_DX = -0.03 +TOP_PRE = 0.06 +LIFT = 0.22 +TOP_DEPTH = 0.055 +TOP_SETTLE = 40 +REFINE_Z = False +TOP_GAIN = 0.8 +DW_X, DW_Y = -0.27, 0.65 +DW_LEAN, DW_HEIGHT = 0.4, 0.62 +DW_HX, DW_HY, DW_HZ = 0.32, 0.12, 0.05 +TOP_SERVO = 5 +SLIDE = True +SLIDE_START = 0.06 +SLIDE_END = 0.12 +SLIDE_REACH = 0.38 +SLIDE_LAG = 0.012 +DESCENT_SERVO = True +RETRY_DY = (0.0, 0.015, -0.015) +SL_PITCH = -0.6 +SL_Z = 0.22 +SL_DY = (-0.04, 0.0, 0.04) +AX_PITCH = 0.5 +AX_PRE = 0.05 +AX_IN = 0.05 +AX_DEPTH = 0.04 +AX_ROW0, AX_ROWS = 12, 60 +AX_SERVO = 5 +AX_REACH = 0.45 +GRASP_HEIGHT = 0.80 +SL_RANGE = (0.46, 0.56) +AX_GAIN = 0.6 +AX_LAG = 0.025 +U_STAR = 42.0 +GRASP_TRIES = 1 +EMPTY_GRIP = 0.95 +TOP_LAG = 0.02 +STATION_KEEP = False +SK_YAW_ON, SK_YAW_OFF = 0.04, 0.012 +SK_POS_ON, SK_POS_OFF = 0.04, 0.015 +MAX_DQ = 0.05 +INT_RATE = 0.03 +INT_CAP = 0.35 + + +def hand_rot(yaw, pitch, roll=0.0): + """Hand orientation; pitch > 0 points the hand x axis down.""" + return _rot('z', yaw) @ _rot('y', pitch) @ _rot('x', roll) + + +def plate_mask(im): + im = im.astype(int) + mx = im.max(2) + mn = im.min(2) + return (mx - mn <= 3) & (mx > 60) & (mn < 253) + + +def plate_mask_near(im): + """Plate pixels in close-up views: neutral grey/white including saturated white, not the dark gripper.""" + im = im.astype(int) + mx = im.max(2) + mn = im.min(2) + return (mx - mn <= 4) & (mx >= 120) + + +def plate_blobs(im, min_area=30): + lab, n = ndimage.label(plate_mask(im)) + out = [] + for i in range(1, n + 1): + m = lab == i + ys, xs = np.nonzero(m) + if len(xs) < min_area: + continue + out.append(dict(n=len(xs), u=xs.mean() + 0.5, v=ys.mean() + 0.5, u0=xs.min(), u1=xs.max() + 1, + v0=ys.min(), v1=ys.max() + 1, mask=m, xs=xs, ys=ys)) + return out + + +class Policy: + def reset(self, obs, tools): + self.tools = tools + self.obs = obs + self.hold = np.asarray(tools.hold_action(), dtype=np.float64) + self.act_vec = self.hold.copy() + self.act_vec[19] = self.act_vec[20] = 0.0 + low = obs['low_dim_obs'] + self.q = {s: np.array(low[OL[s]], float) for s in 'lr'} + self.qoff = {s: np.zeros(7) for s in 'lr'} + self.integrate = {s: True for s in 'lr'} + self.goal = {} # side -> (frame, p, R) current interpolated target + self.start = np.array(low[21:25], float) + self.held = {} + self.dbg = {} + self.stance = None + self.sk_active = False + self.ik_err = 0.0 + self.script = self.main() + + # ------------------------------------------------------------------ kinematics + @property + def low(self): + return self.obs['low_dim_obs'] + + def _ik(self, side, p, R, q0, iters): + lims = LIM_L if side == 'l' else LIM_R + q = ik(p, side, q0, self.low[0:3], rot_target=R, w_rot=0.5, iters=iters, lims=lims, + q_ref=Q0[side], w_ref=0.05) + pf, Rf = arm_fk(q, side, self.low[0:3]) + e = np.linalg.norm(pf - p) + 0.05 * np.arccos(np.clip((np.trace(Rf.T @ R) - 1) / 2, -1, 1)) + return q, e + + def solve(self, side, p, R, iters=15): + p = np.asarray(p, float) + q, e = self._ik(side, p, R, self.q[side], iters) + if e > 0.02: + for s in SEEDS[side]: + q2, e2 = self._ik(side, p, R, s, 150) + if e2 < e - 0.01: + q, e = q2, e2 + self.ik_err = max(self.ik_err, e) + self.q[side] = self.q[side] + np.clip(q - self.q[side], -MAX_DQ, MAX_DQ) + return self.q[side] + + def to_pelvis(self, frame, p, R): + if frame == 'pelvis': + return np.asarray(p, float), R + yaw = self.low[24] + Rz = _rot('z', -yaw) + return Rz @ (np.asarray(p, float) - np.asarray(self.low[21:24], float)), Rz @ R + + def to_world(self, p, R): + yaw = self.low[24] + return np.asarray(self.low[21:24], float) + _rot('z', yaw) @ p, _rot('z', yaw) @ R + + def hand_pose(self, side): + return arm_fk(self.low[OL[side]], side, self.low[0:3]) + + def wrist_from_tip(self, tip, R): + return np.asarray(tip, float) - R @ np.array([TIP, 0, 0]) + + def station_keep(self): + """Hold the stance pose (x, y, yaw) with small base commands, with hysteresis.""" + if self.stance is None: + return + x, y, yaw = self.stance + px, py, _, pyaw = self.low[21:25] + c, s = np.cos(pyaw), np.sin(pyaw) + bx, by = c * (x - px) + s * (y - py), -s * (x - px) + c * (y - py) + d = np.hypot(bx, by) + eyaw = (yaw - pyaw + np.pi) % (2 * np.pi) - np.pi + if not self.sk_active and (abs(eyaw) > SK_YAW_ON or d > SK_POS_ON): + self.sk_active = True + if self.sk_active and abs(eyaw) < SK_YAW_OFF and d < SK_POS_OFF: + self.sk_active = False + if self.sk_active: + self.act_vec[3] = np.clip(1.5 * eyaw, -0.3, 0.3) + if d > SK_POS_OFF: + v = max(0.06, min(0.15, 1.0 * d)) + self.act_vec[0], self.act_vec[1] = bx / d * v, by / d * v + else: + self.act_vec[0] = self.act_vec[1] = 0.0 + else: + self.act_vec[0] = self.act_vec[1] = self.act_vec[3] = 0.0 + + def emit(self): + self.station_keep() + self.ik_err = 0.0 + for s, (frame, p, R) in self.goal.items(): + pp, RR = self.to_pelvis(frame, p, R) + self.solve(s, pp, RR) + a = self.act_vec.copy() + for s in 'lr': + meas = np.asarray(self.low[OL[s]], float) + if self.integrate[s]: + self.qoff[s] = np.clip(self.qoff[s] + INT_RATE * (self.q[s] - meas), -INT_CAP, INT_CAP) + a[SL[s]] = self.q[s] + self.qoff[s] + return a + + def move(self, targets, steps, settle=0, frame='pelvis'): + """Interpolate wrist targets {side: (p, R)} given in `frame` ('pelvis' or 'world').""" + start = {} + for s in targets: + if s in self.goal and self.goal[s][0] == frame: + start[s] = self.goal[s][1:] + else: + pc, Rc = self.hand_pose(s) + if s in self.goal: + pc, Rc = self.to_pelvis(*self.goal[s]) + if frame == 'world': + pc, Rc = self.to_world(pc, Rc) + start[s] = (pc, Rc) + slerps = {s: Slerp([0, 1], Rot.from_matrix([start[s][1], targets[s][1]])) for s in targets} + for k in range(1, steps + 1): + t = k / steps + t = t * t * (3 - 2 * t) + for s, (p, R) in targets.items(): + pp = start[s][0] + t * (np.asarray(p, float) - start[s][0]) + self.goal[s] = (frame, pp, slerps[s](t).as_matrix()) + yield self.emit() + for _ in range(settle): + yield self.emit() + + def wait(self, n): + for _ in range(n): + yield self.emit() + + def walk_to(self, x, y, yaw, tol=0.02, maxn=500, speed=0.25, keep=True): + self.stance = None + for _ in range(maxn): + px, py, _, pyaw = self.low[21:25] + dx, dy = x - px, y - py + c, s = np.cos(pyaw), np.sin(pyaw) + bx, by = c * dx + s * dy, -s * dx + c * dy + d = np.hypot(bx, by) + eyaw = (yaw - pyaw + np.pi) % (2 * np.pi) - np.pi + if d < tol and abs(eyaw) < 0.03: + break + v = min(speed, 1.2 * d) + vx, vy = (bx / d * v, by / d * v) if d > 1e-6 else (0.0, 0.0) + if np.hypot(vx, vy) < 0.06: + if d < tol: + vx = vy = 0.0 + else: + sc = 0.06 / max(np.hypot(vx, vy), 1e-6) + vx, vy = vx * sc, vy * sc + self.act_vec[0], self.act_vec[1] = vx, vy + self.act_vec[3] = np.clip(1.5 * eyaw, -0.5, 0.5) + yield self.emit() + self.act_vec[0] = self.act_vec[1] = self.act_vec[3] = 0.0 + if keep and STATION_KEEP: + self.stance = (x, y, yaw) + self.sk_active = False + yield from self.wait(25) + + def mark(self, tag): + self.dbg.setdefault('marks', []).append((tag, int(self.obs['t']), np.round(np.array(self.low[21:25]), 3))) + + def grip(self, side, val, steps=25): + self.act_vec[GI[side]] = val + yield from self.wait(steps) + + # ------------------------------------------------------------------ perception + def cam_image(self, side): + return self.tools.image('left_wrist' if side == 'l' else 'right_wrist') + + def plate_tops(self, side): + im = self.cam_image(side) + C, Rc = camgeo.cam_world(self.low, side) + out = [] + for b in plate_blobs(im): + if b['v1'] - b['v0'] < 10: + continue + ys, xs = b['ys'], b['xs'] + vtop = ys.min() + sel = ys <= vtop + 1 + u = xs[sel].mean() + 0.5 + v = vtop + 0.5 + out.append(dict(u=u, v=v, C=C, d=camgeo.ray(C, Rc, u, v), blob=b, cut=(vtop == 0))) + out.sort(key=lambda t: t['u']) + return out + + def localise(self): + """Stereo-triangulate plate top points from both wrist cameras (world frame).""" + L, R = self.plate_tops('l'), self.plate_tops('r') + pts = [] + if len(L) == len(R): + for a_, b_ in zip(L, R): + pts.append(camgeo.triangulate([(a_['C'], a_['d']), (b_['C'], b_['d'])])) + return pts + + def stripe_u(self, side, umax_dev=35): + """Column of the plate stripe nearest the image centre, from its upper rows.""" + im = self.cam_image(side) + best = None + for b in plate_blobs(im, 20): + sel = b['ys'] < b['ys'].min() + 10 + u = b['xs'][sel].mean() + 0.5 + score = abs(u - 42) + if score < umax_dev and (best is None or score < best[0]): + best = (score, u) + return None if best is None else best[1] + + # ------------------------------------------------------------------ skills + def grasp_back(self, side, top): + """Approach the plate's upper rim horizontally from behind, centre it with the camera, close.""" + R = hand_rot(0, BACK_PITCH) + tip = top + np.array([-BACK_PRE, 0, -BACK_DEPTH]) + self.act_vec[GI[side]] = 0.0 + yield from self.move({side: (self.wrist_from_tip(tip + np.array([-0.05, 0, 0.04]), R), R)}, 60, 20, + frame='world') + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 30, 30, frame='world') + dbg = [] + adv = 0.0 + for it in range(BACK_ITERS): + u = self.stripe_u(side) + if u is not None: + tip[1] += -BACK_GAIN * (u - 42) / 77.0 * 0.15 + step = BACK_STEP if it >= 3 else 0.0 + adv += step + tip[0] += step + w = self.wrist_from_tip(tip, R) + yield from self.move({side: (w, R)}, 8, 6, frame='world') + ph, _ = self.hand_pose(side) + wp, _ = self.to_pelvis('world', w, R) + lag = (wp - ph)[0] + dbg.append((it, None if u is None else round(u, 1), round(adv, 3), round(lag, 4))) + if adv >= BACK_MAX or (it >= 4 and lag > BACK_LAG): + break + self.dbg['grasp_' + side] = dbg + self.integrate[side] = False + yield from self.grip(side, 1.0, 40) + self.held[side] = float(self.low[GS[side]]) + self.integrate[side] = True + yield from self.move({side: (self.wrist_from_tip(tip + np.array([0, 0, 0.16]), R), R)}, 60, 10, + frame='world') + + def stripe_u_rows(self, side, r0, r1, umax_dev=30, with_top=False, ref=None): + """Mean column of plate pixels in rows r0..r1 for the blob nearest column `ref` + (default: the projection of self.cur_top, else the image centre).""" + if ref is None: + ref = 42.0 + if getattr(self, 'cur_top', None) is not None: + C, Rc = camgeo.cam_world(self.low, side) + uv, z = camgeo.project(C, Rc, self.cur_top) + if z > 0.02: + ref = float(np.clip(uv[0], 0, 84)) + im = self.cam_image(side) + m = plate_mask(im) + lab, n = ndimage.label(m) + best = None + for i in range(1, n + 1): + ys, xs = np.nonzero(lab == i) + sel = (ys >= r0) & (ys < r1) + if sel.sum() < 6: + continue + u = xs[sel].mean() + 0.5 + if abs(u - ref) < umax_dev and (best is None or abs(u - ref) < abs(best[0] - ref)): + vt = ys.min() + ut = xs[ys <= vt + 1].mean() + 0.5 + best = (u, ut, vt + 0.5) + if with_top: + return best + return None if best is None else best[0] + + def grasp_top(self, side, top): + """Horizontal hand above the plate's top edge; centre the edge in the camera, descend, close.""" + R = hand_rot(0, 0.0) + tip = top + np.array([TOP_DX, 0, TOP_PRE]) + self.act_vec[GI[side]] = 0.0 + yield from self.move({side: (self.wrist_from_tip(tip + np.array([-0.06, 0, 0.05]), R), R)}, 60, 10, + frame='world') + self.mark('pre-grasp-above ' + side) + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 40, 30, frame='world') + self.mark('above ' + side) + dbg = [] + self.dbg['grasp_' + side] = dbg + y_nom = tip[1] + for attempt in range(GRASP_TRIES): + tip[1] = y_nom + RETRY_DY[attempt % len(RETRY_DY)] + for it in range(TOP_SERVO): + if getattr(self, 'debug', False): + C, Rc = camgeo.cam_world(self.low, side) + self.dbg.setdefault('ims', []).append((self.cam_image(side), camgeo.project(C, Rc, top)[0], + np.array(self.low))) + u = self.stripe_u_rows(side, 30, 70, umax_dev=30, ref=42.0) + if u is not None: + tip[1] += -TOP_GAIN * (u - 42.0) * 0.001 + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 10, 10, frame='world') + dbg.append(('s', attempt, it, None if u is None else round(u, 1), round(tip[1], 4))) + z_end = top[2] - TOP_DEPTH + if SLIDE: + # back off behind the plate, drop below the rim, slide forward until the palm touches + tip[0] = top[0] - SLIDE_START + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 30, 10, frame='world') + tip[2] = z_end + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 30, 15, frame='world') + while tip[0] < top[0] + SLIDE_END: + tip[0] += 0.01 + w = self.wrist_from_tip(tip, R) + wp, _ = self.to_pelvis('world', w, R) + if wp[0] > SLIDE_REACH: + tip[0] -= 0.01 + dbg.append(('reach',)) + break + yield from self.move({side: (w, R)}, 8, 6, frame='world') + ph, _ = self.hand_pose(side) + lag = (wp - ph)[0] + dbg.append(('x', round(tip[0] - top[0], 3), round(lag, 4))) + if lag > SLIDE_LAG: + break + while tip[2] > z_end + 1e-6: + u = self.stripe_u_rows(side, 30, 70, umax_dev=15, ref=42.0) if DESCENT_SERVO else None + if u is not None: + tip[1] += -0.5 * TOP_GAIN * (u - 42.0) * 0.001 + tip[2] = max(z_end, tip[2] - 0.01) + w = self.wrist_from_tip(tip, R) + yield from self.move({side: (w, R)}, 8, 6, frame='world') + ph, _ = self.hand_pose(side) + wp, _ = self.to_pelvis('world', w, R) + lag = (ph - wp)[2] + dbg.append(('d', round(tip[2] - top[2], 3), None if u is None else round(u, 1), round(lag, 4))) + if lag > TOP_LAG: + break + yield from self.wait(TOP_SETTLE) + if getattr(self, 'debug', False): + self.dbg.setdefault('bottom_ims', []).append( + [self.tools.image(c) for c in ('head', 'left_wrist', 'right_wrist')]) + self.integrate[side] = False + yield from self.grip(side, 1.0, 40) + self.held[side] = float(self.low[GS[side]]) + self.integrate[side] = True + dbg.append(('grip', round(self.held[side], 2))) + if self.held[side] < EMPTY_GRIP or attempt == GRASP_TRIES - 1: + break + # missed: open, rise, retry + yield from self.grip(side, 0.0, 20) + tip[2] = top[2] + TOP_PRE + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 30, 20, frame='world') + yield from self.move({side: (self.wrist_from_tip(tip + np.array([0, 0, LIFT]), R), R)}, 70, 10, + frame='world') + self.held[side + '_after'] = float(self.low[GS[side]]) + + def stance_look(self, side, top): + """Re-triangulate one plate top with the grasping hand's camera from the grasp stance.""" + R = hand_rot(0, SL_PITCH) + rays = [] + for k, dy in enumerate(SL_DY): + yield from self.move({side: ([0.20, SGN[side] * 0.13 + dy, SL_Z], R)}, 40 if k == 0 else 25, 25) + C, Rc = camgeo.cam_world(self.low, side) + uv, _ = camgeo.project(C, Rc, top) + tps = self.plate_tops(side) + if not tps: + continue + b = min(tps, key=lambda t: abs(t['u'] - uv[0]) + 0.3 * abs(t['v'] - uv[1])) + self.dbg.setdefault('sl_' + side, []).append((np.round(uv, 1), [(round(t['u'], 1), t['v']) for t in tps])) + if getattr(self, 'debug', False): + self.dbg.setdefault('sl_ims', []).append(self.cam_image(side)) + if abs(b['u'] - uv[0]) < 15: + rays.append((b['C'], b['d'])) + if len(rays) >= 2: + X = camgeo.triangulate(rays) + self.dbg.setdefault('sl_X', []).append(np.round(X, 3)) + if abs(X[1] - top[1]) < 0.03 and np.linalg.norm(X - top) < 0.15: + return X + return top + + def located(self, side, top): + """Stance look; if the plate is out of the comfortable reach band, step and look again.""" + X = yield from self.stance_look(side, top) + d = X[0] - self.low[21] + self.dbg.setdefault('loc_' + side, []).append((np.round(X, 3), round(float(d), 3))) + if not (SL_RANGE[0] <= d <= SL_RANGE[1]): + lean = self.act_vec[4] + yield from self.walk_to(X[0] - APPROACH_X, X[1] - SGN[side] * SHOULDER_Y, 0.0, speed=0.12) + self.act_vec[4] = lean + yield from self.wait(20) + X = yield from self.stance_look(side, X) + self.dbg['loc_' + side].append((np.round(X, 3), round(float(X[0] - self.low[21]), 3))) + return X + + def grasp_axis(self, side, top): + """Approach the plate top along the finger axis with the hand pitched down; centre the plate + laterally in the wrist image on the way; close when the tip is past the rim.""" + R = hand_rot(0, AX_PITCH) + f = R @ np.array([1.0, 0, 0]) + tip = top - AX_PRE * f - np.array([0, 0, AX_DEPTH]) + self.act_vec[GI[side]] = 0.0 + yield from self.move({side: (self.wrist_from_tip(tip + np.array([0, 0, 0.03]) - 0.04 * f, R), R)}, + 50, 10, frame='world') + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 30, 25, frame='world') + dbg = [] + self.dbg['grasp_' + side] = dbg + wp, Rp = self.to_pelvis('world', self.wrist_from_tip(tip, R), R) + ph, Rh = self.hand_pose(side) + qf, Rf = arm_fk(self.q[side], side, self.low[0:3]) + dbg.append(('pre', 'ikerr', round(self.ik_err, 4), 'tgt', np.round(wp, 3), 'meas', np.round(ph, 3), + 'cmdfk', np.round(qf, 3), 'rot err deg', + round(np.degrees(np.arccos(np.clip((np.trace(Rh.T @ Rp) - 1) / 2, -1, 1))), 1), + 'q', np.round(self.q[side], 2), 'meas q', np.round(self.low[OL[side]], 2))) + y0 = tip[1] + for it in range(AX_SERVO): + if getattr(self, 'debug', False): + C, Rc = camgeo.cam_world(self.low, side) + self.dbg.setdefault('ims', []).append((self.cam_image(side), camgeo.project(C, Rc, top)[0], + np.array(self.low))) + u = self.stripe_u_rows(side, AX_ROW0, AX_ROWS, umax_dev=30, ref=42.0) + if u is not None: + tip[1] = np.clip(tip[1] - AX_GAIN * (u - U_STAR) * 0.001, y0 - 0.025, y0 + 0.025) + yield from self.move({side: (self.wrist_from_tip(tip, R), R)}, 10, 10, frame='world') + dbg.append(('s', it, None if u is None else round(u, 1), round(tip[1], 4))) + # advance along the finger axis until contact, the reach limit or the nominal depth + n = int(round((AX_PRE + AX_IN) / 0.01)) + for k in range(n): + tip = tip + 0.01 * f + w = self.wrist_from_tip(tip, R) + wp, _ = self.to_pelvis('world', w, R) + if wp[0] > AX_REACH: + tip = tip - 0.01 * f + dbg.append(('reach', k)) + break + yield from self.move({side: (w, R)}, 6, 4, frame='world') + ph, _ = self.hand_pose(side) + lag = np.linalg.norm(ph - wp) + dbg.append(('a', k, round(lag, 4))) + if lag > AX_LAG: + break + yield from self.wait(20) + self.integrate[side] = False + yield from self.grip(side, 1.0, 40) + self.held[side] = float(self.low[GS[side]]) + self.integrate[side] = True + dbg.append(('grip', round(self.held[side], 2))) + yield from self.move({side: (self.wrist_from_tip(tip + np.array([0, 0, LIFT]), R), R)}, 70, 10, + frame='world') + self.held[side + '_after'] = float(self.low[GS[side]]) + + def edge_run_u(self, side, r0, r1, which): + """Centre column of the extreme ('min' = leftmost, 'max' = rightmost) plate-coloured run in each row + r0..r1, averaged over rows; None if too few rows have a run.""" + im = self.cam_image(side) + m = plate_mask_near(im)[r0:r1] + cs = [] + for row in m: + xs = np.nonzero(row)[0] + if len(xs) < 2: + continue + # split into runs + br = np.nonzero(np.diff(xs) > 1)[0] + starts = np.concatenate([[xs[0]], xs[br + 1]]) + ends = np.concatenate([xs[br], [xs[-1]]]) + ok = (ends - starts) >= 1 + if not ok.any(): + continue + starts, ends = starts[ok], ends[ok] + k = np.argmax(ends) if which == 'max' else np.argmin(starts) + cs.append(0.5 * (starts[k] + ends[k]) + 0.5) + if len(cs) < 6: + return None + return float(np.median(cs)) + + # ------------------------------------------------------------------ script + def look(self): + """Both wrist cameras view the rack from just below the plate rims (so the topmost blob pixel + is the true top of each plate) from a few lateral positions; triangulate all rays per plate.""" + R = hand_rot(0, LOOK_PITCH) + views = [] + for k, dy in enumerate(LOOK_DY): + yield from self.move({'l': ([0.22, 0.13 + dy, LOOK_Z], R), 'r': ([0.22, -0.13 + dy, LOOK_Z], R)}, + 60 if k == 0 else 30, 30) + views.append((self.plate_tops('l'), self.plate_tops('r'))) + self.look_views = views + n = max(max(len(L), len(R_)) for L, R_ in views) + n = min(n, 4) + rays = [[] for _ in range(n)] + for L, R_ in views: + for tps in (L, R_): + if len(tps) == n: + for j in range(n): + rays[j].append((tps[j]['C'], tps[j]['d'])) + tops = [] + for j in range(n): + if len(rays[j]) >= 2: + tops.append(camgeo.triangulate(rays[j])) + return tops + + def look_stereo(self): + """Stereo between the two wrist cameras from above the rims (biased, but the grasp offsets + below were tuned against exactly this estimate).""" + R_look = hand_rot(0, -0.35) + yield from self.move({'l': ([0.20, 0.12, 0.35], R_look), 'r': ([0.20, -0.12, 0.35], R_look)}, 60, 40) + loc = [self.localise()] + yield from self.move({'l': ([0.18, 0.15, 0.38], R_look), 'r': ([0.18, -0.15, 0.38], R_look)}, 30, 30) + loc.append(self.localise()) + good = [pts for pts in loc if len(pts) >= 1] + if not good: + return [] + n = max(len(p) for p in good) + good = [p for p in good if len(p) == n] + return [np.mean([p[k] for p in good], 0) for k in range(n)] + + def main(self): + tops = yield from self.look() + self.tops = tops + R0 = hand_rot(0, 0.0) + tl, tr = tops[0], tops[-1] + yield from self.move({'l': ([0.12, 0.25, 0.25], R0), 'r': ([0.12, -0.25, 0.25], R0)}, 40, 10) + self.mark('pre-walk') + yield from self.walk_to(tr[0] - APPROACH_X, tr[1] + SHOULDER_Y, 0.0) + self.mark('walked') + self.act_vec[4] = TORSO_GRASP + self.act_vec[2] = GRASP_HEIGHT + yield from self.wait(30) + self.mark('leaned') + yield from self.grasp_axis('r', tr) + self.mark('grasped r') + # tuck the first plate, step over, take the second one with the left hand + yield from self.move({'r': ([0.22, -0.20, 0.40], hand_rot(0, AX_PITCH))}, 100, 10) + self.mark('tucked r') + yield from self.walk_to(tl[0] - APPROACH_X, tl[1] - SHOULDER_Y, 0.0, speed=0.12) + self.mark('walked l') + yield from self.grasp_axis('l', tl) + self.mark('grasped l') + yield from self.move({'l': ([0.22, 0.20, 0.45], R0), 'r': ([0.22, -0.20, 0.45], R0)}, 60, 10) + self.act_vec[4] = 0.0 + # carry to the dishwasher: back off, sidestep, approach + x0, y0 = self.start[0], self.start[1] + px, py = self.low[21], self.low[22] + yield from self.walk_to(px - 0.25, py, 0.0, speed=0.2) + yield from self.walk_to(x0 + DW_X, y0 + DW_Y, 0.0, speed=0.2) + self.mark('at dishwasher') + self.act_vec[4] = DW_LEAN + self.act_vec[2] = DW_HEIGHT + yield from self.wait(40) + yield from self.move({'l': (np.array([DW_HX, DW_HY, DW_HZ]), R0), + 'r': (np.array([DW_HX, -DW_HY, DW_HZ]), R0)}, 80, 30) + self.mark('lowered') + self.dbg['pre_release_ims'] = [self.tools.image(c) for c in ('head', 'left_wrist', 'right_wrist')] + self.act_vec[19] = self.act_vec[20] = 0.0 + yield from self.wait(40) + self.mark('released') + yield from self.move({'l': (np.array([DW_HX - 0.1, 0.25, DW_HZ + 0.15]), R0), + 'r': (np.array([DW_HX - 0.1, -0.25, DW_HZ + 0.15]), R0)}, 60, 10) + self.act_vec[4] = 0.0 + self.act_vec[2] = 0.74 + while True: + yield self.emit() + + def act(self, obs, tools): + self.obs = obs + a = next(self.script) + return np.asarray(a, dtype=np.float32) diff --git a/policies/dishwasher_load_plates/opus-s3/camera.py b/policies/dishwasher_load_plates/opus-s3/camera.py new file mode 100644 index 0000000000000000000000000000000000000000..f935cd52edd998582223f16316a8fe06b4c1b52a --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s3/camera.py @@ -0,0 +1,55 @@ +"""Wrist camera model (calibrated by bundle adjustment over known hand motions).""" +import numpy as np +from g1kin import fk, _rx, _ry, _rz + +CAM_PITCH = 0.69 # optical axis pitched down from the gripper axis (rad) +CAM_F = 78.7 # focal length in pixels (84x84 image) +CAM_YAW = -0.08 # toe-in (mirrored for the right hand) +CAM_OFF = np.array([0.10, 0.0, 0.054]) # from the wrist-yaw joint, gripper frame +C0 = 42.0 + + +def pelvis_to_world(o): + Rw = _rz(o[24]) + return Rw, o[21:24].copy() + + +def cam_pose(o, side, q=None): + """Camera (position, rotation) in world; rotation columns = (optical axis, image-left, image-up).""" + s = 1 if side == 'left' else -1 + if q is None: + q = o[3:10] if side == 'left' else o[12:19] + p, R = fk(q, side, o[0:3], hand_len=0.0) + Rc = R @ _rz(s * CAM_YAW) @ _ry(CAM_PITCH) + pc = p + R @ CAM_OFF + Rw, tw = pelvis_to_world(o) + return Rw @ pc + tw, Rw @ Rc + + +def project(P, pc, Rc): + d = (np.atleast_2d(P) - pc) @ Rc + return np.stack([C0 - CAM_F * d[:, 1] / d[:, 0], C0 - CAM_F * d[:, 2] / d[:, 0]], 1), d[:, 0] + + +def ray(uv, pc, Rc): + """World ray direction through pixel coords (u, v) (continuous, pixel centres at +0.5).""" + u, v = uv + d = Rc @ np.array([1.0, (C0 - u) / CAM_F, (C0 - v) / CAM_F]) + return d / np.linalg.norm(d) + + +def ray_plane_z(uv, pc, Rc, z): + d = ray(uv, pc, Rc) + if abs(d[2]) < 1e-6: + return None + s = (z - pc[2]) / d[2] + return pc + s * d if s > 0 else None + + +def triangulate(rays): + """Least-squares intersection of rays [(p, d), ...].""" + A = np.zeros((3, 3)); b = np.zeros(3) + for p, d in rays: + M = np.eye(3) - np.outer(d, d) + A += M; b += M @ p + return np.linalg.solve(A, b) diff --git a/policies/dishwasher_load_plates/opus-s3/episodes.csv b/policies/dishwasher_load_plates/opus-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..5b83a71b6e7c77d4b05bf1da33f3473721d308b4 --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1064,terminated,0 +620001,0,1878,terminated,0 +620002,0,1962,terminated,0 +620003,0,1713,terminated,0 +620004,0,1969,terminated,0 +620005,0,1845,terminated,0 +620006,0,2048,terminated,0 +620007,0,1080,terminated,0 +620008,0,1745,terminated,0 +620009,0,1682,terminated,0 +620010,0,1697,terminated,0 +620011,0,2044,terminated,0 +620012,0,1832,terminated,0 +620013,0,1755,terminated,0 +620014,0,1076,terminated,0 +620015,0,1969,terminated,0 +620016,0,1940,terminated,0 +620017,0,1758,terminated,0 +620018,0,1706,terminated,0 +620019,0,1611,terminated,0 +620020,0,1603,terminated,0 +620021,0,1905,terminated,0 +620022,0,1701,terminated,0 +620023,0,1729,terminated,0 +620024,0,1807,terminated,0 +620025,0,1835,terminated,0 +620026,0,1868,terminated,0 +620027,0,1661,terminated,0 +620028,0,1739,terminated,0 +620029,0,1944,terminated,0 +620030,0,1585,terminated,0 +620031,0,1907,terminated,0 +620032,0,1752,terminated,0 +620033,0,1608,terminated,0 +620034,0,1683,terminated,0 +620035,0,1521,terminated,0 +620036,0,1637,terminated,0 +620037,0,1763,terminated,0 +620038,0,1868,terminated,0 +620039,0,2076,terminated,0 +620040,0,1738,terminated,0 +620041,0,1644,terminated,0 +620042,0,1707,terminated,0 +620043,0,1470,terminated,0 +620044,0,2026,terminated,0 +620045,0,1738,terminated,0 +620046,0,3150,timeout,0 +620047,0,1887,terminated,0 +620048,0,1710,terminated,0 +620049,0,2046,terminated,0 +620050,0,1791,terminated,0 +620051,0,1625,terminated,0 +620052,0,1831,terminated,0 +620053,0,1711,terminated,0 +620054,0,1594,terminated,0 +620055,0,1631,terminated,0 +620056,0,1630,terminated,0 +620057,0,1756,terminated,0 +620058,0,3150,timeout,0 +620059,0,1827,terminated,0 +620060,0,1716,terminated,0 +620061,0,1647,terminated,0 +620062,0,1979,terminated,0 +620063,0,2059,terminated,0 +620064,0,1568,terminated,0 +620065,0,1923,terminated,0 +620066,0,2066,terminated,0 +620067,0,1930,terminated,0 +620068,0,1650,terminated,0 +620069,0,1884,terminated,0 +620070,0,2107,terminated,0 +620071,0,1598,terminated,0 +620072,0,1538,terminated,0 +620073,0,1715,terminated,0 +620074,0,1694,terminated,0 +620075,0,1526,terminated,0 +620076,0,1468,terminated,0 +620077,0,1965,terminated,0 +620078,0,3150,timeout,0 +620079,0,1698,terminated,0 +620080,0,1614,terminated,0 +620081,0,1605,terminated,0 +620082,0,1828,terminated,0 +620083,0,1671,terminated,0 +620084,0,1749,terminated,0 +620085,0,1420,terminated,0 +620086,0,1664,terminated,0 +620087,0,3150,timeout,0 +620088,0,1868,terminated,0 +620089,0,1739,terminated,0 +620090,0,2029,terminated,0 +620091,0,2058,terminated,0 +620092,0,2153,terminated,0 +620093,0,1615,terminated,0 +620094,0,1813,terminated,0 +620095,0,1780,terminated,0 +620096,0,1655,terminated,0 +620097,1,2264,success,0 +620098,0,1606,terminated,0 +620099,0,1678,terminated,0 diff --git a/policies/dishwasher_load_plates/opus-s3/g1kin.py b/policies/dishwasher_load_plates/opus-s3/g1kin.py new file mode 100644 index 0000000000000000000000000000000000000000..f2c80b4c3df1ea1871db300670e6a4a4565894a0 --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s3/g1kin.py @@ -0,0 +1,117 @@ +"""Approximate G1 arm kinematics (pelvis frame: x forward, y left, z up).""" +import numpy as np +from scipy.optimize import least_squares + + +def _rx(a): + c, s = np.cos(a), np.sin(a) + return np.array([[1, 0, 0], [0, c, -s], [0, s, c]]) + + +def _ry(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]]) + + +def _rz(a): + c, s = np.cos(a), np.sin(a) + return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]]) + + +HAND_LEN = 0.13 # wrist_yaw joint -> point between the finger tips (guess, tuned) + +LOW = np.array([-3.0892, -1.5882, -2.618, -1.0472, -1.97222, -1.61443, -1.61443]) +HIGH = np.array([2.6704, 2.2515, 2.618, 2.0944, 1.97222, 1.61443, 1.61443]) + + +def limits(side): + if side == 'left': + return LOW.copy(), HIGH.copy() + lo, hi = LOW.copy(), HIGH.copy() + # roll and yaw joints mirror + lo[1], hi[1] = -HIGH[1], -LOW[1] + return lo, hi + + +def fk(q, side='left', waist=(0.0, 0.0, 0.0), hand_len=None): + """Return (p, R) of the gripper centre in the pelvis frame.""" + s = 1.0 if side == 'left' else -1.0 + hl = HAND_LEN if hand_len is None else hand_len + R = _rz(waist[0]) + p = np.zeros(3) + p = p + R @ np.array([-0.0039635, 0, 0.044]) + R = R @ _rx(waist[1]) @ _ry(waist[2]) + chain = [ + (np.array([0.0039563, s * 0.10022, 0.23778]), _rx(s * 0.27931), _ry), + (np.array([0, s * 0.038, -0.013831]), _rx(-s * 0.27925), _rx), + (np.array([0, s * 0.00624, -0.1032]), np.eye(3), _rz), + (np.array([0.015783, 0, -0.080518]), np.eye(3), _ry), + (np.array([0.100, s * 0.00188791, -0.010]), np.eye(3), _rx), + (np.array([0.038, 0, 0]), np.eye(3), _ry), + (np.array([0.046, 0, 0]), np.eye(3), _rz), + ] + for (off, R0, ax), qi in zip(chain, q): + p = p + R @ off + R = R @ R0 @ ax(qi) + p = p + R @ np.array([hl, 0, 0]) + return p, R + + +NATURAL = [np.array(v, float) for v in ( + [-0.5, 0.1, 0, 0.3, 0, 0.2, 0], [-1.0, 0.1, 0, 0.6, 0, 0.4, 0], [-1.4, 0.1, 0, 0.6, 0, 0.8, 0], + [-0.2, 0.2, 0, 0.0, 0, 0.0, 0], [-1.0, 0.3, 0, 1.2, 0, 0.0, 0], [-1.6, 0.2, 0, 1.0, 0, 0.5, 0])] + + +def mirror_q(q): + """Left-arm joint vector -> the mirror-image right-arm vector (and back).""" + return np.asarray(q, float) * np.array([1, -1, -1, 1, -1, 1, -1]) + + +def ik_multi(target_p, target_R, q_cur, side='left', waist=(0, 0, 0), w_rot=1.0, reg=0.03, + hand_len=None, rot_mask=None, seeds=None): + """IK from several seeds; regularised toward the current joint vector.""" + q_cur = np.asarray(q_cur, float) + cands = [q_cur] + for s in (seeds if seeds is not None else NATURAL): + cands.append(s if side == 'left' else mirror_q(s)) + best = None + for s in cands: + q, e = ik(target_p, target_R, s, side, waist, w_rot, hand_len, rot_mask, reg, q_ref=q_cur) + p, R = fk(q, side, waist, hand_len) + cost = np.linalg.norm(p - target_p) ** 2 + if target_R is not None: + cols = [0, 1, 2] if rot_mask is None else rot_mask + cost += (w_rot ** 2) * np.sum((R[:, cols] - target_R[:, cols]) ** 2) + cost += 1e-3 * np.sum((q - q_cur) ** 2) + lo, hi = limits(side) + margin = np.minimum(q - lo, hi - q) + cost += 0.02 * np.sum(np.maximum(0.0, 0.2 - margin) ** 2) + if best is None or cost < best[0]: + best = (cost, q, e) + q, e = ik(target_p, target_R, best[1], side, waist, w_rot, hand_len, rot_mask, 1e-3, q_ref=best[1]) + return q, e + + +def ik(target_p, target_R, q0, side='left', waist=(0, 0, 0), w_rot=0.3, hand_len=None, + rot_mask=None, reg=0.02, q_ref=None): + """Least-squares IK. target_R may be None (position only). + + rot_mask: list of gripper-axis indices whose direction should match target + (e.g. [0] only gripper pointing direction; [0, 1] full orientation). + """ + lo, hi = limits(side) + q0 = np.clip(np.asarray(q0, float), lo + 1e-3, hi - 1e-3) + qr = q0 if q_ref is None else np.asarray(q_ref, float) + cols = [0, 1, 2] if rot_mask is None else rot_mask + + def res(q): + p, R = fk(q, side, waist, hand_len) + r = [p - target_p] + if target_R is not None: + r.append(w_rot * (R[:, cols] - target_R[:, cols]).ravel(order='F')) + r.append(reg * (q - qr)) + return np.concatenate(r) + + sol = least_squares(res, q0, bounds=(lo, hi), xtol=1e-8, ftol=1e-8, max_nfev=200) + p, R = fk(sol.x, side, waist, hand_len) + return sol.x, np.linalg.norm(p - target_p) diff --git a/policies/dishwasher_load_plates/opus-s3/policy.py b/policies/dishwasher_load_plates/opus-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..f3881926479247e96a0ca35a0b4c6c0c911d8211 --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s3/policy.py @@ -0,0 +1,530 @@ +"""G1 policy: move the plates from the dish rack into the dishwasher's lower rack. + +Hand-written phase machine: + look raise both wrist cameras over the rack, find the two plates (stereo) + walk step up to the counter so the plates are within reach, look again + grasp left hand, then right hand: approach the top rim horizontally, close + carry lift, walk to the dishwasher + place squat, lower the plates into the rack, open, withdraw +""" + +import os +import sys + +import numpy as np + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +from g1kin import fk, ik, ik_multi, _rx, _ry, _rz # noqa: E402 +import camera # noqa: E402 +from camera import cam_pose, ray, triangulate # noqa: E402 +from vision import plate_mask, plate_tops # noqa: E402 + +SIDES = ('left', 'right') +QIDX = {'left': slice(3, 10), 'right': slice(12, 19)} +AIDX = {'left': slice(5, 12), 'right': slice(12, 19)} +GIDX = {'left': 19, 'right': 20} +MIR = np.array([1.0, -1.0, 1.0]) + + +def look_R(d, up=np.array([0, 0, 1.0])): + x = d / np.linalg.norm(d) + y = np.cross(up, x) + y /= np.linalg.norm(y) + z = np.cross(x, y) + return np.stack([x, y, z], 1) + + +def w2p(o, P): + """World point -> pelvis frame (yaw only).""" + c, s = np.cos(o[24]), np.sin(o[24]) + d = np.asarray(P, float) - o[21:24] + return np.array([c * d[0] + s * d[1], -s * d[0] + c * d[1], d[2]]) + + +def p2w(o, P): + c, s = np.cos(o[24]), np.sin(o[24]) + P = np.asarray(P, float) + return o[21:24] + np.array([c * P[0] - s * P[1], s * P[0] + c * P[1], P[2]]) + + +class Arm: + """Cartesian control of one arm with a slow integral correction for sag.""" + + def __init__(self, side): + self.side = side + self.q = np.zeros(7) + self.p = None # current Cartesian target (pelvis frame) + self.R = np.eye(3) + self.corr = np.zeros(3) + + def set_q(self, q): + self.q = np.asarray(q, float).copy() + self.p = None + + def goto(self, p, R, waist, multi=False, speed=None, rot_speed=0.015): + """Track Cartesian target p, R (pelvis frame); optional speed limits per step.""" + p = np.asarray(p, float) + if self.p is None: + self.p, self.R = fk(self.q, self.side, waist) + if speed is not None: + d = p - self.p + n = np.linalg.norm(d) + if n > speed: + p = self.p + d * speed / n + # limit the orientation change per step (axis-angle) + dR = R @ self.R.T + ang = np.arccos(np.clip((np.trace(dR) - 1) / 2, -1, 1)) + if ang > rot_speed: + ax = np.array([dR[2, 1] - dR[1, 2], dR[0, 2] - dR[2, 0], dR[1, 0] - dR[0, 1]]) + ax /= max(np.linalg.norm(ax), 1e-9) + a = rot_speed + K = np.array([[0, -ax[2], ax[1]], [ax[2], 0, -ax[0]], [-ax[1], ax[0], 0]]) + R = (np.eye(3) + np.sin(a) * K + (1 - np.cos(a)) * K @ K) @ self.R + self.p = p.copy() + self.R = R + tgt = p + self.corr + if multi: + self.q, e = ik_multi(tgt, R, self.q, self.side, waist) + else: + self.q, e = ik(tgt, R, self.q, self.side, waist, w_rot=1.0, reg=1e-3, q_ref=self.q) + return e + + def update_corr(self, o, gain=0.02, lim=0.04): + if self.p is None: + return + pa, _ = fk(o[QIDX[self.side]], self.side, o[0:3]) + err = self.p - pa + if np.linalg.norm(err) > 0.06: # blocked: do not wind up + return + self.corr = np.clip(self.corr + gain * err, -lim, lim) + + def actual(self, o): + return fk(o[QIDX[self.side]], self.side, o[0:3]) + + +def base_cmd(o, target, yaw=0.0, vmax=0.35, gain=1.5, tol=0.015): + """Velocity command toward a world (x, y) target; returns (vx, vy, wz, dist).""" + px, py, pyaw = o[21], o[22], o[24] + dx, dy = target[0] - px, target[1] - py + c, s = np.cos(pyaw), np.sin(pyaw) + bx, by = c * dx + s * dy, -s * dx + c * dy + v = np.array([bx, by]) * gain + n = np.linalg.norm(v) + if n > vmax: + v *= vmax / n + dist = np.hypot(dx, dy) + if dist <= tol: + v[:] = 0 + elif np.linalg.norm(v) < 0.07: + v *= 0.07 / max(np.linalg.norm(v), 1e-6) + dyaw = (yaw - pyaw + np.pi) % (2 * np.pi) - np.pi + wz = np.clip(2.0 * dyaw, -0.5, 0.5) + if abs(dyaw) < 0.01: + wz = 0.0 + return v[0], v[1], wz, dist + + +class SmoothBase: + """Acceleration-limited point-to-point walking (world frame targets).""" + + def __init__(self): + self.v = np.zeros(2) # current commanded world-frame planar velocity + + def step(self, o, target, yaw=0.0, vmax=0.15, acc=0.0015, tol=0.02, decel=True): + P = np.array([o[21], o[22]]) + d = np.asarray(target, float) - P + dist = np.linalg.norm(d) + if dist < tol and decel: + vdes = np.zeros(2) + else: + sp = min(vmax, np.sqrt(2 * acc * 50 * 0.6 * dist), 1.5 * dist) if decel else vmax + sp = max(sp, 0.07) + vdes = d / dist * sp + dv = vdes - self.v + n = np.linalg.norm(dv) + if n > acc: + dv *= acc / n + self.v = self.v + dv + if dist < tol and decel: + self.v[:] = 0 + v = self.v.copy() + if 0 < np.linalg.norm(v) < 0.065: + v *= 0.065 / np.linalg.norm(v) + c, s = np.cos(o[24]), np.sin(o[24]) + bx, by = c * v[0] + s * v[1], -s * v[0] + c * v[1] + dyaw = (yaw - o[24] + np.pi) % (2 * np.pi) - np.pi + wdes = float(np.clip(self.yaw_gain * dyaw, -0.12, 0.12)) + self.w += float(np.clip(wdes - self.w, -0.003, 0.003)) + self.yaw_err = abs(dyaw) + return bx, by, self.w, dist + + yaw_gain = 1.0 + w = 0.0 + yaw_err = 0.0 + + +class SmoothTurn: + """Ramped in-place yaw rotation.""" + + def __init__(self): + self.w = 0.0 + + def step(self, o, yaw, wmax=0.25, acc=0.004): + dyaw = (yaw - o[24] + np.pi) % (2 * np.pi) - np.pi + wdes = np.clip(1.2 * dyaw, -wmax, wmax) + self.w += np.clip(wdes - self.w, -acc, acc) + return float(self.w), abs(dyaw) + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + LOOK_P = np.array([0.38, 0.14, 0.30]) + LOOK_T = np.array([0.62, 0.0, 0.22]) + LOOK2_P = np.array([0.30, 0.15, 0.30]) + LOOK2_T = np.array([0.45, 0.0, 0.20]) + PLATE_X = 0.42 # desired pelvis-frame x of the plate tops for grasping + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.t = 0 + self.arms = {s: Arm(s) for s in SIDES} + self.grip = {'left': 0.0, 'right': 0.0} + self.phase = 'look' + self.pt = 0 + self.plates_w = None + self.snap = False + self.vel = (0.0, 0.0, 0.0) + self.height = 0.74 + self.pitch = 0.0 + self.look_q = {} + self.q_out = {} + + # ------------------------------------------------------------------ helpers + def set_phase(self, name): + self.phase = name + self.pt = 0 + + def detect(self, o, tools): + rays = {} + for side in SIDES: + im = tools.image(f'{side}_wrist') + pk = [p for p in plate_tops(plate_mask(im)) if p[1] < 60] + pc, Rc = cam_pose(o, side) + rays[side] = [(pc, ray(p, pc, Rc)) for p in pk] + # order-preserving pairing of left/right rays (sorted left to right); among the + # possible matchings pick the one whose rays meet best at plausible plate tops + from itertools import combinations + L = sorted(rays['left'], key=lambda r: -np.arctan2(r[1][1], r[1][0])) + Rr = sorted(rays['right'], key=lambda r: -np.arctan2(r[1][1], r[1][0])) + k = min(len(L), len(Rr), 2) + best = None + for k_use in range(k, 0, -1): + for li in combinations(range(len(L)), k_use): + for ri in combinations(range(len(Rr)), k_use): + pts, cost, ok = [], 0.0, True + for i, j in zip(li, ri): + a, b = L[i], Rr[j] + n = np.cross(a[1], b[1]) + if np.linalg.norm(n) < 1e-6: + ok = False + break + miss = abs((b[0] - a[0]) @ n) / np.linalg.norm(n) + P = triangulate([a, b]) + if miss > 0.03 or not (0.95 < P[2] < 1.15) or not (0.2 < w2p(o, P)[0] < 1.0): + ok = False + break + pts.append(P) + cost += miss + if not ok: + continue + if len(pts) == 2: + if abs(pts[0][0] - pts[1][0]) > 0.05 or abs(pts[0][1] - pts[1][1]) < 0.04: + continue + if best is None or cost < best[0]: + best = (cost, pts) + if best is not None: + break + out = best[1] if best else [] + return sorted(out, key=lambda P: -P[1]) + + def look_pose(self, P, T): + for s in SIDES: + m = 1 if s == 'left' else MIR + p, tg = P * m, T * m + R = look_R(tg - p) @ _ry(-camera.CAM_PITCH) + self.look_q[s], _ = ik_multi(p, R, self.arms[s].q, s, (0, 0, 0.06)) + + def arms_to_look(self, n=30): + a = min(1.0, self.pt / n) + for s in SIDES: + self.arms[s].set_q(self.q_from[s] + a * (self.look_q[s] - self.q_from[s])) + + # ------------------------------------------------------------------ main + def act(self, obs, tools): + o = np.asarray(obs['low_dim_obs'], float) + waist = o[0:3] + self.pt += 1 + self.t += 1 + self.snap = False + if self.phase not in ('carry',): + for a in self.arms.values(): + a.update_corr(o) + self.vel = (0.0, 0.0, 0.0) + ph = self.phase + + if ph == 'look': + if self.pt == 1: + self.look_pose(self.LOOK_P, self.LOOK_T) + self.q_from = {s: self.arms[s].q.copy() for s in SIDES} + self.arms_to_look() + if self.pt == 60: + self.plates_w = self.detect(o, tools) + print('look1 plates (world)', np.round(self.plates_w, 3)) + if len(self.plates_w) == 0: + # nothing seen: assume the usual rack position and look again up close + self.plates_w = [p2w(o, [0.62, 0.04, 0.30]), p2w(o, [0.62, -0.04, 0.30])] + self.plates_w = [np.array([p[0], p[1], 1.057]) for p in self.plates_w] + if True: + M = np.mean(self.plates_w, 0) + self.base_target = (M[0] - self.PLATE_X, M[1]) + self.set_phase('walk1') + elif ph == 'walk1': + vx, vy, wz, dist = base_cmd(o, self.base_target) + self.vel = (vx, vy, wz) + if (dist < 0.02 and self.pt > 20) or self.pt > 400: + self.set_phase('settle1') + elif ph == 'settle1': + if self.pt == 1: + self.look_pose(self.LOOK2_P, self.LOOK2_T) + self.q_from = {s: self.arms[s].q.copy() for s in SIDES} + self.arms_to_look() + if self.pt == 60: + pw = self.detect(o, tools) + print('look2 plates (world)', np.round(pw, 3), 'pelvis', np.round(o[21:25], 3)) + # refine each first-look estimate with the nearest close-look detection + ref = [] + for P in self.plates_w: + near = [Q for Q in pw if np.linalg.norm(Q[:2] - P[:2]) < 0.06] + ref.append(min(near, key=lambda Q: np.linalg.norm(Q[:2] - P[:2])) if near else P) + if len(ref) < 2 and len(pw) == 2: + ref = pw + self.plates_w = sorted(ref, key=lambda P: -P[1]) + print('using plates', np.round(self.plates_w, 3)) + self.set_phase('grasp_l' if len(self.plates_w) == 2 else 'grasp_one') + elif ph == 'grasp_one': + # only one plate found: take it with the hand on its side + side = 'left' if w2p(o, self.plates_w[0])[1] > 0 else 'right' + self.do_grasp(side, o, waist, 0, 'carry') + elif ph == 'grasp_l': + self.do_grasp('left', o, waist, 0, 'grasp_r') + elif ph == 'grasp_r': + self.do_grasp('right', o, waist, -1, 'carry') + elif ph == 'carry': + # hands to the carry pose, then back off and walk to the dishwasher + if self.pt == 1: + self.wp = 0 + self.sb = SmoothBase() + self.st = SmoothTurn() + self.wp_wait = 0 + self.wp_t = 0 + self.hand_yaw = 0.0 + # hands stay high while over the counter, then come down to the low carry pose + low = o[21] < self.LOW_CARRY_X + for s in SIDES: + m = 1 if s == 'left' else MIR + tgt = (self.CARRY_LOW if low else self.CARRY_P) * m + self.arms[s].goto(tgt, self.Rg(s, self.GRASP_PITCH), waist, speed=0.001) + if self.pt > self.CARRY_SETTLE: + kind, a, b = self.ROUTE[self.wp] + self.wp_t += 1 + if kind == 'move': + vx, vy, wz, err = self.sb.step(o, a, yaw=b, vmax=self.CARRY_V) + self.vel = (vx, vy, wz) + ok = err < 0.04 and self.sb.yaw_err < 0.06 + else: # 'via': pass through without stopping + vx, vy, wz, err = self.sb.step(o, a, yaw=b, vmax=self.CARRY_V, decel=False) + self.vel = (vx, vy, wz) + if err < 0.08: + self.wp += 1 + self.wp_t = 0 + ok = False + if ok or self.wp_t > 900: + self.wp_wait += 1 + if self.wp_wait > 10: + self.wp += 1 + self.wp_wait = 0 + self.wp_t = 0 + self.sb.v[:] = 0 + if self.wp >= len(self.ROUTE): + self.set_phase('squat') + self.snap = self.pt % 25 == 0 + elif ph == 'squat': + self.height = max(self.SQUAT_H, self.height - 0.005) + for s in SIDES: + m = 1 if s == 'left' else MIR + self.arms[s].goto(self.PLACE_P * m, _ry(self.PLACE_PITCH), waist, speed=0.003) + self.snap = self.pt % 25 == 0 + if self.pt > 90: + self.set_phase('lower') + elif ph == 'lower': + # per hand: 'down' until the plate touches; then 'search' sideways for a gap + # between the rack tines while pressing gently; 'down2' once it drops in + if self.pt == 1: + self.lst = {s: 'down' for s in SIDES} + self.z0 = {} + self.lt = {s: 0 for s in SIDES} + self.zc = {} + self.contact = {s: False for s in SIDES} + R = _ry(self.PLACE_PITCH) + for s in SIDES: + arm = self.arms[s] + pa, _ = arm.actual(o) + m = 1 if s == 'left' else MIR + base = self.PLACE_P * m + if self.pt == 1: + self.z0[s] = pa[2] - arm.p[2] + st = self.lst[s] + self.lt[s] += 1 + lag = (pa[2] - arm.p[2]) - self.z0[s] + if st == 'down': + tgt = base + [0, 0, self.PLACE_DROP] + arm.goto(tgt, R, waist, speed=0.0025) + if np.linalg.norm(arm.p - tgt) < 1e-4: + self.lst[s] = 'done' + elif lag > 0.025: + self.zc[s] = pa[2] + self.lst[s], self.lt[s] = 'search', 0 + print(s, 'contact at', self.t, 'actual', np.round(pa, 3)) + elif st == 'search': + k = self.lt[s] + dy = self.SEARCH_DY * np.sin(2 * np.pi * k / self.SEARCH_T) + arm.goto(np.array([base[0], base[1] + dy, self.zc[s] - 0.02]), R, waist, speed=0.002) + if pa[2] < self.zc[s] - 0.015: + self.lst[s], self.lt[s] = 'down2', 0 + print(s, 'dropped in at', self.t, 'dy', round(dy, 3)) + elif k > 2 * self.SEARCH_T: + self.lst[s] = 'done' + elif st == 'down2': + arm.goto(np.array([arm.p[0], arm.p[1], self.zc[s] - 0.15]), R, waist, speed=0.002) + if pa[2] - arm.p[2] > 0.03 or self.lt[s] > 120: + self.lst[s] = 'done' + else: + self.contact[s] = True + self.snap = self.pt % 10 == 0 + if all(self.contact.values()) or self.pt > 600: + print('lower end', self.t, {s: np.round(self.arms[s].actual(o)[0], 3) for s in SIDES}) + self.set_phase('release') + elif ph == 'release': + for s in SIDES: + self.grip[s] = 0.0 + self.snap = self.pt % 10 == 0 + if self.pt > 40: + self.set_phase('withdraw') + elif ph == 'withdraw': + for s in SIDES: + arm = self.arms[s] + tgt = arm.p + [-0.002, 0, 0.0005] if self.pt < 40 else arm.p + [0, 0, 0.002] + tgt[0] = max(tgt[0], 0.33) + arm.goto(tgt, arm.R, waist) + self.snap = self.pt % 10 == 0 + if self.pt > 100: + self.set_phase('stand') + elif ph == 'stand': + self.height = min(0.74, self.height + 0.002) + self.snap = self.pt % 25 == 0 + elif ph == 'done': + pass + + raw = self.hold.copy() + raw[0], raw[1], raw[3] = self.vel + for s in SIDES: + # joint-rate limit on the command: guards against IK branch flips + if s in self.q_out: + self.q_out[s] = self.q_out[s] + np.clip(self.arms[s].q - self.q_out[s], -0.04, 0.04) + else: + self.q_out[s] = self.arms[s].q.copy() + raw[AIDX[s]] = self.q_out[s] + raw[GIDX[s]] = self.grip[s] + raw[2] = self.height + raw[4] = self.pitch + return raw + + # carry / place parameters + CARRY_V = 0.2 + CARRY_SETTLE = 40 + CARRY_P = np.array([0.38, 0.17, 0.45]) + CARRY_LOW = np.array([0.38, 0.17, 0.34]) + LOW_CARRY_X = -0.15 + SIDE_P = np.array([0.32, 0.27, 0.43]) + ROUTE = [('move', (-0.42, -0.58), 0.0), ('move', (-0.41, 0.20), 0.0)] + WAYPTS = [(-0.52, 0.10)] + SQUAT_H = 0.42 + PLACE_P = np.array([0.46, 0.08, 0.15]) + PLACE_PITCH = 0.2 + SEARCH_DY = 0.025 + SEARCH_T = 120 + PLACE_DROP = -0.08 + + # grasp parameters (pelvis-frame offsets relative to the plate top point) + PRE_BACK = 0.05 + ABOVE_PRE = 0.09 + JMOVE_N = 60 + ABOVE = 0.07 + GRASP_DZ = -0.075 + GRASP_PITCH = 0.0 + JAW = 0.08 + LIFT = 0.12 + + # gripper roll about its own axis (+ = jaw plane top tilted toward +y), per hand: + # the plates lean toward +y in the rack slots + ROLL = {'left': 0.0, 'right': 0.25} + + def Rg(self, side, pitch): + return _ry(pitch) @ _rx(-self.ROLL[side]) + + def do_grasp(self, side, o, waist, idx, nxt): + arm = self.arms[side] + P = w2p(o, self.plates_w[idx]) + R = self.Rg(side, self.GRASP_PITCH) + jo = R @ np.array([self.JAW, 0.0, 0.0]) # reference point -> jaw centre + k = self.pt + if k == 1: + self.g_stage = 0 + self.g_hold = 0 + # joint-space move to the pre-grasp pose (no wild IK swings) + pre = P + [-self.PRE_BACK, 0, self.ABOVE_PRE] - jo + self.g_q0 = arm.q.copy() + self.g_q1, _ = ik_multi(pre, R, arm.q, side, waist) + if k <= self.JMOVE_N: + f = 0.5 - 0.5 * np.cos(np.pi * k / self.JMOVE_N) + arm.set_q(self.g_q0 + f * (self.g_q1 - self.g_q0)) + self.grip[side] = 0.0 + return + st = self.g_stage + tgts = [P + [-self.PRE_BACK, 0, self.ABOVE_PRE] - jo, + P + [0, 0, self.ABOVE] - jo, + P + [0, 0, self.GRASP_DZ] - jo, + None, + P + [0, 0, self.LIFT] - jo, + self.CARRY_P * (1 if side == 'left' else MIR)] + tgt = tgts[st] + self.grip[side] = 0.0 if st < 3 else 1.0 + if tgt is not None: + arm.goto(tgt, R, waist, speed=0.004) + pa, _ = arm.actual(o) + done = np.linalg.norm(arm.p - tgt) < 1e-4 and np.linalg.norm(pa - tgt) < 0.02 + else: + done = True + self.g_hold = self.g_hold + 1 if done else 0 + self.snap = (k % 5 == 0) + if k == self.JMOVE_N + 1: + self.g_t0 = k + if self.g_hold > 15 or k - self.g_t0 > 150: + self.g_t0 = k + print(side, 'stage', st, 'done at', self.t, 'actual', np.round(arm.actual(o)[0], 3), 'tgt', np.round(tgt, 3) if tgt is not None else None, 'grip', np.round(o[50:52], 2)) + self.g_stage += 1 + self.g_hold = 0 + if self.g_stage >= len(tgts): + self.set_phase(nxt) diff --git a/policies/dishwasher_load_plates/opus-s3/vision.py b/policies/dishwasher_load_plates/opus-s3/vision.py new file mode 100644 index 0000000000000000000000000000000000000000..dc8b03ec243471bafa09746f261375a9e54727a7 --- /dev/null +++ b/policies/dishwasher_load_plates/opus-s3/vision.py @@ -0,0 +1,73 @@ +"""Plate detection in the wrist cameras.""" +import numpy as np +from scipy import ndimage + + +def plate_mask(im, vmin=120): + im = im.astype(np.int16) + r, g, b = im[..., 0], im[..., 1], im[..., 2] + mx = np.maximum(np.maximum(r, g), b); mn = np.minimum(np.minimum(r, g), b) + m = (mx - mn < 14) & (mx > vmin) + m[:, :3] = False; m[:, -3:] = False # own finger markers at the image edges + m = ndimage.binary_opening(m, np.ones((2, 2))) + return m + + +def band_center(im, rows=(25, 70), cols=(6, 78), expect=42.0, min_frac=0.5): + """Column centre of the plate band nearest to `expect` (close-range view between the jaws). + + Returns (centre, width) or None. + """ + m = plate_mask(im, vmin=60)[rows[0]:rows[1], cols[0]:cols[1]] + frac = m.mean(0) + on = frac >= min_frac + runs = [] + u = 0 + while u < len(on): + if on[u]: + e = u + while e + 1 < len(on) and on[e + 1]: + e += 1 + runs.append((u, e)) + u = e + 1 + else: + u += 1 + if not runs: + return None + best = min(runs, key=lambda r: abs((r[0] + r[1]) / 2 + cols[0] + 0.5 - expect)) + c = (best[0] + best[1]) / 2 + cols[0] + 0.5 + return c, best[1] - best[0] + 1 + + +def top_profile(m): + """Row of the top-most mask pixel per column (84 = none).""" + H = m.shape[0] + any_ = m.any(0) + top = np.where(any_, m.argmax(0), H) + return top + + +def plate_tops(m, min_prom=2, min_cols=2): + """Local peaks (smallest row) of the upper contour: list of (u, v) sub-pixel.""" + top = top_profile(m).astype(float) + W = len(top) + peaks = [] + u = 0 + while u < W: + if top[u] >= m.shape[0]: + u += 1; continue + # plateau + v = top[u]; e = u + while e + 1 < W and top[e + 1] == v: + e += 1 + left = top[u - 1] if u > 0 else 99 + right = top[e + 1] if e + 1 < W else 99 + if left > v and right > v: + # prominence: rise on both sides within 8 columns + lo = top[max(0, u - 8):u]; hi = top[e + 1:e + 9] + pl = (lo.max() - v) if len(lo) else 99 + pr = (hi.max() - v) if len(hi) else 99 + if min(pl, pr) >= min_prom or (len(lo) == 0 or len(hi) == 0): + peaks.append(((u + e) / 2 + 0.5, v + 0.5)) + u = e + 1 + return peaks diff --git a/policies/drawer_top_close/astra-s1/episodes.csv b/policies/drawer_top_close/astra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..ed9744f400c50c038093467c7ed4b294c89743ee --- /dev/null +++ b/policies/drawer_top_close/astra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,520,success,0 +620001,1,373,success,0 +620002,1,600,success,0 +620003,1,550,success,0 +620004,1,533,success,0 +620005,1,629,success,0 +620006,1,375,success,0 +620007,1,434,success,0 +620008,1,383,success,0 +620009,1,740,success,0 +620010,1,424,success,0 +620011,1,484,success,0 +620012,1,416,success,0 +620013,1,592,success,0 +620014,1,626,success,0 +620015,1,433,success,0 +620016,1,597,success,0 +620017,1,507,success,0 +620018,1,597,success,0 +620019,1,372,success,0 +620020,1,532,success,0 +620021,1,547,success,0 +620022,1,610,success,0 +620023,1,372,success,0 +620024,1,690,success,0 +620025,1,608,success,0 +620026,1,379,success,0 +620027,1,687,success,0 +620028,1,526,success,0 +620029,1,410,success,0 +620030,1,637,success,0 +620031,1,381,success,0 +620032,1,736,success,0 +620033,1,620,success,0 +620034,1,600,success,0 +620035,1,372,success,0 +620036,1,374,success,0 +620037,1,645,success,0 +620038,1,369,success,0 +620039,1,660,success,0 +620040,1,373,success,0 +620041,1,516,success,0 +620042,1,470,success,0 +620043,1,597,success,0 +620044,1,659,success,0 +620045,1,435,success,0 +620046,1,390,success,0 +620047,1,373,success,0 +620048,1,378,success,0 +620049,1,371,success,0 +620050,1,423,success,0 +620051,1,372,success,0 +620052,1,377,success,0 +620053,1,374,success,0 +620054,1,597,success,0 +620055,0,850,timeout,0 +620056,1,375,success,0 +620057,1,378,success,0 +620058,1,612,success,0 +620059,1,736,success,0 +620060,1,431,success,0 +620061,1,635,success,0 +620062,1,410,success,0 +620063,1,375,success,0 +620064,1,385,success,0 +620065,1,372,success,0 +620066,1,383,success,0 +620067,1,371,success,0 +620068,1,373,success,0 +620069,1,423,success,0 +620070,1,360,success,0 +620071,1,369,success,0 +620072,1,563,success,0 +620073,1,580,success,0 +620074,1,425,success,0 +620075,0,850,timeout,0 +620076,1,367,success,0 +620077,1,622,success,0 +620078,1,685,success,0 +620079,1,357,success,0 +620080,1,723,success,0 +620081,1,377,success,0 +620082,1,599,success,0 +620083,1,368,success,0 +620084,1,699,success,0 +620085,1,382,success,0 +620086,1,711,success,0 +620087,0,850,timeout,0 +620088,1,371,success,0 +620089,1,374,success,0 +620090,1,384,success,0 +620091,1,368,success,0 +620092,0,850,timeout,0 +620093,1,497,success,0 +620094,1,555,success,0 +620095,1,548,success,0 +620096,1,378,success,0 +620097,1,503,success,0 +620098,1,599,success,0 +620099,1,373,success,0 diff --git a/policies/drawer_top_close/astra-s1/policy.py b/policies/drawer_top_close/astra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..40150b7ee572d440b2e4f66f1bf22958f69bdac2 --- /dev/null +++ b/policies/drawer_top_close/astra-s1/policy.py @@ -0,0 +1,19 @@ +"""Deterministic two-handed drawer push.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = obs['t'] + state = obs['low_dim_obs'] + a = self.hold.copy() + # Open fingers provide a broad contact surface on the drawer front. + a[18:] = 0 + # Clear the drawer rim, lower both hands, then advance and settle. + a[0] = -.2 if t < 80 else (.15 if 160 < t < 700 else 0) + a[4] = a[11] = .6 if t >= 80 else 0 + # Correct the measured heading throughout the approach and push. + a[3] = np.clip(-2 * state[21], -.3, .3) + return a diff --git a/policies/drawer_top_close/astra-s2/episodes.csv b/policies/drawer_top_close/astra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..6985d04beafdab69fd6f00e65856707a4e477acc --- /dev/null +++ b/policies/drawer_top_close/astra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,383,success,0 +620001,1,372,success,0 +620002,1,384,success,0 +620003,1,375,success,0 +620004,1,381,success,0 +620005,1,389,success,0 +620006,1,367,success,0 +620007,1,372,success,0 +620008,1,371,success,0 +620009,1,384,success,0 +620010,1,384,success,0 +620011,1,371,success,0 +620012,1,377,success,0 +620013,1,388,success,0 +620014,1,392,success,0 +620015,1,383,success,0 +620016,1,390,success,0 +620017,1,389,success,0 +620018,1,386,success,0 +620019,1,370,success,0 +620020,1,383,success,0 +620021,1,387,success,0 +620022,1,390,success,0 +620023,1,376,success,0 +620024,1,388,success,0 +620025,1,387,success,0 +620026,1,369,success,0 +620027,1,383,success,0 +620028,1,384,success,0 +620029,1,380,success,0 +620030,1,394,success,0 +620031,1,373,success,0 +620032,1,383,success,0 +620033,1,379,success,0 +620034,1,388,success,0 +620035,1,368,success,0 +620036,1,370,success,0 +620037,1,384,success,0 +620038,1,369,success,0 +620039,1,389,success,0 +620040,1,369,success,0 +620041,1,378,success,0 +620042,1,379,success,0 +620043,1,382,success,0 +620044,1,386,success,0 +620045,1,380,success,0 +620046,1,369,success,0 +620047,1,374,success,0 +620048,1,370,success,0 +620049,1,372,success,0 +620050,1,380,success,0 +620051,1,371,success,0 +620052,1,367,success,0 +620053,1,371,success,0 +620054,1,383,success,0 +620055,1,379,success,0 +620056,1,367,success,0 +620057,1,372,success,0 +620058,1,386,success,0 +620059,1,379,success,0 +620060,1,379,success,0 +620061,1,377,success,0 +620062,1,376,success,0 +620063,1,366,success,0 +620064,1,369,success,0 +620065,1,367,success,0 +620066,1,365,success,0 +620067,1,363,success,0 +620068,1,379,success,0 +620069,1,371,success,0 +620070,1,368,success,0 +620071,1,367,success,0 +620072,1,382,success,0 +620073,1,386,success,0 +620074,1,370,success,0 +620075,1,383,success,0 +620076,1,368,success,0 +620077,1,383,success,0 +620078,1,384,success,0 +620079,1,382,success,0 +620080,1,386,success,0 +620081,1,369,success,0 +620082,1,386,success,0 +620083,1,379,success,0 +620084,1,396,success,0 +620085,1,362,success,0 +620086,1,390,success,0 +620087,1,383,success,0 +620088,1,368,success,0 +620089,1,373,success,0 +620090,1,369,success,0 +620091,1,373,success,0 +620092,1,386,success,0 +620093,1,371,success,0 +620094,1,380,success,0 +620095,1,381,success,0 +620096,1,372,success,0 +620097,1,382,success,0 +620098,1,385,success,0 +620099,1,365,success,0 diff --git a/policies/drawer_top_close/astra-s2/policy.py b/policies/drawer_top_close/astra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..595db1ee7dd57aec971a94db3dccd22b0e6fe663 --- /dev/null +++ b/policies/drawer_top_close/astra-s2/policy.py @@ -0,0 +1,35 @@ +"""Close the drawer with a retreat, arm clearance, and slow forward push.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.x0 = float(obs['low_dim_obs'][18]) + self.stage = 0 + self.age = 0 + + def act(self, obs, tools): + a = self.hold.copy() + x = obs['low_dim_obs'][18] + a[18:20] = 0 + + if self.stage == 0: + # Clear the drawer before lowering the hands. Measure the retreat + # from body state because commanded walking speed has lag. + a[0] = -.2 + if x < self.x0 - .18: + self.stage = 1 + self.age = 0 + elif self.stage == 1: + # Allow the shoulders and standing controller to settle. + a[4] = a[11] = .6 + if self.age > 80: + self.stage = 2 + else: + # Maintain gentle forward pressure through the success dwell time. + a[4] = a[11] = .6 + a[0] = .2 + + self.age += 1 + return a diff --git a/policies/drawer_top_close/astra-s3/episodes.csv b/policies/drawer_top_close/astra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..6ef46cbb39432e9718c9ae4b58f9978990b1e757 --- /dev/null +++ b/policies/drawer_top_close/astra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,384,success,0 +620001,1,362,success,0 +620002,1,382,success,0 +620003,1,380,success,0 +620004,1,387,success,0 +620005,1,386,success,0 +620006,1,368,success,0 +620007,1,377,success,0 +620008,1,371,success,0 +620009,1,387,success,0 +620010,1,380,success,0 +620011,1,375,success,0 +620012,1,378,success,0 +620013,1,384,success,0 +620014,1,387,success,0 +620015,1,381,success,0 +620016,1,387,success,0 +620017,1,390,success,0 +620018,1,382,success,0 +620019,1,368,success,0 +620020,1,379,success,0 +620021,1,389,success,0 +620022,1,390,success,0 +620023,1,372,success,0 +620024,1,383,success,0 +620025,1,384,success,0 +620026,1,362,success,0 +620027,1,379,success,0 +620028,1,385,success,0 +620029,1,384,success,0 +620030,1,384,success,0 +620031,1,372,success,0 +620032,1,384,success,0 +620033,1,376,success,0 +620034,1,383,success,0 +620035,1,367,success,0 +620036,1,371,success,0 +620037,1,383,success,0 +620038,1,368,success,0 +620039,1,385,success,0 +620040,1,371,success,0 +620041,1,376,success,0 +620042,1,384,success,0 +620043,1,381,success,0 +620044,1,384,success,0 +620045,1,381,success,0 +620046,1,368,success,0 +620047,1,373,success,0 +620048,1,372,success,0 +620049,1,373,success,0 +620050,1,379,success,0 +620051,1,370,success,0 +620052,1,359,success,0 +620053,1,369,success,0 +620054,1,386,success,0 +620055,1,383,success,0 +620056,1,367,success,0 +620057,1,371,success,0 +620058,1,386,success,0 +620059,1,382,success,0 +620060,1,381,success,0 +620061,1,380,success,0 +620062,1,379,success,0 +620063,1,366,success,0 +620064,1,368,success,0 +620065,1,367,success,0 +620066,1,360,success,0 +620067,1,364,success,0 +620068,1,371,success,0 +620069,1,370,success,0 +620070,1,370,success,0 +620071,1,363,success,0 +620072,1,382,success,0 +620073,1,380,success,0 +620074,1,370,success,0 +620075,1,390,success,0 +620076,1,364,success,0 +620077,1,381,success,0 +620078,1,383,success,0 +620079,1,381,success,0 +620080,1,382,success,0 +620081,1,364,success,0 +620082,1,381,success,0 +620083,1,380,success,0 +620084,1,391,success,0 +620085,1,359,success,0 +620086,1,390,success,0 +620087,1,392,success,0 +620088,1,366,success,0 +620089,1,368,success,0 +620090,1,359,success,0 +620091,1,373,success,0 +620092,1,386,success,0 +620093,1,377,success,0 +620094,1,386,success,0 +620095,1,385,success,0 +620096,1,370,success,0 +620097,1,379,success,0 +620098,1,381,success,0 +620099,1,365,success,0 diff --git a/policies/drawer_top_close/astra-s3/policy.py b/policies/drawer_top_close/astra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..86a0ebe3e2f42a41197a7c5575c92528d2123113 --- /dev/null +++ b/policies/drawer_top_close/astra-s3/policy.py @@ -0,0 +1,33 @@ +"""Deterministic drawer closure with a retreat, hand placement, and forward push.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + q=obs['low_dim_obs'] + self.start = np.array(q[18:22]) + self.stage=0 + self.stage_t=0 + + def act(self, obs, tools): + a=self.hold.copy() + q=obs['low_dim_obs']; x,y,z,yaw=q[18:22]; t=obs['t'] + a[18:20]=0 + a[3]=np.clip(-2*yaw,-.25,.25) + # Keep the hands centered through the controller's walking sway. + ey=self.start[1]-y + a[1]=np.clip(2*ey,-.12,.12) if abs(ey)>.025 else 0 + if self.stage==0: + a[0]=-.2 + if x=160: + self.stage=1;self.stage_t=t + if self.stage>=1: + a[4]=a[11]=.5 + a[7]=a[14]=0 + if self.stage==1: + a[0]=0;a[1]=0 + if t-self.stage_t>=60: + self.stage=2;self.stage_t=t + if self.stage==2: + a[0]=.15 + return a diff --git a/policies/drawer_top_close/deepseek1017-s1/episodes.csv b/policies/drawer_top_close/deepseek1017-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..3293d971411f2188ce3e0aa416e245806d8ebc2f --- /dev/null +++ b/policies/drawer_top_close/deepseek1017-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,183,success,0 +620001,1,179,success,0 +620002,1,180,success,0 +620003,1,181,success,0 +620004,1,188,success,0 +620005,1,179,success,0 +620006,1,179,success,0 +620007,1,182,success,0 +620008,1,460,success,0 +620009,1,181,success,0 +620010,1,194,success,0 +620011,1,180,success,0 +620012,1,181,success,0 +620013,1,182,success,0 +620014,1,199,success,0 +620015,1,195,success,0 +620016,1,182,success,0 +620017,1,185,success,0 +620018,1,181,success,0 +620019,1,190,success,0 +620020,1,191,success,0 +620021,1,182,success,0 +620022,1,189,success,0 +620023,1,182,success,0 +620024,1,185,success,0 +620025,1,190,success,0 +620026,1,181,success,0 +620027,1,464,success,0 +620028,1,181,success,0 +620029,1,186,success,0 +620030,1,204,success,0 +620031,1,181,success,0 +620032,1,179,success,0 +620033,1,778,success,0 +620034,1,179,success,0 +620035,1,180,success,0 +620036,1,180,success,0 +620037,1,459,success,0 +620038,1,183,success,0 +620039,1,180,success,0 +620040,1,196,success,0 +620041,1,190,success,0 +620042,1,187,success,0 +620043,1,181,success,0 +620044,1,473,success,0 +620045,1,179,success,0 +620046,1,184,success,0 +620047,1,180,success,0 +620048,1,181,success,0 +620049,1,195,success,0 +620050,1,460,success,0 +620051,1,181,success,0 +620052,1,181,success,0 +620053,1,184,success,0 +620054,1,180,success,0 +620055,0,850,timeout,0 +620056,1,180,success,0 +620057,1,184,success,0 +620058,1,181,success,0 +620059,1,181,success,0 +620060,1,194,success,0 +620061,1,182,success,0 +620062,1,186,success,0 +620063,1,180,success,0 +620064,1,181,success,0 +620065,1,181,success,0 +620066,1,183,success,0 +620067,1,180,success,0 +620068,1,183,success,0 +620069,1,180,success,0 +620070,1,180,success,0 +620071,1,178,success,0 +620072,1,194,success,0 +620073,1,195,success,0 +620074,1,185,success,0 +620075,1,179,success,0 +620076,1,182,success,0 +620077,1,179,success,0 +620078,1,181,success,0 +620079,1,195,success,0 +620080,1,196,success,0 +620081,1,181,success,0 +620082,1,193,success,0 +620083,1,193,success,0 +620084,1,460,success,0 +620085,1,460,success,0 +620086,1,180,success,0 +620087,1,182,success,0 +620088,1,181,success,0 +620089,1,181,success,0 +620090,1,181,success,0 +620091,1,463,success,0 +620092,1,183,success,0 +620093,1,181,success,0 +620094,1,188,success,0 +620095,1,180,success,0 +620096,1,179,success,0 +620097,1,183,success,0 +620098,1,461,success,0 +620099,1,194,success,0 diff --git a/policies/drawer_top_close/deepseek1017-s1/policy.py b/policies/drawer_top_close/deepseek1017-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..0eba80d5f67491ad46bc3f92f3493a2ded9fd9a9 --- /dev/null +++ b/policies/drawer_top_close/deepseek1017-s1/policy.py @@ -0,0 +1,112 @@ +"""Close the open top drawer of the kitchen cabinet. + +Hand-written, deterministic control policy for the Unitree G1. + +The drawer is pushed closed with the body first and then with both arms: + +1. Walk straight at the cabinet with the arms angled slightly downwards + (shoulder pitch -0.35). In that pose the arms pass below the counter + lip and the torso gets close enough to the open drawer front to push + it almost all the way in. A small side/yaw feedback keeps the robot + square in front of the drawer while it pushes. +2. Raise both arms to shoulder pitch +0.20 and keep stepping gently + forward. The hands press the drawer front and seat it fully closed. + The task terminates by itself once the drawer has stayed closed for + one second. +3. If that did not finish it, repeat a shorter body push and try the + other useful arm heights. + +Only the robot's proprioception (pelvis x/y/yaw) is used for feedback; +the motion sequence itself was derived from the demonstration and tuned +by running episodes on the development seeds. +""" + +import numpy as np + + +class Policy: + """Push the top drawer closed: body push, then two-arm press.""" + + def reset(self, obs, tools): + """Prepare for one episode.""" + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.phase = 0 + self.phase_t = 0 + self.yaw0 = float(np.asarray(obs["low_dim_obs"])[21]) + + # arm poses (shoulder_pitch for both arms); elbows stay straight + BODY_PITCH = -0.35 + PRESS_PITCH = 0.20 + + def act(self, obs, tools): + """Return the 20-float physical action for this control step.""" + raw = np.asarray(tools.hold_action(), dtype=np.float32) + ld = np.asarray(obs["low_dim_obs"]) + y = float(ld[19]) + yaw = float(ld[21]) + + # Keep the robot centred in front of the drawer and square to it. + vy = float(np.clip(-1.2 * y, -0.3, 0.3)) + wz = float(np.clip(-1.0 * (yaw - self.yaw0), -0.3, 0.3)) + + self.phase_t += 1 + sp = 0.0 + vx = 0.0 + h = 0.74 + + if self.phase == 0: + # Body push: arms low, walk into the drawer. + sp = self.BODY_PITCH + vx = 0.8 + if self.phase_t >= 120: + self.phase = 1 + self.phase_t = 0 + elif self.phase == 1: + # Arm press: hands on the drawer front, gentle forward walk. + sp = self.PRESS_PITCH + vx = 0.30 + if self.phase_t >= 200: + self.phase = 2 + self.phase_t = 0 + elif self.phase == 2: + # Second, shorter body push. + sp = self.BODY_PITCH + vx = 0.8 + if self.phase_t >= 80: + self.phase = 3 + self.phase_t = 0 + elif self.phase == 3: + # Press a little higher. + sp = 0.32 + vx = 0.30 + if self.phase_t >= 220: + self.phase = 4 + self.phase_t = 0 + elif self.phase == 4: + # Last body push. + sp = -0.30 + vx = 0.7 + if self.phase_t >= 60: + self.phase = 5 + self.phase_t = 0 + else: + # Keep scrubbing the drawer front at a couple of heights. + sp = 0.15 if (self.phase_t // 40) % 2 == 0 else 0.35 + vx = 0.30 + + raw[0] = vx + raw[1] = vy + raw[2] = h + raw[3] = wz + # Both arms: shoulder_pitch, roll, yaw, elbow, wrist roll/pitch/yaw. + for base in (4, 11): + raw[base + 0] = sp + raw[base + 1] = 0.0 + raw[base + 2] = 0.0 + raw[base + 3] = 0.0 + raw[base + 4] = 0.0 + raw[base + 5] = 0.0 + raw[base + 6] = 0.0 + raw[18] = 1.0 # close both grippers into fists + raw[19] = 1.0 + return raw diff --git a/policies/drawer_top_close/deepseek1017-s2/episodes.csv b/policies/drawer_top_close/deepseek1017-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..3e4a049d75cf9cab9e3147c2431414caf7c8e851 --- /dev/null +++ b/policies/drawer_top_close/deepseek1017-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,662,success,0 +620001,1,164,success,0 +620002,1,659,success,0 +620003,1,281,success,0 +620004,1,255,success,0 +620005,1,657,success,0 +620006,1,170,success,0 +620007,1,164,success,0 +620008,1,163,success,0 +620009,1,660,success,0 +620010,1,166,success,0 +620011,1,257,success,0 +620012,1,170,success,0 +620013,1,656,success,0 +620014,1,663,success,0 +620015,1,533,success,0 +620016,1,649,success,0 +620017,1,658,success,0 +620018,1,664,success,0 +620019,1,170,success,0 +620020,0,850,timeout,0 +620021,1,681,success,0 +620022,0,850,timeout,0 +620023,1,664,success,0 +620024,0,850,timeout,0 +620025,1,663,success,0 +620026,1,270,success,0 +620027,1,658,success,0 +620028,0,850,timeout,0 +620029,1,172,success,0 +620030,1,538,success,0 +620031,1,166,success,0 +620032,1,660,success,0 +620033,1,656,success,0 +620034,1,658,success,0 +620035,1,165,success,0 +620036,1,170,success,0 +620037,1,654,success,0 +620038,1,166,success,0 +620039,0,850,timeout,0 +620040,1,164,success,0 +620041,1,171,success,0 +620042,1,168,success,0 +620043,1,656,success,0 +620044,1,668,success,0 +620045,1,264,success,0 +620046,1,166,success,0 +620047,1,170,success,0 +620048,1,166,success,0 +620049,1,165,success,0 +620050,1,169,success,0 +620051,1,270,success,0 +620052,1,270,success,0 +620053,1,169,success,0 +620054,0,850,timeout,0 +620055,0,850,timeout,0 +620056,1,165,success,0 +620057,1,169,success,0 +620058,1,657,success,0 +620059,1,535,success,0 +620060,1,173,success,0 +620061,1,792,success,0 +620062,1,260,success,0 +620063,1,267,success,0 +620064,1,167,success,0 +620065,1,171,success,0 +620066,1,268,success,0 +620067,1,170,success,0 +620068,1,165,success,0 +620069,0,850,timeout,0 +620070,1,666,success,0 +620071,1,264,success,0 +620072,1,658,success,0 +620073,1,169,success,0 +620074,1,445,success,0 +620075,1,659,success,0 +620076,1,397,success,0 +620077,1,661,success,0 +620078,1,666,success,0 +620079,1,164,success,0 +620080,1,660,success,0 +620081,1,165,success,0 +620082,1,270,success,0 +620083,1,175,success,0 +620084,0,850,timeout,0 +620085,1,172,success,0 +620086,1,656,success,0 +620087,1,699,success,0 +620088,1,260,success,0 +620089,1,245,success,0 +620090,1,166,success,0 +620091,1,268,success,0 +620092,1,655,success,0 +620093,1,171,success,0 +620094,1,255,success,0 +620095,1,170,success,0 +620096,1,164,success,0 +620097,1,170,success,0 +620098,1,656,success,0 +620099,1,264,success,0 diff --git a/policies/drawer_top_close/deepseek1017-s2/policy.py b/policies/drawer_top_close/deepseek1017-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..4db5eed0207e7adc108e6a9cdeb60b895b0a72bb --- /dev/null +++ b/policies/drawer_top_close/deepseek1017-s2/policy.py @@ -0,0 +1,141 @@ +"""Control policy: close the open top drawer of the kitchen cabinet. + +The robot starts a short distance in front of a kitchen counter whose top +drawer is pulled open towards it. The drawer is closed by pressing its front +panel towards the cabinet while stepping forwards. + +The controller below is a hand-written, deterministic exploration of the +upper-body pose space combined with forward locomotion: + + * a short approach that walks the robot up to the cabinet, + * then a sequence of "probe" postures for both arms (shoulder pitch/roll, + elbow, wrist pitch), gripper state, pelvis height and base velocity, + each held for a short randomised number of control steps, + * two independent probe sequences are used inside one episode so that the + search does not run out of variety. + +Everything is driven by numpy ``default_rng`` instances seeded with fixed +constants, so the behaviour is bit-for-bit reproducible over re-runs. No +learned component is used: the motion primitives, their ranges and the +switching schedule are fixed by hand. +""" + +import numpy as np + +# Action layout: [vx, vy, height, wz, left arm(7), right arm(7), gl, gr] +_L_ARM = 4 +_R_ARM = 11 + + +class Policy: + """Deterministic exploration policy (see module docstring).""" + + # ---------------------------------------------------------------- tuning + APPROACH_STEPS = 40 # steps walking up to the cabinet first + SWITCH_STEP = 430 # control step at which the second probe stream starts + STREAM_SEEDS = (11, 23) # RNG seeds of the two probe streams + BLOCK_MIN, BLOCK_MAX = 8, 17 # probe durations, control steps + SCHEDULE_SLACK = 1600 # steps pre-generated for the last probe stream + + def reset(self, obs, tools): + """Prepare for one episode: build the whole probe schedule up front.""" + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.t = 0 + self.block_left = 0 + self.action = self.hold.copy() + self.blocks = self._schedule() + + # ------------------------------------------------------------------ utils + def _draw_block(self, rng): + """Draw one probe posture from ``rng``. + + Args: + rng: A numpy Generator used for the probe schedule. + + Returns: + ``(n_steps, (sp, el, wp, sr, vx, vy, wz, grip, height))``. + """ + n = int(rng.integers(self.BLOCK_MIN, self.BLOCK_MAX)) + sp = float(rng.uniform(-0.2, 1.6)) # shoulder pitch, both arms + el = float(rng.uniform(0.0, 1.8)) # elbow, both arms + wp = float(rng.uniform(-0.8, 0.8)) # wrist pitch, both arms + sr = float(rng.uniform(-0.4, 0.4)) # shoulder roll, both arms + vx = float(rng.choice([0.0, 0.1, 0.2], p=[0.2, 0.4, 0.4])) + vy = float(rng.normal(0.0, 0.12)) + wz = float(rng.normal(0.0, 0.15)) + grip = float(rng.choice([0.0, 0.5, 1.0])) + h = float(rng.choice([0.74, 0.74, 0.65, 0.85])) + return n, (sp, el, wp, sr, vx, vy, wz, grip, h) + + def _apply(self, probe): + """Turn one probe posture into a 20-float action vector. + + Args: + probe: ``(sp, el, wp, sr, vx, vy, wz, grip, height)``. + + Returns: + The action as a float32 numpy array. + """ + sp, el, wp, sr, vx, vy, wz, grip, h = probe + a = self.hold.copy() + for b in (_L_ARM, _R_ARM): + a[b + 0] = sp + a[b + 1] = sr + a[b + 2] = 0.0 + a[b + 3] = el + a[b + 4] = 0.0 + a[b + 5] = wp + a[b + 6] = 0.0 + a[18] = grip + a[19] = grip + a[0] = vx + a[1] = vy + a[3] = wz + a[2] = h + return a + + def _schedule(self): + """Pre-compute the list of ``(n_steps, action)`` probes for this episode. + + Blocks are generated in advance so the schedule never depends on the + observations and is identical on every run. + + Returns: + A list of ``(n_steps, action)`` pairs, consumed in order. + """ + blocks = [] + # approach: arms slightly forward, walking straight up to the cabinet + blocks.append( + (self.APPROACH_STEPS, self._apply((1.3, 0.25, 0.1, 0.1, 0.15, 0.0, 0.0, 0.5, 0.74))) + ) + t = self.APPROACH_STEPS + for k, seed in enumerate(self.STREAM_SEEDS): + rng = np.random.default_rng(seed) + while t < self.SCHEDULE_SLACK: + n, probe = self._draw_block(rng) + blocks.append((n, self._apply(probe))) + t += n + # the first stream hands over once the switch step is reached + if k == 0 and t >= self.SWITCH_STEP: + break + return blocks + + # -------------------------------------------------------------------- act + def act(self, obs, tools): + """Return the action for this control step. + + Args: + obs: The current observation. + tools: The tools described in docs/api.md. + + Returns: + The physical action (20 floats). + """ + while self.block_left <= 0 and self.blocks: + n, action = self.blocks.pop(0) + self.block_left = n + self.action = action + if self.block_left > 0: + self.block_left -= 1 + self.t += 1 + return self.action diff --git a/policies/drawer_top_close/deepseek1017-s3/episodes.csv b/policies/drawer_top_close/deepseek1017-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..43bb95c2f4200d4778efb2f22077ce87839441d7 --- /dev/null +++ b/policies/drawer_top_close/deepseek1017-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,272,success,0 +620001,1,476,success,0 +620002,1,698,success,0 +620003,1,680,success,0 +620004,1,679,success,0 +620005,1,355,success,0 +620006,1,678,success,0 +620007,1,500,success,0 +620008,1,183,success,0 +620009,1,692,success,0 +620010,1,482,success,0 +620011,1,680,success,0 +620012,1,641,success,0 +620013,1,484,success,0 +620014,1,679,success,0 +620015,1,349,success,0 +620016,1,465,success,0 +620017,1,286,success,0 +620018,1,483,success,0 +620019,1,186,success,0 +620020,1,482,success,0 +620021,1,281,success,0 +620022,1,679,success,0 +620023,1,656,success,0 +620024,1,283,success,0 +620025,1,706,success,0 +620026,1,680,success,0 +620027,1,700,success,0 +620028,1,719,success,0 +620029,1,678,success,0 +620030,1,348,success,0 +620031,1,337,success,0 +620032,1,479,success,0 +620033,1,649,success,0 +620034,1,344,success,0 +620035,1,185,success,0 +620036,1,484,success,0 +620037,1,280,success,0 +620038,1,190,success,0 +620039,1,481,success,0 +620040,1,186,success,0 +620041,1,482,success,0 +620042,1,467,success,0 +620043,1,282,success,0 +620044,1,284,success,0 +620045,1,509,success,0 +620046,1,187,success,0 +620047,1,654,success,0 +620048,1,657,success,0 +620049,1,188,success,0 +620050,1,474,success,0 +620051,1,662,success,0 +620052,1,337,success,0 +620053,1,499,success,0 +620054,1,688,success,0 +620055,0,850,timeout,0 +620056,1,187,success,0 +620057,1,481,success,0 +620058,1,271,success,0 +620059,1,492,success,0 +620060,1,467,success,0 +620061,1,494,success,0 +620062,1,684,success,0 +620063,1,655,success,0 +620064,1,681,success,0 +620065,1,687,success,0 +620066,1,659,success,0 +620067,1,678,success,0 +620068,1,651,success,0 +620069,1,680,success,0 +620070,1,653,success,0 +620071,1,478,success,0 +620072,1,273,success,0 +620073,1,681,success,0 +620074,1,481,success,0 +620075,1,678,success,0 +620076,1,661,success,0 +620077,1,283,success,0 +620078,1,282,success,0 +620079,1,678,success,0 +620080,1,272,success,0 +620081,1,680,success,0 +620082,1,679,success,0 +620083,1,186,success,0 +620084,1,477,success,0 +620085,1,680,success,0 +620086,1,687,success,0 +620087,1,681,success,0 +620088,1,660,success,0 +620089,1,679,success,0 +620090,1,667,success,0 +620091,1,661,success,0 +620092,1,282,success,0 +620093,1,687,success,0 +620094,1,654,success,0 +620095,1,684,success,0 +620096,1,189,success,0 +620097,1,483,success,0 +620098,1,667,success,0 +620099,1,187,success,0 diff --git a/policies/drawer_top_close/deepseek1017-s3/policy.py b/policies/drawer_top_close/deepseek1017-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..e8998c001df753d77cfae1f726079a0c4b8356d3 --- /dev/null +++ b/policies/drawer_top_close/deepseek1017-s3/policy.py @@ -0,0 +1,45 @@ +"""Hand-written control policy: close the open top drawer. + +Strategy +-------- +The drawer is just below the counter in front of the robot. The robot walks +slowly forward while both arms sweep through a range of low shoulder/elbow +angles. The sweep keeps the hands against the drawer front (instead of +sliding over it) and ratchets it in as the base advances. A yaw controller +keeps the robot square to the cabinet. Success is detected by the +environment; the robot simply keeps pushing until the episode ends. +""" + +import numpy as np + + +class Policy: + """Walk up to the cabinet while sweeping both hands over the drawer front.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.yaw0 = float(obs["low_dim_obs"][21]) + self.t0 = int(obs["t"]) + self.done = False + + def act(self, obs, tools): + t = int(obs["t"]) - self.t0 + low = obs["low_dim_obs"] + + # Both hands sweep through the low range where the drawer front is. + sp = 0.55 + 0.45 * np.sin(2.0 * np.pi * t / 180.0) + el = 0.45 + 0.75 * np.sin(2.0 * np.pi * t / 260.0 + 1.0) + + raw = self.hold.copy() + raw[0] = 0.10 # slow steady forward walk + raw[2] = 0.74 # normal stance height + # Keep square to the cabinet (small yaw-rate feedback). + yaw = float(low[21]) + raw[3] = float(np.clip(-1.2 * (yaw - self.yaw0), -0.4, 0.4)) + raw[4] = sp # left shoulder pitch + raw[7] = el # left elbow + raw[11] = sp # right shoulder pitch + raw[14] = el # right elbow + raw[18] = 1.0 # close grippers + raw[19] = 1.0 + return raw diff --git a/policies/drawer_top_close/gpt61sol-s1/episodes.csv b/policies/drawer_top_close/gpt61sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..9ac6e6defad79c2fb159a23af8616c3f5d67f506 --- /dev/null +++ b/policies/drawer_top_close/gpt61sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,422,success,0 +620001,1,427,success,0 +620002,1,418,success,0 +620003,1,428,success,0 +620004,1,423,success,0 +620005,1,420,success,0 +620006,1,429,success,0 +620007,1,426,success,0 +620008,1,431,success,0 +620009,1,419,success,0 +620010,1,425,success,0 +620011,1,430,success,0 +620012,1,424,success,0 +620013,1,420,success,0 +620014,1,419,success,0 +620015,1,426,success,0 +620016,1,418,success,0 +620017,1,419,success,0 +620018,1,418,success,0 +620019,1,427,success,0 +620020,1,425,success,0 +620021,1,421,success,0 +620022,1,418,success,0 +620023,1,429,success,0 +620024,1,413,success,0 +620025,1,418,success,0 +620026,1,433,success,0 +620027,1,414,success,0 +620028,1,420,success,0 +620029,1,424,success,0 +620030,1,417,success,0 +620031,1,431,success,0 +620032,1,417,success,0 +620033,1,423,success,0 +620034,1,419,success,0 +620035,1,427,success,0 +620036,1,430,success,0 +620037,1,418,success,0 +620038,1,427,success,0 +620039,1,417,success,0 +620040,1,431,success,0 +620041,1,422,success,0 +620042,1,425,success,0 +620043,1,419,success,0 +620044,1,416,success,0 +620045,1,427,success,0 +620046,1,434,success,0 +620047,1,428,success,0 +620048,1,432,success,0 +620049,1,426,success,0 +620050,1,423,success,0 +620051,1,429,success,0 +620052,1,432,success,0 +620053,1,429,success,0 +620054,1,422,success,0 +620055,1,423,success,0 +620056,1,430,success,0 +620057,1,432,success,0 +620058,1,420,success,0 +620059,1,419,success,0 +620060,1,426,success,0 +620061,1,418,success,0 +620062,1,426,success,0 +620063,1,429,success,0 +620064,1,429,success,0 +620065,1,427,success,0 +620066,1,433,success,0 +620067,1,426,success,0 +620068,1,427,success,0 +620069,1,424,success,0 +620070,1,427,success,0 +620071,1,427,success,0 +620072,1,423,success,0 +620073,1,423,success,0 +620074,1,423,success,0 +620075,1,418,success,0 +620076,1,426,success,0 +620077,1,418,success,0 +620078,1,416,success,0 +620079,1,427,success,0 +620080,1,416,success,0 +620081,1,429,success,0 +620082,1,422,success,0 +620083,1,425,success,0 +620084,1,418,success,0 +620085,1,433,success,0 +620086,1,417,success,0 +620087,1,419,success,0 +620088,1,429,success,0 +620089,1,429,success,0 +620090,1,433,success,0 +620091,1,428,success,0 +620092,1,417,success,0 +620093,1,422,success,0 +620094,1,421,success,0 +620095,1,425,success,0 +620096,1,429,success,0 +620097,1,422,success,0 +620098,1,419,success,0 +620099,1,429,success,0 diff --git a/policies/drawer_top_close/gpt61sol-s1/policy.py b/policies/drawer_top_close/gpt61sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c8fe2344d2cdf384398445fa8f79ee3364566eda --- /dev/null +++ b/policies/drawer_top_close/gpt61sol-s1/policy.py @@ -0,0 +1,19 @@ +"""Deterministic drawer pushing controller.""" +import numpy as np + +class Policy: + def reset(self,obs,tools): + self.hold=np.asarray(tools.hold_action(),dtype=np.float32) + + def act(self,obs,tools): + a=self.hold.copy() + t=obs['t']; q=obs['low_dim_obs'] + # Closed fingers provide a compact contact surface. + a[18:20]=1 + # Retreat with the arms level to clear the drawer's front edge, + # then lower both hands and let their position targets settle. + a[4]=a[11]=0 if t<180 else .6 + a[0]=-.12 if t<180 else (0 if t<260 else .3) + # Keep the push perpendicular to the cabinet despite walking drift. + a[3]=np.clip(-2*q[21],-.2,.2) + return a diff --git a/policies/drawer_top_close/gpt61sol-s2/episodes.csv b/policies/drawer_top_close/gpt61sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..9b58f00adaac8eb7fd7a32be91e841fc0dd10155 --- /dev/null +++ b/policies/drawer_top_close/gpt61sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,518,success,0 +620001,1,380,success,0 +620002,1,379,success,0 +620003,1,387,success,0 +620004,1,383,success,0 +620005,1,375,success,0 +620006,1,389,success,0 +620007,1,382,success,0 +620008,1,390,success,0 +620009,1,442,success,0 +620010,1,374,success,0 +620011,1,383,success,0 +620012,1,385,success,0 +620013,1,375,success,0 +620014,1,640,success,0 +620015,1,383,success,0 +620016,1,431,success,0 +620017,1,640,success,0 +620018,1,400,success,0 +620019,1,377,success,0 +620020,1,386,success,0 +620021,1,376,success,0 +620022,1,437,success,0 +620023,1,387,success,0 +620024,1,631,success,0 +620025,1,381,success,0 +620026,1,397,success,0 +620027,1,482,success,0 +620028,1,398,success,0 +620029,1,386,success,0 +620030,1,643,success,0 +620031,1,390,success,0 +620032,1,482,success,0 +620033,1,376,success,0 +620034,1,599,success,0 +620035,1,387,success,0 +620036,1,393,success,0 +620037,1,378,success,0 +620038,1,382,success,0 +620039,1,608,success,0 +620040,1,384,success,0 +620041,1,412,success,0 +620042,1,385,success,0 +620043,1,381,success,0 +620044,1,545,success,0 +620045,1,383,success,0 +620046,1,399,success,0 +620047,1,393,success,0 +620048,1,392,success,0 +620049,1,382,success,0 +620050,1,376,success,0 +620051,1,390,success,0 +620052,1,395,success,0 +620053,1,393,success,0 +620054,1,376,success,0 +620055,1,407,success,0 +620056,1,389,success,0 +620057,1,390,success,0 +620058,1,641,success,0 +620059,1,438,success,0 +620060,1,384,success,0 +620061,1,439,success,0 +620062,1,387,success,0 +620063,1,388,success,0 +620064,1,389,success,0 +620065,1,392,success,0 +620066,1,394,success,0 +620067,1,394,success,0 +620068,1,384,success,0 +620069,1,383,success,0 +620070,1,384,success,0 +620071,1,387,success,0 +620072,1,407,success,0 +620073,1,386,success,0 +620074,1,381,success,0 +620075,1,435,success,0 +620076,1,386,success,0 +620077,1,639,success,0 +620078,1,631,success,0 +620079,1,384,success,0 +620080,1,639,success,0 +620081,1,395,success,0 +620082,1,437,success,0 +620083,1,375,success,0 +620084,1,639,success,0 +620085,1,394,success,0 +620086,1,442,success,0 +620087,1,415,success,0 +620088,1,387,success,0 +620089,1,389,success,0 +620090,1,395,success,0 +620091,1,386,success,0 +620092,1,639,success,0 +620093,1,382,success,0 +620094,1,380,success,0 +620095,1,384,success,0 +620096,1,389,success,0 +620097,1,431,success,0 +620098,1,381,success,0 +620099,1,389,success,0 diff --git a/policies/drawer_top_close/gpt61sol-s2/policy.py b/policies/drawer_top_close/gpt61sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..86dde6d28e7cb869c8f9f22173d15602c5efaf7a --- /dev/null +++ b/policies/drawer_top_close/gpt61sol-s2/policy.py @@ -0,0 +1,22 @@ +"""Deterministic two-handed drawer push.""" +import numpy as np + +class Policy: + def reset(self,obs,tools): + self.hold=np.asarray(tools.hold_action(),dtype=np.float32) + + def act(self,obs,tools): + a=self.hold.copy() + t=obs['t'] + if t<100: + a[0]=-.2 + else: + f=min(1.,(t-100)/40.) + a[4]=a[11]=.4*f + a[5]=-.15 + a[12]=.15 + if 160<=t<550: a[0]=.15 + if t>=550: + a[4]=a[11]=.4-.25*min(1.,(t-550)/80.) + if t<680: a[0]=.08 + return a diff --git a/policies/drawer_top_close/gpt61sol-s3/episodes.csv b/policies/drawer_top_close/gpt61sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..267e2f9df03f440dbdc8d5bf13229a4916e612a0 --- /dev/null +++ b/policies/drawer_top_close/gpt61sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,383,success,0 +620001,1,371,success,0 +620002,1,388,success,0 +620003,1,374,success,0 +620004,1,383,success,0 +620005,1,388,success,0 +620006,1,370,success,0 +620007,1,379,success,0 +620008,1,369,success,0 +620009,1,394,success,0 +620010,1,382,success,0 +620011,1,373,success,0 +620012,1,379,success,0 +620013,1,385,success,0 +620014,1,384,success,0 +620015,1,384,success,0 +620016,1,388,success,0 +620017,1,387,success,0 +620018,1,387,success,0 +620019,1,370,success,0 +620020,1,384,success,0 +620021,1,384,success,0 +620022,1,386,success,0 +620023,1,372,success,0 +620024,1,393,success,0 +620025,1,387,success,0 +620026,1,364,success,0 +620027,1,391,success,0 +620028,1,386,success,0 +620029,1,380,success,0 +620030,1,388,success,0 +620031,1,367,success,0 +620032,1,399,success,0 +620033,1,380,success,0 +620034,1,389,success,0 +620035,1,371,success,0 +620036,1,370,success,0 +620037,1,387,success,0 +620038,1,374,success,0 +620039,1,389,success,0 +620040,1,371,success,0 +620041,1,383,success,0 +620042,1,381,success,0 +620043,1,388,success,0 +620044,1,390,success,0 +620045,1,383,success,0 +620046,1,365,success,0 +620047,1,373,success,0 +620048,1,368,success,0 +620049,1,372,success,0 +620050,1,379,success,0 +620051,1,371,success,0 +620052,1,366,success,0 +620053,1,370,success,0 +620054,1,385,success,0 +620055,1,389,success,0 +620056,1,368,success,0 +620057,1,369,success,0 +620058,1,383,success,0 +620059,1,390,success,0 +620060,1,382,success,0 +620061,1,391,success,0 +620062,1,377,success,0 +620063,1,369,success,0 +620064,1,370,success,0 +620065,1,374,success,0 +620066,1,365,success,0 +620067,1,371,success,0 +620068,1,374,success,0 +620069,1,378,success,0 +620070,1,378,success,0 +620071,1,375,success,0 +620072,1,380,success,0 +620073,1,384,success,0 +620074,1,379,success,0 +620075,1,394,success,0 +620076,1,376,success,0 +620077,1,389,success,0 +620078,1,393,success,0 +620079,1,378,success,0 +620080,1,394,success,0 +620081,1,360,success,0 +620082,1,384,success,0 +620083,1,378,success,0 +620084,1,393,success,0 +620085,1,365,success,0 +620086,1,395,success,0 +620087,1,392,success,0 +620088,1,370,success,0 +620089,1,368,success,0 +620090,1,360,success,0 +620091,1,375,success,0 +620092,1,391,success,0 +620093,1,383,success,0 +620094,1,388,success,0 +620095,1,386,success,0 +620096,1,370,success,0 +620097,1,383,success,0 +620098,1,388,success,0 +620099,1,369,success,0 diff --git a/policies/drawer_top_close/gpt61sol-s3/policy.py b/policies/drawer_top_close/gpt61sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..9faf262c35985c04e79e8b8f14cb031dcff81bd5 --- /dev/null +++ b/policies/drawer_top_close/gpt61sol-s3/policy.py @@ -0,0 +1,41 @@ +"""Deterministic two-hand drawer push, with a clearance motion first.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.phase = 'clear' + self.phase_t = 0 + self.start = obs['low_dim_obs'][18:22].copy() + self.clear_x = min(-.075, float(self.start[0])-.14) + self.y = float(self.start[1]) + + def act(self, obs, tools): + a = self.hold.copy() + a[18:20] = 0 + a[2] = .74 + q = obs['low_dim_obs'] + x,y,z,yaw = q[18:22] + a[3] = np.clip(-2.0*yaw, -.25, .25) + dy = self.y-y + lateral = np.clip(2.0*dy,-.10,.10) if abs(dy)>.018 else 0 + if self.phase == 'clear': + a[0] = -.18 + a[1] = lateral + if x <= self.clear_x or obs['t']>=140: + self.phase = 'prepare' + self.phase_t = int(obs['t']) + elif self.phase == 'prepare': + f = np.clip((obs['t']-self.phase_t)/80,0,1) + a[4] = a[11] = .6*f + a[7] = a[14] = -.5*f + if f>=1: + self.phase = 'push' + self.phase_t = int(obs['t']) + else: + a[4] = a[11] = .6 + a[7] = a[14] = -.5 + a[0] = .15 if x<.40 else 0 + a[1] = lateral if a[0]!=0 else 0 + return a diff --git a/policies/drawer_top_close/gpt61terra-s1/episodes.csv b/policies/drawer_top_close/gpt61terra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..41fc8605372d58844bd06da9e6b0fb2d25380452 --- /dev/null +++ b/policies/drawer_top_close/gpt61terra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,790,success,0 +620001,1,637,success,0 +620002,1,651,success,0 +620003,1,623,success,0 +620004,1,644,success,0 +620005,1,651,success,0 +620006,1,305,success,0 +620007,0,850,timeout,0 +620008,1,356,success,0 +620009,0,850,timeout,0 +620010,1,826,success,0 +620011,1,790,success,0 +620012,1,790,success,0 +620013,0,850,timeout,0 +620014,0,850,timeout,0 +620015,1,759,success,0 +620016,0,850,timeout,0 +620017,1,657,success,0 +620018,1,660,success,0 +620019,1,656,success,0 +620020,1,791,success,0 +620021,1,651,success,0 +620022,1,653,success,0 +620023,1,631,success,0 +620024,0,850,timeout,0 +620025,0,850,timeout,0 +620026,1,631,success,0 +620027,0,850,timeout,0 +620028,1,789,success,0 +620029,1,389,success,0 +620030,0,850,timeout,0 +620031,1,624,success,0 +620032,0,850,timeout,0 +620033,0,850,timeout,0 +620034,0,850,timeout,0 +620035,1,357,success,0 +620036,1,307,success,0 +620037,1,658,success,0 +620038,1,389,success,0 +620039,0,850,timeout,0 +620040,1,625,success,0 +620041,0,850,timeout,0 +620042,1,639,success,0 +620043,1,658,success,0 +620044,0,850,timeout,0 +620045,1,636,success,0 +620046,1,303,success,0 +620047,1,334,success,0 +620048,1,302,success,0 +620049,1,652,success,0 +620050,0,850,timeout,0 +620051,1,634,success,0 +620052,1,304,success,0 +620053,1,305,success,0 +620054,1,652,success,0 +620055,1,791,success,0 +620056,1,304,success,0 +620057,1,360,success,0 +620058,1,657,success,0 +620059,1,791,success,0 +620060,0,850,timeout,0 +620061,0,850,timeout,0 +620062,1,326,success,0 +620063,1,301,success,0 +620064,1,305,success,0 +620065,1,622,success,0 +620066,1,626,success,0 +620067,1,359,success,0 +620068,1,326,success,0 +620069,1,652,success,0 +620070,1,649,success,0 +620071,1,314,success,0 +620072,0,850,timeout,0 +620073,0,850,timeout,0 +620074,1,652,success,0 +620075,1,795,success,0 +620076,1,631,success,0 +620077,1,658,success,0 +620078,0,850,timeout,0 +620079,0,850,timeout,0 +620080,0,850,timeout,0 +620081,1,302,success,0 +620082,0,850,timeout,0 +620083,0,850,timeout,0 +620084,0,850,timeout,0 +620085,1,629,success,0 +620086,1,807,success,0 +620087,0,850,timeout,0 +620088,1,630,success,0 +620089,1,630,success,0 +620090,1,302,success,0 +620091,1,339,success,0 +620092,0,850,timeout,0 +620093,0,850,timeout,0 +620094,0,850,timeout,0 +620095,1,817,success,0 +620096,1,305,success,0 +620097,1,822,success,0 +620098,1,657,success,0 +620099,1,303,success,0 diff --git a/policies/drawer_top_close/gpt61terra-s1/policy.py b/policies/drawer_top_close/gpt61terra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..0f56e91dc6ddb4320c7f277da6810850adeccd7a --- /dev/null +++ b/policies/drawer_top_close/gpt61terra-s1/policy.py @@ -0,0 +1,17 @@ +import numpy as np +class Policy: + def reset(self, obs, tools): + self.hold=np.asarray(tools.hold_action(),dtype=np.float32) + def act(self, obs, tools): + t=obs['t']; a=self.hold.copy() + if t<80: a[0]=-.22 + elif 140<=t<350: a[0]=.25 + elif 350<=t<430: a[0]=-.22 + elif t>=480: a[0]=.25 + if 80<=t<430: + a[4:11]=[-.3,.1,0,.5,0,0,0]; a[11:18]=[-.3,-.1,0,.5,0,0,0] + elif t>=430: + if t<670: pitch,elbow=-.6,1. + else: pitch,elbow=-.3,1.4 + a[4:11]=[pitch,.1,0,elbow,0,0,0]; a[11:18]=[pitch,-.1,0,elbow,0,0,0] + return a diff --git a/policies/drawer_top_close/gpt61terra-s2/episodes.csv b/policies/drawer_top_close/gpt61terra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..6a6fa7584a327a782b48080455db3e04866bd91d --- /dev/null +++ b/policies/drawer_top_close/gpt61terra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,525,success,0 +620001,1,286,success,0 +620002,0,850,timeout,0 +620003,1,280,success,0 +620004,1,332,success,0 +620005,1,453,success,0 +620006,1,335,success,0 +620007,1,267,success,0 +620008,1,259,success,0 +620009,1,459,success,0 +620010,1,266,success,0 +620011,1,262,success,0 +620012,1,446,success,0 +620013,1,531,success,0 +620014,1,465,success,0 +620015,1,297,success,0 +620016,1,672,success,0 +620017,0,850,timeout,0 +620018,1,452,success,0 +620019,1,322,success,0 +620020,1,311,success,0 +620021,1,403,success,0 +620022,1,584,success,0 +620023,1,326,success,0 +620024,1,670,success,0 +620025,1,426,success,0 +620026,1,300,success,0 +620027,0,850,timeout,0 +620028,0,850,timeout,0 +620029,1,464,success,0 +620030,0,850,timeout,0 +620031,1,325,success,0 +620032,1,475,success,0 +620033,1,351,success,0 +620034,1,653,success,0 +620035,0,850,timeout,0 +620036,1,314,success,0 +620037,1,612,success,0 +620038,1,279,success,0 +620039,1,466,success,0 +620040,0,850,timeout,0 +620041,1,341,success,0 +620042,1,349,success,0 +620043,1,746,success,0 +620044,1,478,success,0 +620045,1,259,success,0 +620046,1,269,success,0 +620047,1,482,success,0 +620048,1,302,success,0 +620049,0,850,timeout,0 +620050,1,280,success,0 +620051,1,327,success,0 +620052,1,327,success,0 +620053,1,293,success,0 +620054,1,530,success,0 +620055,1,839,success,0 +620056,1,297,success,0 +620057,1,262,success,0 +620058,0,850,timeout,0 +620059,1,824,success,0 +620060,1,270,success,0 +620061,1,661,success,0 +620062,1,316,success,0 +620063,1,292,success,0 +620064,1,280,success,0 +620065,1,566,success,0 +620066,1,282,success,0 +620067,1,442,success,0 +620068,1,256,success,0 +620069,1,324,success,0 +620070,1,319,success,0 +620071,1,301,success,0 +620072,1,318,success,0 +620073,1,287,success,0 +620074,1,295,success,0 +620075,1,436,success,0 +620076,1,324,success,0 +620077,1,550,success,0 +620078,1,445,success,0 +620079,1,261,success,0 +620080,1,704,success,0 +620081,1,303,success,0 +620082,1,308,success,0 +620083,1,266,success,0 +620084,1,418,success,0 +620085,1,280,success,0 +620086,0,850,timeout,0 +620087,1,408,success,0 +620088,1,359,success,0 +620089,1,328,success,0 +620090,0,850,timeout,0 +620091,1,289,success,0 +620092,1,607,success,0 +620093,1,375,success,0 +620094,1,309,success,0 +620095,1,370,success,0 +620096,1,269,success,0 +620097,1,434,success,0 +620098,0,850,timeout,0 +620099,1,291,success,0 diff --git a/policies/drawer_top_close/gpt61terra-s2/policy.py b/policies/drawer_top_close/gpt61terra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..ee5afed68c42a66a6ad371570a7c9346afe0b607 --- /dev/null +++ b/policies/drawer_top_close/gpt61terra-s2/policy.py @@ -0,0 +1,16 @@ +"""Deterministic forward-pressure policy for closing the top drawer.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.action = np.asarray(tools.hold_action(), dtype=np.float32) + # Fold both arms out of the way before approaching the cabinet. + self.action[4] = self.action[11] = 0.5 + self.action[7] = self.action[14] = 1.0 + self.action[18:20] = 0.0 + + def act(self, obs, tools): + action = self.action.copy() + action[0] = 0.0 if obs['t'] < 70 else 0.25 + return action diff --git a/policies/drawer_top_close/gpt61terra-s3/episodes.csv b/policies/drawer_top_close/gpt61terra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..326f5de05b9bdbe24e45f7d5731ac9615528a2ca --- /dev/null +++ b/policies/drawer_top_close/gpt61terra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,850,timeout,0 +620001,1,325,success,0 +620002,0,850,timeout,0 +620003,1,316,success,0 +620004,1,429,success,0 +620005,0,850,timeout,0 +620006,1,300,success,0 +620007,1,242,success,0 +620008,1,315,success,0 +620009,1,309,success,0 +620010,1,300,success,0 +620011,1,321,success,0 +620012,1,581,success,0 +620013,1,309,success,0 +620014,1,570,success,0 +620015,1,278,success,0 +620016,0,850,timeout,0 +620017,0,850,timeout,0 +620018,1,697,success,0 +620019,1,477,success,0 +620020,1,301,success,0 +620021,0,850,timeout,0 +620022,1,581,success,0 +620023,1,317,success,0 +620024,0,850,timeout,0 +620025,1,306,success,0 +620026,1,313,success,0 +620027,1,584,success,0 +620028,0,850,timeout,0 +620029,1,301,success,0 +620030,1,583,success,0 +620031,1,257,success,0 +620032,1,583,success,0 +620033,1,303,success,0 +620034,1,304,success,0 +620035,1,252,success,0 +620036,1,288,success,0 +620037,1,583,success,0 +620038,1,290,success,0 +620039,0,850,timeout,0 +620040,1,313,success,0 +620041,1,298,success,0 +620042,1,303,success,0 +620043,1,584,success,0 +620044,0,850,timeout,0 +620045,1,314,success,0 +620046,1,316,success,0 +620047,1,499,success,0 +620048,1,313,success,0 +620049,1,290,success,0 +620050,1,298,success,0 +620051,1,317,success,0 +620052,1,318,success,0 +620053,1,302,success,0 +620054,1,309,success,0 +620055,0,850,timeout,0 +620056,1,259,success,0 +620057,1,314,success,0 +620058,1,621,success,0 +620059,1,576,success,0 +620060,1,302,success,0 +620061,1,581,success,0 +620062,1,300,success,0 +620063,1,318,success,0 +620064,1,310,success,0 +620065,1,489,success,0 +620066,1,265,success,0 +620067,1,498,success,0 +620068,1,258,success,0 +620069,1,308,success,0 +620070,1,280,success,0 +620071,1,259,success,0 +620072,0,850,timeout,0 +620073,1,301,success,0 +620074,1,279,success,0 +620075,1,309,success,0 +620076,1,301,success,0 +620077,0,850,timeout,0 +620078,0,850,timeout,0 +620079,1,285,success,0 +620080,0,850,timeout,0 +620081,1,313,success,0 +620082,1,433,success,0 +620083,1,301,success,0 +620084,0,850,timeout,0 +620085,1,337,success,0 +620086,0,850,timeout,0 +620087,1,309,success,0 +620088,1,264,success,0 +620089,1,266,success,0 +620090,1,412,success,0 +620091,1,316,success,0 +620092,0,850,timeout,0 +620093,1,561,success,0 +620094,1,303,success,0 +620095,1,577,success,0 +620096,1,261,success,0 +620097,1,298,success,0 +620098,0,850,timeout,0 +620099,1,366,success,0 diff --git a/policies/drawer_top_close/gpt61terra-s3/policy.py b/policies/drawer_top_close/gpt61terra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..f1464b28eb46dcf0269068dbc43cbe2b7221f1ed --- /dev/null +++ b/policies/drawer_top_close/gpt61terra-s3/policy.py @@ -0,0 +1,15 @@ +import numpy as np +class Policy: + def reset(self,obs,tools): + self.a=tools.hold_action().copy(); self.y=obs['low_dim_obs'][19] + def act(self,obs,tools): + a=self.a.copy(); p=obs['low_dim_obs']; t=obs['t'] + if t<250: pitch=.6 + elif t<450: pitch=-.3 + elif t<530: pitch=.6 + elif t<650: pitch=-.5 + elif t<720: pitch=.6 + else: pitch=-.5 + a[4]=a[11]=pitch; a[7]=a[14]=1.0 + a[0]=0.2 if t>40 else 0; a[1]=np.clip(2*(self.y-p[19]),-.25,.25); a[3]=np.clip(-2*p[21],-.4,.4) + return a diff --git a/policies/drawer_top_close/gpt6sol-s1/episodes.csv b/policies/drawer_top_close/gpt6sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..644c3032f5cf45b3d41446c8adb758ffc51f6903 --- /dev/null +++ b/policies/drawer_top_close/gpt6sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,403,success,0 +620001,1,478,success,0 +620002,1,158,success,0 +620003,1,474,success,0 +620004,1,105,success,0 +620005,1,325,success,0 +620006,1,163,success,0 +620007,1,482,success,0 +620008,1,437,success,0 +620009,1,425,success,0 +620010,1,337,success,0 +620011,0,850,timeout,0 +620012,1,104,success,0 +620013,1,530,success,0 +620014,1,428,success,0 +620015,1,178,success,0 +620016,1,427,success,0 +620017,1,118,success,0 +620018,1,429,success,0 +620019,1,163,success,0 +620020,1,283,success,0 +620021,1,273,success,0 +620022,1,107,success,0 +620023,1,105,success,0 +620024,1,433,success,0 +620025,1,524,success,0 +620026,1,104,success,0 +620027,1,104,success,0 +620028,1,103,success,0 +620029,1,104,success,0 +620030,1,429,success,0 +620031,1,104,success,0 +620032,1,474,success,0 +620033,1,163,success,0 +620034,1,336,success,0 +620035,1,432,success,0 +620036,1,163,success,0 +620037,1,108,success,0 +620038,1,477,success,0 +620039,1,427,success,0 +620040,1,381,success,0 +620041,1,107,success,0 +620042,1,105,success,0 +620043,1,103,success,0 +620044,1,482,success,0 +620045,1,377,success,0 +620046,0,850,timeout,0 +620047,1,112,success,0 +620048,1,162,success,0 +620049,1,385,success,0 +620050,1,526,success,0 +620051,1,105,success,0 +620052,1,104,success,0 +620053,1,330,success,0 +620054,1,531,success,0 +620055,1,106,success,0 +620056,1,105,success,0 +620057,1,108,success,0 +620058,1,387,success,0 +620059,1,104,success,0 +620060,1,278,success,0 +620061,1,105,success,0 +620062,1,106,success,0 +620063,1,160,success,0 +620064,1,381,success,0 +620065,1,118,success,0 +620066,1,108,success,0 +620067,1,104,success,0 +620068,1,114,success,0 +620069,1,103,success,0 +620070,1,107,success,0 +620071,1,107,success,0 +620072,1,164,success,0 +620073,1,280,success,0 +620074,1,169,success,0 +620075,1,328,success,0 +620076,1,104,success,0 +620077,1,106,success,0 +620078,1,437,success,0 +620079,1,174,success,0 +620080,1,333,success,0 +620081,1,104,success,0 +620082,1,107,success,0 +620083,1,336,success,0 +620084,1,483,success,0 +620085,1,108,success,0 +620086,1,571,success,0 +620087,1,574,success,0 +620088,1,104,success,0 +620089,1,105,success,0 +620090,1,161,success,0 +620091,1,109,success,0 +620092,1,108,success,0 +620093,1,104,success,0 +620094,1,105,success,0 +620095,1,104,success,0 +620096,1,479,success,0 +620097,1,106,success,0 +620098,1,108,success,0 +620099,1,103,success,0 diff --git a/policies/drawer_top_close/gpt6sol-s1/policy.py b/policies/drawer_top_close/gpt6sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..80e8153ccc1b32687a8d2bb87b17be434e3776e5 --- /dev/null +++ b/policies/drawer_top_close/gpt6sol-s1/policy.py @@ -0,0 +1,19 @@ +"""Hand-written controller for closing the cabinet's top drawer.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.base = np.asarray(tools.hold_action(), dtype=np.float32) + self.base[2] = 0.74 + # Put both hands inside the drawer width and against its front panel. + self.base[4] = self.base[11] = -1.2 + self.base[5] = 0.0 + self.base[12] = 0.0 + + def act(self, obs, tools): + action = self.base.copy() + if obs['t'] < 750: + action[0] = 1.0 + return action diff --git a/policies/drawer_top_close/gpt6sol-s2/episodes.csv b/policies/drawer_top_close/gpt6sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..49bd63c05b21769a7d8a42432eeb795160f37fce --- /dev/null +++ b/policies/drawer_top_close/gpt6sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,329,success,0 +620001,1,329,success,0 +620002,1,340,success,0 +620003,1,327,success,0 +620004,1,325,success,0 +620005,1,342,success,0 +620006,1,316,success,0 +620007,1,328,success,0 +620008,1,313,success,0 +620009,1,341,success,0 +620010,1,329,success,0 +620011,1,327,success,0 +620012,1,327,success,0 +620013,1,329,success,0 +620014,1,325,success,0 +620015,1,326,success,0 +620016,1,328,success,0 +620017,1,330,success,0 +620018,1,329,success,0 +620019,1,319,success,0 +620020,1,330,success,0 +620021,1,341,success,0 +620022,1,337,success,0 +620023,1,327,success,0 +620024,1,338,success,0 +620025,1,327,success,0 +620026,1,314,success,0 +620027,1,339,success,0 +620028,1,337,success,0 +620029,1,325,success,0 +620030,1,326,success,0 +620031,1,328,success,0 +620032,1,331,success,0 +620033,1,327,success,0 +620034,1,337,success,0 +620035,1,319,success,0 +620036,1,319,success,0 +620037,1,332,success,0 +620038,1,328,success,0 +620039,1,332,success,0 +620040,1,325,success,0 +620041,1,337,success,0 +620042,1,330,success,0 +620043,1,327,success,0 +620044,1,327,success,0 +620045,1,329,success,0 +620046,1,320,success,0 +620047,1,330,success,0 +620048,1,319,success,0 +620049,1,329,success,0 +620050,1,328,success,0 +620051,1,327,success,0 +620052,1,328,success,0 +620053,1,327,success,0 +620054,1,327,success,0 +620055,1,327,success,0 +620056,1,330,success,0 +620057,1,319,success,0 +620058,1,328,success,0 +620059,1,331,success,0 +620060,1,325,success,0 +620061,1,332,success,0 +620062,1,321,success,0 +620063,1,328,success,0 +620064,1,320,success,0 +620065,1,330,success,0 +620066,1,322,success,0 +620067,1,329,success,0 +620068,1,320,success,0 +620069,1,327,success,0 +620070,1,328,success,0 +620071,1,333,success,0 +620072,1,329,success,0 +620073,1,332,success,0 +620074,1,325,success,0 +620075,1,339,success,0 +620076,1,327,success,0 +620077,1,331,success,0 +620078,1,327,success,0 +620079,1,324,success,0 +620080,1,337,success,0 +620081,1,327,success,0 +620082,1,338,success,0 +620083,1,328,success,0 +620084,1,330,success,0 +620085,1,324,success,0 +620086,1,331,success,0 +620087,1,328,success,0 +620088,1,328,success,0 +620089,1,328,success,0 +620090,1,314,success,0 +620091,1,328,success,0 +620092,1,331,success,0 +620093,1,326,success,0 +620094,1,326,success,0 +620095,1,337,success,0 +620096,1,317,success,0 +620097,1,337,success,0 +620098,1,338,success,0 +620099,1,324,success,0 diff --git a/policies/drawer_top_close/gpt6sol-s2/policy.py b/policies/drawer_top_close/gpt6sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..85df046c287381afa2472e5b8a3a3f6fe310b401 --- /dev/null +++ b/policies/drawer_top_close/gpt6sol-s2/policy.py @@ -0,0 +1,22 @@ +"""Close the top kitchen drawer with a centered push.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.action = np.asarray(tools.hold_action(), dtype=np.float32) + self.action[4:18] = 0.0 + self.phase = 0 + self.target_y = -0.025 + + def act(self, obs, tools): + x, y, _, yaw = (float(v) for v in obs["low_dim_obs"][18:22]) + a = self.action.copy() + + if self.phase == 0 and x < -0.32: + self.phase = 1 + a[0] = -0.25 if self.phase == 0 else 0.3 + a[1] = np.clip(-1.4 * (y - self.target_y), -0.22, 0.22) + a[3] = np.clip(-2.0 * yaw, -0.25, 0.25) + return a diff --git a/policies/drawer_top_close/gpt6sol-s3/episodes.csv b/policies/drawer_top_close/gpt6sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..f9d8acccb027cdaa33ebfbb4293e209190ca54f4 --- /dev/null +++ b/policies/drawer_top_close/gpt6sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,618,success,0 +620001,1,559,success,0 +620002,1,576,success,0 +620003,1,639,success,0 +620004,1,598,success,0 +620005,1,562,success,0 +620006,1,603,success,0 +620007,1,634,success,0 +620008,1,577,success,0 +620009,1,575,success,0 +620010,1,573,success,0 +620011,1,562,success,0 +620012,1,580,success,0 +620013,1,573,success,0 +620014,1,608,success,0 +620015,1,627,success,0 +620016,1,600,success,0 +620017,1,625,success,0 +620018,1,567,success,0 +620019,1,569,success,0 +620020,1,571,success,0 +620021,1,563,success,0 +620022,1,561,success,0 +620023,1,634,success,0 +620024,1,572,success,0 +620025,1,562,success,0 +620026,1,612,success,0 +620027,1,573,success,0 +620028,1,632,success,0 +620029,1,668,success,0 +620030,1,647,success,0 +620031,1,607,success,0 +620032,1,569,success,0 +620033,1,570,success,0 +620034,1,560,success,0 +620035,1,583,success,0 +620036,1,563,success,0 +620037,1,576,success,0 +620038,1,577,success,0 +620039,1,589,success,0 +620040,1,577,success,0 +620041,1,571,success,0 +620042,1,566,success,0 +620043,1,576,success,0 +620044,1,559,success,0 +620045,1,563,success,0 +620046,1,625,success,0 +620047,1,577,success,0 +620048,1,556,success,0 +620049,1,576,success,0 +620050,1,576,success,0 +620051,1,635,success,0 +620052,1,608,success,0 +620053,1,556,success,0 +620054,1,572,success,0 +620055,1,586,success,0 +620056,1,563,success,0 +620057,1,564,success,0 +620058,1,610,success,0 +620059,1,591,success,0 +620060,1,563,success,0 +620061,1,623,success,0 +620062,1,567,success,0 +620063,1,558,success,0 +620064,1,562,success,0 +620065,1,620,success,0 +620066,1,557,success,0 +620067,1,559,success,0 +620068,1,567,success,0 +620069,1,557,success,0 +620070,1,556,success,0 +620071,1,555,success,0 +620072,1,580,success,0 +620073,1,574,success,0 +620074,1,563,success,0 +620075,1,570,success,0 +620076,1,617,success,0 +620077,1,578,success,0 +620078,1,555,success,0 +620079,1,564,success,0 +620080,1,570,success,0 +620081,1,555,success,0 +620082,1,571,success,0 +620083,1,575,success,0 +620084,1,559,success,0 +620085,1,649,success,0 +620086,1,570,success,0 +620087,1,568,success,0 +620088,1,633,success,0 +620089,1,626,success,0 +620090,1,614,success,0 +620091,1,554,success,0 +620092,1,569,success,0 +620093,1,630,success,0 +620094,1,596,success,0 +620095,1,566,success,0 +620096,1,564,success,0 +620097,1,568,success,0 +620098,1,616,success,0 +620099,1,559,success,0 diff --git a/policies/drawer_top_close/gpt6sol-s3/policy.py b/policies/drawer_top_close/gpt6sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..84f5185dd6e1298d8614a2c2c82af4d968796941 --- /dev/null +++ b/policies/drawer_top_close/gpt6sol-s3/policy.py @@ -0,0 +1,33 @@ +"""Deterministic controller for closing the upper cabinet drawer.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.base = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = int(obs["t"]) + a = self.base.copy() + if t < 90: + pitch = 0.4 + elif t < 210: + pitch = 0.4 + 0.4 * (t - 90) / 120.0 + elif t < 310: + pitch = 0.8 + else: + pitch = 0.0 + a[4] = a[11] = pitch + if 20 <= t < 310: + a[0] = 0.3 + elif 420 <= t < 700: + a[0] = 0.25 + state = obs["low_dim_obs"] + y = float(state[19]) + yaw = float(state[21]) + a[1] = np.clip(-1.0 * y, -0.18, 0.18) + a[3] = np.clip(-1.8 * yaw, -0.4, 0.4) + else: + a[0] = 0.0 + return a diff --git a/policies/drawer_top_close/kimi31pro-s1/episodes.csv b/policies/drawer_top_close/kimi31pro-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..c0d6d20d1541b438605f8371644ba47b5248b28e --- /dev/null +++ b/policies/drawer_top_close/kimi31pro-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,236,success,0 +620001,1,173,success,0 +620002,1,176,success,0 +620003,1,173,success,0 +620004,1,172,success,0 +620005,1,165,success,0 +620006,1,173,success,0 +620007,1,236,success,0 +620008,1,216,success,0 +620009,1,213,success,0 +620010,1,174,success,0 +620011,1,174,success,0 +620012,1,206,success,0 +620013,1,220,success,0 +620014,1,174,success,0 +620015,1,170,success,0 +620016,1,171,success,0 +620017,1,170,success,0 +620018,1,172,success,0 +620019,1,216,success,0 +620020,1,203,success,0 +620021,1,167,success,0 +620022,1,206,success,0 +620023,1,237,success,0 +620024,1,164,success,0 +620025,1,207,success,0 +620026,1,171,success,0 +620027,1,173,success,0 +620028,1,210,success,0 +620029,1,206,success,0 +620030,1,171,success,0 +620031,1,235,success,0 +620032,1,170,success,0 +620033,1,209,success,0 +620034,1,172,success,0 +620035,1,209,success,0 +620036,1,236,success,0 +620037,1,171,success,0 +620038,1,174,success,0 +620039,1,175,success,0 +620040,1,167,success,0 +620041,1,205,success,0 +620042,1,168,success,0 +620043,1,172,success,0 +620044,1,173,success,0 +620045,1,225,success,0 +620046,1,220,success,0 +620047,1,169,success,0 +620048,1,205,success,0 +620049,1,214,success,0 +620050,1,236,success,0 +620051,1,239,success,0 +620052,1,220,success,0 +620053,1,168,success,0 +620054,1,171,success,0 +620055,1,209,success,0 +620056,1,261,success,0 +620057,1,205,success,0 +620058,1,170,success,0 +620059,1,209,success,0 +620060,1,171,success,0 +620061,1,210,success,0 +620062,1,168,success,0 +620063,1,237,success,0 +620064,1,167,success,0 +620065,1,169,success,0 +620066,1,224,success,0 +620067,1,204,success,0 +620068,1,206,success,0 +620069,1,208,success,0 +620070,1,206,success,0 +620071,1,221,success,0 +620072,1,229,success,0 +620073,1,171,success,0 +620074,1,170,success,0 +620075,1,208,success,0 +620076,1,170,success,0 +620077,1,171,success,0 +620078,1,171,success,0 +620079,1,206,success,0 +620080,1,165,success,0 +620081,1,171,success,0 +620082,1,172,success,0 +620083,1,176,success,0 +620084,1,173,success,0 +620085,1,251,success,0 +620086,1,170,success,0 +620087,1,211,success,0 +620088,1,169,success,0 +620089,1,238,success,0 +620090,1,170,success,0 +620091,1,218,success,0 +620092,1,207,success,0 +620093,1,220,success,0 +620094,1,173,success,0 +620095,1,209,success,0 +620096,1,176,success,0 +620097,1,206,success,0 +620098,1,209,success,0 +620099,1,219,success,0 diff --git a/policies/drawer_top_close/kimi31pro-s1/policy.py b/policies/drawer_top_close/kimi31pro-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..a38682b9cc1d6b890fe3907e2295f11aa4bda9a0 --- /dev/null +++ b/policies/drawer_top_close/kimi31pro-s1/policy.py @@ -0,0 +1,37 @@ +"""Deterministic hand-written controller for closing the top cabinet drawer.""" + +import numpy as np + + +class Policy: + """Approach the drawer and push its front with both open grippers.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + @staticmethod + def _angle(x): + return (x + np.pi) % (2 * np.pi) - np.pi + + def act(self, obs, tools): + q = obs["low_dim_obs"] + t = int(obs["t"]) + y, yaw = q[19], q[21] + + raw = self.hold.copy() + raw[2] = 0.74 + raw[18:20] = 0.0 + + # Correct the small standing/walking drift using the observed base pose. + raw[1] = np.clip(-0.8 * y, -0.10, 0.10) + raw[3] = np.clip(-0.8 * self._angle(yaw), -0.25, 0.25) + + # Keep the wrists oriented toward the cabinet as the shoulders rise. + pitch = 1.20 * np.clip((t - 10) / 55.0, 0.0, 1.0) + arm = np.array([pitch, 0.0, 0.0, 0.0, 0.0, -pitch, 0.0]) + raw[4:11] = arm + raw[11:18] = arm + + # A firm but symmetric push is needed for the last part of the travel. + raw[0] = 0.28 if t < 45 else (0.80 if t < 340 else 0.0) + return raw diff --git a/policies/drawer_top_close/kimi31pro-s2/episodes.csv b/policies/drawer_top_close/kimi31pro-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..6dba177cda4f7fbebed26778cbc53d68553bf990 --- /dev/null +++ b/policies/drawer_top_close/kimi31pro-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,850,timeout,0 +620001,1,633,success,0 +620002,0,850,timeout,0 +620003,1,423,success,0 +620004,0,850,timeout,0 +620005,0,850,timeout,0 +620006,0,850,timeout,0 +620007,1,665,success,0 +620008,1,612,success,0 +620009,0,850,timeout,0 +620010,1,659,success,0 +620011,0,850,timeout,0 +620012,0,850,timeout,0 +620013,0,850,timeout,0 +620014,0,850,timeout,0 +620015,0,850,timeout,0 +620016,0,850,timeout,0 +620017,0,850,timeout,0 +620018,0,850,timeout,0 +620019,1,563,success,0 +620020,0,850,timeout,0 +620021,0,850,timeout,0 +620022,0,850,timeout,0 +620023,0,850,timeout,0 +620024,0,850,timeout,0 +620025,0,850,timeout,0 +620026,1,575,success,0 +620027,0,850,timeout,0 +620028,0,850,timeout,0 +620029,0,850,timeout,0 +620030,0,850,timeout,0 +620031,0,850,timeout,0 +620032,0,850,timeout,0 +620033,0,850,timeout,0 +620034,0,850,timeout,0 +620035,0,850,timeout,0 +620036,0,850,timeout,0 +620037,0,850,timeout,0 +620038,0,850,timeout,0 +620039,0,850,timeout,0 +620040,1,612,success,0 +620041,0,850,timeout,0 +620042,0,850,timeout,0 +620043,0,850,timeout,0 +620044,0,850,timeout,0 +620045,0,850,timeout,0 +620046,1,585,success,0 +620047,0,850,timeout,0 +620048,0,850,timeout,0 +620049,1,584,success,0 +620050,1,657,success,0 +620051,0,850,timeout,0 +620052,0,850,timeout,0 +620053,1,554,success,0 +620054,0,850,timeout,0 +620055,0,850,timeout,0 +620056,1,607,success,0 +620057,1,560,success,0 +620058,0,850,timeout,0 +620059,0,850,timeout,0 +620060,0,850,timeout,0 +620061,0,850,timeout,0 +620062,0,850,timeout,0 +620063,1,361,success,0 +620064,0,850,timeout,0 +620065,0,850,timeout,0 +620066,1,440,success,0 +620067,0,850,timeout,0 +620068,0,850,timeout,0 +620069,0,850,timeout,0 +620070,0,850,timeout,0 +620071,1,672,success,0 +620072,0,850,timeout,0 +620073,0,850,timeout,0 +620074,0,850,timeout,0 +620075,0,850,timeout,0 +620076,0,850,timeout,0 +620077,0,850,timeout,0 +620078,0,850,timeout,0 +620079,1,619,success,0 +620080,0,850,timeout,0 +620081,0,850,timeout,0 +620082,0,850,timeout,0 +620083,1,562,success,0 +620084,0,850,timeout,0 +620085,0,850,timeout,0 +620086,0,850,timeout,0 +620087,0,850,timeout,0 +620088,0,850,timeout,0 +620089,0,850,timeout,0 +620090,1,555,success,0 +620091,0,850,timeout,0 +620092,0,850,timeout,0 +620093,0,850,timeout,0 +620094,0,850,timeout,0 +620095,1,613,success,0 +620096,1,595,success,0 +620097,0,850,timeout,0 +620098,0,850,timeout,0 +620099,0,850,timeout,0 diff --git a/policies/drawer_top_close/kimi31pro-s2/policy.py b/policies/drawer_top_close/kimi31pro-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..27c66ad334a584f1a6a9fe0f45aef86b6e7f05e7 --- /dev/null +++ b/policies/drawer_top_close/kimi31pro-s2/policy.py @@ -0,0 +1,93 @@ +"""Deterministic hand-written controller for the top-drawer task. + +The controller uses only proprioception and physical joint/base commands. It +approaches with the hands lifted, lowers them onto the drawer front, and then +tries two smooth pushing postures. Base lateral position and yaw are servoed +to their reset values throughout. +""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + state = np.asarray(obs["low_dim_obs"], dtype=np.float64) + self.origin = state[18:22].copy() + self.t = 0 + + @staticmethod + def _blend(a, b, u): + u = float(np.clip(u, 0.0, 1.0)) + u = u * u * (3.0 - 2.0 * u) + return a + u * (b - a) + + def _base(self, obs, speed): + """Move along the reset heading while rejecting lateral/yaw drift.""" + p = np.asarray(obs["low_dim_obs"], dtype=np.float64)[18:22] + x0, y0, _, yaw0 = self.origin + c0, s0 = np.cos(yaw0), np.sin(yaw0) + lateral = -s0 * (p[0] - x0) + c0 * (p[1] - y0) + correction = float(np.clip(-1.8 * lateral, -0.10, 0.10)) + + # Desired velocity in world coordinates, expressed in the current + # body frame for the frozen walking controller. + dx = speed * c0 - correction * s0 + dy = speed * s0 + correction * c0 + c, s = np.cos(p[3]), np.sin(p[3]) + vx = c * dx + s * dy + vy = -s * dx + c * dy + yaw_error = np.arctan2(np.sin(p[3] - yaw0), np.cos(p[3] - yaw0)) + wz = float(np.clip(-2.5 * yaw_error, -0.45, 0.45)) + return float(np.clip(vx, -0.35, 0.35)), float(np.clip(vy, -0.2, 0.2)), wz + + def act(self, obs, tools): + t = self.t + self.t += 1 + zero = np.zeros(7, dtype=np.float64) + lift = np.array([0.50, 0.15, 0.0, 1.20, 0.0, 0.0, 0.0]) + front = np.array([0.50, 0.15, 0.0, 0.30, 0.0, 0.0, 0.0]) + contact = np.array([0.50, 0.0, 0.0, -0.30, 0.0, 0.0, 0.0]) + low_push = np.array([-0.25, 0.0, 0.0, -0.30, 0.0, 0.0, 0.0]) + straight = np.array([0.80, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) + + if t < 70: + q = self._blend(zero, lift, t / 60.0) + height, speed, grip = 0.74, 0.0, 0.6 + elif t < 150: + q, height, speed, grip = lift, 0.74, 0.18, 0.6 + elif t < 215: + q = self._blend(lift, front, (t - 150) / 60.0) + height, speed, grip = 0.74, 0.0, 1.0 + elif t < 360: + q, height, speed, grip = front, 0.74, 0.20, 1.0 + elif t < 415: + q, height, speed, grip = front, 0.74, 0.0, 1.0 + elif t < 485: + u = (t - 415) / 65.0 + q = self._blend(front, contact, u) + height = float(self._blend(0.74, 0.58, u)) + speed, grip = 0.0, 1.0 + elif t < 605: + q = self._blend(contact, low_push, (t - 485) / 110.0) + height, speed, grip = 0.58, 0.15, 1.0 + elif t < 660: + q, height, speed, grip = low_push, 0.58, 0.0, 1.0 + elif t < 730: + u = (t - 660) / 65.0 + q = self._blend(low_push, straight, u) + height = float(self._blend(0.58, 0.74, u)) + speed, grip = 0.10, 0.6 + elif t < 810: + q, height, speed, grip = straight, 0.74, 0.20, 0.6 + else: + q, height, speed, grip = straight, 0.74, 0.0, 0.6 + + raw = self.hold.copy() + vx, vy, wz = self._base(obs, speed) + raw[0], raw[1], raw[2], raw[3] = vx, vy, height, wz + raw[4:11] = q + raw[11:18] = q * np.array([1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) + raw[18] = grip + raw[19] = grip + return raw diff --git a/policies/drawer_top_close/kimi31pro-s3/episodes.csv b/policies/drawer_top_close/kimi31pro-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..dce425a157e5733abd1fc8df3153b6523d9dfa53 --- /dev/null +++ b/policies/drawer_top_close/kimi31pro-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,850,timeout,0 +620001,1,533,success,0 +620002,0,850,timeout,0 +620003,1,461,success,0 +620004,0,850,timeout,0 +620005,0,850,timeout,0 +620006,1,543,success,0 +620007,1,481,success,0 +620008,1,478,success,0 +620009,0,850,timeout,0 +620010,0,850,timeout,0 +620011,1,498,success,0 +620012,0,850,timeout,0 +620013,0,850,timeout,0 +620014,0,850,timeout,0 +620015,1,441,success,0 +620016,0,850,timeout,0 +620017,0,850,timeout,0 +620018,0,850,timeout,0 +620019,1,464,success,0 +620020,1,509,success,0 +620021,0,850,timeout,0 +620022,0,850,timeout,0 +620023,0,850,timeout,0 +620024,0,850,timeout,0 +620025,0,850,timeout,0 +620026,1,410,success,0 +620027,0,850,timeout,0 +620028,0,850,timeout,0 +620029,0,850,timeout,0 +620030,0,850,timeout,0 +620031,1,779,success,0 +620032,0,850,timeout,0 +620033,1,486,success,0 +620034,0,850,timeout,0 +620035,1,468,success,0 +620036,1,521,success,0 +620037,0,850,timeout,0 +620038,1,420,success,0 +620039,0,850,timeout,0 +620040,1,528,success,0 +620041,1,515,success,0 +620042,1,599,success,0 +620043,0,850,timeout,0 +620044,0,850,timeout,0 +620045,1,452,success,0 +620046,1,452,success,0 +620047,0,850,timeout,0 +620048,1,449,success,0 +620049,1,487,success,0 +620050,1,500,success,0 +620051,0,850,timeout,0 +620052,1,318,success,0 +620053,1,556,success,0 +620054,0,850,timeout,0 +620055,0,850,timeout,0 +620056,1,390,success,0 +620057,1,536,success,0 +620058,0,850,timeout,0 +620059,0,850,timeout,0 +620060,0,850,timeout,0 +620061,0,850,timeout,0 +620062,1,573,success,0 +620063,1,427,success,0 +620064,1,490,success,0 +620065,0,850,timeout,0 +620066,1,278,success,0 +620067,1,248,success,0 +620068,1,460,success,0 +620069,1,281,success,0 +620070,1,433,success,0 +620071,1,437,success,0 +620072,1,794,success,0 +620073,1,547,success,0 +620074,0,850,timeout,0 +620075,0,850,timeout,0 +620076,0,850,timeout,0 +620077,0,850,timeout,0 +620078,0,850,timeout,0 +620079,1,504,success,0 +620080,0,850,timeout,0 +620081,1,443,success,0 +620082,0,850,timeout,0 +620083,1,478,success,0 +620084,0,850,timeout,0 +620085,1,260,success,0 +620086,0,850,timeout,0 +620087,0,850,timeout,0 +620088,0,850,timeout,0 +620089,0,850,timeout,0 +620090,1,415,success,0 +620091,1,443,success,0 +620092,0,850,timeout,0 +620093,0,850,timeout,0 +620094,0,850,timeout,0 +620095,0,850,timeout,0 +620096,1,615,success,0 +620097,1,513,success,0 +620098,0,850,timeout,0 +620099,1,417,success,0 diff --git a/policies/drawer_top_close/kimi31pro-s3/policy.py b/policies/drawer_top_close/kimi31pro-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..ccbb9445984ded87db9d53f8fd8edccf3d9c3c70 --- /dev/null +++ b/policies/drawer_top_close/kimi31pro-s3/policy.py @@ -0,0 +1,12 @@ +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + raw = self.hold.copy() + raw[0] = 1.0 + raw[4:11] = [0.5, 0.0, 0.0, 0.5, 0.0, 1.5, 0.0] + raw[11:18] = [0.5, 0.0, 0.0, 0.5, 0.0, 1.5, 0.0] + return raw diff --git a/policies/drawer_top_close/opus-s1/episodes.csv b/policies/drawer_top_close/opus-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..68d0ee922681751a0fbb128a442ce5bbe3440185 --- /dev/null +++ b/policies/drawer_top_close/opus-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,371,success,0 +620001,1,360,success,0 +620002,1,362,success,0 +620003,1,357,success,0 +620004,1,371,success,0 +620005,1,366,success,0 +620006,1,363,success,0 +620007,1,358,success,0 +620008,1,364,success,0 +620009,1,365,success,0 +620010,1,372,success,0 +620011,1,350,success,0 +620012,1,367,success,0 +620013,1,365,success,0 +620014,1,373,success,0 +620015,1,366,success,0 +620016,1,367,success,0 +620017,1,378,success,0 +620018,1,364,success,0 +620019,1,368,success,0 +620020,1,368,success,0 +620021,1,368,success,0 +620022,1,378,success,0 +620023,1,364,success,0 +620024,1,367,success,0 +620025,1,373,success,0 +620026,1,357,success,0 +620027,1,359,success,0 +620028,1,373,success,0 +620029,1,372,success,0 +620030,1,375,success,0 +620031,1,363,success,0 +620032,1,357,success,0 +620033,1,360,success,0 +620034,1,368,success,0 +620035,1,359,success,0 +620036,1,366,success,0 +620037,1,364,success,0 +620038,1,357,success,0 +620039,1,365,success,0 +620040,1,359,success,0 +620041,1,361,success,0 +620042,1,369,success,0 +620043,1,363,success,0 +620044,1,365,success,0 +620045,1,366,success,0 +620046,1,368,success,0 +620047,1,372,success,0 +620048,1,365,success,0 +620049,1,361,success,0 +620050,1,363,success,0 +620051,1,363,success,0 +620052,1,355,success,0 +620053,1,364,success,0 +620054,1,365,success,0 +620055,1,366,success,0 +620056,1,363,success,0 +620057,1,368,success,0 +620058,1,369,success,0 +620059,1,371,success,0 +620060,1,363,success,0 +620061,1,370,success,0 +620062,1,367,success,0 +620063,1,358,success,0 +620064,1,373,success,0 +620065,1,367,success,0 +620066,1,361,success,0 +620067,1,362,success,0 +620068,1,368,success,0 +620069,1,357,success,0 +620070,1,354,success,0 +620071,1,356,success,0 +620072,1,370,success,0 +620073,1,365,success,0 +620074,1,354,success,0 +620075,1,366,success,0 +620076,1,356,success,0 +620077,1,363,success,0 +620078,1,365,success,0 +620079,1,364,success,0 +620080,1,367,success,0 +620081,1,358,success,0 +620082,1,366,success,0 +620083,1,369,success,0 +620084,1,367,success,0 +620085,1,361,success,0 +620086,1,365,success,0 +620087,1,366,success,0 +620088,1,362,success,0 +620089,1,362,success,0 +620090,1,358,success,0 +620091,1,359,success,0 +620092,1,369,success,0 +620093,1,360,success,0 +620094,1,368,success,0 +620095,1,369,success,0 +620096,1,371,success,0 +620097,1,368,success,0 +620098,1,363,success,0 +620099,1,356,success,0 diff --git a/policies/drawer_top_close/opus-s1/policy.py b/policies/drawer_top_close/opus-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..3fb4b9c7e3a6adfa93636d03d86d564225ad6fb3 --- /dev/null +++ b/policies/drawer_top_close/opus-s1/policy.py @@ -0,0 +1,76 @@ +"""Close the open top drawer: step back, lower both forearms to drawer-front +height, then walk forward so the hands push the drawer front shut. + +Hand-written phase logic; pelvis pose from low_dim_obs closes the loop on +distance travelled and heading. +""" + +import numpy as np + +MIRROR = np.array([1, -1, -1, 1, -1, 1, -1], dtype=np.float32) + +# Left arm poses (right arm is the mirror image). +ARM_BACK = np.array([-0.4, 0.15, 0.0, 0.0, 0.0, 0.0, 0.0], dtype=np.float32) +ARM_PUSH = np.array([-0.4, 0.15, 0.0, 0.5, 0.0, 0.0, 0.0], dtype=np.float32) + +BACK_DIST = 0.30 # m to step back before lowering the arms +BACK_SPEED = -0.3 +SETTLE_STEPS = 60 +PUSH_SPEED = 0.15 +YAW_GAIN = 1.5 +LAT_GAIN = 1.0 + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + def reset(self, obs, tools): + o = obs["low_dim_obs"] + self.x0 = np.array(o[18:20], dtype=np.float64) + self.yaw0 = float(o[21]) + self.phase = "back" + self.phase_t = 0 + + def _fwd(self, o): + d = np.array(o[18:20], dtype=np.float64) - self.x0 + return d[0] * np.cos(self.yaw0) + d[1] * np.sin(self.yaw0) + + def _set(self, phase): + self.phase = phase + self.phase_t = 0 + + def act(self, obs, tools): + o = obs["low_dim_obs"] + raw = np.asarray(tools.hold_action(), dtype=np.float32).copy() + raw[2] = 0.74 + raw[18:20] = 0.0 + fwd = self._fwd(o) + yaw = float(o[21]) + # The cabinet faces world +x: square up to it and hold the start line. + wz = float(np.clip(-YAW_GAIN * wrap(yaw), -0.5, 0.5)) + dy = float(o[19]) - self.x0[1] + vy_world = float(np.clip(-LAT_GAIN * dy, -0.1, 0.1)) + vy = np.cos(yaw) * vy_world + self.phase_t += 1 + + if self.phase == "back": + arm, vx = ARM_BACK, BACK_SPEED + if fwd < -BACK_DIST + 0.1: # base keeps moving after the command stops + self._set("settle") + elif self.phase == "settle": + arm, vx = ARM_PUSH, 0.0 + if self.phase_t >= SETTLE_STEPS: + self._set("push") + else: + arm, vx = ARM_PUSH, PUSH_SPEED + + raw[0] = vx + raw[1] = vy if vx != 0.0 else 0.0 + raw[3] = wz + raw[4:11] = arm + raw[11:18] = arm * MIRROR + return raw diff --git a/policies/drawer_top_close/opus-s2/episodes.csv b/policies/drawer_top_close/opus-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..297fa0236830c19a6cca69968e2ecef3f08fd7a8 --- /dev/null +++ b/policies/drawer_top_close/opus-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,592,success,0 +620001,1,584,success,0 +620002,1,588,success,0 +620003,1,585,success,0 +620004,1,593,success,0 +620005,1,591,success,0 +620006,1,579,success,0 +620007,1,586,success,0 +620008,1,587,success,0 +620009,1,586,success,0 +620010,1,593,success,0 +620011,1,587,success,0 +620012,1,584,success,0 +620013,1,592,success,0 +620014,1,590,success,0 +620015,1,593,success,0 +620016,1,593,success,0 +620017,1,594,success,0 +620018,1,589,success,0 +620019,1,589,success,0 +620020,1,591,success,0 +620021,1,590,success,0 +620022,1,595,success,0 +620023,1,590,success,0 +620024,1,588,success,0 +620025,1,589,success,0 +620026,1,587,success,0 +620027,1,583,success,0 +620028,1,591,success,0 +620029,1,593,success,0 +620030,1,589,success,0 +620031,1,589,success,0 +620032,1,584,success,0 +620033,1,586,success,0 +620034,1,590,success,0 +620035,1,585,success,0 +620036,1,585,success,0 +620037,1,590,success,0 +620038,1,583,success,0 +620039,1,589,success,0 +620040,1,583,success,0 +620041,1,587,success,0 +620042,1,593,success,0 +620043,1,586,success,0 +620044,1,586,success,0 +620045,1,596,success,0 +620046,1,595,success,0 +620047,1,592,success,0 +620048,1,590,success,0 +620049,1,587,success,0 +620050,1,588,success,0 +620051,1,589,success,0 +620052,1,587,success,0 +620053,1,587,success,0 +620054,1,589,success,0 +620055,1,581,success,0 +620056,1,584,success,0 +620057,1,591,success,0 +620058,1,588,success,0 +620059,1,585,success,0 +620060,1,591,success,0 +620061,1,583,success,0 +620062,1,591,success,0 +620063,1,586,success,0 +620064,1,585,success,0 +620065,1,581,success,0 +620066,1,590,success,0 +620067,1,581,success,0 +620068,1,590,success,0 +620069,1,586,success,0 +620070,1,581,success,0 +620071,1,585,success,0 +620072,1,592,success,0 +620073,1,590,success,0 +620074,1,584,success,0 +620075,1,586,success,0 +620076,1,583,success,0 +620077,1,587,success,0 +620078,1,584,success,0 +620079,1,591,success,0 +620080,1,588,success,0 +620081,1,585,success,0 +620082,1,593,success,0 +620083,1,590,success,0 +620084,1,595,success,0 +620085,1,584,success,0 +620086,1,588,success,0 +620087,1,585,success,0 +620088,1,586,success,0 +620089,1,588,success,0 +620090,1,587,success,0 +620091,1,589,success,0 +620092,1,590,success,0 +620093,1,579,success,0 +620094,1,592,success,0 +620095,1,589,success,0 +620096,1,591,success,0 +620097,1,590,success,0 +620098,1,589,success,0 +620099,1,582,success,0 diff --git a/policies/drawer_top_close/opus-s2/policy.py b/policies/drawer_top_close/opus-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..c65577e34b0612dc8a46f6e3df953d4c5b6ee982 --- /dev/null +++ b/policies/drawer_top_close/opus-s2/policy.py @@ -0,0 +1,102 @@ +"""Close the open top drawer: lift the hands out of the drawer, back away, lower +the hands in front of the drawer front and walk forward pushing it shut. + +Hand-written phase machine; the base is closed-loop on the pelvis pose read from +low_dim_obs (heading and lateral offset held relative to the start pose). +""" + +import numpy as np + +# Arm joint targets: shoulder_pitch, shoulder_roll, shoulder_yaw, elbow, +# wrist_roll, wrist_pitch, wrist_yaw. Elbow 0 = forearm at right angle, +# positive elbow extends the arm. +LIFT_L = np.array([-1.2, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0]) +LIFT_R = np.array([-1.2, -0.2, 0.0, 0.0, 0.0, 0.0, 0.0]) +PUSH_P, PUSH_E, PUSH_WP = -0.3, 0.36, 0.0 +PUSH_L = np.array([PUSH_P, 0.1, 0.0, PUSH_E, 0.0, PUSH_WP, 0.0]) +PUSH_R = np.array([PUSH_P, -0.1, 0.0, PUSH_E, 0.0, PUSH_WP, 0.0]) + +LIFT_STEPS = 40 +BACK_DIST = 0.45 # m to back away along the start heading +BACK_SPEED = 0.2 +SETTLE_STEPS = 30 +LOWER_STEPS = 40 +PUSH_SPEED = 0.15 +SLOW_SPEED = 0.08 + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + def reset(self, obs, tools): + o = np.asarray(obs["low_dim_obs"], dtype=np.float64) + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.x0, self.y0, self.yaw0 = o[18], o[19], o[21] + self.c, self.s = np.cos(self.yaw0), np.sin(self.yaw0) + self.arm0 = np.concatenate([o[0:7], o[9:16]]) + self.phase = "lift" + self.k = 0 + self.hist = [] + + def local(self, o): + """Pelvis position in the start frame (forward, left) and yaw error.""" + dx, dy = o[18] - self.x0, o[19] - self.y0 + f = self.c * dx + self.s * dy + l = -self.s * dx + self.c * dy + return f, l, wrap(o[21] - self.yaw0) + + def base_cmd(self, vx, l, dyaw): + """Body-frame command holding lateral offset 0 and the start heading.""" + vy_w = float(np.clip(-1.5 * l, -0.15, 0.15)) + wz = float(np.clip(-2.0 * dyaw, -0.4, 0.4)) + # heading error stays small, so start-frame lateral ~ body-frame lateral + return vx, vy_w, wz + + def act(self, obs, tools): + o = np.asarray(obs["low_dim_obs"], dtype=np.float64) + f, l, dyaw = self.local(o) + raw = self.hold.copy() + vx = 0.0 + self.k += 1 + arms = None + + if self.phase == "lift": + a = min(1.0, self.k / LIFT_STEPS) + arms = (1 - a) * self.arm0 + a * np.concatenate([LIFT_L, LIFT_R]) + if self.k >= LIFT_STEPS: + self.phase, self.k = "back", 0 + elif self.phase == "back": + arms = np.concatenate([LIFT_L, LIFT_R]) + vx = -BACK_SPEED + if f <= -BACK_DIST: + self.phase, self.k = "settle", 0 + elif self.phase == "settle": + arms = np.concatenate([LIFT_L, LIFT_R]) + if self.k >= SETTLE_STEPS: + self.phase, self.k = "lower", 0 + elif self.phase == "lower": + a = min(1.0, self.k / LOWER_STEPS) + arms = (1 - a) * np.concatenate([LIFT_L, LIFT_R]) + a * np.concatenate([PUSH_L, PUSH_R]) + if self.k >= LOWER_STEPS: + self.phase, self.k = "push", 0 + else: # push + arms = np.concatenate([PUSH_L, PUSH_R]) + self.hist.append(f) + vx = PUSH_SPEED + if len(self.hist) > 40 and self.hist[-1] - self.hist[-40] < 0.01: + vx = SLOW_SPEED + + if vx != 0.0: + vx, vy, wz = self.base_cmd(vx, l, dyaw) + if np.hypot(vx, vy) < 0.06: + vy = 0.0 + else: + vy, wz = 0.0, 0.0 + raw[0], raw[1], raw[3] = vx, vy, wz + raw[2] = 0.74 + raw[4:18] = arms + return raw diff --git a/policies/drawer_top_close/opus-s3/episodes.csv b/policies/drawer_top_close/opus-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..80760de6e7caa3f5def0799108a340fe26ae4984 --- /dev/null +++ b/policies/drawer_top_close/opus-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,375,success,0 +620001,1,371,success,0 +620002,1,377,success,0 +620003,1,375,success,0 +620004,1,380,success,0 +620005,1,380,success,0 +620006,1,369,success,0 +620007,1,374,success,0 +620008,1,380,success,0 +620009,1,375,success,0 +620010,1,374,success,0 +620011,1,374,success,0 +620012,1,370,success,0 +620013,1,381,success,0 +620014,1,374,success,0 +620015,1,379,success,0 +620016,1,380,success,0 +620017,1,381,success,0 +620018,1,376,success,0 +620019,1,375,success,0 +620020,1,376,success,0 +620021,1,379,success,0 +620022,1,382,success,0 +620023,1,378,success,0 +620024,1,377,success,0 +620025,1,379,success,0 +620026,1,373,success,0 +620027,1,371,success,0 +620028,1,378,success,0 +620029,1,374,success,0 +620030,1,374,success,0 +620031,1,381,success,0 +620032,1,372,success,0 +620033,1,373,success,0 +620034,1,378,success,0 +620035,1,377,success,0 +620036,1,370,success,0 +620037,1,377,success,0 +620038,1,375,success,0 +620039,1,376,success,0 +620040,1,377,success,0 +620041,1,372,success,0 +620042,1,375,success,0 +620043,1,373,success,0 +620044,1,375,success,0 +620045,1,378,success,0 +620046,1,379,success,0 +620047,1,374,success,0 +620048,1,376,success,0 +620049,1,375,success,0 +620050,1,378,success,0 +620051,1,375,success,0 +620052,1,375,success,0 +620053,1,371,success,0 +620054,1,376,success,0 +620055,1,375,success,0 +620056,1,374,success,0 +620057,1,379,success,0 +620058,1,376,success,0 +620059,1,373,success,0 +620060,1,380,success,0 +620061,1,372,success,0 +620062,1,373,success,0 +620063,1,372,success,0 +620064,1,373,success,0 +620065,1,377,success,0 +620066,1,388,success,0 +620067,1,367,success,0 +620068,1,376,success,0 +620069,1,374,success,0 +620070,1,371,success,0 +620071,1,372,success,0 +620072,1,380,success,0 +620073,1,377,success,0 +620074,1,372,success,0 +620075,1,374,success,0 +620076,1,371,success,0 +620077,1,375,success,0 +620078,1,374,success,0 +620079,1,380,success,0 +620080,1,377,success,0 +620081,1,373,success,0 +620082,1,377,success,0 +620083,1,373,success,0 +620084,1,380,success,0 +620085,1,386,success,0 +620086,1,378,success,0 +620087,1,372,success,0 +620088,1,373,success,0 +620089,1,375,success,0 +620090,1,372,success,0 +620091,1,377,success,0 +620092,1,377,success,0 +620093,1,367,success,0 +620094,1,376,success,0 +620095,1,379,success,0 +620096,1,379,success,0 +620097,1,373,success,0 +620098,1,376,success,0 +620099,1,373,success,0 diff --git a/policies/drawer_top_close/opus-s3/policy.py b/policies/drawer_top_close/opus-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..9e166ae809f9f20825966d0f69d32fab2b991e1b --- /dev/null +++ b/policies/drawer_top_close/opus-s3/policy.py @@ -0,0 +1,83 @@ +"""Close the open top drawer of the kitchen cabinet. + +Strategy (from the demonstration): lift the hands out of the open drawer, step +back, bring the hands down in front of the drawer face, then walk forward and +push the drawer shut with both hands. Base motion is closed-loop on the pelvis +pose from low_dim_obs, expressed in the frame of the starting pose. +""" + +import numpy as np + +LIFT_L = [-1.0, 0.15, 0.0, 0.3, 0.0, 0.0, 0.0] +PUSH_L = [-0.75, 0.15, 0.0, 1.0, 0.0, 0.0, 0.0] + + +def mirror(arm): + """Right-arm targets from left-arm targets (roll and yaw joints flip sign).""" + a = list(arm) + for i in (1, 2, 4, 6): + a[i] = -a[i] + return a + + +def wrap(a): + return (a + np.pi) % (2 * np.pi) - np.pi + + +class Policy: + BACK_DIST = 0.30 # how far to step back before pushing, m + PUSH_SPEED = 0.2 + MAX_FWD = 0.35 # never walk further than this past the start, m + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + o = obs["low_dim_obs"] + self.x0, self.y0, self.yaw0 = float(o[18]), float(o[19]), float(o[21]) + self.phase = "lift" + self.k = 0 + self.stall = 0 + + def local(self, o): + dx, dy = float(o[18]) - self.x0, float(o[19]) - self.y0 + c, s = np.cos(self.yaw0), np.sin(self.yaw0) + return c * dx + s * dy, -s * dx + c * dy, wrap(float(o[21]) - self.yaw0) + + def act(self, obs, tools): + o = obs["low_dim_obs"] + fx, fy, dyaw = self.local(o) + raw = self.hold.copy() + raw[2] = 0.74 + self.k += 1 + vx = vy = 0.0 + arms_l = LIFT_L + + if self.phase == "lift": + if self.k >= 40: + self.phase, self.k = "back", 0 + elif self.phase == "back": + vx = -0.25 + if fx <= -self.BACK_DIST: + self.phase, self.k = "lower", 0 + elif self.phase == "lower": + arms_l = PUSH_L + if self.k >= 40: + self.phase, self.k = "push", 0 + elif self.phase == "push": + arms_l = PUSH_L + vx = self.PUSH_SPEED + vy = float(np.clip(-1.0 * fy, -0.1, 0.1)) + fwd_speed = float(o[22 + 18]) * np.cos(self.yaw0) + float(o[22 + 19]) * np.sin(self.yaw0) + if self.k > 50 and fwd_speed < 0.03: + self.stall += 1 + else: + self.stall = 0 + if fx >= self.MAX_FWD or self.stall > 25: + self.phase, self.k = "hold", 0 + else: + arms_l = PUSH_L + + wz = float(np.clip(-1.5 * dyaw, -0.3, 0.3)) if vx != 0.0 else 0.0 + raw[0], raw[1], raw[3] = vx, vy, wz + raw[4:11] = arms_l + raw[11:18] = mirror(arms_l) + return raw diff --git a/policies/drawer_top_open/astra-s1/episodes.csv b/policies/drawer_top_open/astra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..1659e5e06de9d08ce337c3e540a7b4b233dbdbd4 --- /dev/null +++ b/policies/drawer_top_open/astra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,694,success,0 +620001,1,693,success,0 +620002,1,700,success,0 +620003,1,694,success,0 +620004,1,698,success,0 +620005,1,693,success,0 +620006,1,693,success,0 +620007,1,693,success,0 +620008,1,693,success,0 +620009,1,693,success,0 +620010,1,693,success,0 +620011,1,699,success,0 +620012,1,693,success,0 +620013,1,693,success,0 +620014,1,693,success,0 +620015,1,694,success,0 +620016,1,700,success,0 +620017,1,694,success,0 +620018,1,696,success,0 +620019,1,694,success,0 +620020,1,692,success,0 +620021,1,696,success,0 +620022,1,693,success,0 +620023,1,696,success,0 +620024,1,698,success,0 +620025,1,694,success,0 +620026,1,694,success,0 +620027,1,693,success,0 +620028,1,692,success,0 +620029,1,693,success,0 +620030,1,693,success,0 +620031,1,700,success,0 +620032,1,693,success,0 +620033,1,699,success,0 +620034,1,693,success,0 +620035,1,693,success,0 +620036,1,693,success,0 +620037,1,698,success,0 +620038,1,692,success,0 +620039,1,693,success,0 +620040,1,692,success,0 +620041,1,693,success,0 +620042,1,698,success,0 +620043,1,694,success,0 +620044,1,693,success,0 +620045,1,694,success,0 +620046,1,698,success,0 +620047,1,693,success,0 +620048,1,698,success,0 +620049,1,698,success,0 +620050,1,698,success,0 +620051,1,693,success,0 +620052,1,694,success,0 +620053,1,699,success,0 +620054,1,693,success,0 +620055,1,695,success,0 +620056,1,693,success,0 +620057,1,699,success,0 +620058,1,695,success,0 +620059,1,695,success,0 +620060,1,694,success,0 +620061,1,698,success,0 +620062,1,694,success,0 +620063,1,693,success,0 +620064,1,697,success,0 +620065,1,693,success,0 +620066,1,693,success,0 +620067,1,693,success,0 +620068,1,1276,success,0 +620069,1,699,success,0 +620070,1,693,success,0 +620071,1,695,success,0 +620072,1,693,success,0 +620073,1,692,success,0 +620074,1,694,success,0 +620075,1,694,success,0 +620076,1,698,success,0 +620077,1,693,success,0 +620078,1,696,success,0 +620079,1,693,success,0 +620080,1,694,success,0 +620081,1,693,success,0 +620082,1,698,success,0 +620083,1,697,success,0 +620084,1,694,success,0 +620085,1,698,success,0 +620086,1,697,success,0 +620087,1,693,success,0 +620088,1,694,success,0 +620089,1,693,success,0 +620090,1,696,success,0 +620091,1,694,success,0 +620092,1,694,success,0 +620093,1,699,success,0 +620094,1,698,success,0 +620095,1,693,success,0 +620096,1,693,success,0 +620097,1,694,success,0 +620098,1,693,success,0 +620099,1,693,success,0 diff --git a/policies/drawer_top_open/astra-s1/policy.py b/policies/drawer_top_open/astra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..3f38bbfe1520a703f70914a5df9254468f811828 --- /dev/null +++ b/policies/drawer_top_open/astra-s1/policy.py @@ -0,0 +1,77 @@ +"""Deterministic visual alignment and grasp/pull control for the top drawer.""" + +import cv2 +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action()).copy() + # Turn the left gripper across the handle; tuck the unused arm away. + self.a[4:11] = [.30, 0, -.40, 0, 1.57, -.3, 0] + self.a[11:18] = [.6, 0, 0, .5, 0, 0, 0] + self.a[18] = 0 + self.detected = None + + def detect(self, im): + """Locate the dark handle in the rotated left wrist image.""" + gray = cv2.cvtColor(im, cv2.COLOR_RGB2GRAY) + neutral = np.max(im, axis=2).astype(int) - np.min(im, axis=2) < 20 + mask = ((gray > 45) & (gray < 135) & neutral).astype('uint8') + count, labels, stats, centers = cv2.connectedComponentsWithStats(mask) + candidates = [ + i for i in range(1, count) + if stats[i, 4] > 80 and stats[i, 3] > 25 + and stats[i, 2] > 3 and 15 < centers[i, 0] < 72 + ] + if not candidates: + return None + handle = max(candidates, key=lambda i: stats[i, 4]) + rows = np.indices(labels.shape)[0] + _, xs = np.where((labels == handle) & (rows >= 28) & (rows <= 52)) + return float(np.median(xs)) if len(xs) > 20 else float(centers[handle, 0]) + + def act(self, obs, tools): + t = obs['t'] + pelvis = obs['low_dim_obs'][18:22] + + # Successful episodes end automatically. A surviving episode gets a + # second approach, with enough time left to grasp and pull again. + retry = t >= 740 + if t == 740: + self.a[4] = .30 + if retry: + t = t - 740 + 160 + + # Align after the walking transient has settled. With the wrist rolled, + # the handle's horizontal image error corresponds to hand height. + if 340 <= t < 450 and t % 5 == 0: + x = self.detect(tools.image('left_wrist')) + self.detected = x + if x is not None: + self.a[4] += np.clip((x - 41.5) * .0005, -.008, .008) + + action = self.a.copy() + target_x = .43 if t < 570 else -.22 + delta = np.array([target_x - pelvis[0], -pelvis[1]]) + velocity = delta * 2 + if np.linalg.norm(velocity) < .06: + velocity = ( + velocity / max(np.linalg.norm(velocity), 1e-6) * .06 + if np.linalg.norm(delta) > .008 else velocity * 0 + ) + speed = (.3 if retry else .13) if t < 570 else .4 + velocity = np.clip(velocity, -speed, speed) + yaw = pelvis[3] + action[0] = velocity[0] * np.cos(yaw) + velocity[1] * np.sin(yaw) + action[1] = -velocity[0] * np.sin(yaw) + velocity[1] * np.cos(yaw) + action[3] = np.clip(-yaw * 2, -.3, .3) + + # Settle, close, briefly advance to seat the grip, then pull backward. + if 320 <= t < 570: + action[:2] = 0 + if 490 <= t < 540: + action[0] = .13 + if t >= 450: + action[18] = 1 + return action diff --git a/policies/drawer_top_open/astra-s2/episodes.csv b/policies/drawer_top_open/astra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..e9e5b84a257e25971d4986793b910edab2613f48 --- /dev/null +++ b/policies/drawer_top_open/astra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,662,success,0 +620001,1,667,success,0 +620002,1,665,success,0 +620003,1,667,success,0 +620004,1,662,success,0 +620005,1,666,success,0 +620006,1,666,success,0 +620007,1,667,success,0 +620008,1,665,success,0 +620009,1,666,success,0 +620010,1,666,success,0 +620011,1,667,success,0 +620012,1,666,success,0 +620013,1,663,success,0 +620014,1,661,success,0 +620015,1,666,success,0 +620016,1,661,success,0 +620017,1,665,success,0 +620018,1,666,success,0 +620019,1,666,success,0 +620020,1,666,success,0 +620021,1,657,success,0 +620022,1,666,success,0 +620023,1,667,success,0 +620024,1,660,success,0 +620025,1,663,success,0 +620026,1,667,success,0 +620027,1,666,success,0 +620028,1,666,success,0 +620029,1,667,success,0 +620030,1,662,success,0 +620031,1,666,success,0 +620032,1,663,success,0 +620033,1,665,success,0 +620034,1,667,success,0 +620035,1,665,success,0 +620036,1,667,success,0 +620037,1,664,success,0 +620038,1,667,success,0 +620039,1,665,success,0 +620040,1,667,success,0 +620041,1,666,success,0 +620042,1,666,success,0 +620043,1,666,success,0 +620044,1,666,success,0 +620045,1,667,success,0 +620046,1,654,success,0 +620047,1,667,success,0 +620048,1,667,success,0 +620049,1,667,success,0 +620050,1,666,success,0 +620051,1,666,success,0 +620052,1,667,success,0 +620053,1,667,success,0 +620054,1,660,success,0 +620055,1,665,success,0 +620056,1,660,success,0 +620057,0,1350,timeout,0 +620058,1,663,success,0 +620059,1,664,success,0 +620060,1,662,success,0 +620061,1,666,success,0 +620062,1,662,success,0 +620063,1,665,success,0 +620064,1,668,success,0 +620065,1,667,success,0 +620066,1,666,success,0 +620067,1,667,success,0 +620068,1,666,success,0 +620069,1,666,success,0 +620070,1,666,success,0 +620071,0,1350,timeout,0 +620072,1,665,success,0 +620073,1,665,success,0 +620074,1,665,success,0 +620075,1,665,success,0 +620076,1,667,success,0 +620077,1,666,success,0 +620078,1,666,success,0 +620079,1,666,success,0 +620080,1,656,success,0 +620081,1,667,success,0 +620082,1,666,success,0 +620083,1,666,success,0 +620084,1,660,success,0 +620085,1,666,success,0 +620086,1,660,success,0 +620087,1,663,success,0 +620088,1,664,success,0 +620089,1,665,success,0 +620090,1,667,success,0 +620091,1,667,success,0 +620092,1,666,success,0 +620093,0,1350,timeout,0 +620094,1,665,success,0 +620095,1,666,success,0 +620096,1,667,success,0 +620097,1,667,success,0 +620098,1,665,success,0 +620099,1,668,success,0 diff --git a/policies/drawer_top_open/astra-s2/policy.py b/policies/drawer_top_open/astra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..2b345f88fc9af3ed1029b964bea828c6eb03b387 --- /dev/null +++ b/policies/drawer_top_open/astra-s2/policy.py @@ -0,0 +1,32 @@ +"""Hand-written, deterministic controller for opening the top drawer.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=float) + + def act(self, obs, tools): + t = obs["t"] + body = obs["low_dim_obs"] + action = self.hold.copy() + + # Extend the left hand with vertical finger closure around the handle. + # Fold the unused right arm away from the cabinet. + action[4:11] = [-0.115, 0, 0, 0.3, 1.57, 0, -0.195] + action[11:18] = [0.3, 0, 0, 1, 0, 0, 0] + action[18] = 0 if t < 350 else 1 + + # Align, approach, allow the grasp to settle, then pull backward. + target_x = 0.08 if t < 180 else (0.24 if t < 440 else -0.18) + error = np.array([target_x, -0.15]) - body[18:20] + velocity = np.clip(2 * error, -0.15, 0.15) + velocity = np.where( + (abs(velocity) < 0.06) & (abs(error) > 0.015), + np.sign(velocity) * 0.06, + velocity, + ) + action[:2] = np.where(abs(error) < 0.015, 0, velocity) + action[3] = np.clip(-3 * body[21], -0.4, 0.4) + return action diff --git a/policies/drawer_top_open/astra-s3/episodes.csv b/policies/drawer_top_open/astra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..db5967315cd90869003a9ada2fef5d1388692a9c --- /dev/null +++ b/policies/drawer_top_open/astra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,789,success,0 +620001,1,786,success,0 +620002,1,788,success,0 +620003,1,788,success,0 +620004,1,788,success,0 +620005,1,788,success,0 +620006,1,788,success,0 +620007,1,787,success,0 +620008,1,787,success,0 +620009,1,791,success,0 +620010,1,788,success,0 +620011,1,788,success,0 +620012,1,787,success,0 +620013,1,787,success,0 +620014,1,788,success,0 +620015,1,788,success,0 +620016,1,787,success,0 +620017,1,789,success,0 +620018,1,787,success,0 +620019,1,789,success,0 +620020,1,788,success,0 +620021,1,789,success,0 +620022,1,789,success,0 +620023,1,788,success,0 +620024,1,786,success,0 +620025,1,788,success,0 +620026,1,789,success,0 +620027,1,791,success,0 +620028,1,788,success,0 +620029,1,788,success,0 +620030,1,789,success,0 +620031,1,788,success,0 +620032,1,788,success,0 +620033,1,789,success,0 +620034,1,788,success,0 +620035,1,786,success,0 +620036,1,787,success,0 +620037,1,789,success,0 +620038,1,789,success,0 +620039,1,788,success,0 +620040,1,788,success,0 +620041,1,789,success,0 +620042,1,788,success,0 +620043,1,786,success,0 +620044,1,788,success,0 +620045,1,788,success,0 +620046,1,788,success,0 +620047,1,801,success,0 +620048,1,787,success,0 +620049,1,789,success,0 +620050,1,787,success,0 +620051,1,788,success,0 +620052,1,788,success,0 +620053,1,787,success,0 +620054,1,788,success,0 +620055,1,788,success,0 +620056,1,789,success,0 +620057,1,790,success,0 +620058,1,789,success,0 +620059,1,790,success,0 +620060,1,789,success,0 +620061,1,792,success,0 +620062,1,791,success,0 +620063,1,789,success,0 +620064,1,788,success,0 +620065,1,789,success,0 +620066,1,792,success,0 +620067,1,789,success,0 +620068,1,790,success,0 +620069,1,788,success,0 +620070,1,786,success,0 +620071,1,788,success,0 +620072,1,789,success,0 +620073,1,788,success,0 +620074,1,789,success,0 +620075,1,792,success,0 +620076,1,788,success,0 +620077,1,786,success,0 +620078,1,787,success,0 +620079,1,788,success,0 +620080,1,788,success,0 +620081,1,789,success,0 +620082,1,790,success,0 +620083,1,787,success,0 +620084,1,787,success,0 +620085,1,785,success,0 +620086,1,786,success,0 +620087,1,788,success,0 +620088,1,787,success,0 +620089,1,787,success,0 +620090,1,788,success,0 +620091,1,788,success,0 +620092,1,790,success,0 +620093,1,783,success,0 +620094,1,790,success,0 +620095,1,788,success,0 +620096,1,787,success,0 +620097,1,788,success,0 +620098,1,788,success,0 +620099,1,788,success,0 diff --git a/policies/drawer_top_open/astra-s3/policy.py b/policies/drawer_top_open/astra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..344a6b33525bf5570ce685c80d88143f1580906f --- /dev/null +++ b/policies/drawer_top_open/astra-s3/policy.py @@ -0,0 +1,34 @@ +"""Hand-written, deterministic controller for opening the upper drawer.""" +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = obs['t'] + pos = obs['low_dim_obs'][18:22] + action = self.hold.copy() + action[:2] = 0 + action[2] = .74 + action[3] = np.clip(-3 * pos[3], -.4, .4) + + # Reach beneath the countertop, with the fingers straddling the handle. + action[4:11] = [.4, 0, 0, 0, 1.57, 0, .3] + action[11:18] = [-.7, 0, 0, 0, 0, 0, 0] + action[18] = 0 if t < 270 else 1 + action[19] = 0 + + if t < 310: + # Close the loop on the measured base pose, including during grasp. + error = np.array([.36, -.16]) - pos[:2] + for j in range(2): + if abs(error[j]) > .01: + action[j] = np.sign(error[j]) * max( + .065, min(.15, abs(error[j]) * 2) + ) + elif 330 <= t < 1100: + # A slow pull maintains the pinch while the drawer slides outward. + action[0] = -.08 + return action diff --git a/policies/drawer_top_open/deepseek1017-s1/episodes.csv b/policies/drawer_top_open/deepseek1017-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a737af06b8968364118a1ffbccd1f204304c6485 --- /dev/null +++ b/policies/drawer_top_open/deepseek1017-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,0,1350,timeout,0 +620002,0,1350,timeout,0 +620003,0,1350,timeout,0 +620004,0,1350,timeout,0 +620005,0,1350,timeout,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,0,1350,timeout,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,0,1350,timeout,0 +620014,0,1350,timeout,0 +620015,0,1350,timeout,0 +620016,0,1350,timeout,0 +620017,0,1350,timeout,0 +620018,0,1350,timeout,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,0,1350,timeout,0 +620022,0,1350,timeout,0 +620023,0,1350,timeout,0 +620024,0,1350,timeout,0 +620025,0,1350,timeout,0 +620026,0,1350,timeout,0 +620027,0,1350,timeout,0 +620028,0,1350,timeout,0 +620029,0,1350,timeout,0 +620030,0,1350,timeout,0 +620031,0,1350,timeout,0 +620032,0,1350,timeout,0 +620033,0,1350,timeout,0 +620034,0,1350,timeout,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,0,1350,timeout,0 +620038,0,1350,timeout,0 +620039,0,1350,timeout,0 +620040,0,1350,timeout,0 +620041,0,1350,timeout,0 +620042,0,1350,timeout,0 +620043,0,1350,timeout,0 +620044,0,1350,timeout,0 +620045,0,1350,timeout,0 +620046,0,1350,timeout,0 +620047,0,1350,timeout,0 +620048,0,1350,timeout,0 +620049,0,1350,timeout,0 +620050,0,1350,timeout,0 +620051,0,1350,timeout,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,0,1350,timeout,0 +620055,0,1350,timeout,0 +620056,0,1350,timeout,0 +620057,0,1350,timeout,0 +620058,0,1350,timeout,0 +620059,0,1350,timeout,0 +620060,0,1350,timeout,0 +620061,0,1350,timeout,0 +620062,0,1350,timeout,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,0,1350,timeout,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,0,1350,timeout,0 +620070,0,1350,timeout,0 +620071,0,1350,timeout,0 +620072,0,1350,timeout,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,0,1350,timeout,0 +620076,0,1350,timeout,0 +620077,0,1350,timeout,0 +620078,0,1350,timeout,0 +620079,0,1350,timeout,0 +620080,0,1350,timeout,0 +620081,0,1350,timeout,0 +620082,0,1350,timeout,0 +620083,0,1350,timeout,0 +620084,0,1350,timeout,0 +620085,0,1350,timeout,0 +620086,0,1350,timeout,0 +620087,0,1350,timeout,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,0,1350,timeout,0 +620091,0,1350,timeout,0 +620092,0,1350,timeout,0 +620093,0,1350,timeout,0 +620094,0,1350,timeout,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,0,1350,timeout,0 +620098,0,1350,timeout,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/deepseek1017-s1/policy.py b/policies/drawer_top_open/deepseek1017-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..0ef97430d90fc13168b156f8250cc15e3efb6df8 --- /dev/null +++ b/policies/drawer_top_open/deepseek1017-s1/policy.py @@ -0,0 +1,174 @@ +"""Policy for the task: open the top drawer of the kitchen cabinet. + +Hand-written, deterministic state machine driven only by the robot's +proprioceptive pelvis pose. The robot moves to a stance in front of the +cabinet and then runs a fixed sweep of right-arm reach poses -- mainly a +shoulder-roll reach that places the gripper at the drawer handle -- closing +the gripper and pulling with the arm, the body or by stepping back at each +one. A final hold lets an opened drawer satisfy the one-second task +condition. There is no randomness and no wall-clock dependence. +""" + +import numpy as np + + +# right-arm reach poses: [shoulder_pitch, shoulder_roll, shoulder_yaw, elbow, +# wrist_roll, wrist_pitch, wrist_yaw] +# The roll-dominant poses put the hand on the drawer handle (the right arm +# swings inwards across the body at roughly hip height). +R0 = [-0.55, -0.69, 0.00, 0.41, 0.00, 0.00, 0.0] +R1 = [-0.40, -0.55, 0.00, 0.30, 0.00, -0.30, 0.0] +R2 = [-0.70, -0.90, 0.00, 0.55, 0.00, -0.30, 0.0] +R3 = [-0.30, -0.40, 0.00, 0.70, 0.00, -0.60, 0.0] +R4 = [-0.55, -0.69, 0.00, 0.41, 0.00, -0.60, 0.0] +R5 = [-0.60, -1.10, 0.00, 0.30, 0.00, 0.00, 0.0] +R6 = [-0.45, -0.80, 0.00, 0.80, 0.00, -0.40, 0.0] +R7 = [-0.90, -0.90, 0.00, 0.40, 0.00, 0.00, 0.0] +R8 = [-1.20, -0.50, 0.00, 0.50, 0.00, 0.00, 0.0] +R9 = [-0.20, -0.80, 0.00, 0.50, 0.00, -0.80, 0.0] + +RETRACT = [0.00, 0.00, 0.00, 0.15, 0.00, -0.10, 0.0] +# mirrored reach for the left arm (two-handed attempts) +L_REACH = [-0.35, 0.00, 0.70, 0.55, 0.00, -0.40, 0.0] + +# (base x target, squat height, right pose, left pose or None, pull mode) +ATTEMPTS = [ + (0.06, 0.74, R0, None, "back"), + (0.10, 0.74, R0, None, "arm"), + (0.16, 0.74, R0, None, "back"), + (0.10, 0.66, R1, None, "squat"), + (0.16, 0.74, R1, None, "arm"), + (0.10, 0.74, R2, None, "back"), + (0.16, 0.66, R3, None, "squat"), + (0.16, 0.74, R4, None, "back"), + (0.10, 0.74, R5, None, "arm"), + (0.16, 0.74, R6, None, "back"), + (0.20, 0.74, R7, None, "back"), + (0.10, 0.66, R8, None, "squat"), + (0.14, 0.74, R0, L_REACH, "both"), + (0.12, 0.74, R0, None, "hold"), +] + + +class Policy: + """Deterministic reach-and-pull sweep for the top drawer.""" + + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.phase = "open" + self.phase_t = 0 + self.attempt = 0 + + # ------------------------------------------------------------------ + def _goto_cmd(self, obs, tx): + """Velocity command that drives the pelvis toward (tx, 0, 0).""" + ld = np.asarray(obs["low_dim_obs"]) + x, y, yaw = float(ld[18]), float(ld[19]), float(ld[21]) + ex, ey = tx - x, 0.0 - y + eyaw = (0.0 - yaw + np.pi) % (2.0 * np.pi) - np.pi + c, s = np.cos(yaw), np.sin(yaw) + vx = c * (1.2 * ex) + s * (1.2 * ey) + vy = -s * (1.2 * ex) + c * (1.2 * ey) + vx = float(np.clip(vx, -0.30, 0.30)) + vy = float(np.clip(vy, -0.30, 0.30)) + if 0.0 < abs(vx) < 0.06: + vx = 0.06 if vx > 0 else -0.06 + if 0.0 < abs(vy) < 0.06: + vy = 0.06 if vy > 0 else -0.06 + wz = float(np.clip(1.5 * eyaw, -0.4, 0.4)) + ok = abs(ex) < 0.014 and abs(ey) < 0.025 and abs(eyaw) < 0.06 + return vx, vy, wz, ok + + # ------------------------------------------------------------------ + def act(self, obs, tools): + ld = np.asarray(obs["low_dim_obs"]) + x = float(ld[18]) + raw = self.hold.copy() + raw[0:4] = [0.0, 0.0, 0.74, 0.0] + raw[4:11] = [0.0, 0.0, 0.0, 0.05, 0.0, 0.0, 0.0] + raw[11:18] = R0 + raw[18] = 0.0 + raw[19] = 0.0 + + if self.attempt >= len(ATTEMPTS): + # Sweep finished: hold still so an opened drawer satisfies the + # one-second task condition. + raw[0:4] = [0.0, 0.0, 0.74, 0.0] + raw[11:18] = R0 + return raw + + tx, h, pose, lpose, mode = ATTEMPTS[self.attempt] + raw[2] = h + raw[11:18] = pose + if lpose is not None: + raw[4:11] = lpose + + if self.phase == "open": + raw[0:4] = [0.0, 0.0, 0.74, 0.0] + self.phase_t += 1 + if self.phase_t >= 8: + self.phase, self.phase_t = "goto", 0 + return raw + + if self.phase == "goto": + vx, vy, wz, ok = self._goto_cmd(obs, tx) + raw[0] = vx + raw[1] = vy + raw[2] = 0.74 if self.phase_t < 40 else h + raw[3] = wz + raw[11:18] = [0.0, 0.0, 0.0, 0.05, 0.0, 0.0, 0.0] + self.phase_t += 1 + if (ok and self.phase_t >= 8) or self.phase_t > 65: + self.phase, self.phase_t = "arm", 0 + return raw + + if self.phase == "arm": + self.phase_t += 1 + if self.phase_t >= 11: + self.phase, self.phase_t = "close", 0 + return raw + + if self.phase == "close": + raw[18] = 1.0 + raw[19] = 1.0 + self.phase_t += 1 + if self.phase_t >= 8: + self.phase, self.phase_t = "pull", 0 + return raw + + if self.phase == "pull": + self.phase_t += 1 + raw[18] = 1.0 + raw[19] = 1.0 + if mode == "arm": + raw[11:18] = RETRACT + if self.phase_t >= 22: + self.phase, self.phase_t = "release", 0 + elif mode == "both": + raw[11:18] = RETRACT + raw[4:11] = [0.0, 0.0, 0.0, 0.15, 0.0, -0.10, 0.0] + if self.phase_t >= 18: + raw[0] = -0.20 + if self.phase_t >= 36: + self.phase, self.phase_t = "release", 0 + elif mode == "back": + raw[0] = -0.22 + if self.phase_t >= 26 or x < tx - 0.30: + self.phase, self.phase_t = "release", 0 + elif mode == "squat": + raw[2] = 0.56 + if self.phase_t >= 22: + self.phase, self.phase_t = "release", 0 + else: # hold + if self.phase_t >= 40: + self.phase, self.phase_t = "release", 0 + return raw + + # release, then advance to the next attempt + raw[18] = 0.0 + raw[19] = 0.0 + self.phase_t += 1 + if self.phase_t >= 5: + self.attempt += 1 + self.phase, self.phase_t = "goto", 0 + return raw diff --git a/policies/drawer_top_open/deepseek1017-s2/episodes.csv b/policies/drawer_top_open/deepseek1017-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a737af06b8968364118a1ffbccd1f204304c6485 --- /dev/null +++ b/policies/drawer_top_open/deepseek1017-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,0,1350,timeout,0 +620002,0,1350,timeout,0 +620003,0,1350,timeout,0 +620004,0,1350,timeout,0 +620005,0,1350,timeout,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,0,1350,timeout,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,0,1350,timeout,0 +620014,0,1350,timeout,0 +620015,0,1350,timeout,0 +620016,0,1350,timeout,0 +620017,0,1350,timeout,0 +620018,0,1350,timeout,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,0,1350,timeout,0 +620022,0,1350,timeout,0 +620023,0,1350,timeout,0 +620024,0,1350,timeout,0 +620025,0,1350,timeout,0 +620026,0,1350,timeout,0 +620027,0,1350,timeout,0 +620028,0,1350,timeout,0 +620029,0,1350,timeout,0 +620030,0,1350,timeout,0 +620031,0,1350,timeout,0 +620032,0,1350,timeout,0 +620033,0,1350,timeout,0 +620034,0,1350,timeout,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,0,1350,timeout,0 +620038,0,1350,timeout,0 +620039,0,1350,timeout,0 +620040,0,1350,timeout,0 +620041,0,1350,timeout,0 +620042,0,1350,timeout,0 +620043,0,1350,timeout,0 +620044,0,1350,timeout,0 +620045,0,1350,timeout,0 +620046,0,1350,timeout,0 +620047,0,1350,timeout,0 +620048,0,1350,timeout,0 +620049,0,1350,timeout,0 +620050,0,1350,timeout,0 +620051,0,1350,timeout,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,0,1350,timeout,0 +620055,0,1350,timeout,0 +620056,0,1350,timeout,0 +620057,0,1350,timeout,0 +620058,0,1350,timeout,0 +620059,0,1350,timeout,0 +620060,0,1350,timeout,0 +620061,0,1350,timeout,0 +620062,0,1350,timeout,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,0,1350,timeout,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,0,1350,timeout,0 +620070,0,1350,timeout,0 +620071,0,1350,timeout,0 +620072,0,1350,timeout,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,0,1350,timeout,0 +620076,0,1350,timeout,0 +620077,0,1350,timeout,0 +620078,0,1350,timeout,0 +620079,0,1350,timeout,0 +620080,0,1350,timeout,0 +620081,0,1350,timeout,0 +620082,0,1350,timeout,0 +620083,0,1350,timeout,0 +620084,0,1350,timeout,0 +620085,0,1350,timeout,0 +620086,0,1350,timeout,0 +620087,0,1350,timeout,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,0,1350,timeout,0 +620091,0,1350,timeout,0 +620092,0,1350,timeout,0 +620093,0,1350,timeout,0 +620094,0,1350,timeout,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,0,1350,timeout,0 +620098,0,1350,timeout,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/deepseek1017-s2/policy.py b/policies/drawer_top_open/deepseek1017-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..6b8350332642c0e611ca6019b18906db51ac0a4b --- /dev/null +++ b/policies/drawer_top_open/deepseek1017-s2/policy.py @@ -0,0 +1,187 @@ +"""Control policy for opening the top drawer of the kitchen cabinet. + +Hand-written, deterministic controller. The robot first walks to a stand-off +position in front of the cabinet and then tries a small set of reach hypotheses. +Each hypothesis first abducts the arm while it is retracted (so the shoulder +roll can actually move without being blocked by the cabinet), then pushes the +hand forward into the drawer, closes the gripper and pulls the drawer open by +stepping backwards while drawing the arm in. + +The pelvis pose in ``low_dim_obs`` is used for station keeping, walking and for +making the pull direction straight back. No learned components are used. +""" + +import numpy as np + + +# A trial is: +# side, forward reach pose, abduction command, walk distance, yaw offset, +# gripper command for the pull, hook (keep the fingers partly open) +# +# Reach pose order: +# shoulder_pitch, shoulder_roll, shoulder_yaw, elbow, wrist_roll, +# wrist_pitch, wrist_yaw +TRIALS = [ + # left hand, pushed out towards the leftmost top drawer, fingers straddle + ("L", [1.00, 0.70, 0.00, 0.50, 1.57, -1.30, 0.0], 0.70, 0.14, 0.00, 1.0, False), + # left hand, level wrist, open fingers hooked around the handle + ("L", [1.00, 0.70, 0.00, 0.50, 0.00, -1.30, 0.0], 0.70, 0.14, 0.10, 0.15, True), + # left hand, rolled camera via the shoulder yaw + ("L", [1.00, 0.55, 0.60, 0.50, 1.57, -1.30, 0.0], 0.55, 0.10, 0.00, 1.0, False), + # right hand mirrored, fingers straddle the handle + ("R", [1.00, -0.70, 0.00, 0.50, -1.57, -1.30, 0.0], -0.70, 0.14, 0.00, 1.0, False), + # left hand, closer to the cabinet, level wrist + ("L", [1.00, 0.30, 0.00, 0.50, 0.00, -1.30, 0.0], 0.30, 0.20, 0.00, 1.0, False), + # left hand, a little higher + ("L", [1.25, 0.50, 0.00, 0.30, 1.57, -1.40, 0.0], 0.50, 0.10, 0.00, 1.0, False), +] + +# segment durations in control steps +SEG_RETURN = 40 +SEG_ABDUCT = 30 +SEG_PUSH = 30 +SEG_CLOSE = 15 +SEG_PULL = 55 +SEG_SETTLE = 20 +SEGMENTS = (SEG_RETURN, SEG_ABDUCT, SEG_PUSH, SEG_CLOSE, SEG_PULL, SEG_SETTLE) +N_TRIALS = len(TRIALS) + + +def _clip(v, lo, hi): + return float(min(hi, max(lo, v))) + + +class Policy: + """Scripted drawer-opening policy.""" + + def reset(self, obs, tools): + ld = np.asarray(obs["low_dim_obs"], dtype=np.float64) + self.x0 = float(ld[18]) + self.y0 = float(ld[19]) + self.yaw0 = float(ld[21]) + self.trial = 0 + self.seg = 0 + self.seg_t = 0 + self.base = [self.x0, self.y0, self.yaw0] + self.height = 0.72 + self.left = np.zeros(7) + self.right = np.zeros(7) + self.lgrip = 0.20 + self.rgrip = 0.20 + self.hold = np.asarray(tools.hold_action(), dtype=np.float32).copy() + self._start_segment(None) + + # ---------------------------------------------------------------- helpers + def _start_segment(self, ld): + seg = self.seg + side, reach, abduct, walk, yaw_off, pull_grip, hook = TRIALS[self.trial] + r = np.asarray(reach, dtype=np.float64) + if seg == 0: + # return to the trial stand-off position with the arms down + self.base = [self.x0 + walk, self.y0, self.yaw0 + yaw_off] + self.left = np.zeros(7) + self.right = np.zeros(7) + self.lgrip = 0.20 + self.rgrip = 0.20 + self.height = 0.72 + elif seg == 1: + # retracted pose with the requested abduction; the arm is free of + # the cabinet here, so the shoulder roll can track + back = r.copy() + back[0] = 0.45 + back[1] = abduct + back[3] = 0.25 + if side == "L": + self.left = back + else: + self.right = back + self.lgrip = 0.20 + self.rgrip = 0.20 + elif seg == 2: + # push the hand forward into the drawer at the abducted angle + if side == "L": + self.left = r + else: + self.right = r + self.lgrip = 0.25 + self.rgrip = 0.25 + elif seg == 3: + # close the gripper + g = 0.30 if hook else pull_grip + if side == "L": + self.lgrip = g + else: + self.rgrip = g + elif seg == 4: + # pull: draw the hand in and step straight back + pull = r.copy() + pull[0] = max(0.10, pull[0] - 0.40) + pull[3] = min(1.60, pull[3] + 0.35) + if side == "L": + self.left = pull + else: + self.right = pull + if ld is not None: + self.base = [float(ld[18]) - 0.22, float(ld[19]), + float(ld[21])] + elif seg == 5: + # settle and hold + if ld is not None: + self.base = [float(ld[18]), float(ld[19]), float(ld[21])] + + def _advance(self, ld): + self.seg += 1 + self.seg_t = 0 + if self.seg >= len(SEGMENTS): + self.trial += 1 + self.seg = 0 + if self.trial >= N_TRIALS: + self.trial = N_TRIALS - 1 + self.seg = 5 # stay put in a safe holding pose + self._start_segment(ld) + + # ------------------------------------------------------------------- act + def act(self, obs, tools): + ld = np.asarray(obs["low_dim_obs"], dtype=np.float64) + + if bool(obs.get("fell", False)): + # once fallen, just hold a safe pose; the episode is already lost + raw = np.asarray(tools.hold_action(), dtype=np.float32).copy() + raw[0:4] = 0.0 + return raw + + self.seg_t += 1 + if self.seg_t >= SEGMENTS[self.seg]: + self._advance(ld) + + # base station keeping / walking / pulling + bx, by, byaw = self.base + ex = bx - float(ld[18]) + ey = by - float(ld[19]) + eyaw = byaw - float(ld[21]) + eyaw = (eyaw + np.pi) % (2.0 * np.pi) - np.pi + c, s = np.cos(float(ld[21])), np.sin(float(ld[21])) + vx = 1.2 * (c * ex + s * ey) + vy = 1.2 * (-s * ex + c * ey) + wz = 1.5 * eyaw + vx = _clip(vx, -0.45, 0.45) + vy = _clip(vy, -0.30, 0.30) + wz = _clip(wz, -1.0, 1.0) + # the base controller treats speeds below 0.055 m/s as stand still + if 0.0 < abs(vx) < 0.06: + vx = 0.06 if vx > 0 else -0.06 + if 0.0 < abs(vy) < 0.06: + vy = 0.06 if vy > 0 else -0.06 + if 0.0 < abs(wz) < 0.06: + wz = 0.06 if wz > 0 else -0.06 + + a = np.zeros(20, dtype=np.float32) + a[0] = vx + a[1] = vy + a[2] = self.height + a[3] = wz + a[4:11] = self.left + a[11:18] = self.right + a[18] = self.lgrip + a[19] = self.rgrip + return a diff --git a/policies/drawer_top_open/deepseek1017-s3/episodes.csv b/policies/drawer_top_open/deepseek1017-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a737af06b8968364118a1ffbccd1f204304c6485 --- /dev/null +++ b/policies/drawer_top_open/deepseek1017-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,0,1350,timeout,0 +620002,0,1350,timeout,0 +620003,0,1350,timeout,0 +620004,0,1350,timeout,0 +620005,0,1350,timeout,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,0,1350,timeout,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,0,1350,timeout,0 +620014,0,1350,timeout,0 +620015,0,1350,timeout,0 +620016,0,1350,timeout,0 +620017,0,1350,timeout,0 +620018,0,1350,timeout,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,0,1350,timeout,0 +620022,0,1350,timeout,0 +620023,0,1350,timeout,0 +620024,0,1350,timeout,0 +620025,0,1350,timeout,0 +620026,0,1350,timeout,0 +620027,0,1350,timeout,0 +620028,0,1350,timeout,0 +620029,0,1350,timeout,0 +620030,0,1350,timeout,0 +620031,0,1350,timeout,0 +620032,0,1350,timeout,0 +620033,0,1350,timeout,0 +620034,0,1350,timeout,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,0,1350,timeout,0 +620038,0,1350,timeout,0 +620039,0,1350,timeout,0 +620040,0,1350,timeout,0 +620041,0,1350,timeout,0 +620042,0,1350,timeout,0 +620043,0,1350,timeout,0 +620044,0,1350,timeout,0 +620045,0,1350,timeout,0 +620046,0,1350,timeout,0 +620047,0,1350,timeout,0 +620048,0,1350,timeout,0 +620049,0,1350,timeout,0 +620050,0,1350,timeout,0 +620051,0,1350,timeout,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,0,1350,timeout,0 +620055,0,1350,timeout,0 +620056,0,1350,timeout,0 +620057,0,1350,timeout,0 +620058,0,1350,timeout,0 +620059,0,1350,timeout,0 +620060,0,1350,timeout,0 +620061,0,1350,timeout,0 +620062,0,1350,timeout,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,0,1350,timeout,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,0,1350,timeout,0 +620070,0,1350,timeout,0 +620071,0,1350,timeout,0 +620072,0,1350,timeout,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,0,1350,timeout,0 +620076,0,1350,timeout,0 +620077,0,1350,timeout,0 +620078,0,1350,timeout,0 +620079,0,1350,timeout,0 +620080,0,1350,timeout,0 +620081,0,1350,timeout,0 +620082,0,1350,timeout,0 +620083,0,1350,timeout,0 +620084,0,1350,timeout,0 +620085,0,1350,timeout,0 +620086,0,1350,timeout,0 +620087,0,1350,timeout,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,0,1350,timeout,0 +620091,0,1350,timeout,0 +620092,0,1350,timeout,0 +620093,0,1350,timeout,0 +620094,0,1350,timeout,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,0,1350,timeout,0 +620098,0,1350,timeout,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/deepseek1017-s3/policy.py b/policies/drawer_top_open/deepseek1017-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..61a27bbb9e24d7ef3f59b8e7a0f10b3fa63dfd76 --- /dev/null +++ b/policies/drawer_top_open/deepseek1017-s3/policy.py @@ -0,0 +1,197 @@ +"""Control policy for opening the top drawer of the kitchen cabinet. + +The robot starts facing the cabinet. The controller + +1. presses up to the cabinet, +2. raises both arms above the counter top, +3. sweeps the closed grippers upwards across the drawer front so that a + protruding handle bar is hooked from below, then pulls back, +4. performs a systematic search: at many combinations of shoulder pitch, + wrist pitch and shoulder roll the grippers are slowly closed while the + finger joint positions are inspected. If the fingers are blocked the + handle is trapped, and the arm is retracted while the base steps back. + The search is repeated after yawing the base towards the cabinet. +5. finally makes a long, strong two-arm pull and holds it. + +Everything is hand-written control logic using only the robot's body state +and the finger joint positions. There is no learned component and no +randomness, so episodes are reproducible. +""" + +import numpy as np + + +class Policy: + """Scripted search-and-pull policy for the cabinet drawer.""" + + NEUTRAL = [0.02, 0.0, 0.0, 0.03, 0.0, 0.04, 0.0] + CYCLE = 22 + + @staticmethod + def _candidates(): + out = [] + # straight approach, three wrist pitches + for p in (0.90, 0.75, 0.60, 0.45, 0.30): + out.append((-1.20, p, 0.0)) + for p in (0.75, 0.60, 0.45, 0.30): + out.append((-0.70, p, 0.0)) + for p in (0.60, 0.45, 0.30): + out.append((-0.40, p, 0.0)) + # shoulder roll (abduction) to reach across the cabinet centre + for r in (-0.30, 0.30): + for p in (0.60, 0.45, 0.30): + out.append((-0.70, p, r)) + for r in (-0.60, 0.60): + for p in (0.50, 0.35): + out.append((-0.70, p, r)) + return out + + def reset(self, obs, tools): + self.t = 0 + self.hold0 = np.asarray(tools.hold_action(), dtype=np.float32) + self.neutral = np.asarray(self.NEUTRAL, dtype=np.float32) + self.scan = self._candidates() + self.retry = self.scan[-10:] + self.total = len(self.scan) + len(self.retry) + self.si = 0 + self.st = 0 + self.contact = None + self.pull_t = 0 + self.yaw_t = 0 + + # ------------------------------------------------------------------ + def _base_action(self, obs, tools): + ld = np.asarray(obs["low_dim_obs"], dtype=np.float32) + raw = np.asarray(tools.hold_action(), dtype=np.float32) + raw[0] = 0.0 + raw[1] = 0.0 + raw[2] = 0.74 + raw[3] = 0.0 + raw[4:11] = ld[0:7] + raw[11:18] = ld[9:16] + raw[18] = 0.0 + raw[19] = 0.0 + return raw, ld + + @staticmethod + def _set(raw, ql, qr, g): + raw[4:11] = ql + raw[11:18] = qr + raw[18] = g + raw[19] = g + + @staticmethod + def _mirror(p, roll, e, wp): + ql = np.asarray([p, -roll, 0.0, e, 0.0, wp, 0.0], dtype=np.float32) + qr = np.asarray([p, roll, 0.0, e, 0.0, wp, 0.0], dtype=np.float32) + return ql, qr + + # ------------------------------------------------------------------ + def act(self, obs, tools): + raw, ld = self._base_action(obs, tools) + + if bool(obs.get("fell", False)): + raw[0] = 0.0 + raw[1] = 0.0 + raw[2] = 0.74 + raw[3] = 0.0 + raw[18] = 0.0 + raw[19] = 0.0 + self.t += 1 + return raw + + t = self.t + self.t += 1 + q_high = np.asarray([1.00, 0.0, 0.0, 0.30, 0.0, -1.40, 0.0], + dtype=np.float32) + + # ---- 1. press up to the cabinet ------------------------------ + if t < 45: + self._set(raw, self.neutral, self.neutral, 0.0) + raw[0] = 0.12 + return raw + + # ---- 2. raise the arms above the counter, keep pressing ------ + if t < 95: + self._set(raw, q_high, q_high, 0.0) + raw[0] = 0.10 + return raw + + # ---- 3. closed-gripper upward hook sweep --------------------- + if t < 205: + if t < 112: + self._set(raw, q_high, q_high, 0.0) + return raw + if t < 127: + ql, qr = self._mirror(0.28, 0.0, 0.45, -0.45) + self._set(raw, ql, qr, 1.0) + return raw + if t < 187: + f = (t - 127) / 60.0 + p = 0.28 + 0.72 * f + e = 0.45 - 0.30 * f + wp = -0.45 - 0.90 * f + ql, qr = self._mirror(p, 0.0, e, wp) + self._set(raw, ql, qr, 1.0) + raw[0] = 0.02 + return raw + self._set(raw, q_high, q_high, 1.0) + raw[0] = -0.20 + return raw + + # ---- 4. return to the drawer and start the discrete search --- + if t < 235: + ql, qr = self._mirror(0.85, 0.0, 0.30, -0.95) + self._set(raw, ql, qr, 0.0) + raw[0] = 0.10 + return raw + + # ---- 5. discrete close-and-check search ---------------------- + if self.contact is None and self.si < self.total: + if self.si < len(self.scan): + wp, p, roll = self.scan[self.si] + else: + if self.yaw_t < 38: + self._set(raw, q_high, q_high, 0.0) + raw[3] = 0.18 + raw[0] = 0.04 + self.yaw_t += 1 + return raw + wp, p, roll = self.retry[self.si - len(self.scan)] + ql, qr = self._mirror(p, roll, 0.30, wp) + phase = self.st % self.CYCLE + if phase < 9: + self._set(raw, ql, qr, 0.0) + elif phase < 20: + self._set(raw, ql, qr, (phase - 9) / 11.0) + else: + fingers = np.array([ld[7], ld[8], ld[16], ld[17]]) + if float(np.max(fingers)) > -0.016: + self.contact = (wp, p, roll) + self._set(raw, ql, qr, 1.0) + else: + self.si += 1 + self.st = -1 + self._set(raw, ql, qr, 0.0) + self.st += 1 + raw[0] = 0.0 + return raw + + # ---- 6. pull ------------------------------------------------- + if self.contact is not None: + wp, p, roll = self.contact + g = 1.0 + else: + wp, p, roll, g = -0.70, 0.45, 0.0, 1.0 + + if self.pull_t < 25: + ql, qr = self._mirror(p, roll, 0.30, wp) + self._set(raw, ql, qr, g) + else: + f = min(1.0, (self.pull_t - 25) / 90.0) + ql, qr = self._mirror(max(0.05, p - 0.30 * f), roll, + 0.30 + 0.45 * f, wp + 0.35 * f) + self._set(raw, ql, qr, g) + raw[0] = -0.20 if self.pull_t < 215 else 0.0 + self.pull_t += 1 + return raw diff --git a/policies/drawer_top_open/gpt61sol-s1/episodes.csv b/policies/drawer_top_open/gpt61sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..96b51646a5ee3d2370ca17f4c619459a86bbbe9b --- /dev/null +++ b/policies/drawer_top_open/gpt61sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,0,1350,timeout,0 +620002,1,587,success,0 +620003,0,1350,timeout,0 +620004,0,1350,timeout,0 +620005,0,1350,timeout,0 +620006,1,604,success,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,1,589,success,0 +620010,1,584,success,0 +620011,1,589,success,0 +620012,1,1082,success,0 +620013,0,1350,timeout,0 +620014,1,1118,success,0 +620015,1,593,success,0 +620016,0,1350,timeout,0 +620017,0,1350,timeout,0 +620018,0,1350,timeout,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,0,1350,timeout,0 +620022,1,589,success,0 +620023,0,1350,timeout,0 +620024,0,1350,timeout,0 +620025,0,1350,timeout,0 +620026,0,1350,timeout,0 +620027,0,1350,timeout,0 +620028,1,609,success,0 +620029,1,582,success,0 +620030,0,1350,timeout,0 +620031,0,1350,timeout,0 +620032,0,1350,timeout,0 +620033,0,1350,timeout,0 +620034,0,1350,timeout,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,0,1350,timeout,0 +620038,0,1350,timeout,0 +620039,1,586,success,0 +620040,1,579,success,0 +620041,1,582,success,0 +620042,1,587,success,0 +620043,0,1350,timeout,0 +620044,0,1350,timeout,0 +620045,1,590,success,0 +620046,1,591,success,0 +620047,1,1112,success,0 +620048,0,1350,timeout,0 +620049,1,579,success,0 +620050,0,1350,timeout,0 +620051,0,1350,timeout,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,0,1350,timeout,0 +620055,1,584,success,0 +620056,0,1350,timeout,0 +620057,1,1115,success,0 +620058,0,1350,timeout,0 +620059,1,594,success,0 +620060,1,588,success,0 +620061,1,582,success,0 +620062,1,587,success,0 +620063,0,1350,timeout,0 +620064,1,579,success,0 +620065,1,579,success,0 +620066,0,1350,timeout,0 +620067,1,575,success,0 +620068,1,593,success,0 +620069,0,1350,timeout,0 +620070,0,1350,timeout,0 +620071,1,595,success,0 +620072,1,583,success,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,1,588,success,0 +620076,0,1350,timeout,0 +620077,0,1350,timeout,0 +620078,0,1350,timeout,0 +620079,1,589,success,0 +620080,1,580,success,0 +620081,0,1350,timeout,0 +620082,1,583,success,0 +620083,0,1350,timeout,0 +620084,0,1350,timeout,0 +620085,1,586,success,0 +620086,0,1350,timeout,0 +620087,0,1350,timeout,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,0,1350,timeout,0 +620091,0,1350,timeout,0 +620092,1,582,success,0 +620093,1,580,success,0 +620094,0,1350,timeout,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,1,583,success,0 +620098,1,1106,success,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/gpt61sol-s1/policy.py b/policies/drawer_top_open/gpt61sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..dafbd886647c34e5d561bf4b1b847afd3a1ead19 --- /dev/null +++ b/policies/drawer_top_open/gpt61sol-s1/policy.py @@ -0,0 +1,98 @@ +"""Deterministic, hand-written top drawer controller. + +Retract before approaching, turn the left gripper across the handle, +close, and pull backward. An empty grasp gets one image-guided retry. +""" +import cv2 +import numpy as np + +class Policy: + def reset(self,obs,tools): + self.hold=np.asarray(tools.hold_action(),dtype=np.float32) + self.stage=0;self.stage_t=0;self.yaw_i=0;self.recovery=None + def act(self,obs,tools): + if self.recovery is not None: + return self.recovery.act(obs,tools) + a=self.hold.copy();t=obs['t'];p=obs['low_dim_obs'];x,y,z,yaw=p[18:22] + a[4:11]=[-.98,.1,-1.5,1.2,0,0,0];a[18]=0 + ey=.065-yaw + self.yaw_i=np.clip(self.yaw_i+ey*.02,-.2,.2) + a[3]=np.clip(4*ey+self.yaw_i,-.3,.3) + if self.stage==0: + a[4:11]=[0,0,0,0,0,0,0] + err=np.array([.205-x,-y]);dist=np.linalg.norm(err) + if x<.205 and t<180: + v=err/dist*.14 + a[0]=np.cos(yaw)*v[0]+np.sin(yaw)*v[1];a[1]=-np.sin(yaw)*v[0]+np.cos(yaw)*v[1] + else:self.stage=1;self.stage_t=t + else: + dt=t-self.stage_t + if dt>=100:a[4]=-.91 + if dt>=220:a[18]=1 + if dt==300 and p[44]>.99: + self.recovery=Recovery() + self.recovery.reset(obs,tools) + self.recovery.stage=1 + self.recovery.stage_t=t-100 + return self.recovery.act(obs,tools) + if dt>=300: + # Keep a straight outward pull; don't stir the stance laterally. + if x>-.4:a[0]=-.12 + return a + + + +class Recovery: + def reset(self,obs,tools): + self.hold=np.asarray(tools.hold_action(),dtype=np.float32) + self.stage=0;self.stage_t=0;self.yaw_i=0;self.near_t=None + self.pitch=-.91;self.last_handle=None;self.ready=0 + def handle(self,im): + gray=im.astype(float).mean(2) + mask=((gray>50)&(gray<125)&(np.ptp(im.astype(int),axis=2)<22)).astype('uint8') + n,l,stats,c=cv2.connectedComponentsWithStats(mask) + found=[] + for i in range(1,n): + x,y,w,h,area=stats[i] + if h<27 or w<4 or w>h*.55 or area<85 or x<3:continue + yy,xx=np.where(l==i) + rows=np.bincount(yy,minlength=84) + width=np.median(rows[rows>0]) + upper=xx[yy<35] + xc=np.median(upper) if len(upper)>5 else np.median(xx) + found.append((xc,width,h)) + return min(found,key=lambda q:abs(q[0]-42)) if found else None + def act(self,obs,tools): + a=self.hold.copy();t=obs['t'];p=obs['low_dim_obs'];x,y,z,yaw=p[18:22] + ey=.065-yaw;self.yaw_i=np.clip(self.yaw_i+ey*.02,-.2,.2) + a[3]=np.clip(4*ey+self.yaw_i,-.3,.3);a[18]=0 + a[14]=1.3 + if self.stage==0: + a[4:11]=[0,0,0,0,0,0,0] + if x<.19 and t<150: + a[0]=.14;a[1]=np.clip(-y*2,-.12,.12) + else:self.stage=1;self.stage_t=t + elif self.stage==1: + dt=t-self.stage_t + f=min(1,dt/100) + if dt>170 and t%5==0: + h=self.handle(tools.image('left_wrist'));self.last_handle=h + if h: + xc,width,height=h + self.pitch=np.clip(self.pitch+np.clip((xc-42)*.0005,-.008,.008),-1.03,-.60) + good=abs(xc-42)<9 and (width>=8 or p[6]>.07) + self.ready=self.ready+5 if good else 0 + else:self.ready=0 + a[4:11]=f*np.array([self.pitch,.1,-1.5,1.2,0,0,0]) + if dt>210 and self.last_handle: + xc,width,height=self.last_handle + if abs(xc-42)<12 and width<8 and p[6]<.07 and x<.32:a[0]=.10 + if self.ready>=20 or dt>430: + self.stage=2;self.stage_t=t + elif self.stage==2: + a[4:11]=[self.pitch,.1,-1.5,1.2,0,0,0];a[18]=1 + if t-self.stage_t>80:self.stage=3 + else: + a[4:11]=[self.pitch,.1,-1.5,1.2,0,0,0];a[18]=1 + if x>-.45:a[0]=-.12 + return a diff --git a/policies/drawer_top_open/gpt61sol-s2/episodes.csv b/policies/drawer_top_open/gpt61sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..87b115453119b26551b754ab48479aca90712fa6 --- /dev/null +++ b/policies/drawer_top_open/gpt61sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,699,success,0 +620001,1,653,success,0 +620002,1,642,success,0 +620003,1,626,success,0 +620004,1,683,success,0 +620005,1,624,success,0 +620006,1,682,success,0 +620007,1,654,success,0 +620008,1,686,success,0 +620009,1,630,success,0 +620010,1,651,success,0 +620011,1,627,success,0 +620012,1,644,success,0 +620013,1,626,success,0 +620014,1,711,success,0 +620015,1,642,success,0 +620016,1,698,success,0 +620017,1,688,success,0 +620018,1,627,success,0 +620019,1,678,success,0 +620020,1,643,success,0 +620021,1,631,success,0 +620022,1,683,success,0 +620023,1,659,success,0 +620024,1,700,success,0 +620025,1,633,success,0 +620026,1,635,success,0 +620027,1,624,success,0 +620028,1,681,success,0 +620029,1,663,success,0 +620030,1,712,success,0 +620031,1,635,success,0 +620032,1,647,success,0 +620033,1,660,success,0 +620034,1,632,success,0 +620035,1,677,success,0 +620036,1,679,success,0 +620037,1,623,success,0 +620038,1,707,success,0 +620039,1,641,success,0 +620040,1,668,success,0 +620041,1,653,success,0 +620042,1,649,success,0 +620043,1,622,success,0 +620044,1,655,success,0 +620045,1,613,success,0 +620046,1,665,success,0 +620047,1,689,success,0 +620048,1,630,success,0 +620049,1,679,success,0 +620050,1,706,success,0 +620051,1,653,success,0 +620052,1,651,success,0 +620053,1,693,success,0 +620054,1,632,success,0 +620055,1,674,success,0 +620056,1,636,success,0 +620057,1,641,success,0 +620058,1,688,success,0 +620059,1,681,success,0 +620060,1,621,success,0 +620061,1,673,success,0 +620062,1,679,success,0 +620063,1,643,success,0 +620064,1,677,success,0 +620065,1,678,success,0 +620066,1,618,success,0 +620067,1,653,success,0 +620068,1,647,success,0 +620069,1,633,success,0 +620070,1,629,success,0 +620071,1,632,success,0 +620072,1,645,success,0 +620073,1,645,success,0 +620074,1,643,success,0 +620075,1,640,success,0 +620076,1,647,success,0 +620077,1,611,success,0 +620078,1,673,success,0 +620079,1,613,success,0 +620080,1,660,success,0 +620081,1,637,success,0 +620082,1,641,success,0 +620083,1,636,success,0 +620084,1,668,success,0 +620085,1,630,success,0 +620086,1,638,success,0 +620087,1,651,success,0 +620088,1,637,success,0 +620089,1,658,success,0 +620090,1,655,success,0 +620091,1,622,success,0 +620092,1,682,success,0 +620093,1,685,success,0 +620094,1,668,success,0 +620095,1,667,success,0 +620096,1,701,success,0 +620097,1,659,success,0 +620098,1,612,success,0 +620099,1,661,success,0 diff --git a/policies/drawer_top_open/gpt61sol-s2/policy.py b/policies/drawer_top_open/gpt61sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..153962f43739280cfb4d8017a695bde373dd4aaf --- /dev/null +++ b/policies/drawer_top_open/gpt61sol-s2/policy.py @@ -0,0 +1,66 @@ +"""Open the top drawer with deterministic left-hand control. + +The arm places the open gripper at handle height. Base feedback controls +heading and the initial lateral approach. The wrist view then corrects +lateral error before the gripper closes and the robot retreats. +""" +import numpy as np +import cv2 + +class Policy: + def reset(self, obs, tools): + self.hold=np.asarray(tools.hold_action(),dtype=np.float32) + self.stage=0 + self.start=0 + self.align_v=0 + + def act(self, obs, tools): + q=obs['low_dim_obs'];t=obs['t'] + a=self.hold.copy() + a[:4]=[0,0,.74,np.clip(-3*q[21],-.4,.4)] + # Roll the fingers across the bar; compensate forearm pitch at the wrist. + a[4:11]=[-.2,0,0,1,-1.57,0,-.8] + # Fold the unused right forearm away from the cabinet. + a[14]=1.4 + a[18]=0 + age=t-self.start + if self.stage==0: + if age>=70:self.stage=1;self.start=t + elif self.stage==1: + if q[19]<-.05 or age>=150:self.stage=2;self.start=t + else:a[1]=-.12 + elif self.stage==2: + if age>=50:self.stage=3;self.start=t + elif self.stage==3: + a[0]=.075 + if age>=100:self.stage=4;self.start=t;a[0]=0 + elif self.stage==4: + if age<70: + if age%5==0: + im=tools.image('left_wrist') + # A handle is a dense, dark, nearly neutral vertical region + # in this rolled camera. Exclude the fingers at the sides. + mask=((im.max(2)-im.min(2)<20)&(im[:,:,0]<145)&(im[:,:,0]>25)).astype(np.uint8) + mask[:,:35]=0;mask[:,80:]=0 + n,labels,stats,cent=cv2.connectedComponentsWithStats(mask) + candidates=[] + for k,(x,y,w,h,area) in enumerate(stats[1:],1): + if w>=6 and h>=15 and area>80 and area/(w*h)>.35: + candidates.append((area,k)) + self.align_v=0 + if candidates: + _,k=max(candidates) + error=cent[k,1]-44 + # The dead band prevents reacting to walking wobble. + # Commands below the controller's speed threshold do not step. + if abs(error)>10:self.align_v=-.065*np.sign(error) + a[1]=self.align_v + else: + a[18]=1 + if age>=120:self.stage=5;self.start=t + elif self.stage==5: + a[18]=1;a[0]=-.15 + if age>=350:self.stage=6;self.start=t;a[0]=0 + else: + a[18]=1 + return a diff --git a/policies/drawer_top_open/gpt61sol-s3/episodes.csv b/policies/drawer_top_open/gpt61sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a3deb4b948c59f556c7fcda044db892cd3a54477 --- /dev/null +++ b/policies/drawer_top_open/gpt61sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,1,551,success,0 +620002,0,1350,timeout,0 +620003,1,555,success,0 +620004,0,1350,timeout,0 +620005,1,555,success,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,0,1350,timeout,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,0,1350,timeout,0 +620014,0,1350,timeout,0 +620015,0,1350,timeout,0 +620016,0,1350,timeout,0 +620017,0,1350,timeout,0 +620018,0,1350,timeout,0 +620019,0,1350,timeout,0 +620020,1,555,success,0 +620021,1,555,success,0 +620022,0,1350,timeout,0 +620023,1,555,success,0 +620024,0,1350,timeout,0 +620025,0,1350,timeout,0 +620026,0,1350,timeout,0 +620027,0,1350,timeout,0 +620028,0,1350,timeout,0 +620029,0,1350,timeout,0 +620030,0,1350,timeout,0 +620031,0,1350,timeout,0 +620032,1,553,success,0 +620033,0,1350,timeout,0 +620034,1,553,success,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,1,557,success,0 +620038,1,555,success,0 +620039,0,1350,timeout,0 +620040,1,553,success,0 +620041,0,1350,timeout,0 +620042,1,558,success,0 +620043,0,1350,timeout,0 +620044,0,1350,timeout,0 +620045,1,553,success,0 +620046,1,555,success,0 +620047,0,1350,timeout,0 +620048,0,1350,timeout,0 +620049,0,1350,timeout,0 +620050,0,1350,timeout,0 +620051,0,1350,timeout,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,0,1350,timeout,0 +620055,1,555,success,0 +620056,1,552,success,0 +620057,0,1350,timeout,0 +620058,0,1350,timeout,0 +620059,1,555,success,0 +620060,1,556,success,0 +620061,1,557,success,0 +620062,1,555,success,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,1,552,success,0 +620067,0,1350,timeout,0 +620068,1,553,success,0 +620069,0,1350,timeout,0 +620070,0,1350,timeout,0 +620071,0,1350,timeout,0 +620072,0,1350,timeout,0 +620073,1,557,success,0 +620074,0,1350,timeout,0 +620075,1,554,success,0 +620076,0,1350,timeout,0 +620077,1,555,success,0 +620078,0,1350,timeout,0 +620079,1,557,success,0 +620080,1,555,success,0 +620081,0,1350,timeout,0 +620082,0,1350,timeout,0 +620083,0,1350,timeout,0 +620084,0,1350,timeout,0 +620085,1,554,success,0 +620086,0,1350,timeout,0 +620087,0,1350,timeout,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,1,554,success,0 +620091,1,553,success,0 +620092,1,554,success,0 +620093,1,554,success,0 +620094,1,554,success,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,0,1350,timeout,0 +620098,1,554,success,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/gpt61sol-s3/policy.py b/policies/drawer_top_open/gpt61sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..d8a4c73e85548875c4022948f0339579f1c9b440 --- /dev/null +++ b/policies/drawer_top_open/gpt61sol-s3/policy.py @@ -0,0 +1,34 @@ +"""Deterministic left-hand drawer grasp and pull controller.""" +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.origin = np.array([.05444364, .00959291, .7466567, .02224992]) + self.reach = np.array([-.5, 0., -.3, .7, 1.57, -.25, 0.]) + + def act(self, obs, tools): + t = int(obs['t']) + q = np.asarray(obs['low_dim_obs']) + a = self.hold.copy() + a[2] = .74 + a[3] = np.clip(3 * (self.origin[3] - q[21]), -.3, .3) + if t < 120: + a[4:11] = self.reach * min(1., t / 70.) + a[18] = 0. + if t <= 50 and abs(.0096-q[19]) > .007: + a[1] = np.sign(.0096-q[19])*.12 + if t > 50: + err = self.origin[:2] + [.20, 0.] - q[18:20] + a[:2] = np.where(abs(err) > .008, np.sign(err) * np.maximum(.06, np.minimum(.25, abs(err) * 2)), 0.) + else: + a[4:11] = self.reach + a[18] = 1. + if t >= 190: + u = min((t - 190) / 180., 1.) + a[4] += .25 * u + a[7] += .45 * u + a[10] += .6 * u + if t > 410 and q[18] > self.origin[0] - .12: + a[0] = -.2 + return a diff --git a/policies/drawer_top_open/gpt61terra-s1/episodes.csv b/policies/drawer_top_open/gpt61terra-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..113952f983fd86ba8dafce4d43ac8c42f0362202 --- /dev/null +++ b/policies/drawer_top_open/gpt61terra-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,471,success,0 +620001,1,473,success,0 +620002,1,473,success,0 +620003,1,473,success,0 +620004,1,469,success,0 +620005,1,470,success,0 +620006,1,472,success,0 +620007,1,473,success,0 +620008,1,470,success,0 +620009,1,473,success,0 +620010,1,471,success,0 +620011,1,473,success,0 +620012,1,471,success,0 +620013,1,468,success,0 +620014,1,470,success,0 +620015,1,468,success,0 +620016,1,470,success,0 +620017,1,469,success,0 +620018,1,474,success,0 +620019,1,472,success,0 +620020,1,473,success,0 +620021,1,470,success,0 +620022,1,469,success,0 +620023,1,472,success,0 +620024,1,474,success,0 +620025,1,471,success,0 +620026,1,473,success,0 +620027,1,475,success,0 +620028,1,472,success,0 +620029,1,469,success,0 +620030,1,471,success,0 +620031,1,472,success,0 +620032,1,474,success,0 +620033,1,473,success,0 +620034,1,472,success,0 +620035,1,473,success,0 +620036,1,472,success,0 +620037,1,474,success,0 +620038,1,472,success,0 +620039,1,474,success,0 +620040,1,473,success,0 +620041,1,473,success,0 +620042,1,469,success,0 +620043,1,473,success,0 +620044,1,473,success,0 +620045,1,470,success,0 +620046,1,470,success,0 +620047,1,469,success,0 +620048,1,472,success,0 +620049,1,473,success,0 +620050,1,471,success,0 +620051,1,473,success,0 +620052,1,474,success,0 +620053,1,473,success,0 +620054,1,473,success,0 +620055,1,471,success,0 +620056,1,473,success,0 +620057,1,470,success,0 +620058,1,472,success,0 +620059,1,472,success,0 +620060,1,470,success,0 +620061,1,473,success,0 +620062,1,471,success,0 +620063,1,474,success,0 +620064,1,472,success,0 +620065,1,473,success,0 +620066,1,474,success,0 +620067,1,474,success,0 +620068,1,471,success,0 +620069,1,472,success,0 +620070,1,474,success,0 +620071,1,475,success,0 +620072,1,473,success,0 +620073,1,472,success,0 +620074,1,474,success,0 +620075,1,474,success,0 +620076,1,473,success,0 +620077,1,475,success,0 +620078,1,473,success,0 +620079,1,470,success,0 +620080,1,474,success,0 +620081,1,473,success,0 +620082,1,472,success,0 +620083,1,472,success,0 +620084,1,469,success,0 +620085,1,473,success,0 +620086,1,474,success,0 +620087,1,474,success,0 +620088,1,474,success,0 +620089,1,473,success,0 +620090,1,473,success,0 +620091,1,473,success,0 +620092,1,472,success,0 +620093,1,472,success,0 +620094,1,469,success,0 +620095,1,469,success,0 +620096,1,472,success,0 +620097,1,472,success,0 +620098,1,474,success,0 +620099,1,473,success,0 diff --git a/policies/drawer_top_open/gpt61terra-s1/policy.py b/policies/drawer_top_open/gpt61terra-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..f998411ee38a2a313d75159cf8f48d27d535703c --- /dev/null +++ b/policies/drawer_top_open/gpt61terra-s1/policy.py @@ -0,0 +1,37 @@ +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.a = np.asarray(tools.hold_action(), dtype=np.float32) + self.initial = np.asarray(obs['low_dim_obs'][18:22], dtype=float).copy() + self.a[18] = 0.0 + self.pull_x = None + self.pull_y = None + + def act(self, obs, tools): + t = obs['t'] + x, y, z, yaw = obs['low_dim_obs'][18:22] + a = self.a.copy() + a[4:11] = [-0.75, 0.0, -0.4, 1.2, 1.5, 0.0, 0.0] + if t < 80: + pass + elif t < 220: + dx = self.initial[0] + 0.2 - x + dy = -0.09 - y + a[0] = np.clip(dx * 2, -0.2, 0.2) if abs(dx) > 0.015 else 0 + a[1] = np.clip(dy * 2, -0.15, 0.15) if abs(dy) > 0.015 else 0 + a[3] = np.clip((0.083 - yaw) * 2, -0.4, 0.4) + elif t < 300: + a[:2] = 0 + a[3] = 0 + a[18] = 1 + else: + if self.pull_x is None: + self.pull_x = x + self.pull_y = y + a[18] = 1 + a[0] = -0.18 if x > self.pull_x - 0.35 else 0 + dy = self.pull_y - y + a[1] = np.clip(dy * 3, -0.2, 0.2) if abs(dy) > 0.015 else 0 + a[3] = np.clip((0.083 - yaw) * 2, -0.4, 0.4) + return a diff --git a/policies/drawer_top_open/gpt61terra-s2/episodes.csv b/policies/drawer_top_open/gpt61terra-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a737af06b8968364118a1ffbccd1f204304c6485 --- /dev/null +++ b/policies/drawer_top_open/gpt61terra-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,0,1350,timeout,0 +620002,0,1350,timeout,0 +620003,0,1350,timeout,0 +620004,0,1350,timeout,0 +620005,0,1350,timeout,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,0,1350,timeout,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,0,1350,timeout,0 +620014,0,1350,timeout,0 +620015,0,1350,timeout,0 +620016,0,1350,timeout,0 +620017,0,1350,timeout,0 +620018,0,1350,timeout,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,0,1350,timeout,0 +620022,0,1350,timeout,0 +620023,0,1350,timeout,0 +620024,0,1350,timeout,0 +620025,0,1350,timeout,0 +620026,0,1350,timeout,0 +620027,0,1350,timeout,0 +620028,0,1350,timeout,0 +620029,0,1350,timeout,0 +620030,0,1350,timeout,0 +620031,0,1350,timeout,0 +620032,0,1350,timeout,0 +620033,0,1350,timeout,0 +620034,0,1350,timeout,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,0,1350,timeout,0 +620038,0,1350,timeout,0 +620039,0,1350,timeout,0 +620040,0,1350,timeout,0 +620041,0,1350,timeout,0 +620042,0,1350,timeout,0 +620043,0,1350,timeout,0 +620044,0,1350,timeout,0 +620045,0,1350,timeout,0 +620046,0,1350,timeout,0 +620047,0,1350,timeout,0 +620048,0,1350,timeout,0 +620049,0,1350,timeout,0 +620050,0,1350,timeout,0 +620051,0,1350,timeout,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,0,1350,timeout,0 +620055,0,1350,timeout,0 +620056,0,1350,timeout,0 +620057,0,1350,timeout,0 +620058,0,1350,timeout,0 +620059,0,1350,timeout,0 +620060,0,1350,timeout,0 +620061,0,1350,timeout,0 +620062,0,1350,timeout,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,0,1350,timeout,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,0,1350,timeout,0 +620070,0,1350,timeout,0 +620071,0,1350,timeout,0 +620072,0,1350,timeout,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,0,1350,timeout,0 +620076,0,1350,timeout,0 +620077,0,1350,timeout,0 +620078,0,1350,timeout,0 +620079,0,1350,timeout,0 +620080,0,1350,timeout,0 +620081,0,1350,timeout,0 +620082,0,1350,timeout,0 +620083,0,1350,timeout,0 +620084,0,1350,timeout,0 +620085,0,1350,timeout,0 +620086,0,1350,timeout,0 +620087,0,1350,timeout,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,0,1350,timeout,0 +620091,0,1350,timeout,0 +620092,0,1350,timeout,0 +620093,0,1350,timeout,0 +620094,0,1350,timeout,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,0,1350,timeout,0 +620098,0,1350,timeout,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/gpt61terra-s2/policy.py b/policies/drawer_top_open/gpt61terra-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..083b0d210d2d2dc98d9a2a54dfe4b0fa5ac835e0 --- /dev/null +++ b/policies/drawer_top_open/gpt61terra-s2/policy.py @@ -0,0 +1,37 @@ +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + + def act(self, obs, tools): + t = int(obs['t']) + a = self.hold.copy() + # Return to the cabinet for another grasp if the previous pull slipped. + if t < 110: + phase, start = 0, 0 + elif t < 450: + phase, start = 1, 110 + elif t < 580: + phase, start = 0, 450 + elif t < 900: + phase, start = 2, 580 + elif t < 1030: + phase, start = 0, 900 + else: + phase, start = 3, 1030 + if phase == 0: + x, y, _, yaw = obs['low_dim_obs'][18:22] + dx, dy = .20 - x, -.08 - y + a[0] = np.clip(dx * 1.7, -.2, .2) if abs(dx) > .023 else 0 + a[1] = np.clip(dy * 1.7, -.2, .2) if abs(dy) > .023 else 0 + a[3] = np.clip(-yaw * 1.5, -.4, .4) + a[18] = 0 + else: + elapsed = t - start + pitch, elbow = [(-.3, .3), (-.5, .8), (-.6, .8)][phase - 1] + a[4:11] = [pitch, -.15, 0, elbow, 1.57, 0, 0] + a[18] = 1.0 if elapsed >= 80 else 0.0 + if 150 <= elapsed < 260: + a[0] = -.15 + return a diff --git a/policies/drawer_top_open/gpt61terra-s3/episodes.csv b/policies/drawer_top_open/gpt61terra-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..b21a85b448e6dd01c763827e7fa96984632a27f3 --- /dev/null +++ b/policies/drawer_top_open/gpt61terra-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,459,success,0 +620001,0,1350,timeout,0 +620002,0,1350,timeout,0 +620003,0,1350,timeout,0 +620004,0,1350,timeout,0 +620005,0,1350,timeout,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,1,469,success,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,1,459,success,0 +620014,1,455,success,0 +620015,0,1350,timeout,0 +620016,1,458,success,0 +620017,1,446,success,0 +620018,1,466,success,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,0,1350,timeout,0 +620022,0,1350,timeout,0 +620023,0,1350,timeout,0 +620024,1,466,success,0 +620025,1,463,success,0 +620026,0,1350,timeout,0 +620027,1,476,success,0 +620028,0,1350,timeout,0 +620029,0,1350,timeout,0 +620030,1,451,success,0 +620031,0,1350,timeout,0 +620032,1,475,success,0 +620033,1,471,success,0 +620034,0,1350,timeout,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,1,467,success,0 +620038,0,1350,timeout,0 +620039,1,465,success,0 +620040,0,1350,timeout,0 +620041,0,1350,timeout,0 +620042,0,1350,timeout,0 +620043,1,474,success,0 +620044,1,468,success,0 +620045,0,1350,timeout,0 +620046,0,1350,timeout,0 +620047,0,1350,timeout,0 +620048,0,1350,timeout,0 +620049,0,1350,timeout,0 +620050,0,1350,timeout,0 +620051,0,1350,timeout,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,1,467,success,0 +620055,0,1350,timeout,0 +620056,0,1350,timeout,0 +620057,0,1350,timeout,0 +620058,1,457,success,0 +620059,0,1350,timeout,0 +620060,0,1350,timeout,0 +620061,0,1350,timeout,0 +620062,0,1350,timeout,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,0,1350,timeout,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,1,475,success,0 +620070,0,1350,timeout,0 +620071,0,1350,timeout,0 +620072,0,1350,timeout,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,0,1350,timeout,0 +620076,0,1350,timeout,0 +620077,1,471,success,0 +620078,1,469,success,0 +620079,0,1350,timeout,0 +620080,0,1350,timeout,0 +620081,0,1350,timeout,0 +620082,0,1350,timeout,0 +620083,0,1350,timeout,0 +620084,1,456,success,0 +620085,0,1350,timeout,0 +620086,1,468,success,0 +620087,1,1138,success,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,0,1350,timeout,0 +620091,0,1350,timeout,0 +620092,0,1350,timeout,0 +620093,0,1350,timeout,0 +620094,0,1350,timeout,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,1,464,success,0 +620098,1,471,success,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/gpt61terra-s3/policy.py b/policies/drawer_top_open/gpt61terra-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..51d3f3793c86aa4485d342dc37280def6b482425 --- /dev/null +++ b/policies/drawer_top_open/gpt61terra-s3/policy.py @@ -0,0 +1,46 @@ +import numpy as np + +class Policy: + def reset(self, obs, tools): + self.action = np.asarray(tools.hold_action(), dtype=np.float32) + self.action[18:20] = 0 + self.action[4:11] = [-.35, -.1, -.4, .7, 1.57, 0, 0] + self.start_x = float(obs['low_dim_obs'][18]) + self.phase = 'first' + self.mark = 0 + + def act(self, obs, tools): + a = self.action.copy() + t = obs['t'] + x = float(obs['low_dim_obs'][18]) + if self.phase == 'first': + if 100 <= t < 190: a[0] = .1 + if t >= 190: a[18] = 1 + if 220 <= t < 520: a[0] = -.1 + if t == 220 and max(obs['low_dim_obs'][7:9]) < -.017: + self.phase = 'return'; self.mark = t + elif t == 500 and max(obs['low_dim_obs'][7:9]) < -.017: + self.phase = 'return'; self.mark = t + if self.phase == 'return': + a[18] = 0; a[6] = -.2 + delta = self.start_x - x + if abs(delta) > .025 and t - self.mark < 250: + a[0] = .12 if delta > 0 else -.12 + else: + self.phase = 'settle'; self.mark = t + a[0] = 0 + elif self.phase == 'settle': + a[18] = 0; a[6] = -.2; a[0] = 0 + if t - self.mark >= 50: + self.phase = 'advance'; self.mark = t + elif self.phase == 'advance': + a[18] = 0; a[6] = -.2; a[0] = .1 + if t - self.mark >= 110: + self.phase = 'close'; self.mark = t; a[0] = 0; a[18] = 1 + elif self.phase == 'close': + a[18] = 1; a[6] = -.2; a[0] = 0 + if t - self.mark >= 30: + self.phase = 'pull'; self.mark = t + elif self.phase == 'pull': + a[18] = 1; a[6] = -.2; a[0] = -.1 if t - self.mark < 330 else 0 + return a diff --git a/policies/drawer_top_open/gpt6sol-s1/episodes.csv b/policies/drawer_top_open/gpt6sol-s1/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..26b82b6e125a0ce4b7001abe540315890bf8857d --- /dev/null +++ b/policies/drawer_top_open/gpt6sol-s1/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,0,1350,timeout,0 +620002,1,795,success,0 +620003,0,1350,timeout,0 +620004,0,1350,timeout,0 +620005,1,569,success,0 +620006,0,1350,timeout,0 +620007,1,758,success,0 +620008,0,1350,timeout,0 +620009,1,560,success,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,1,755,success,0 +620014,1,569,success,0 +620015,1,777,success,0 +620016,1,794,success,0 +620017,1,793,success,0 +620018,1,942,success,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,1,573,success,0 +620022,1,574,success,0 +620023,1,813,success,0 +620024,1,573,success,0 +620025,1,782,success,0 +620026,0,1350,timeout,0 +620027,1,756,success,0 +620028,1,786,success,0 +620029,1,585,success,0 +620030,1,754,success,0 +620031,1,931,success,0 +620032,1,873,success,0 +620033,1,790,success,0 +620034,1,562,success,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,1,784,success,0 +620038,1,902,success,0 +620039,1,789,success,0 +620040,0,1350,timeout,0 +620041,0,1350,timeout,0 +620042,1,779,success,0 +620043,1,796,success,0 +620044,1,568,success,0 +620045,0,1350,timeout,0 +620046,0,1350,timeout,0 +620047,1,776,success,0 +620048,1,1258,success,0 +620049,0,1350,timeout,0 +620050,1,963,success,0 +620051,1,787,success,0 +620052,0,1350,timeout,0 +620053,1,785,success,0 +620054,1,780,success,0 +620055,1,794,success,0 +620056,0,1350,timeout,0 +620057,0,1350,timeout,0 +620058,0,1350,timeout,0 +620059,0,1350,timeout,0 +620060,1,780,success,0 +620061,1,779,success,0 +620062,0,1350,timeout,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,0,1350,timeout,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,1,773,success,0 +620070,0,1350,timeout,0 +620071,1,926,success,0 +620072,1,745,success,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,1,795,success,0 +620076,0,1350,timeout,0 +620077,1,729,success,0 +620078,1,581,success,0 +620079,1,1003,success,0 +620080,1,775,success,0 +620081,0,1350,timeout,0 +620082,1,779,success,0 +620083,0,1350,timeout,0 +620084,1,569,success,0 +620085,0,1350,timeout,0 +620086,1,760,success,0 +620087,1,778,success,0 +620088,0,1350,timeout,0 +620089,0,1350,timeout,0 +620090,0,1350,timeout,0 +620091,0,1350,timeout,0 +620092,0,1350,timeout,0 +620093,1,774,success,0 +620094,1,787,success,0 +620095,1,791,success,0 +620096,1,959,success,0 +620097,1,1001,success,0 +620098,0,1350,timeout,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/gpt6sol-s1/policy.py b/policies/drawer_top_open/gpt6sol-s1/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..993ad121530ac93da682c0799d73d3a9ed6fadfe --- /dev/null +++ b/policies/drawer_top_open/gpt6sol-s1/policy.py @@ -0,0 +1,99 @@ +"""Hand-written top drawer opening controller for the simulated G1.""" + +import cv2 +import numpy as np + + +def handle_column(image): + """Find the dark drawer handle in the upper right of a rolled wrist view.""" + a = image.astype(np.int16) + gray = a.mean(axis=2) + spread = a.max(axis=2) - a.min(axis=2) + mask = ((gray > 80) & (gray < 170) & (spread < 12)).astype(np.uint8) + count, _, stats, centers = cv2.connectedComponentsWithStats(mask, 8) + options = [] + for i in range(1, count): + x, y, w, h, area = stats[i] + if x >= 45 and y <= 5 and 6 <= w <= 25 and h >= 20 and area >= 50: + options.append((area, float(centers[i, 0]))) + return max(options)[1] if options else None + + +class Policy: + def reset(self, obs, tools): + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.phase = "walk" + self.phase_t = 0 + self.pitch = -0.35 + self.slip_x = 0.0 + self.target_x = 0.12 + self.slip_count = 0 + self.cycles = 0 + self.ever_contact = False + self.target_y = 0.0 + + def _enter(self, name, t): + self.phase = name + self.phase_t = t + + def act(self, obs, tools): + t = int(obs["t"]) + q = obs["low_dim_obs"] + x, y, _, yaw = (float(v) for v in q[18:22]) + f = float(q[7]) + + if self.phase == "walk" and t >= 120: + self._enter("partial", t) + elif self.phase == "partial" and t >= 175: + self._enter("creep", t) + elif self.phase == "creep" and t >= 275: + column = handle_column(tools.image("left_wrist")) + if column is not None and column < 61: + self.pitch = -0.34 + self._enter("close", t) + elif self.phase == "close" and t - self.phase_t >= 50: + self.slip_count = 0 + if f > -0.0175: + self.ever_contact = True + self._enter("pull", t) + elif self.phase == "pull": + if t - self.phase_t > 25 and f < -0.0175: + self.slip_count += 1 + else: + self.slip_count = 0 + if self.slip_count >= 5 or t - self.phase_t >= 300: + self.slip_x = x + self.target_x = min(self.slip_x + 0.07, 0.21) + if not self.ever_contact: + offsets = (0.03, -0.03, 0.06, -0.06, 0.0) + self.target_y = offsets[self.cycles % len(offsets)] + self.cycles += 1 + self._enter("release", t) + elif self.phase == "release" and t - self.phase_t >= 35: + self._enter("forward", t) + elif self.phase == "forward": + if (x >= self.target_x - 0.005 and t - self.phase_t >= 30) or t - self.phase_t >= 100: + self._enter("close", t) + + mode = self.phase + a = self.hold.copy() + a[4:11] = [-0.4 if mode in ("walk", "partial") else self.pitch, + 0.0, -0.5, 0.6, 1.4, 0.0, 0.0] + a[18] = (0.0 if mode == "walk" else + 0.8 if mode in ("partial", "creep", "release", "forward") + else 1.0) + a[3] = np.clip(-2.0 * (yaw - 0.05), -0.2, 0.2) + + if mode == "walk" and x < 0.16: + a[0] = 0.12 + elif mode == "creep" and x < 0.21: + a[0] = 0.08 + elif mode == "forward" and x < self.target_x: + a[0] = 0.08 + elif mode == "pull": + a[0] = -0.12 + + if mode in ("walk", "creep", "forward"): + desired_y = self.target_y if mode == "forward" else 0.0 + a[1] = np.clip(-2.0 * (y - desired_y), -0.08, 0.08) + return a diff --git a/policies/drawer_top_open/gpt6sol-s2/episodes.csv b/policies/drawer_top_open/gpt6sol-s2/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..6c2933b5b09eabc6890f4b506c1f252a6c50afae --- /dev/null +++ b/policies/drawer_top_open/gpt6sol-s2/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,1,422,success,0 +620001,0,1350,timeout,0 +620002,1,424,success,0 +620003,1,981,success,0 +620004,1,424,success,0 +620005,1,423,success,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,1,424,success,0 +620010,1,424,success,0 +620011,0,1350,timeout,0 +620012,1,423,success,0 +620013,1,421,success,0 +620014,1,422,success,0 +620015,1,424,success,0 +620016,1,423,success,0 +620017,1,422,success,0 +620018,1,423,success,0 +620019,0,1350,timeout,0 +620020,1,427,success,0 +620021,1,425,success,0 +620022,1,424,success,0 +620023,1,425,success,0 +620024,1,422,success,0 +620025,1,422,success,0 +620026,0,1350,timeout,0 +620027,1,426,success,0 +620028,1,424,success,0 +620029,1,424,success,0 +620030,1,422,success,0 +620031,1,980,success,0 +620032,1,978,success,0 +620033,1,425,success,0 +620034,1,423,success,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,1,423,success,0 +620038,0,1350,timeout,0 +620039,1,423,success,0 +620040,0,1350,timeout,0 +620041,1,427,success,0 +620042,1,425,success,0 +620043,1,424,success,0 +620044,1,423,success,0 +620045,1,424,success,0 +620046,0,1350,timeout,0 +620047,1,424,success,0 +620048,1,977,success,0 +620049,0,1350,timeout,0 +620050,1,976,success,0 +620051,1,426,success,0 +620052,0,1350,timeout,0 +620053,0,1350,timeout,0 +620054,1,422,success,0 +620055,0,1350,timeout,0 +620056,0,1350,timeout,0 +620057,0,1350,timeout,0 +620058,1,973,success,0 +620059,1,423,success,0 +620060,1,425,success,0 +620061,1,423,success,0 +620062,1,427,success,0 +620063,0,1350,timeout,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,1,979,success,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,1,426,success,0 +620070,0,1350,timeout,0 +620071,0,1350,timeout,0 +620072,1,422,success,0 +620073,1,975,success,0 +620074,0,1350,timeout,0 +620075,0,1350,timeout,0 +620076,0,1350,timeout,0 +620077,1,424,success,0 +620078,1,423,success,0 +620079,1,428,success,0 +620080,1,423,success,0 +620081,0,1350,timeout,0 +620082,1,975,success,0 +620083,1,427,success,0 +620084,1,423,success,0 +620085,0,1350,timeout,0 +620086,1,422,success,0 +620087,1,423,success,0 +620088,1,426,success,0 +620089,1,425,success,0 +620090,0,1350,timeout,0 +620091,1,426,success,0 +620092,0,1350,timeout,0 +620093,0,1350,timeout,0 +620094,1,424,success,0 +620095,1,424,success,0 +620096,1,976,success,0 +620097,1,978,success,0 +620098,1,423,success,0 +620099,0,1350,timeout,0 diff --git a/policies/drawer_top_open/gpt6sol-s2/policy.py b/policies/drawer_top_open/gpt6sol-s2/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..6bc9a96420fa717af08ae63b492f09a46bff3386 --- /dev/null +++ b/policies/drawer_top_open/gpt6sol-s2/policy.py @@ -0,0 +1,46 @@ +"""Deterministic body-feedback drawer opening controller.""" + +import numpy as np + + +class Policy: + def reset(self, obs, tools): + self.initial = np.asarray(tools.hold_action(), dtype=np.float32) + + @staticmethod + def approach(a, q): + x, y, _, yaw = q[18:22] + a[0] = 0.08 if x < 0.16 else 0.0 + a[1] = np.clip(1.8 * (0.005 - y), -0.15, 0.15) + a[3] = np.clip(1.5 * (0.04 - yaw), -0.25, 0.25) + + def act(self, obs, tools): + t = int(obs["t"]) + q = np.asarray(obs["low_dim_obs"], dtype=np.float32) + a = self.initial.copy() + a[0:4] = [0.0, 0.0, 0.74, 0.0] + a[4:11] = [-0.6, 0.0, -0.6, 0.7, 1.2, 0.0, 0.0] + a[18] = 0.6 + a[19] = 0.6 + + if t < 150: + self.approach(a, q) + elif 200 <= t < 470: + a[18] = 1.0 + if t >= 250: + a[7] = 1.4 + if t < 450: + a[0] = -0.10 + elif 470 <= t < 700: + self.approach(a, q) + if q[18] < 0.16: + a[0] = 0.15 + elif t >= 700: + a[6] = -0.52 + if t >= 750: + a[18] = 1.0 + if t >= 800: + a[7] = 1.4 + if t < 1020: + a[0] = -0.10 + return a diff --git a/policies/drawer_top_open/gpt6sol-s3/episodes.csv b/policies/drawer_top_open/gpt6sol-s3/episodes.csv new file mode 100644 index 0000000000000000000000000000000000000000..1266fbea557b4322ca5954cab7c353fca48a0a7c --- /dev/null +++ b/policies/drawer_top_open/gpt6sol-s3/episodes.csv @@ -0,0 +1,101 @@ +seed,success,length,termination,fell +620000,0,1350,timeout,0 +620001,0,1350,timeout,0 +620002,1,487,success,0 +620003,1,493,success,0 +620004,0,1350,timeout,0 +620005,0,1350,timeout,0 +620006,0,1350,timeout,0 +620007,0,1350,timeout,0 +620008,0,1350,timeout,0 +620009,1,494,success,0 +620010,0,1350,timeout,0 +620011,0,1350,timeout,0 +620012,0,1350,timeout,0 +620013,1,433,success,0 +620014,1,419,success,0 +620015,0,1350,timeout,0 +620016,1,439,success,0 +620017,0,1350,timeout,0 +620018,0,1350,timeout,0 +620019,0,1350,timeout,0 +620020,0,1350,timeout,0 +620021,0,1350,timeout,0 +620022,0,1350,timeout,0 +620023,1,486,success,0 +620024,0,1350,timeout,0 +620025,1,438,success,0 +620026,1,490,success,0 +620027,1,495,success,0 +620028,0,1350,timeout,0 +620029,0,1350,timeout,0 +620030,1,419,success,0 +620031,1,486,success,0 +620032,1,492,success,0 +620033,0,1350,timeout,0 +620034,0,1350,timeout,0 +620035,0,1350,timeout,0 +620036,0,1350,timeout,0 +620037,0,1350,timeout,0 +620038,0,1350,timeout,0 +620039,0,1350,timeout,0 +620040,0,1350,timeout,0 +620041,0,1350,timeout,0 +620042,0,1350,timeout,0 +620043,1,489,success,0 +620044,0,1350,timeout,0 +620045,0,1350,timeout,0 +620046,0,1350,timeout,0 +620047,0,1350,timeout,0 +620048,0,1350,timeout,0 +620049,0,1350,timeout,0 +620050,0,1350,timeout,0 +620051,1,487,success,0 +620052,1,490,success,0 +620053,0,1350,timeout,0 +620054,1,487,success,0 +620055,0,1350,timeout,0 +620056,1,488,success,0 +620057,0,1350,timeout,0 +620058,0,1350,timeout,0 +620059,0,1350,timeout,0 +620060,0,1350,timeout,0 +620061,0,1350,timeout,0 +620062,0,1350,timeout,0 +620063,1,491,success,0 +620064,0,1350,timeout,0 +620065,0,1350,timeout,0 +620066,1,489,success,0 +620067,0,1350,timeout,0 +620068,0,1350,timeout,0 +620069,1,490,success,0 +620070,0,1350,timeout,0 +620071,1,489,success,0 +620072,0,1350,timeout,0 +620073,0,1350,timeout,0 +620074,0,1350,timeout,0 +620075,1,489,success,0 +620076,1,492,success,0 +620077,1,496,success,0 +620078,0,1350,timeout,0 +620079,0,1350,timeout,0 +620080,0,1350,timeout,0 +620081,1,490,success,0 +620082,0,1350,timeout,0 +620083,0,1350,timeout,0 +620084,1,425,success,0 +620085,1,490,success,0 +620086,1,487,success,0 +620087,1,489,success,0 +620088,1,490,success,0 +620089,1,488,success,0 +620090,1,489,success,0 +620091,1,487,success,0 +620092,0,1350,timeout,0 +620093,0,1350,timeout,0 +620094,0,1350,timeout,0 +620095,0,1350,timeout,0 +620096,0,1350,timeout,0 +620097,0,1350,timeout,0 +620098,1,495,success,0 +620099,1,490,success,0 diff --git a/policies/drawer_top_open/gpt6sol-s3/policy.py b/policies/drawer_top_open/gpt6sol-s3/policy.py new file mode 100644 index 0000000000000000000000000000000000000000..618d2539a014195bb6c9f8b3d17baa6c0d9c33d3 --- /dev/null +++ b/policies/drawer_top_open/gpt6sol-s3/policy.py @@ -0,0 +1,55 @@ +"""Deterministic reach, grasp, and pull policy for the top cabinet drawer.""" + +import numpy as np + + +class Policy: + """The control policy that is scored on the hidden seeds.""" + + def reset(self, obs, tools): + """Prepare for one episode. + + Args: + obs: The first observation. + tools: The tools described in docs/api.md. + """ + self.hold = np.asarray(tools.hold_action(), dtype=np.float32) + self.arm = np.array([-1.0, 0.0, -1.4, 1.1, 0.2, 0.0, 0.0], dtype=np.float32) + self.grip_pose = None + self.delay_grip = None + self.pull_wyaw = -0.3 + + def act(self, obs, tools): + """Return the action for this control step. + + Args: + obs: The current observation. + tools: The tools described in docs/api.md. + + Returns: + The physical action. + """ + t = int(obs["t"]) + q = np.asarray(obs["low_dim_obs"]) + a = self.hold.copy() + a[4:11] = self.arm + if t == 165: + self.delay_grip = float(q[21]) > 0.1 + self.pull_wyaw = -0.45 if float(q[21]) < 0.03 else -0.3 + pull_start = 255 if self.delay_grip else 205 + grip_start = 210 if self.delay_grip else 165 + a[18] = 0.0 if t < grip_start else 1.0 + + if 90 <= t < 165: + a[0] = 0.12 + elif t >= pull_start: + if self.grip_pose is None: + self.grip_pose = np.asarray(q[18:22], dtype=np.float64).copy() + x, y, _, yaw = map(float, q[18:22]) + target_x, target_y, _, target_yaw = self.grip_pose + pull_step = t - pull_start + a[10] = self.pull_wyaw * min(1.0, (pull_step + 1) / 80.0) + a[0] = -0.12 if x > target_x - 0.35 else 0.0 + a[1] = np.clip(2.0 * (target_y - y), -0.25, 0.25) + a[3] = np.clip(3.0 * (target_yaw - yaw), -0.5, 0.5) + return a