Professional Documents
Culture Documents
#include <cstring>
#include <mujoco/mujoco.h>
MuJoCo has a library of BLAS-like functions that are very useful; indeed a large
part of the code base consists of calling such functions internally.
mju_<functions>
The top-level simulation function mj_step basically does two things: compute the
forward dynamics in continuous time, and then integrate over a time period
specified by mjModel.opt.timestep. Forward dynamics computes the acceleration
mjData.qacc at time mjData.time, given the state and control at time mjData.time.
The numerical integrator then advances the state and time to mjData.time +
mjModel.opt.timestep.
//----------------------------------------------------------------------
Method 2:
The same effect (as above) can be achieved without using a control callback. This
is done by breaking mj_step in two parts: before the control is needed, and after
the control is needed. The simulation loop now becomes
while( d->time<10 ) {
mj_step1(m, d);
// set d->ctrl or d->qfrc_applied or d->xfrc_applied
mj_step2(m, d);
}
There is one complication however: this only works with Euler integration.
//----------------------------------------------------------------------
Example from mujoco forum
// simulation loop
while (d->time<10) {
my_controller(m, d); // writes controls into d->ctrl
mj_step(m, d);
}
//----------------------------------------------------------------------