# Open-loop trajectory-fit action2code policy generated from the RoboCasa GT EE trajectory
# Task: PickPlaceCounterToStandMixer
# Episode: episode_000000

from primitives import moveJoint, moveLinear, moveC, moveA, moveWholeBodyPath, moveActionSequence, grasp, release, wait

SCENE_ARTIFACT = '../../../artifacts/20260324/PickPlaceCounterToStandMixer/20260324_205324_pick-place-counter-to-stand-mixer_episode_000000_action2code-open-loop-joint_initial-scene.json'
POLICY_METADATA = {
    'policy_kind': 'open_loop_joint',
    'policy_variant': 'open-loop-joint',
    'task_name': 'PickPlaceCounterToStandMixer',
    'episode_id': 'episode_000000',
    'scene_artifact_path': '../../../artifacts/20260324/PickPlaceCounterToStandMixer/20260324_205324_pick-place-counter-to-stand-mixer_episode_000000_action2code-open-loop-joint_initial-scene.json',
    'fitting_summary_path': '../../../artifacts/20260324/PickPlaceCounterToStandMixer/20260324_205324_pick-place-counter-to-stand-mixer_episode_000000_action2code-open-loop-joint_fitting-summary.json',
    'extracted_pose_metadata_path': '../../../artifacts/20260324/PickPlaceCounterToStandMixer/20260324_205324_pick-place-counter-to-stand-mixer_episode_000000_action2code-open-loop-joint_extracted-pose-metadata.json',
    'stable_grasp_contact_t': 103,
    'stable_release_contact_loss_t': 205,
    'uses_moveC': False,
    'controller_mode': 'whole_body_ik',
}

OBJ_POSE_T0 = pose(x=0.450597, y=-2.724891, z=0.945693, qw=0.780276, qx=-0.015604, qy=0.038384, qz=0.624061)
GOAL_RECEPTACLE_POSE = pose(x=0.514671, y=-2.520127, z=0.976133, qw=0.764566, qx=-0.047227, qy=0.518679, qz=0.379711)

