Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Google deepmind Mujoco mj step

From Leeroopedia
Knowledge Sources
Domains Physics_Simulation, Numerical_Integration
Last Updated 2026-02-15 06:00 GMT

Overview

Concrete tool for advancing the MuJoCo simulation by one timestep provided by the MuJoCo C API.

Description

The mj_step function performs one complete simulation step: state validation, forward dynamics (via mj_forward), and time integration. The integrator is selected from the model options (Euler, RK4, or implicit). After calling this function, d->time is advanced by m->opt.timestep and all state variables are updated.

Usage

Call this function in a loop to run a simulation. Set d->ctrl before each call to apply control signals. The timestep is determined by m->opt.timestep (default 0.002 seconds).

Code Reference

Source Location

  • Repository: mujoco
  • File: src/engine/engine_forward.c
  • Lines: 1422-1456

Signature

void mj_step(const mjModel* m, mjData* d);

Import

#include <mujoco/mujoco.h>

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Compiled physics model (immutable)
d mjData* Yes Simulation state with control signals in d->ctrl

Outputs

Name Type Description
d (modified) mjData* Advanced state: updated qpos, qvel, time, contacts, forces

Usage Examples

Basic Simulation Loop

#include <mujoco/mujoco.h>

// Load and initialize
mjModel* m = mj_loadXML("humanoid.xml", NULL, error, 1000);
mjData* d = mj_makeData(m);

// Simulate for 10 seconds
while (d->time < 10.0) {
    // Set control signals
    d->ctrl[0] = 1.0;  // actuator 0

    // Advance simulation by one timestep
    mj_step(m, d);
}

printf("Final time: %f\n", d->time);
mj_deleteData(d);
mj_deleteModel(m);

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment