MCPcopy Create free account
hub / github.com/TeleHuman/TextOp / run_simulator

Function run_simulator

TextOpTracker/scripts/replay_npz.py:65–100  ·  view source on GitHub ↗
(sim: sim_utils.SimulationContext, scene: InteractiveScene)

Source from the content-addressed store, hash-verified

63
64
65def run_simulator(sim: sim_utils.SimulationContext, scene: InteractiveScene):
66 # Extract scene entities
67 robot: Articulation = scene["robot"]
68 # Define simulation stepping
69 sim_dt = sim.get_physics_dt()
70
71 motion_file = str(Path("./artifacts") / Path(args_cli.motion_file) / "motion.npz")
72
73 motion = MotionLoader(
74 motion_file,
75 torch.tensor([0], dtype=torch.long, device=sim.device),
76 sim.device,
77 )
78 time_steps = torch.zeros(scene.num_envs, dtype=torch.long, device=sim.device)
79
80 # Simulation loop
81 while simulation_app.is_running():
82 time_steps += 1
83 reset_ids = time_steps >= motion.time_step_total
84 time_steps[reset_ids] = 0
85
86 root_states = robot.data.default_root_state.clone()
87 root_states[:, :3] = motion.body_pos_w[time_steps][:, 0] + scene.env_origins[:, None, :]
88 root_states[:, 3:7] = motion.body_quat_w[time_steps][:, 0]
89 root_states[:, 7:10] = motion.body_lin_vel_w[time_steps][:, 0]
90 root_states[:, 10:] = motion.body_ang_vel_w[time_steps][:, 0]
91
92 robot.write_root_state_to_sim(root_states)
93 robot.write_joint_state_to_sim(motion.joint_pos[time_steps], motion.joint_vel[time_steps])
94 scene.write_data_to_sim()
95 sim.render() # We don't want physic (sim.step())
96 scene.update(sim_dt)
97
98 pos_lookat = root_states[0, :3].cpu().numpy()
99 if time_steps < 10:
100 sim.set_camera_view(pos_lookat + np.array([2.0, 2.0, 0.5]), pos_lookat)
101
102
103def main():

Callers 1

mainFunction · 0.70

Calls 2

MotionLoaderClass · 0.90
updateMethod · 0.45

Tested by

no test coverage detected