APPROACH_003_JOINTS = [-0.012990, -1.077401, -0.006991, -2.255860, 0.042297, 1.533706, 0.709825]  # t=3
APPROACH_006_JOINTS = [-0.008342, -1.076983, 0.079505, -2.260973, 0.052826, 1.535837, 0.751832]  # t=6
APPROACH_007_JOINTS = [-0.006859, -1.077014, 0.114771, -2.265794, 0.052448, 1.538381, 0.769514]  # t=7
APPROACH_009_JOINTS = [-0.003476, -1.077217, 0.187703, -2.281297, 0.053462, 1.547415, 0.806455]  # t=9
APPROACH_012_JOINTS = [0.003318, -1.076005, 0.297482, -2.308323, 0.062312, 1.571917, 0.856292]  # t=12
APPROACH_014_JOINTS = [0.006799, -1.067403, 0.370898, -2.322806, 0.066712, 1.597943, 0.892110]  # t=14
APPROACH_015_JOINTS = [0.007422, -1.058077, 0.407902, -2.329633, 0.068030, 1.615851, 0.912445]  # t=15
APPROACH_018_JOINTS = [0.005630, -1.014764, 0.518844, -2.342261, 0.072048, 1.674452, 0.980954]  # t=18
APPROACH_021_JOINTS = [-0.003717, -0.949513, 0.627938, -2.353936, 0.082826, 1.751865, 1.063624]  # t=21
APPROACH_022_JOINTS = [-0.011160, -0.922789, 0.659658, -2.362844, 0.078457, 1.782352, 1.097709]  # t=22
APPROACH_024_JOINTS = [-0.031441, -0.868345, 0.705534, -2.386096, 0.057795, 1.840496, 1.168827]  # t=24
APPROACH_027_JOINTS = [-0.071458, -0.777306, 0.746070, -2.412687, 0.022007, 1.915432, 1.281348]  # t=27
APPROACH_030_JOINTS = [-0.121482, -0.662738, 0.758855, -2.394826, -0.019066, 1.934505, 1.374027]  # t=30
APPROACH_033_JOINTS = [-0.159159, -0.553630, 0.772092, -2.337997, -0.046658, 1.882599, 1.466678]  # t=33
APPROACH_034_JOINTS = [-0.166170, -0.523988, 0.777795, -2.317642, -0.049819, 1.856134, 1.499815]  # t=34
APPROACH_036_JOINTS = [-0.171910, -0.479510, 0.784261, -2.284070, -0.046084, 1.795115, 1.563011]  # t=36
APPROACH_039_JOINTS = [-0.167860, -0.436018, 0.776954, -2.253901, -0.023635, 1.708737, 1.630957]  # t=39
APPROACH_041_JOINTS = [-0.163347, -0.407416, 0.764163, -2.237789, -0.009108, 1.660904, 1.661931]  # t=41
APPROACH_042_JOINTS = [-0.161274, -0.390919, 0.757875, -2.230481, -0.005271, 1.643561, 1.679040]  # t=42
APPROACH_045_JOINTS = [-0.152634, -0.340828, 0.743999, -2.213251, -0.006280, 1.620389, 1.742598]  # t=45
APPROACH_046_JOINTS = [-0.148617, -0.324662, 0.740815, -2.211000, -0.009295, 1.621738, 1.765688]  # t=46
APPROACH_048_JOINTS = [-0.139214, -0.291919, 0.734992, -2.213286, -0.016236, 1.633440, 1.811288]  # t=48
APPROACH_051_JOINTS = [-0.120711, -0.249995, 0.728789, -2.232199, -0.035272, 1.679642, 1.885662]  # t=51
APPROACH_054_JOINTS = [-0.097442, -0.227111, 0.722772, -2.263674, -0.064298, 1.749324, 1.964003]  # t=54
APPROACH_057_JOINTS = [-0.072525, -0.224343, 0.715441, -2.305821, -0.102186, 1.830915, 2.035471]  # t=57
APPROACH_060_JOINTS = [-0.048972, -0.251797, 0.701164, -2.353295, -0.139632, 1.896773, 2.085149]  # t=60
DESCEND_061_JOINTS = [-0.041955, -0.266969, 0.694813, -2.370965, -0.149118, 1.915359, 2.096721]  # t=61
DESCEND_062_JOINTS = [-0.035734, -0.283929, 0.687337, -2.389590, -0.157319, 1.933582, 2.105160]  # t=62
DESCEND_064_JOINTS = [-0.027233, -0.319987, 0.663456, -2.430211, -0.167622, 1.960909, 2.101963]  # t=64
DESCEND_066_JOINTS = [-0.022218, -0.358725, 0.633058, -2.471297, -0.169599, 1.980122, 2.076788]  # t=66
DESCEND_068_JOINTS = [-0.017118, -0.397276, 0.609972, -2.509624, -0.160544, 1.995087, 2.048120]  # t=68
DESCEND_070_JOINTS = [-0.011920, -0.431503, 0.598081, -2.542019, -0.146024, 2.008930, 2.026241]  # t=70
DESCEND_071_JOINTS = [-0.010343, -0.445197, 0.594280, -2.556116, -0.140108, 2.017743, 2.018020]  # t=71
DESCEND_072_JOINTS = [-0.009664, -0.455462, 0.591724, -2.569288, -0.135435, 2.029022, 2.011553]  # t=72
DESCEND_074_JOINTS = [-0.010427, -0.464970, 0.591598, -2.595486, -0.129438, 2.058860, 2.005958]  # t=74
DESCEND_075_JOINTS = [-0.011238, -0.465835, 0.594144, -2.606823, -0.127327, 2.075243, 2.006596]  # t=75
DESCEND_076_JOINTS = [-0.012225, -0.465104, 0.598004, -2.615041, -0.125715, 2.090661, 2.008990]  # t=76
DESCEND_078_JOINTS = [-0.015577, -0.458656, 0.606634, -2.624401, -0.125704, 2.117341, 2.016261]  # t=78
DESCEND_080_JOINTS = [-0.019680, -0.447906, 0.616541, -2.624338, -0.127183, 2.135677, 2.025206]  # t=80
DESCEND_082_JOINTS = [-0.025157, -0.430868, 0.626703, -2.620473, -0.132582, 2.153401, 2.037029]  # t=82
DESCEND_084_JOINTS = [-0.031498, -0.408929, 0.636682, -2.613907, -0.142373, 2.170460, 2.051870]  # t=84
DESCEND_086_JOINTS = [-0.037542, -0.385217, 0.646077, -2.605081, -0.154929, 2.183032, 2.068584]  # t=86
DESCEND_088_JOINTS = [-0.043151, -0.359177, 0.653833, -2.603842, -0.169737, 2.197397, 2.086853]  # t=88
DESCEND_090_JOINTS = [-0.049936, -0.322432, 0.660964, -2.614913, -0.193919, 2.236107, 2.113801]  # t=90
DESCEND_092_JOINTS = [-0.053507, -0.291119, 0.667864, -2.600256, -0.217672, 2.267319, 2.142363]  # t=92
DESCEND_093_JOINTS = [-0.053465, -0.281997, 0.669963, -2.592726, -0.226943, 2.264702, 2.153445]  # t=93
DESCEND_094_JOINTS = [-0.052379, -0.276793, 0.670364, -2.586970, -0.232858, 2.257449, 2.160471]  # t=94
DESCEND_095_JOINTS = [-0.050756, -0.273089, 0.669475, -2.582170, -0.236547, 2.251017, 2.164362]  # t=95
DESCEND_096_JOINTS = [-0.048791, -0.270066, 0.667941, -2.578228, -0.239113, 2.246131, 2.166813]  # t=96
DESCEND_098_JOINTS = [-0.044256, -0.265482, 0.663914, -2.572682, -0.242949, 2.239418, 2.170152]  # t=98
DESCEND_100_JOINTS = [-0.039320, -0.262421, 0.659413, -2.569477, -0.246204, 2.235752, 2.172955]  # t=100
DESCEND_101_JOINTS = [-0.036811, -0.261565, 0.657185, -2.568613, -0.248068, 2.235002, 2.174750]  # t=101
GRASP_HOLD_103_JOINTS = [-0.030764, -0.262860, 0.654591, -2.568577, -0.248061, 2.230090, 2.177405]  # t=103
LIFT_104_JOINTS = [-0.026343, -0.269429, 0.655538, -2.568506, -0.245856, 2.222751, 2.180157]  # t=104
LIFT_105_JOINTS = [-0.020743, -0.281714, 0.658531, -2.568274, -0.242607, 2.213691, 2.185278]  # t=105
LIFT_106_JOINTS = [-0.013466, -0.302424, 0.664957, -2.566879, -0.238999, 2.201463, 2.194948]  # t=106
LIFT_107_JOINTS = [-0.004383, -0.332503, 0.674751, -2.564177, -0.233795, 2.185312, 2.208486]  # t=107
LIFT_108_JOINTS = [0.005887, -0.370641, 0.686012, -2.560289, -0.226313, 2.165935, 2.222848]  # t=108
LIFT_109_JOINTS = [0.016623, -0.415129, 0.697403, -2.557163, -0.217722, 2.145311, 2.237009]  # t=109
TRANSPORT_112_JOINTS = [0.046445, -0.569787, 0.723628, -2.563222, -0.194432, 2.096567, 2.270721]  # t=112
TRANSPORT_114_JOINTS = [0.064422, -0.680690, 0.731562, -2.576330, -0.175482, 2.072639, 2.276967]  # t=114
TRANSPORT_115_JOINTS = [0.072332, -0.737157, 0.728226, -2.585021, -0.165155, 2.062889, 2.272902]  # t=115
TRANSPORT_117_JOINTS = [0.085299, -0.850885, 0.704031, -2.608701, -0.149293, 2.050973, 2.249109]  # t=117
TRANSPORT_118_JOINTS = [0.089874, -0.906416, 0.681250, -2.624504, -0.144422, 2.046568, 2.226103]  # t=118
TRANSPORT_120_JOINTS = [0.097321, -1.013234, 0.619301, -2.657988, -0.136667, 2.035054, 2.154292]  # t=120
TRANSPORT_121_JOINTS = [0.099180, -1.061444, 0.583219, -2.673228, -0.135485, 2.027197, 2.107380]  # t=121
TRANSPORT_124_JOINTS = [0.089663, -1.173028, 0.463551, -2.703228, -0.149981, 2.007946, 1.962765]  # t=124
TRANSPORT_125_JOINTS = [0.081971, -1.196285, 0.424398, -2.704718, -0.157912, 2.005196, 1.916734]  # t=125
TRANSPORT_127_JOINTS = [0.060062, -1.219721, 0.350204, -2.696100, -0.179229, 2.006575, 1.833760]  # t=127
TRANSPORT_128_JOINTS = [0.048447, -1.225025, 0.316184, -2.686482, -0.187929, 1.998158, 1.793762]  # t=128
TRANSPORT_130_JOINTS = [0.027316, -1.225099, 0.259756, -2.665985, -0.194712, 1.964450, 1.716251]  # t=130
TRANSPORT_131_JOINTS = [0.017961, -1.218683, 0.238409, -2.655731, -0.192986, 1.941606, 1.679488]  # t=131
TRANSPORT_133_JOINTS = [0.003339, -1.191363, 0.217996, -2.631929, -0.174900, 1.881852, 1.615595]  # t=133
TRANSPORT_134_JOINTS = [-0.003282, -1.172089, 0.215094, -2.615509, -0.165009, 1.848571, 1.590789]  # t=134
TRANSPORT_136_JOINTS = [-0.016034, -1.128007, 0.214683, -2.579674, -0.149449, 1.785569, 1.553243]  # t=136
TRANSPORT_139_JOINTS = [-0.031293, -1.065567, 0.222278, -2.544872, -0.133485, 1.722158, 1.523381]  # t=139
TRANSPORT_142_JOINTS = [-0.042209, -1.019349, 0.227611, -2.511998, -0.127456, 1.675839, 1.506543]  # t=142
TRANSPORT_144_JOINTS = [-0.048324, -0.995979, 0.226100, -2.499623, -0.129228, 1.658735, 1.499809]  # t=144
TRANSPORT_145_JOINTS = [-0.050747, -0.986839, 0.225130, -2.502981, -0.130241, 1.659402, 1.498800]  # t=145
TRANSPORT_147_JOINTS = [-0.054056, -0.975822, 0.223234, -2.525651, -0.132287, 1.674831, 1.499582]  # t=147
TRANSPORT_148_JOINTS = [-0.055047, -0.973728, 0.222143, -2.541105, -0.133391, 1.686360, 1.500411]  # t=148
TRANSPORT_151_JOINTS = [-0.056641, -0.976280, 0.216092, -2.588784, -0.138502, 1.723536, 1.501075]  # t=151
TRANSPORT_154_JOINTS = [-0.056360, -0.983632, 0.211911, -2.634996, -0.140839, 1.760897, 1.502257]  # t=154
TRANSPORT_157_JOINTS = [-0.055300, -0.993329, 0.210691, -2.666409, -0.141514, 1.786533, 1.504015]  # t=157
TRANSPORT_160_JOINTS = [-0.054870, -0.999526, 0.208890, -2.691799, -0.142483, 1.807130, 1.504546]  # t=160
TRANSPORT_163_JOINTS = [-0.054876, -1.002184, 0.207370, -2.721179, -0.144108, 1.832864, 1.506685]  # t=163
TRANSPORT_165_JOINTS = [-0.055552, -1.003537, 0.203736, -2.735227, -0.148137, 1.849157, 1.506849]  # t=165
TRANSPORT_166_JOINTS = [-0.056123, -1.002978, 0.201258, -2.740327, -0.150628, 1.857463, 1.506601]  # t=166
TRANSPORT_169_JOINTS = [-0.055940, -1.002098, 0.196573, -2.743673, -0.150783, 1.871852, 1.500330]  # t=169
TRANSPORT_172_JOINTS = [-0.055333, -1.000370, 0.192548, -2.746635, -0.148287, 1.884743, 1.493255]  # t=172
TRANSPORT_175_JOINTS = [-0.054895, -0.998944, 0.189317, -2.749196, -0.146587, 1.895978, 1.487916]  # t=175
TRANSPORT_178_JOINTS = [-0.055602, -0.990106, 0.186579, -2.749254, -0.147204, 1.914387, 1.485513]  # t=178
TRANSPORT_179_JOINTS = [-0.055961, -0.986896, 0.186124, -2.748230, -0.147661, 1.917527, 1.485465]  # t=179
TRANSPORT_180_JOINTS = [-0.056201, -0.984681, 0.186037, -2.747008, -0.147853, 1.917857, 1.485494]  # t=180
TRANSPORT_181_JOINTS = [-0.056321, -0.983289, 0.186045, -2.745867, -0.147867, 1.917274, 1.485500]  # t=181
TRANSPORT_184_JOINTS = [-0.056389, -0.981243, 0.186047, -2.744051, -0.147873, 1.916233, 1.485507]  # t=184
TRANSPORT_187_JOINTS = [-0.056389, -0.980909, 0.186047, -2.743825, -0.147875, 1.916176, 1.485510]  # t=187
PLACE_188_JOINTS = [-0.056389, -0.980910, 0.186045, -2.743825, -0.147876, 1.916173, 1.485509]  # t=188
PLACE_189_JOINTS = [-0.056535, -0.981251, 0.185449, -2.743792, -0.148401, 1.915670, 1.485277]  # t=189
PLACE_190_JOINTS = [-0.056701, -0.982146, 0.184333, -2.743938, -0.149092, 1.914522, 1.484359]  # t=190
PLACE_191_JOINTS = [-0.056834, -0.983497, 0.182967, -2.744333, -0.149829, 1.913240, 1.483015]  # t=191
PLACE_192_JOINTS = [-0.057004, -0.985302, 0.181360, -2.744831, -0.150892, 1.911556, 1.481542]  # t=192
PLACE_193_JOINTS = [-0.057221, -0.987492, 0.179532, -2.745215, -0.152236, 1.909831, 1.480106]  # t=193
PLACE_194_JOINTS = [-0.057398, -0.990682, 0.177687, -2.743947, -0.153665, 1.908007, 1.479085]  # t=194
PLACE_195_JOINTS = [-0.056931, -0.998980, 0.176824, -2.738318, -0.153870, 1.898687, 1.478771]  # t=195
PLACE_196_JOINTS = [-0.055424, -1.014688, 0.177223, -2.727963, -0.152357, 1.879585, 1.478555]  # t=196
PLACE_197_JOINTS = [-0.053545, -1.035892, 0.177195, -2.715909, -0.151072, 1.856638, 1.477915]  # t=197
PLACE_198_JOINTS = [-0.051442, -1.061879, 0.176438, -2.702889, -0.150142, 1.831039, 1.476558]  # t=198
PLACE_199_JOINTS = [-0.049180, -1.091298, 0.175038, -2.689716, -0.149462, 1.805951, 1.474746]  # t=199
PLACE_200_JOINTS = [-0.046951, -1.122571, 0.172951, -2.676591, -0.149343, 1.783142, 1.472666]  # t=200
PLACE_201_JOINTS = [-0.044882, -1.154577, 0.170235, -2.663052, -0.149742, 1.762684, 1.470341]  # t=201
PLACE_202_JOINTS = [-0.043099, -1.185877, 0.166971, -2.649283, -0.150671, 1.745413, 1.467819]  # t=202
PLACE_203_JOINTS = [-0.041673, -1.215408, 0.163320, -2.635401, -0.152086, 1.731778, 1.465356]  # t=203
PLACE_204_JOINTS = [-0.040596, -1.242792, 0.159497, -2.621346, -0.153795, 1.720548, 1.462918]  # t=204
PLACE_205_JOINTS = [-0.039777, -1.267924, 0.155905, -2.606604, -0.155333, 1.710073, 1.460328]  # t=205
RELEASE_POSE_205_JOINTS = [-0.039777, -1.267924, 0.155905, -2.606604, -0.155333, 1.710073, 1.460328]  # t=205
RETRACT_206_JOINTS = [-0.039095, -1.291440, 0.153035, -2.591079, -0.156270, 1.699012, 1.457962]  # t=206
RETRACT_207_JOINTS = [-0.038529, -1.313985, 0.150796, -2.576054, -0.156812, 1.687373, 1.456045]  # t=207
RETRACT_208_JOINTS = [-0.038129, -1.335821, 0.148639, -2.562245, -0.157551, 1.676509, 1.454461]  # t=208
RETRACT_209_JOINTS = [-0.037765, -1.357800, 0.146476, -2.549909, -0.157867, 1.666104, 1.453395]  # t=209
RETRACT_210_JOINTS = [-0.037289, -1.380950, 0.144274, -2.540074, -0.157052, 1.657814, 1.453682]  # t=210
RETRACT_211_JOINTS = [-0.036665, -1.405095, 0.141896, -2.534607, -0.154829, 1.651686, 1.454938]  # t=211
RETRACT_212_JOINTS = [-0.035946, -1.428758, 0.139800, -2.534737, -0.152393, 1.650662, 1.455967]  # t=212
RETRACT_213_JOINTS = [-0.035192, -1.451490, 0.138444, -2.540466, -0.150511, 1.654750, 1.456591]  # t=213
RETRACT_214_JOINTS = [-0.034418, -1.474039, 0.137751, -2.549226, -0.149153, 1.660732, 1.456897]  # t=214
RETRACT_215_JOINTS = [-0.033568, -1.497013, 0.137342, -2.558709, -0.147929, 1.665032, 1.456613]  # t=215
RETRACT_216_JOINTS = [-0.032583, -1.520431, 0.137063, -2.567817, -0.146475, 1.666875, 1.455501]  # t=216
RETRACT_217_JOINTS = [-0.031469, -1.543767, 0.136772, -2.576470, -0.144680, 1.666468, 1.453162]  # t=217
RETRACT_218_JOINTS = [-0.030243, -1.566661, 0.136285, -2.584400, -0.142542, 1.664465, 1.449420]  # t=218
RETRACT_219_JOINTS = [-0.028908, -1.588744, 0.135460, -2.591710, -0.139989, 1.661725, 1.444159]  # t=219
RETRACT_220_JOINTS = [-0.027525, -1.609224, 0.134169, -2.598869, -0.137082, 1.659221, 1.437377]  # t=220
APPROACH_000_JOINTS = [-0.014476, -1.078757, -0.024756, -2.256547, 0.035256, 1.537006, 0.704026]  # t=1

