Spaces:
Sleeping
Sleeping
This will make the black disc fly in toward the center from the tray’s corner as intended, with clean and controllable motion.
Browse files- tray_sim.py +15 -1
tray_sim.py
CHANGED
|
@@ -15,6 +15,19 @@ def run_tray_simulation(seed=0, num_objects=N_OBJECTS, azimuth=45, elevation=-25
|
|
| 15 |
model = mujoco.MjModel.from_xml_path(MODEL_PATH)
|
| 16 |
data = mujoco.MjData(model)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Object initialization
|
| 19 |
for i in range(num_objects):
|
| 20 |
obj_start = i * 7 # 7 DOF per free joint body
|
|
@@ -46,7 +59,8 @@ def run_tray_simulation(seed=0, num_objects=N_OBJECTS, azimuth=45, elevation=-25
|
|
| 46 |
for t in range(SIM_STEPS):
|
| 47 |
if t == PUSH_START_STEP:
|
| 48 |
# Activate pusher
|
| 49 |
-
data.qvel[pusher_vel_idx:pusher_vel_idx+3] = [-0.05, 0.05, 0.0] # toward center
|
|
|
|
| 50 |
|
| 51 |
mujoco.mj_step(model, data)
|
| 52 |
renderer.update_scene(data, camera=cam, scene_option=scene_option)
|
|
|
|
| 15 |
model = mujoco.MjModel.from_xml_path(MODEL_PATH)
|
| 16 |
data = mujoco.MjData(model)
|
| 17 |
|
| 18 |
+
# Pusher setup
|
| 19 |
+
pusher_pos = np.array([0.35, -0.35, 0.08]) # Slightly outside tray corner
|
| 20 |
+
pusher_quat = [1, 0, 0, 0]
|
| 21 |
+
data.qpos[pusher_idx:pusher_idx+3] = pusher_pos
|
| 22 |
+
data.qpos[pusher_idx+3:pusher_idx+7] = pusher_quat
|
| 23 |
+
|
| 24 |
+
# Compute velocity towards center
|
| 25 |
+
target = np.array([0.0, 0.0, 0.05])
|
| 26 |
+
direction = target - pusher_pos
|
| 27 |
+
direction[2] = 0.0
|
| 28 |
+
direction /= np.linalg.norm(direction)
|
| 29 |
+
push_velocity = 0.15 * direction # Adjust magnitude
|
| 30 |
+
|
| 31 |
# Object initialization
|
| 32 |
for i in range(num_objects):
|
| 33 |
obj_start = i * 7 # 7 DOF per free joint body
|
|
|
|
| 59 |
for t in range(SIM_STEPS):
|
| 60 |
if t == PUSH_START_STEP:
|
| 61 |
# Activate pusher
|
| 62 |
+
#data.qvel[pusher_vel_idx:pusher_vel_idx+3] = [-0.05, 0.05, 0.0] # toward center
|
| 63 |
+
data.qvel[pusher_vel_idx:pusher_vel_idx+3] = push_velocity # toward center
|
| 64 |
|
| 65 |
mujoco.mj_step(model, data)
|
| 66 |
renderer.update_scene(data, camera=cam, scene_option=scene_option)
|