16HOME_POSE = [0.0, 0.2618, 3.1416, -2.2689, 0.0, 0.9599, 1.5708]
31def build_scene(model_path: str) -> tuple[mjk.Scene, mjk.Robot]:
32 spec = mjk.SceneSpec()
35 spec.add_skybox =
True
36 robot_spec = mjk.RobotSpec()
37 robot_spec.path = model_path
38 spec.robots = [robot_spec]
39 scene = mjk.Scene.build(spec)
40 robot = mjk.Robot.from_scene(scene,
"base_link",
"bracelet_link")
46 resolution = mjk.VideoResolution.R1080p
47 for arg
in sys.argv[1:]:
48 if arg.endswith(
".mp4"):
50 elif arg
in RESOLUTIONS:
51 resolution = RESOLUTIONS[arg]
53 print(f
"Unknown argument '{arg}'; using 1080p", file=sys.stderr)
55 model_path = mjk.menagerie.model_path(
"kinova_gen3", env_var=
"MJ_KDL_MODEL")
60 robot.ctrl_mode = mjk.CtrlMode.TORQUE
61 robot.set_joint_pos(HOME_POSE, call_forward=
True)
63 robot.jnt_trq_cmd = list(robot.gravity_torques(GRAVITY_Z))
65 recorder = mjk.VideoRecorder.open_preset(scene, out_path, resolution, FPS)
67 recorder.set_free_camera(distance=1.8, azimuth=0.0, elevation=-20.0, lookat=(0.0, 0.0, 0.5))
69 total_steps = int(DURATION / scene.timestep())
70 steps_per_frame = max(1, int(1.0 / (FPS * scene.timestep())))
71 step_per_deg = 360.0 / total_steps
73 print(f
"Recording {DURATION} s to {out_path} ({total_steps} steps, {FPS} fps)...")
74 for step
in range(total_steps):
76 robot.jnt_trq_cmd = list(robot.gravity_torques(GRAVITY_Z))
78 if step % steps_per_frame == 0:
79 recorder.set_free_camera(
81 azimuth=math.fmod(step * step_per_deg, 360.0),
83 lookat=(0.0, 0.0, 0.5),
85 if not recorder.record_frame():
86 print(f
"record_frame() failed at step {step}", file=sys.stderr)
88 print(f
"Saved: {out_path}")
90 if recorder
is not None: