﻿# MuJoCo contact logs: margin and gap can produce records without active forces

Distinguish detected contact records from active contact constraints when using MuJoCo margin and gap for proximity monitoring or contact counts.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/simulation-mujoco-contact-margin-gap-inactive-records/
Language: en

## A contact counter may be counting proximity records

A twin monitor increments a collision counter whenever a contact appears in mjData.contact. After a developer adds a proximity margin, the counter rises while reported contact force remains absent for some pairs. The discrepancy can be intentional model behavior. Establish whether the monitor means detected proximity, an active constraint or a force exceeding an application threshold. Those populations need separate definitions before counts can support a failure label or policy reward.

## Separate inclusion and activation thresholds

The [MJCF reference](https://mujoco.readthedocs.io/en/3.3.7/XMLreference.html) defines margin as the distance threshold for including contacts in the global contact array. The contact becomes active when surface distance is below margin minus gap. A positive gap can therefore retain a region of inactive contact records for custom computations. Do not summarize this as a sensor proving physical touching. In particular, the configured margin can admit separated surfaces, and the force-active boundary need not coincide with geometric zero distance.

## Read distance alongside force semantics

The [contact model](https://mujoco.readthedocs.io/en/3.3.7/computation/index.html) describes positive distance for separated geoms, zero for touching and negative for penetration, while treating contact detection and constraint-force computation as distinct parts of the pipeline. Preserve those geometric values with effective margin and gap. Even inside an active regime, force interpretation depends on the constraint solution and model conditions. An array count alone cannot reconstruct those conditions, and a zero-force result alone cannot establish that a pair was never detected.

## Propose an approach-distance fixture

A proposed model-only fixture should move a simple pair through clearly separated, detected-but-inactive and active regions under explicitly chosen settings. Inspect contact distance, pair identity, relevant activation information and extracted force at each declared computation boundary. Avoid exact-threshold samples initially so comparison precision does not obscure the rule. Hold other bodies and applied inputs fixed. This is a suggested inspection protocol, not a measured sensor accuracy result or a contact experiment on hardware.

## Make monitoring labels reflect their population

Acceptance should retain effective pair parameters rather than only one geom’s XML values, because contact parameter resolution can change the resulting settings. Define separate labels for detected proximity and application-relevant force. If the reward penalizes any contact record, state that it penalizes the chosen proximity regime, not necessarily physical impact. Retain pair identity across aggregation so multiple contact points or repeated timesteps do not silently become counts of independent collision incidents.

## Keep contact representation separate from physical events

A correctly classified simulator record still depends on geometry, numerical settings and contact modeling assumptions. The [GraspNet score guide](/journal/fg2-graspnet-raw-friction-score-not-success-probability/) explains another model-based contact-evidence boundary; [software reproducibility](/journal/software-stack-reproducibility/) supports retaining the effective configuration. Here the specific conclusion is whether the recorded pair crossed detection or active-constraint boundaries in the examined model. Physical collision detection, impact severity and safe operation require their own evidence.