# Phase-level helper functions keep the open-loop policy readable while preserving
# the exact primitive execution order used at runtime.

def move_to_pregrasp():
    """Coarse approach into the pregrasp corridor."""
    moveJoint(APPROACH_000_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_003_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_006_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_007_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_009_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_012_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_014_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_015_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_018_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_021_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_022_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_024_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_027_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_030_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_033_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_034_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_036_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_039_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_041_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_042_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_045_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_046_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_048_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_051_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_054_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_057_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_060_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)

def execute_grasp_approach():
    """Final Cartesian descent into grasp alignment."""
    moveJoint(DESCEND_061_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_062_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_064_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_066_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_068_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_070_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_071_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_072_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_074_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_075_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_076_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_078_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_080_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_082_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_084_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_086_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_088_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_090_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_092_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_093_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_094_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_095_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_096_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_098_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_100_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_101_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)

def close_gripper_on_object():
    """Close the gripper and let the grasp settle briefly."""
    grasp(hold_target=GRASP_HOLD_103_JOINTS, input_type='joint', close_steps=1, settle_steps=0, gripper=1.0, require_contact_count=4)
    wait(duration=0.05, hold_target=GRASP_HOLD_103_JOINTS, input_type='joint', gripper=1.0)

def lift_object():
    """Lift the grasped object clear of the counter."""
    moveJoint(LIFT_104_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_105_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_106_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_107_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_108_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_109_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)

