Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco mj forward

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

Overview

Concrete tool for computing all derived simulation quantities from the current state provided by the MuJoCo C API.

Description

The mj_forward function runs the complete forward dynamics pipeline: forward kinematics, collision detection, constraint construction, and constraint solving. It populates all fields in mjData based on the current qpos, qvel, and ctrl values. This is a convenience wrapper around mj_forwardSkip with no stages skipped.

Usage

Call this function after setting initial state (qpos, qvel) to compute all derived quantities, or when you need a full state evaluation without time integration. Used internally by mj_step.

Code Reference

Source Location

  • Repository: mujoco
  • File: src/engine/engine_forward.c
  • Lines: 1416-1418

Signature

void mj_forward(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
d mjData* Yes Simulation state with qpos, qvel, ctrl set

Outputs

Name Type Description
d (modified) mjData* All derived fields populated: xpos, xquat, sensordata, contact, efc_*, qacc, etc.

Usage Examples

#include <mujoco/mujoco.h>

// After loading model and making data
mjModel* m = mj_loadXML("arm.xml", NULL, error, 1000);
mjData* d = mj_makeData(m);

// Set initial joint positions
d->qpos[0] = 0.5;  // first joint angle
d->qpos[1] = -0.3; // second joint angle

// Compute full state (positions, velocities, forces, contacts)
mj_forward(m, d);

// Now d->xpos, d->xquat, d->sensordata, etc. are valid
printf("End-effector position: %f %f %f\n",
       d->xpos[3*6], d->xpos[3*6+1], d->xpos[3*6+2]);

Related Pages

Implements Principle

Page Connections

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