28static constexpr double kHomePose[7] = { 0.0, 0.2618, 3.1416, -2.2689, 0.0, 0.9599, 1.5708 };
44int main(
int argc,
char *argv[])
46 std::string outmp4 =
"sim.mp4";
48 for (
int i = 1; i < argc; ++i) {
49 std::string a(argv[i]);
50 if (a.size() >= 4 && a.substr(a.size() - 4) ==
".mp4")
53 res = parse_resolution(a);
64 r.
path = mjcf.c_str();
67 mjModel *model =
nullptr;
68 mjData *data =
nullptr;
70 std::cerr <<
"build_scene() failed\n";
76 std::cerr <<
"init_robot_from_mjcf() failed\n";
81 unsigned n =
static_cast<unsigned>(robot.
n_joints);
82 KDL::ChainDynParam dyn(robot.
chain, KDL::Vector(0.0, 0.0, sc.
gravity_z));
85 KDL::JntArray q_home(n);
86 for (
unsigned i = 0; i < n; ++i) q_home(i) = kHomePose[i];
91 KDL::JntArray q(n), g(n);
92 dyn.JntToGravity(q_home, g);
93 for (
unsigned i = 0; i < n; ++i) robot.
jnt_trq_cmd[i] = g(i);
98 std::cerr <<
"init_video_recorder() failed -- is EGL available and ffmpeg installed?\n";
105 vr.
cam.elevation = -20.0;
106 vr.
cam.distance = 1.8;
107 vr.
cam.lookat[2] = 0.5;
109 const int total_steps =
static_cast<int>(kDuration / model->opt.timestep);
110 const double step_per_deg = 360.0 / total_steps;
111 const int steps_per_frame = std::max(1,
static_cast<int>(1.0 / (kFps * model->opt.timestep)));
113 std::cout <<
"Recording " << kDuration <<
" s to " << outmp4 <<
" (" << total_steps
114 <<
" steps, " << kFps <<
" fps)...\n";
116 for (
int step = 0; step < total_steps; ++step) {
119 for (
unsigned i = 0; i < n; ++i) q(i) = robot.
jnt_pos_msr[i];
120 dyn.JntToGravity(q, g);
121 for (
unsigned i = 0; i < n; ++i) robot.
jnt_trq_cmd[i] = g(i);
125 if (step % steps_per_frame == 0) {
126 vr.
cam.azimuth = std::fmod(step * step_per_deg, 360.0);
128 std::cerr <<
"record_frame() failed at step " << step <<
"\n";
136 std::cout <<
"Saved: " << outmp4 <<
"\n";
bool init_video_recorder(VideoRecorder *vr, mjModel *model, const char *out_path, int width=1280, int height=720, int fps=60)
bool init_robot_from_mjcf(Robot *r, mjModel *model, mjData *data, const char *base_body, const char *tip_body, const char *prefix="", const ToolFrameSpec *tool=nullptr)