def transport_to_place():
    """Carry the object through the curved transport corridor."""
    moveJoint(TRANSPORT_112_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_114_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_115_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_117_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_118_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_120_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_121_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_124_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_125_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_127_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_128_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_130_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_131_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_133_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_134_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_136_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_139_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_142_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_144_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_145_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_147_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_148_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_151_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_154_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_157_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_160_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_163_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_165_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_166_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_169_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_172_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_175_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_178_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_179_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_180_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(TRANSPORT_181_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(TRANSPORT_184_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(TRANSPORT_187_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)

def prepare_release():
    """Set the object into the receptacle and stabilize before release."""
    moveJoint(PLACE_188_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_189_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_190_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_191_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_192_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_193_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_194_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_195_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_196_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_197_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_198_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_199_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_200_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_201_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_202_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_203_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_204_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_205_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    wait(duration=0.05, hold_target=RELEASE_POSE_205_JOINTS, input_type='joint', gripper=-1.0)

def release_object():
    """Open the gripper and hold briefly to avoid disturbing the placement."""
    release(hold_target=RELEASE_POSE_205_JOINTS, input_type='joint', open_steps=1, settle_steps=0, gripper=-1.0)
    wait(duration=0.05, hold_target=RELEASE_POSE_205_JOINTS, input_type='joint', gripper=-1.0)

def retreat_after_release():
    """Retreat away from the placed object without clipping it."""
    moveJoint(RETRACT_206_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_207_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_208_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_209_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_210_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_211_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_212_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_213_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_214_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_215_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_216_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_217_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_218_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_219_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_220_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)

move_to_pregrasp()
execute_grasp_approach()
close_gripper_on_object()
lift_object()
transport_to_place()
prepare_release()
release_object()
retreat_after_release()

# Fitting strategy:
# - adaptive per-phase waypoint selection on EE position + quaternion error
# - tight tolerances near descend / lift / place, looser tolerances in transport
# - optional moveC / moveA / segmented moveLinear chains / moveActionSequence when a segment is better represented by a smooth or constrained path
# - GT used only during generation; runtime execution uses this saved policy plus scene artifact


# Open-loop trajectory-fit action2code policy generated from the RoboCasa GT EE trajectory
# Task: PickPlaceCounterToStove
# Episode: episode_000000

from primitives import moveJoint, moveLinear, moveC, moveA, moveWholeBodyPath, moveActionSequence, grasp, release, wait

SCENE_ARTIFACT = '../../../artifacts/20260324/PickPlaceCounterToStove/20260324_205325_pick-place-counter-to-stove_episode_000000_action2code-open-loop-joint_initial-scene.json'
POLICY_METADATA = {
    'policy_kind': 'open_loop_joint',
    'policy_variant': 'open-loop-joint',
    'task_name': 'PickPlaceCounterToStove',
    'episode_id': 'episode_000000',
    'scene_artifact_path': '../../../artifacts/20260324/PickPlaceCounterToStove/20260324_205325_pick-place-counter-to-stove_episode_000000_action2code-open-loop-joint_initial-scene.json',
    'fitting_summary_path': '../../../artifacts/20260324/PickPlaceCounterToStove/20260324_205325_pick-place-counter-to-stove_episode_000000_action2code-open-loop-joint_fitting-summary.json',
    'extracted_pose_metadata_path': '../../../artifacts/20260324/PickPlaceCounterToStove/20260324_205325_pick-place-counter-to-stove_episode_000000_action2code-open-loop-joint_extracted-pose-metadata.json',
    'stable_grasp_contact_t': 108,
    'stable_release_contact_loss_t': 204,
    'uses_moveC': False,
    'controller_mode': 'whole_body_ik',
}

OBJ_POSE_T0 = pose(x=3.676318, y=-0.456473, z=0.956975, qw=0.982452, qx=-0.051797, qy=0.011214, qz=-0.178828)
GOAL_RECEPTACLE_POSE = pose(x=3.334379, y=-0.452215, z=0.945905, qw=0.844765, qx=0.013306, qy=-0.005060, qz=-0.534949)

APPROACH_005_JOINTS = [-0.013523, -1.068459, -0.025862, -2.282748, 0.013932, 1.499470, 0.739696]  # t=5
APPROACH_007_JOINTS = [-0.018256, -1.095183, -0.043147, -2.292639, -0.003733, 1.470068, 0.741090]  # t=7
APPROACH_010_JOINTS = [-0.026420, -1.145320, -0.070119, -2.321847, -0.033100, 1.441413, 0.745715]  # t=10
APPROACH_015_JOINTS = [-0.042241, -1.225255, -0.131431, -2.366543, -0.099343, 1.414468, 0.741065]  # t=15
APPROACH_020_JOINTS = [-0.061820, -1.272265, -0.195526, -2.389705, -0.178132, 1.414667, 0.764632]  # t=20
APPROACH_024_JOINTS = [-0.081748, -1.284664, -0.247144, -2.388523, -0.259621, 1.420666, 0.826054]  # t=24
APPROACH_025_JOINTS = [-0.086789, -1.281757, -0.263620, -2.387872, -0.284999, 1.429072, 0.844540]  # t=25
APPROACH_030_JOINTS = [-0.109261, -1.232803, -0.368123, -2.373415, -0.417885, 1.486614, 0.939193]  # t=30
APPROACH_035_JOINTS = [-0.123058, -1.149410, -0.485106, -2.339887, -0.529992, 1.556457, 1.020827]  # t=35
APPROACH_037_JOINTS = [-0.124969, -1.110229, -0.534872, -2.321330, -0.565070, 1.590559, 1.045560]  # t=37
APPROACH_040_JOINTS = [-0.122028, -1.045274, -0.614118, -2.284639, -0.600064, 1.643308, 1.063747]  # t=40
APPROACH_045_JOINTS = [-0.097513, -0.925213, -0.739944, -2.198257, -0.603469, 1.719110, 1.037918]  # t=45
APPROACH_050_JOINTS = [-0.048186, -0.794508, -0.837563, -2.113282, -0.561824, 1.792431, 0.984193]  # t=50
APPROACH_055_JOINTS = [0.018316, -0.642289, -0.948432, -2.067278, -0.513246, 1.917503, 0.974777]  # t=55
APPROACH_056_JOINTS = [0.033453, -0.608535, -0.972498, -2.061797, -0.500833, 1.948407, 0.978531]  # t=56
APPROACH_060_JOINTS = [0.099726, -0.463432, -1.077828, -2.043284, -0.431265, 2.081724, 0.982416]  # t=60
APPROACH_065_JOINTS = [0.197907, -0.243531, -1.224470, -2.035284, -0.265995, 2.276179, 0.940692]  # t=65
APPROACH_068_JOINTS = [0.251799, -0.073357, -1.309990, -2.045342, -0.085121, 2.407460, 0.862100]  # t=68
APPROACH_070_JOINTS = [0.251893, 0.051713, -1.338788, -2.058072, 0.086767, 2.486238, 0.759932]  # t=70
APPROACH_075_JOINTS = [0.021091, 0.256535, -1.159847, -2.013315, 0.441302, 2.512504, 0.520628]  # t=75
APPROACH_080_JOINTS = [-0.285187, 0.363482, -0.905783, -1.834820, 0.524751, 2.352827, 0.433355]  # t=80
APPROACH_082_JOINTS = [-0.378722, 0.402809, -0.829224, -1.747501, 0.504047, 2.270454, 0.436930]  # t=82
APPROACH_085_JOINTS = [-0.478767, 0.455291, -0.734332, -1.621982, 0.446005, 2.167258, 0.474638]  # t=85
APPROACH_086_JOINTS = [-0.503506, 0.472790, -0.706860, -1.583783, 0.426340, 2.141235, 0.492983]  # t=86
APPROACH_090_JOINTS = [-0.571262, 0.526356, -0.615896, -1.469422, 0.377142, 2.057670, 0.561140]  # t=90
APPROACH_095_JOINTS = [-0.609947, 0.579908, -0.544343, -1.410979, 0.346832, 2.029508, 0.611461]  # t=95
DESCEND_096_JOINTS = [-0.613999, 0.592244, -0.534049, -1.403411, 0.341876, 2.032724, 0.619677]  # t=96
DESCEND_097_JOINTS = [-0.617457, 0.605114, -0.524872, -1.396244, 0.337558, 2.036868, 0.627247]  # t=97
DESCEND_098_JOINTS = [-0.620286, 0.618567, -0.516191, -1.389047, 0.333960, 2.041933, 0.634488]  # t=98
DESCEND_099_JOINTS = [-0.622570, 0.632286, -0.507318, -1.381068, 0.332527, 2.048252, 0.641662]  # t=99
DESCEND_100_JOINTS = [-0.624724, 0.647233, -0.498474, -1.371630, 0.332827, 2.057047, 0.648800]  # t=100
DESCEND_101_JOINTS = [-0.627205, 0.664174, -0.490040, -1.360150, 0.334254, 2.068164, 0.655304]  # t=101
DESCEND_102_JOINTS = [-0.630482, 0.681016, -0.484014, -1.346042, 0.335493, 2.078368, 0.661146]  # t=102
GRASP_104_JOINTS = [-0.642183, 0.708840, -0.484475, -1.306522, 0.336662, 2.085654, 0.665818]  # t=104
GRASP_107_JOINTS = [-0.671236, 0.763885, -0.487105, -1.226833, 0.349429, 2.085540, 0.658269]  # t=107
GRASP_108_JOINTS = [-0.682481, 0.784092, -0.485555, -1.195623, 0.355749, 2.079931, 0.655245]  # t=108
GRASP_HOLD_108_JOINTS = [-0.682481, 0.784092, -0.485555, -1.195623, 0.355749, 2.079931, 0.655245]  # t=108
LIFT_109_JOINTS = [-0.693918, 0.803603, -0.483324, -1.162822, 0.361107, 2.070217, 0.653704]  # t=109
LIFT_110_JOINTS = [-0.705169, 0.821470, -0.480350, -1.130542, 0.365039, 2.055253, 0.653429]  # t=110
LIFT_111_JOINTS = [-0.715744, 0.837225, -0.476352, -1.100163, 0.367322, 2.036005, 0.654297]  # t=111
LIFT_112_JOINTS = [-0.725455, 0.851454, -0.471569, -1.072048, 0.367003, 2.014830, 0.655310]  # t=112
LIFT_113_JOINTS = [-0.734069, 0.863918, -0.466420, -1.045442, 0.363423, 1.992632, 0.655984]  # t=113
LIFT_114_JOINTS = [-0.741428, 0.874607, -0.460880, -1.020208, 0.357194, 1.970399, 0.657560]  # t=114
LIFT_115_JOINTS = [-0.747937, 0.883896, -0.455486, -0.996855, 0.348878, 1.949154, 0.659801]  # t=115
LIFT_116_JOINTS = [-0.753687, 0.890825, -0.449418, -0.976319, 0.341463, 1.926826, 0.662180]  # t=116
LIFT_117_JOINTS = [-0.758218, 0.893897, -0.442564, -0.959080, 0.335326, 1.901493, 0.665142]  # t=117
LIFT_118_JOINTS = [-0.761870, 0.893477, -0.436311, -0.945338, 0.328716, 1.874748, 0.666876]  # t=118
LIFT_119_JOINTS = [-0.764847, 0.890066, -0.430780, -0.935042, 0.321909, 1.847855, 0.665674]  # t=119
LIFT_120_JOINTS = [-0.767581, 0.882215, -0.426149, -0.927547, 0.317036, 1.820302, 0.660589]  # t=120
LIFT_121_JOINTS = [-0.770185, 0.870277, -0.422476, -0.923953, 0.314331, 1.791533, 0.651049]  # t=121
LIFT_122_JOINTS = [-0.772725, 0.854721, -0.420312, -0.924963, 0.312929, 1.762105, 0.637515]  # t=122
LIFT_123_JOINTS = [-0.774998, 0.836256, -0.419558, -0.930586, 0.312597, 1.733445, 0.621043]  # t=123
TRANSPORT_125_JOINTS = [-0.777792, 0.791236, -0.421423, -0.955498, 0.313640, 1.679666, 0.582954]  # t=125
TRANSPORT_127_JOINTS = [-0.774915, 0.736829, -0.425642, -0.999075, 0.312046, 1.630089, 0.540754]  # t=127
TRANSPORT_129_JOINTS = [-0.763644, 0.675883, -0.430207, -1.061318, 0.306235, 1.591732, 0.503050]  # t=129
TRANSPORT_131_JOINTS = [-0.744398, 0.609808, -0.435351, -1.142628, 0.299442, 1.572581, 0.471743]  # t=131
TRANSPORT_133_JOINTS = [-0.717507, 0.538786, -0.441111, -1.237928, 0.293073, 1.573837, 0.450113]  # t=133
TRANSPORT_135_JOINTS = [-0.682270, 0.466226, -0.445516, -1.339233, 0.280160, 1.590844, 0.442916]  # t=135
TRANSPORT_137_JOINTS = [-0.640860, 0.392177, -0.450252, -1.442899, 0.258461, 1.614621, 0.447649]  # t=137
TRANSPORT_139_JOINTS = [-0.596011, 0.316240, -0.455875, -1.546950, 0.234450, 1.643416, 0.459577]  # t=139
TRANSPORT_141_JOINTS = [-0.549193, 0.239906, -0.461280, -1.648802, 0.209807, 1.675770, 0.479070]  # t=141
TRANSPORT_143_JOINTS = [-0.501847, 0.163639, -0.466509, -1.746823, 0.184799, 1.709794, 0.510119]  # t=143
TRANSPORT_145_JOINTS = [-0.454965, 0.087688, -0.470611, -1.840355, 0.158577, 1.744329, 0.551173]  # t=145
TRANSPORT_147_JOINTS = [-0.410293, 0.015766, -0.474824, -1.927142, 0.132943, 1.780006, 0.595233]  # t=147
TRANSPORT_149_JOINTS = [-0.368719, -0.046368, -0.479277, -2.002443, 0.110073, 1.819447, 0.638471]  # t=149
TRANSPORT_151_JOINTS = [-0.329769, -0.093501, -0.481195, -2.062727, 0.093438, 1.861690, 0.680742]  # t=151
TRANSPORT_153_JOINTS = [-0.293125, -0.123470, -0.479670, -2.107202, 0.083959, 1.904810, 0.722078]  # t=153
TRANSPORT_155_JOINTS = [-0.259446, -0.132203, -0.477572, -2.141374, 0.081989, 1.952888, 0.757928]  # t=155
TRANSPORT_157_JOINTS = [-0.229296, -0.122081, -0.475841, -2.173143, 0.088097, 2.008301, 0.784048]  # t=157
TRANSPORT_159_JOINTS = [-0.203269, -0.100906, -0.473851, -2.198551, 0.100411, 2.065781, 0.800460]  # t=159
TRANSPORT_160_JOINTS = [-0.192257, -0.087203, -0.473747, -2.207516, 0.107732, 2.093638, 0.804563]  # t=160
PLACE_162_JOINTS = [-0.174650, -0.056786, -0.475590, -2.216851, 0.124477, 2.141823, 0.804894]  # t=162
PLACE_163_JOINTS = [-0.167672, -0.041722, -0.476182, -2.217450, 0.133615, 2.160329, 0.802705]  # t=163
PLACE_164_JOINTS = [-0.161878, -0.028677, -0.476500, -2.215345, 0.142120, 2.173344, 0.800029]  # t=164
PLACE_166_JOINTS = [-0.153151, -0.006252, -0.475764, -2.204991, 0.156495, 2.188094, 0.794774]  # t=166
PLACE_168_JOINTS = [-0.147965, 0.010191, -0.474712, -2.191089, 0.166139, 2.189145, 0.788045]  # t=168
PLACE_170_JOINTS = [-0.146187, 0.018868, -0.475277, -2.179877, 0.170512, 2.181699, 0.779651]  # t=170
PLACE_172_JOINTS = [-0.146373, 0.022487, -0.475759, -2.173057, 0.174029, 2.175534, 0.768720]  # t=172
PLACE_174_JOINTS = [-0.148161, 0.019845, -0.478287, -2.172248, 0.178464, 2.171791, 0.751780]  # t=174
PLACE_176_JOINTS = [-0.150878, 0.010530, -0.482771, -2.178551, 0.185614, 2.172967, 0.728589]  # t=176
PLACE_178_JOINTS = [-0.153476, -0.002760, -0.487549, -2.191009, 0.197497, 2.182924, 0.703179]  # t=178
PLACE_180_JOINTS = [-0.155614, -0.019214, -0.492896, -2.208763, 0.212550, 2.199446, 0.674629]  # t=180
PLACE_182_JOINTS = [-0.157673, -0.042860, -0.501081, -2.232493, 0.231523, 2.219564, 0.640464]  # t=182
PLACE_184_JOINTS = [-0.158473, -0.069138, -0.509703, -2.261475, 0.261344, 2.252750, 0.598501]  # t=184
PLACE_186_JOINTS = [-0.156848, -0.085578, -0.515461, -2.292613, 0.297457, 2.298464, 0.552977]  # t=186
PLACE_188_JOINTS = [-0.153648, -0.087806, -0.519165, -2.321115, 0.316522, 2.336766, 0.512594]  # t=188
PLACE_190_JOINTS = [-0.149721, -0.075801, -0.523546, -2.337335, 0.333526, 2.365826, 0.462455]  # t=190
PLACE_192_JOINTS = [-0.146254, -0.048288, -0.530490, -2.340059, 0.362405, 2.388548, 0.394100]  # t=192
PLACE_194_JOINTS = [-0.140793, -0.014421, -0.525248, -2.320075, 0.396199, 2.390628, 0.335439]  # t=194
PLACE_196_JOINTS = [-0.137659, 0.012376, -0.517882, -2.294712, 0.415059, 2.367375, 0.284923]  # t=196
PLACE_198_JOINTS = [-0.139021, 0.028787, -0.516173, -2.273240, 0.428959, 2.337977, 0.212813]  # t=198
PLACE_199_JOINTS = [-0.140636, 0.036895, -0.515461, -2.263538, 0.438561, 2.328740, 0.167135]  # t=199
PLACE_200_JOINTS = [-0.142743, 0.043259, -0.514715, -2.255725, 0.449553, 2.320391, 0.115892]  # t=200
PLACE_202_JOINTS = [-0.149265, 0.043359, -0.516969, -2.247732, 0.477876, 2.297442, 0.000846]  # t=202
PLACE_204_JOINTS = [-0.158087, 0.032074, -0.524612, -2.250449, 0.516771, 2.274081, -0.128883]  # t=204
RELEASE_POSE_204_JOINTS = [-0.158087, 0.032074, -0.524612, -2.250449, 0.516771, 2.274081, -0.128883]  # t=204
RETRACT_207_JOINTS = [-0.171551, 0.000371, -0.543277, -2.266790, 0.578583, 2.242458, -0.334314]  # t=207
RETRACT_210_JOINTS = [-0.182509, -0.048035, -0.571633, -2.290541, 0.637924, 2.200724, -0.540127]  # t=210
RETRACT_212_JOINTS = [-0.186946, -0.087379, -0.594384, -2.300589, 0.661666, 2.159935, -0.650597]  # t=212
RETRACT_213_JOINTS = [-0.187847, -0.108226, -0.605307, -2.300873, 0.665574, 2.136095, -0.689391]  # t=213
RETRACT_216_JOINTS = [-0.186517, -0.176143, -0.638312, -2.287607, 0.648910, 2.057096, -0.751537]  # t=216
RETRACT_219_JOINTS = [-0.182742, -0.257018, -0.681763, -2.275827, 0.613176, 1.981591, -0.771756]  # t=219
RETRACT_220_JOINTS = [-0.181382, -0.287882, -0.699684, -2.276668, 0.601058, 1.961720, -0.776146]  # t=220
RETRACT_222_JOINTS = [-0.178410, -0.349816, -0.741778, -2.286700, 0.572849, 1.935256, -0.787111]  # t=222
RETRACT_224_JOINTS = [-0.173492, -0.406992, -0.792359, -2.302536, 0.546118, 1.921772, -0.804746]  # t=224
RETRACT_225_JOINTS = [-0.169384, -0.432726, -0.818796, -2.310446, 0.535648, 1.918719, -0.814587]  # t=225
RETRACT_228_JOINTS = [-0.150062, -0.505994, -0.900072, -2.334680, 0.525338, 1.915240, -0.861252]  # t=228
RETRACT_231_JOINTS = [-0.125851, -0.579580, -0.977615, -2.349797, 0.514836, 1.907509, -0.904092]  # t=231
RETRACT_234_JOINTS = [-0.091304, -0.630211, -1.030752, -2.362471, 0.477955, 1.927039, -0.906370]  # t=234
RETRACT_237_JOINTS = [-0.053709, -0.672496, -1.074843, -2.360546, 0.433483, 1.939101, -0.887312]  # t=237
RETRACT_240_JOINTS = [-0.016426, -0.711477, -1.112759, -2.353070, 0.388285, 1.945200, -0.860533]  # t=240
RETRACT_243_JOINTS = [0.020853, -0.746813, -1.148917, -2.341426, 0.348200, 1.948308, -0.831000]  # t=243
RETRACT_246_JOINTS = [0.058153, -0.778230, -1.184464, -2.323670, 0.307972, 1.950821, -0.806235]  # t=246
RETRACT_249_JOINTS = [0.095791, -0.806941, -1.218852, -2.301289, 0.268268, 1.952542, -0.784848]  # t=249
RETRACT_251_JOINTS = [0.121301, -0.825146, -1.241665, -2.283829, 0.242654, 1.951418, -0.771544]  # t=251
APPROACH_000_JOINTS = [-0.008776, -1.053450, -0.007885, -2.280536, 0.030928, 1.524001, 0.744791]  # t=1

# Phase-level helper functions keep the open-loop policy readable while preserving
# the exact primitive execution order used at runtime.

def move_to_pregrasp():
    """Coarse approach into the pregrasp corridor."""
    moveJoint(APPROACH_000_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_005_JOINTS, input_type='joint', steps=4, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_007_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_010_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_015_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_020_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_024_JOINTS, input_type='joint', steps=4, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_025_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_030_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_035_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_037_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_040_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_045_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_050_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_055_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_056_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_060_JOINTS, input_type='joint', steps=4, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_065_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_068_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_070_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_075_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_080_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_082_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_085_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_086_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_090_JOINTS, input_type='joint', steps=4, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_095_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)

def execute_grasp_approach():
    """Final Cartesian descent into grasp alignment."""
    moveJoint(DESCEND_096_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_097_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_098_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_099_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_100_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_101_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_102_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)

def close_gripper_on_object():
    """Close the gripper and let the grasp settle briefly."""
    moveJoint(GRASP_104_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(GRASP_107_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(GRASP_108_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    wait(duration=0.05, hold_target=GRASP_HOLD_108_JOINTS, input_type='joint', gripper=-0.3)
    grasp(hold_target=GRASP_HOLD_108_JOINTS, input_type='joint', close_steps=1, settle_steps=0, gripper=1.0, require_contact_count=4)
    wait(duration=0.05, hold_target=GRASP_HOLD_108_JOINTS, input_type='joint', gripper=1.0)

def lift_object():
    """Lift the grasped object clear of the counter."""
    moveJoint(LIFT_109_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_110_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_111_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_112_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_113_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_114_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_115_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_116_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_117_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_118_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_119_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_120_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_121_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_122_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_123_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)

def transport_to_place():
    """Carry the object through the curved transport corridor."""
    moveJoint(TRANSPORT_125_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_127_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_129_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_131_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_133_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_135_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_137_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_139_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_141_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_143_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_145_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_147_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_149_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_151_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_153_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_155_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_157_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_159_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(TRANSPORT_160_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)

def prepare_release():
    """Set the object into the receptacle and stabilize before release."""
    moveJoint(PLACE_162_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_163_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_164_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_166_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_168_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_170_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_172_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_174_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_176_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_178_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_180_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_182_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_184_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_186_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_188_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_190_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_192_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_194_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_196_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_198_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_199_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_200_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_202_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_204_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    wait(duration=0.05, hold_target=RELEASE_POSE_204_JOINTS, input_type='joint', gripper=-1.0)

def release_object():
    """Open the gripper and hold briefly to avoid disturbing the placement."""
    release(hold_target=RELEASE_POSE_204_JOINTS, input_type='joint', open_steps=1, settle_steps=0, gripper=-1.0)
    wait(duration=0.05, hold_target=RELEASE_POSE_204_JOINTS, input_type='joint', gripper=-1.0)

def retreat_after_release():
    """Retreat away from the placed object without clipping it."""
    moveJoint(RETRACT_207_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_210_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_212_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_213_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_216_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_219_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_220_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_222_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_224_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_225_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_228_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_231_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_234_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_237_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_240_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_243_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_246_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_249_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_251_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)

move_to_pregrasp()
execute_grasp_approach()
close_gripper_on_object()
lift_object()
transport_to_place()
prepare_release()
release_object()
retreat_after_release()

# Fitting strategy:
# - adaptive per-phase waypoint selection on EE position + quaternion error
# - tight tolerances near descend / lift / place, looser tolerances in transport
# - optional moveC / moveA / segmented moveLinear chains / moveActionSequence when a segment is better represented by a smooth or constrained path
# - GT used only during generation; runtime execution uses this saved policy plus scene artifact

Pick the onion from the plate and place it in the pan.

container

all pan receptacle cookware pots_and_pans

all plate receptacle container container_set2


# Open-loop trajectory-fit action2code policy generated from the RoboCasa GT EE trajectory
# Task: PickPlaceCounterToToasterOven
# Episode: episode_000000

from primitives import moveJoint, moveLinear, moveC, moveA, moveWholeBodyPath, moveActionSequence, grasp, release, wait

SCENE_ARTIFACT = '../../../artifacts/20260324/PickPlaceCounterToToasterOven/20260324_205326_pick-place-counter-to-toaster-oven_episode_000000_action2code-open-loop-joint_initial-scene.json'
POLICY_METADATA = {
    'policy_kind': 'open_loop_joint',
    'policy_variant': 'open-loop-joint',
    'task_name': 'PickPlaceCounterToToasterOven',
    'episode_id': 'episode_000000',
    'scene_artifact_path': '../../../artifacts/20260324/PickPlaceCounterToToasterOven/20260324_205326_pick-place-counter-to-toaster-oven_episode_000000_action2code-open-loop-joint_initial-scene.json',
    'fitting_summary_path': '../../../artifacts/20260324/PickPlaceCounterToToasterOven/20260324_205326_pick-place-counter-to-toaster-oven_episode_000000_action2code-open-loop-joint_fitting-summary.json',
    'extracted_pose_metadata_path': '../../../artifacts/20260324/PickPlaceCounterToToasterOven/20260324_205326_pick-place-counter-to-toaster-oven_episode_000000_action2code-open-loop-joint_extracted-pose-metadata.json',
    'stable_grasp_contact_t': 78,
    'stable_release_contact_loss_t': 190,
    'uses_moveC': False,
    'controller_mode': 'whole_body_ik',
}

OBJ_POSE_T0 = pose(x=3.897510, y=-0.817711, z=0.938869, qw=0.961859, qx=-0.017658, qy=-0.052518, qz=-0.267877)
GOAL_RECEPTACLE_POSE = pose(x=3.896720, y=-0.819733, z=0.930654, qw=0.999785, qx=-0.000143, qy=-0.000466, qz=-0.020716)

APPROACH_003_JOINTS = [-0.008768, -1.046349, -0.023816, -2.260687, 0.042563, 1.536417, 0.714462]  # t=3
APPROACH_006_JOINTS = [-0.014274, -1.130902, -0.050993, -2.263930, 0.019785, 1.460560, 0.697882]  # t=6
APPROACH_009_JOINTS = [-0.026252, -1.229555, -0.117655, -2.292857, -0.036740, 1.391466, 0.676778]  # t=9
APPROACH_012_JOINTS = [-0.040179, -1.312174, -0.199065, -2.347486, -0.112687, 1.362082, 0.639622]  # t=12
APPROACH_015_JOINTS = [-0.054081, -1.349230, -0.287823, -2.416428, -0.198701, 1.371918, 0.605578]  # t=15
APPROACH_016_JOINTS = [-0.058903, -1.352774, -0.319801, -2.435532, -0.226117, 1.378634, 0.598025]  # t=16
APPROACH_018_JOINTS = [-0.068697, -1.350577, -0.387815, -2.464463, -0.279212, 1.394838, 0.581914]  # t=18
APPROACH_021_JOINTS = [-0.082525, -1.327028, -0.486418, -2.496731, -0.361531, 1.447711, 0.565256]  # t=21
APPROACH_024_JOINTS = [-0.090560, -1.272563, -0.567924, -2.523095, -0.435442, 1.548425, 0.581030]  # t=24
APPROACH_027_JOINTS = [-0.088183, -1.181964, -0.641554, -2.538593, -0.492206, 1.657898, 0.617608]  # t=27
APPROACH_028_JOINTS = [-0.083517, -1.142288, -0.665022, -2.538535, -0.504160, 1.691740, 0.630331]  # t=28
APPROACH_030_JOINTS = [-0.066191, -1.051304, -0.705537, -2.532158, -0.506631, 1.751523, 0.651125]  # t=30
APPROACH_033_JOINTS = [-0.029063, -0.906315, -0.742405, -2.503883, -0.484563, 1.825257, 0.663810]  # t=33
APPROACH_036_JOINTS = [0.007820, -0.763927, -0.765899, -2.462018, -0.458481, 1.868125, 0.667504]  # t=36
APPROACH_039_JOINTS = [0.040594, -0.630352, -0.786778, -2.422805, -0.411710, 1.879811, 0.657105]  # t=39
APPROACH_042_JOINTS = [0.067743, -0.498765, -0.827139, -2.374204, -0.346525, 1.896714, 0.611366]  # t=42
APPROACH_045_JOINTS = [0.084266, -0.382523, -0.870864, -2.329685, -0.266839, 1.916481, 0.539635]  # t=45
APPROACH_048_JOINTS = [0.089738, -0.279633, -0.907136, -2.288110, -0.179607, 1.931544, 0.455868]  # t=48
DESCEND_049_JOINTS = [0.089162, -0.248839, -0.912610, -2.274010, -0.153481, 1.932153, 0.432040]  # t=49
DESCEND_050_JOINTS = [0.087632, -0.219344, -0.913963, -2.260889, -0.128518, 1.933265, 0.411947]  # t=50
DESCEND_052_JOINTS = [0.080674, -0.164613, -0.908007, -2.235294, -0.082951, 1.931755, 0.380542]  # t=52
DESCEND_054_JOINTS = [0.067594, -0.114354, -0.894845, -2.211519, -0.045540, 1.925474, 0.356952]  # t=54
DESCEND_055_JOINTS = [0.058413, -0.091985, -0.887470, -2.201601, -0.028841, 1.921869, 0.345298]  # t=55
DESCEND_056_JOINTS = [0.047625, -0.071575, -0.879825, -2.193816, -0.013148, 1.919861, 0.332987]  # t=56
DESCEND_058_JOINTS = [0.023107, -0.032700, -0.860556, -2.186117, 0.012597, 1.920100, 0.312090]  # t=58
DESCEND_060_JOINTS = [-0.004126, 0.006341, -0.836405, -2.183906, 0.030830, 1.927401, 0.297965]  # t=60
DESCEND_062_JOINTS = [-0.033421, 0.042750, -0.809670, -2.183921, 0.049019, 1.940065, 0.284283]  # t=62
DESCEND_063_JOINTS = [-0.048254, 0.058076, -0.794944, -2.184142, 0.058061, 1.944413, 0.278208]  # t=63
DESCEND_064_JOINTS = [-0.062831, 0.070846, -0.779093, -2.184909, 0.066478, 1.947444, 0.273774]  # t=64
DESCEND_066_JOINTS = [-0.090377, 0.088486, -0.744664, -2.190189, 0.081536, 1.952215, 0.269958]  # t=66
DESCEND_067_JOINTS = [-0.103277, 0.093181, -0.727748, -2.193316, 0.085687, 1.954562, 0.270894]  # t=67
DESCEND_068_JOINTS = [-0.115975, 0.095845, -0.713180, -2.194768, 0.086454, 1.956940, 0.272339]  # t=68
DESCEND_069_JOINTS = [-0.128134, 0.095918, -0.700481, -2.194257, 0.084417, 1.956895, 0.274751]  # t=69
DESCEND_070_JOINTS = [-0.139382, 0.095490, -0.688337, -2.194105, 0.081815, 1.957105, 0.277791]  # t=70
DESCEND_071_JOINTS = [-0.149735, 0.094858, -0.676977, -2.194238, 0.079000, 1.957665, 0.281025]  # t=71
DESCEND_072_JOINTS = [-0.159218, 0.094152, -0.666537, -2.194592, 0.076188, 1.958574, 0.284117]  # t=72
DESCEND_074_JOINTS = [-0.175769, 0.092390, -0.648881, -2.195200, 0.071073, 1.960224, 0.288631]  # t=74
DESCEND_076_JOINTS = [-0.189136, 0.088297, -0.635075, -2.195909, 0.066290, 1.957773, 0.291936]  # t=76
DESCEND_077_JOINTS = [-0.194792, 0.084242, -0.630003, -2.196496, 0.062618, 1.954054, 0.293001]  # t=77
GRASP_HOLD_078_JOINTS = [-0.199577, 0.079049, -0.625256, -2.198286, 0.058738, 1.949239, 0.293688]  # t=78
LIFT_079_JOINTS = [-0.203588, 0.073129, -0.620990, -2.202061, 0.054486, 1.944704, 0.294310]  # t=79
LIFT_080_JOINTS = [-0.207041, 0.066604, -0.617779, -2.207264, 0.049602, 1.941515, 0.294767]  # t=80
LIFT_081_JOINTS = [-0.210007, 0.059192, -0.615723, -2.213698, 0.044141, 1.938824, 0.295085]  # t=81
LIFT_082_JOINTS = [-0.212553, 0.050889, -0.614886, -2.221034, 0.037975, 1.936662, 0.295233]  # t=82
LIFT_083_JOINTS = [-0.215576, 0.037168, -0.618220, -2.227917, 0.030453, 1.930119, 0.292084]  # t=83
LIFT_084_JOINTS = [-0.219183, 0.017089, -0.626008, -2.235406, 0.021569, 1.920331, 0.284654]  # t=84
LIFT_085_JOINTS = [-0.223201, -0.010566, -0.637654, -2.243495, 0.013258, 1.907859, 0.273525]  # t=85
LIFT_086_JOINTS = [-0.227497, -0.045993, -0.652737, -2.252520, 0.005671, 1.894257, 0.258776]  # t=86
LIFT_087_JOINTS = [-0.231788, -0.087401, -0.670263, -2.263098, -0.002096, 1.881318, 0.241601]  # t=87
LIFT_088_JOINTS = [-0.235925, -0.133931, -0.689478, -2.274540, -0.011113, 1.868148, 0.223660]  # t=88
PLACE_090_JOINTS = [-0.242631, -0.237120, -0.727690, -2.295507, -0.035117, 1.838839, 0.192954]  # t=90
PLACE_092_JOINTS = [-0.247219, -0.348182, -0.761259, -2.310515, -0.069507, 1.798543, 0.171491]  # t=92
PLACE_094_JOINTS = [-0.252037, -0.468766, -0.791158, -2.318228, -0.104043, 1.747412, 0.154053]  # t=94
PLACE_096_JOINTS = [-0.257949, -0.594031, -0.813005, -2.321437, -0.134951, 1.690022, 0.147097]  # t=96
PLACE_098_JOINTS = [-0.266067, -0.720800, -0.822724, -2.321668, -0.160141, 1.626982, 0.152333]  # t=98
PLACE_100_JOINTS = [-0.277214, -0.847993, -0.817399, -2.320569, -0.174854, 1.557668, 0.167158]  # t=100
PLACE_102_JOINTS = [-0.291807, -0.973480, -0.801128, -2.320533, -0.177832, 1.489649, 0.188421]  # t=102
PLACE_104_JOINTS = [-0.308036, -1.093042, -0.774051, -2.322182, -0.168826, 1.424916, 0.217053]  # t=104
PLACE_106_JOINTS = [-0.325009, -1.204241, -0.734709, -2.324888, -0.150541, 1.361898, 0.261778]  # t=106
PLACE_108_JOINTS = [-0.341270, -1.305192, -0.684942, -2.326385, -0.124252, 1.303422, 0.327206]  # t=108
PLACE_110_JOINTS = [-0.353742, -1.392644, -0.630262, -2.322892, -0.086103, 1.253490, 0.412962]  # t=110
PLACE_112_JOINTS = [-0.362138, -1.466967, -0.578341, -2.313804, -0.039552, 1.210388, 0.518703]  # t=112
PLACE_114_JOINTS = [-0.366171, -1.529025, -0.532513, -2.309420, 0.013022, 1.175256, 0.639931]  # t=114
PLACE_116_JOINTS = [-0.366225, -1.581717, -0.480202, -2.300651, 0.060709, 1.151421, 0.761303]  # t=116
PLACE_118_JOINTS = [-0.362931, -1.624710, -0.421420, -2.286933, 0.108888, 1.140183, 0.889137]  # t=118
PLACE_120_JOINTS = [-0.356168, -1.658937, -0.360793, -2.267467, 0.156209, 1.133402, 1.019681]  # t=120
PLACE_122_JOINTS = [-0.346192, -1.683744, -0.295463, -2.248814, 0.197639, 1.137981, 1.148000]  # t=122
PLACE_124_JOINTS = [-0.333629, -1.701164, -0.224360, -2.232323, 0.228991, 1.148301, 1.270038]  # t=124
PLACE_126_JOINTS = [-0.319475, -1.714721, -0.148044, -2.218014, 0.246961, 1.160083, 1.384704]  # t=126
PLACE_128_JOINTS = [-0.305373, -1.726649, -0.065295, -2.218978, 0.256466, 1.184010, 1.499593]  # t=128
PLACE_130_JOINTS = [-0.289823, -1.732801, 0.019649, -2.235508, 0.270575, 1.225310, 1.605735]  # t=130
PLACE_132_JOINTS = [-0.271801, -1.731311, 0.094614, -2.257775, 0.278262, 1.274105, 1.697776]  # t=132
PLACE_134_JOINTS = [-0.250473, -1.731464, 0.145652, -2.288080, 0.279701, 1.312537, 1.780509]  # t=134
PLACE_136_JOINTS = [-0.225183, -1.746316, 0.162032, -2.337589, 0.295801, 1.345600, 1.865172]  # t=136
PLACE_138_JOINTS = [-0.199426, -1.764158, 0.173880, -2.401289, 0.316345, 1.395970, 1.935116]  # t=138
PLACE_140_JOINTS = [-0.175042, -1.762905, 0.188210, -2.456904, 0.335907, 1.443331, 1.998219]  # t=140
PLACE_142_JOINTS = [-0.152288, -1.762846, 0.202226, -2.515798, 0.362383, 1.489687, 2.048952]  # t=142
PLACE_144_JOINTS = [-0.131931, -1.761432, 0.217538, -2.579339, 0.391898, 1.545074, 2.080621]  # t=144
PLACE_146_JOINTS = [-0.115013, -1.751176, 0.237925, -2.638085, 0.414824, 1.602384, 2.094477]  # t=146
PLACE_148_JOINTS = [-0.100447, -1.735146, 0.264064, -2.683282, 0.428978, 1.649637, 2.100813]  # t=148
PLACE_150_JOINTS = [-0.086083, -1.721229, 0.292720, -2.722692, 0.445157, 1.690751, 2.106465]  # t=150
PLACE_152_JOINTS = [-0.071365, -1.711774, 0.324289, -2.766101, 0.464602, 1.737424, 2.110271]  # t=152
PLACE_154_JOINTS = [-0.056142, -1.705121, 0.355937, -2.813742, 0.485196, 1.788318, 2.111561]  # t=154
PLACE_156_JOINTS = [-0.040253, -1.699018, 0.387234, -2.864956, 0.507138, 1.843222, 2.110619]  # t=156
PLACE_158_JOINTS = [-0.023636, -1.690661, 0.418598, -2.915745, 0.531630, 1.903267, 2.107533]  # t=158
PLACE_160_JOINTS = [-0.004641, -1.688723, 0.448653, -2.959928, 0.554034, 1.963657, 2.104867]  # t=160
PLACE_162_JOINTS = [0.017875, -1.693259, 0.481131, -3.004430, 0.578172, 2.020365, 2.104993]  # t=162
PLACE_164_JOINTS = [0.041970, -1.691379, 0.518647, -3.051396, 0.609526, 2.081183, 2.104874]  # t=164
PLACE_166_JOINTS = [0.062510, -1.684527, 0.547983, -3.073214, 0.628217, 2.128419, 2.113243]  # t=166
PLACE_168_JOINTS = [0.070446, -1.650885, 0.572805, -3.071937, 0.635863, 2.178261, 2.130918]  # t=168
PLACE_170_JOINTS = [0.073441, -1.610431, 0.584008, -3.071841, 0.635803, 2.228762, 2.141758]  # t=170
PLACE_172_JOINTS = [0.071967, -1.556147, 0.591724, -3.071830, 0.639367, 2.294794, 2.143874]  # t=172
PLACE_174_JOINTS = [0.066846, -1.490348, 0.595955, -3.070838, 0.645228, 2.369755, 2.138112]  # t=174
PLACE_176_JOINTS = [0.059959, -1.417136, 0.598184, -3.068151, 0.653138, 2.444855, 2.126440]  # t=176
PLACE_178_JOINTS = [0.053234, -1.327334, 0.609085, -3.068512, 0.671620, 2.519757, 2.111661]  # t=178
PLACE_180_JOINTS = [0.043150, -1.224793, 0.619158, -3.060931, 0.692328, 2.604997, 2.086491]  # t=180
PLACE_181_JOINTS = [0.031960, -1.169736, 0.613571, -3.043726, 0.691723, 2.648758, 2.065093]  # t=181
PLACE_182_JOINTS = [0.018459, -1.111249, 0.605644, -3.022587, 0.687616, 2.686156, 2.044363]  # t=182
PLACE_184_JOINTS = [-0.008514, -1.003718, 0.588387, -2.977544, 0.673093, 2.738488, 2.010494]  # t=184
PLACE_185_JOINTS = [-0.020577, -0.956545, 0.581248, -2.956251, 0.664141, 2.758663, 1.998116]  # t=185
RELEASE_POSE_185_JOINTS = [-0.020577, -0.956545, 0.581248, -2.956251, 0.664141, 2.758663, 1.998116]  # t=185
RETRACT_190_JOINTS = [-0.051305, -0.825250, 0.557670, -2.890628, 0.619842, 2.802639, 1.975560]  # t=190
RETRACT_191_JOINTS = [-0.049935, -0.824815, 0.554772, -2.889287, 0.613966, 2.799828, 1.978173]  # t=191
RETRACT_192_JOINTS = [-0.045879, -0.834073, 0.552239, -2.891820, 0.609526, 2.792435, 1.982586]  # t=192
RETRACT_194_JOINTS = [-0.030828, -0.877574, 0.549472, -2.909311, 0.604768, 2.772349, 1.994601]  # t=194
RETRACT_195_JOINTS = [-0.019762, -0.910405, 0.550324, -2.924197, 0.604949, 2.763798, 2.001803]  # t=195
RETRACT_196_JOINTS = [-0.005605, -0.952221, 0.553109, -2.943910, 0.606918, 2.755495, 2.010118]  # t=196
RETRACT_198_JOINTS = [0.036661, -1.077803, 0.567337, -3.003460, 0.616745, 2.738391, 2.033391]  # t=198
RETRACT_200_JOINTS = [0.092273, -1.231789, 0.597756, -3.076595, 0.632403, 2.730074, 2.067492]  # t=200
RETRACT_201_JOINTS = [0.114117, -1.309536, 0.616097, -3.074294, 0.631382, 2.695303, 2.097642]  # t=201
RETRACT_202_JOINTS = [0.130578, -1.392422, 0.632726, -3.072516, 0.618844, 2.643576, 2.136584]  # t=202
RETRACT_204_JOINTS = [0.161309, -1.559710, 0.649578, -3.072075, 0.585588, 2.545057, 2.213223]  # t=204
RETRACT_206_JOINTS = [0.188224, -1.713237, 0.642735, -3.071889, 0.544600, 2.474674, 2.270413]  # t=206
RETRACT_207_JOINTS = [0.200895, -1.771745, 0.633358, -3.068769, 0.522580, 2.446933, 2.292656]  # t=207
RETRACT_208_JOINTS = [0.209789, -1.766013, 0.604973, -3.040499, 0.478290, 2.431890, 2.321101]  # t=208
RETRACT_210_JOINTS = [0.217601, -1.763061, 0.521113, -2.960826, 0.360905, 2.373505, 2.379235]  # t=210
RETRACT_212_JOINTS = [0.215088, -1.762857, 0.457820, -2.879472, 0.283977, 2.313712, 2.416336]  # t=212
RETRACT_214_JOINTS = [0.202272, -1.762382, 0.409652, -2.808230, 0.246804, 2.268977, 2.430627]  # t=214
RETRACT_215_JOINTS = [0.192249, -1.760818, 0.388042, -2.776890, 0.237133, 2.254444, 2.431693]  # t=215
RETRACT_216_JOINTS = [0.180671, -1.756799, 0.365855, -2.747594, 0.233261, 2.240066, 2.430575]  # t=216
RETRACT_218_JOINTS = [0.154756, -1.746477, 0.317536, -2.686903, 0.233266, 2.203453, 2.423724]  # t=218
RETRACT_220_JOINTS = [0.127143, -1.733159, 0.260461, -2.620530, 0.234686, 2.145478, 2.409365]  # t=220
RETRACT_222_JOINTS = [0.098591, -1.706756, 0.199367, -2.546068, 0.236618, 2.067488, 2.390766]  # t=222
RETRACT_223_JOINTS = [0.084490, -1.686613, 0.169825, -2.507602, 0.239540, 2.018345, 2.382586]  # t=223
RETRACT_224_JOINTS = [0.070465, -1.659416, 0.140688, -2.469864, 0.244622, 1.965308, 2.377330]  # t=224
RETRACT_225_JOINTS = [0.057259, -1.626808, 0.110982, -2.432830, 0.252367, 1.906015, 2.373305]  # t=225
APPROACH_000_JOINTS = [-0.007579, -1.023571, -0.021337, -2.264957, 0.044880, 1.570495, 0.715520]  # t=1

# Phase-level helper functions keep the open-loop policy readable while preserving
# the exact primitive execution order used at runtime.

def move_to_pregrasp():
    """Coarse approach into the pregrasp corridor."""
    moveJoint(APPROACH_000_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_003_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_006_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_009_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_012_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_015_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_016_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_018_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_021_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_024_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_027_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_028_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_030_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_033_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_036_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_039_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_042_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_045_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)
    moveJoint(APPROACH_048_JOINTS, input_type='joint', steps=3, settle_steps=0, gripper=-1.000)

def execute_grasp_approach():
    """Final Cartesian descent into grasp alignment."""
    moveJoint(DESCEND_049_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_050_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_052_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_054_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_055_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_056_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_058_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_060_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_062_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_063_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_064_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_066_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_067_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_068_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_069_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(DESCEND_070_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_071_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_072_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_074_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_076_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(DESCEND_077_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)

def close_gripper_on_object():
    """Close the gripper and let the grasp settle briefly."""
    grasp(hold_target=GRASP_HOLD_078_JOINTS, input_type='joint', close_steps=1, settle_steps=0, gripper=1.0, require_contact_count=4)
    wait(duration=0.05, hold_target=GRASP_HOLD_078_JOINTS, input_type='joint', gripper=1.0)

def lift_object():
    """Lift the grasped object clear of the counter."""
    moveJoint(LIFT_079_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_080_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_081_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_082_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_083_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_084_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_085_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_086_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_087_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)
    moveJoint(LIFT_088_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=1.000)

def prepare_release():
    """Set the object into the receptacle and stabilize before release."""
    moveJoint(PLACE_090_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_092_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_094_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_096_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_098_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_100_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_102_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_104_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_106_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_108_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_110_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_112_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_114_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_116_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_118_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_120_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_122_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_124_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_126_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_128_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_130_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_132_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_134_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_136_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_138_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_140_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_142_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_144_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_146_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_148_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_150_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_152_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_154_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_156_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_158_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_160_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_162_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_164_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_166_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_168_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_170_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_172_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_174_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_176_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_178_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_180_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=1.000)
    moveJoint(PLACE_181_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_182_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_184_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(PLACE_185_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    wait(duration=0.05, hold_target=RELEASE_POSE_185_JOINTS, input_type='joint', gripper=-1.0)

def release_object():
    """Open the gripper and hold briefly to avoid disturbing the placement."""
    release(hold_target=RELEASE_POSE_185_JOINTS, input_type='joint', open_steps=1, settle_steps=0, gripper=-1.0)
    wait(duration=0.05, hold_target=RELEASE_POSE_185_JOINTS, input_type='joint', gripper=-1.0)

def retreat_after_release():
    """Retreat away from the placed object without clipping it."""
    moveJoint(RETRACT_190_JOINTS, input_type='joint', steps=5, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_191_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_192_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_194_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_195_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_196_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_198_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_200_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_201_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_202_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_204_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_206_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_207_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_208_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_210_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_212_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_214_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_215_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_216_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_218_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_220_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_222_JOINTS, input_type='joint', steps=2, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_223_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_224_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)
    moveJoint(RETRACT_225_JOINTS, input_type='joint', steps=1, settle_steps=0, gripper=-1.000)

move_to_pregrasp()
execute_grasp_approach()
close_gripper_on_object()
lift_object()
prepare_release()
release_object()
retreat_after_release()

# Fitting strategy:
# - adaptive per-phase waypoint selection on EE position + quaternion error
# - tight tolerances near descend / lift / place, looser tolerances in transport
# - optional moveC / moveA / segmented moveLinear chains / moveActionSequence when a segment is better represented by a smooth or constrained path
# - GT used only during generation; runtime execution uses this saved policy plus scene artifact

Place the baguette on the rack of the toaster oven.