2424MJ_MAXIMP = mujoco .mjMAXIMP # maximum constraint impedance
2525MJ_MAXCONPAIR = mujoco .mjMAXCONPAIR
2626MJ_MINMU = mujoco .mjMINMU # minimum friction
27+ # TODO(team): set with mujoco.mjMINAWAKE after mjwarp depends
28+ # on mujoco > 3.4.0 in pyproject.toml
29+ MJ_MINAWAKE = 10 # minimum number of timesteps before sleeping
2730# maximum size (by number of edges) of an horizon in EPA algorithm
2831MJ_MAX_EPAHORIZON = 24
2932# maximum average number of trianglarfaces EPA can insert at each iteration
@@ -174,14 +177,50 @@ class EnableBit(enum.IntFlag):
174177 ENERGY: energy computation
175178 INVDISCRETE: discrete-time inverse dynamics
176179 MULTICCD: multiple contacts with CCD
180+ SLEEP: sleeping
177181 """
178182
179183 ENERGY = mujoco .mjtEnableBit .mjENBL_ENERGY
180184 INVDISCRETE = mujoco .mjtEnableBit .mjENBL_INVDISCRETE
181185 MULTICCD = mujoco .mjtEnableBit .mjENBL_MULTICCD
186+ SLEEP = mujoco .mjtEnableBit .mjENBL_SLEEP
182187 # unsupported: OVERRIDE, FWDINV, ISLAND
183188
184189
190+ class SleepPolicy (enum .IntEnum ):
191+ """Per-tree sleep policy.
192+
193+ Attributes:
194+ AUTO: compiler chooses sleep policy
195+ AUTO_NEVER: compiler sleep policy: never
196+ AUTO_ALLOWED: compiler sleep policy: allowed
197+ NEVER: user sleep policy: never
198+ ALLOWED: user sleep policy: allowed
199+ INIT: user sleep policy: initialized asleep
200+ """
201+
202+ AUTO = mujoco .mjtSleepPolicy .mjSLEEP_AUTO
203+ AUTO_NEVER = mujoco .mjtSleepPolicy .mjSLEEP_AUTO_NEVER
204+ AUTO_ALLOWED = mujoco .mjtSleepPolicy .mjSLEEP_AUTO_ALLOWED
205+ NEVER = mujoco .mjtSleepPolicy .mjSLEEP_NEVER
206+ ALLOWED = mujoco .mjtSleepPolicy .mjSLEEP_ALLOWED
207+ INIT = mujoco .mjtSleepPolicy .mjSLEEP_INIT
208+
209+
210+ class SleepState (enum .IntEnum ):
211+ """Sleep state for bodies.
212+
213+ Attributes:
214+ ASLEEP: body is asleep
215+ AWAKE: body is awake
216+ STATIC: body is static (world body or mocap)
217+ """
218+
219+ ASLEEP = 0
220+ AWAKE = 1
221+ STATIC = 2
222+
223+
185224class TrnType (enum .IntEnum ):
186225 """Type of actuator transmission.
187226
@@ -647,6 +686,7 @@ class Option:
647686 tolerance: main solver tolerance
648687 ls_tolerance: CG/Newton linesearch tolerance
649688 ccd_tolerance: convex collision detection tolerance
689+ sleep_tolerance: sleep velocity tolerance
650690 density: density of medium
651691 viscosity: viscosity of medium
652692 gravity: gravitational acceleration
@@ -683,6 +723,7 @@ class Option:
683723 tolerance : array ("*" , float )
684724 ls_tolerance : array ("*" , float )
685725 ccd_tolerance : array ("*" , float )
726+ sleep_tolerance : float
686727 density : array ("*" , float )
687728 viscosity : array ("*" , float )
688729 gravity : array ("*" , wp .vec3 )
@@ -835,6 +876,8 @@ class Model:
835876 dof_armature: dof armature inertia/mass (*, nv)
836877 dof_damping: damping coefficient (*, nv)
837878 dof_invweight0: diag. inverse inertia in qpos0 (*, nv)
879+ dof_length: dof length for weighting velocity norm (nv,)
880+ tree_sleep_policy: tree sleep policy (SleepPolicy) (ntree,)
838881 geom_type: geometric type (GeomType) (ngeom,)
839882 geom_contype: geom contact type (ngeom,)
840883 geom_conaffinity: geom contact affinity (ngeom,)
@@ -1186,6 +1229,8 @@ class Model:
11861229 dof_armature : array ("*" , "nv" , float )
11871230 dof_damping : array ("*" , "nv" , float )
11881231 dof_invweight0 : array ("*" , "nv" , float )
1232+ dof_length : array ("nv" , float )
1233+ tree_sleep_policy : array ("ntree" , int )
11891234 geom_type : array ("ngeom" , int )
11901235 geom_contype : array ("ngeom" , int )
11911236 geom_conaffinity : array ("ngeom" , int )
@@ -1562,6 +1607,9 @@ class Data:
15621607 nf: number of friction constraints (nworld,)
15631608 nl: number of limit constraints (nworld,)
15641609 nefc: number of constraints (nworld,)
1610+ ntree_awake: number of awake trees (nworld,)
1611+ nbody_awake: number of awake bodies (nworld,)
1612+ nv_awake: number of awake dofs (nworld,)
15651613 time: simulation time (nworld,)
15661614 energy: potential, kinetic energy (nworld, 2)
15671615 qpos: position (nworld, nq)
@@ -1577,6 +1625,7 @@ class Data:
15771625 qacc: acceleration (nworld, nv)
15781626 act_dot: time-derivative of actuator activation (nworld, na)
15791627 sensordata: sensor data array (nworld, nsensordata,)
1628+ tree_asleep: tree asleep counter; >=0: asleep cycle (nworld, ntree)
15801629 xpos: Cartesian position of body frame (nworld, nbody, 3)
15811630 xquat: Cartesian orientation of body frame (nworld, nbody, 4)
15821631 xmat: Cartesian orientation of body frame (nworld, nbody, 3, 3)
@@ -1612,6 +1661,10 @@ class Data:
16121661 qLD: L'*D*L factorization of M (nworld, nv, nv) if dense
16131662 (nworld, 1, nC) if sparse
16141663 qLDiagInv: 1/diag(D) (nworld, nv)
1664+ tree_awake: is tree awake; 0: asleep; 1: awake (nworld, ntree)
1665+ body_awake: body sleep state (SleepState) (nworld, nbody)
1666+ body_awake_ind: indices of awake/static bodies (nworld, nbody)
1667+ dof_awake_ind: indices of awake dofs (nworld, nv)
16151668 flexedge_velocity: flex edge velocities (nworld, nflexedge)
16161669 ten_velocity: tendon velocities (nworld, ntendon)
16171670 actuator_velocity: actuator velocities (nworld, nu)
@@ -1660,6 +1713,9 @@ class Data:
16601713 nf : array ("nworld" , int )
16611714 nl : array ("nworld" , int )
16621715 nefc : array ("nworld" , int )
1716+ ntree_awake : array ("nworld" , int )
1717+ nbody_awake : array ("nworld" , int )
1718+ nv_awake : array ("nworld" , int )
16631719 time : array ("nworld" , float )
16641720 energy : array ("nworld" , wp .vec2 )
16651721 qpos : array ("nworld" , "nq" , float )
@@ -1675,6 +1731,7 @@ class Data:
16751731 qacc : array ("nworld" , "nv" , float )
16761732 act_dot : array ("nworld" , "na" , float )
16771733 sensordata : array ("nworld" , "nsensordata" , float )
1734+ tree_asleep : array ("nworld" , "ntree" , int )
16781735 xpos : array ("nworld" , "nbody" , wp .vec3 )
16791736 xquat : array ("nworld" , "nbody" , wp .quat )
16801737 xmat : array ("nworld" , "nbody" , wp .mat33 )
@@ -1708,6 +1765,10 @@ class Data:
17081765 qM : wp .array3d (dtype = float )
17091766 qLD : wp .array3d (dtype = float )
17101767 qLDiagInv : array ("nworld" , "nv" , float )
1768+ tree_awake : array ("nworld" , "ntree" , int )
1769+ body_awake : array ("nworld" , "nbody" , int )
1770+ body_awake_ind : array ("nworld" , "nbody" , int )
1771+ dof_awake_ind : array ("nworld" , "nv" , int )
17111772 flexedge_velocity : array ("nworld" , "nflexedge" , float )
17121773 ten_velocity : array ("nworld" , "ntendon" , float )
17131774 actuator_velocity : array ("nworld" , "nu" , float )
0 commit comments