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 Engine Setconst

From Leeroopedia
Knowledge Sources
Domains Physics Simulation, Model Initialization, Kinematics
Last Updated 2026-02-15 04:00 GMT

Overview

Computes and sets model constants that depend on the reference configuration (qpos0) or are fixed properties of the model topology.

Description

engine_setconst.c initializes derived quantities in the mjModel that are computed from the base model specification. This includes fixed quantities independent of qpos0 (subtree masses, gravity compensation counts, tree topology, tendon and actuator length ranges) and configuration-dependent quantities computed at qpos0 (diagonal mass matrix elements via the composite rigid body algorithm, flex element sparsity patterns, joint spring reference lengths, and model statistics like center of mass and bounding box extent). The function mj_setConst() serves as the main entry point, and mj_setLengthRange() computes actuator length ranges through simulation-based sampling.

Usage

Called once during model compilation via mj_setConst() to precompute all derived model constants. Also called when the model reference configuration changes. mj_setLengthRange() is called for actuators that need length range computation, either during compilation or explicitly by the user.

Code Reference

Source Location

Key Functions

// main entry: compute all model constants
void mj_setConst(mjModel* m, mjData* d);

// compute actuator length ranges by simulation sampling
int mj_setLengthRange(mjModel* m, mjData* d, int index,
                      const mjLROpt* opt, char* error, int error_sz);

// compute dof_M0 via composite rigid body algorithm
static void mj_setM0(mjModel* m, mjData* d);

// set fixed quantities (topology-dependent, qpos0-independent)
static void setFixed(mjModel* m, mjData* d);

// set quantities evaluated at qpos0
static void set0(mjModel* m, mjData* d);

// compute model statistics (center, extent, bounding box)
static void setStat(mjModel* m, mjData* d);

// set spring reference lengths
static void setSpring(mjModel* m, mjData* d);

// compute flex element sparsity structure
static void makeFlexSparse(mjModel* m, mjData* d);

// align flex vertex positions
static void mj_alignFlex(mjModel* m, mjData* d);

Import

#include "engine/engine_setconst.h"

I/O Contract

Inputs

Name Type Required Description
m mjModel* Yes Model to initialize (modified in place)
d mjData* Yes Temporary simulation data used for computation
index int Yes (setLengthRange) Actuator index
opt const mjLROpt* Yes (setLengthRange) Length range computation options

Outputs

Name Type Description
m->dof_M0 mjtNum* Diagonal mass matrix at reference configuration
m->body_subtreemass mjtNum* Subtree mass for each body
m->body_treeid int* Tree index for each body
m->stat.center mjtNum[3] Model center of mass
m->stat.extent mjtNum Model bounding sphere radius
m->jnt_stiffness (spring ref) mjtNum* Spring reference lengths
return (setLengthRange) int 0 on success, -1 on failure

Related Pages

Page Connections

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