Add boolean flags for gravity compensation and surface velocity in mjModel.

These fields (`flg_gravcomp` and `flg_surfacevel`) replace the fast-path checks originally guarded by `ngravcomp` and (recently) `nsurfacevel`. Since the engine uses these integers only as flags (zero vs non-zero), migrating them to actual booleans makes them writeable from the Python bindings at runtime without violating size/dimension constraints.

The legacy integer field `ngravcomp` is marked as deprecated and will be removed in a future release.

PiperOrigin-RevId: 949779204
Change-Id: Ifab1f026063a4239302e6ad689663b611b59dda8
This commit is contained in:
Yuval Tassa
2026-07-17 15:04:37 -07:00
committed by Copybara-Service
parent ebd4abae03
commit a04b0c5b97
20 changed files with 111 additions and 34 deletions
+1 -1
View File
@@ -228,7 +228,7 @@ def fwd_actuation(m: Model, d: Data) -> Data:
qfrc_actuator = d._impl.actuator_moment.T @ force
if m.ngravcomp:
if m.flg_gravcomp:
# actuator-level gravity compensation, skip if added as passive force
qfrc_actuator += d.qfrc_gravcomp * m.jnt_actgravcomp[m.dof_jntid]
+1 -1
View File
@@ -145,7 +145,7 @@ def passive(m: Model, d: Data) -> Data:
qfrc_passive = _spring_damper(m, d)
qfrc_gravcomp = jp.zeros(m.nv)
if m.ngravcomp and not m.opt.disableflags & DisableBit.GRAVITY:
if m.flg_gravcomp and not m.opt.disableflags & DisableBit.GRAVITY:
qfrc_gravcomp = _gravcomp(m, d)
# add gravcomp unless added via actuators
qfrc_passive += qfrc_gravcomp * (1 - m.jnt_actgravcomp[m.dof_jntid])
+2
View File
@@ -641,6 +641,8 @@ class Model(PyTreeNode):
nJmom: int # pylint:disable=invalid-name
nJten: int # pylint:disable=invalid-name
ngravcomp: int
flg_gravcomp: bool
flg_surfacevel: bool
nuserdata: int
nsensordata: int
npluginstate: int