Skip to content

Commit 3473e4e

Browse files
havesscopybara-github
authored andcommitted
Add group support to mjcPhysics equivalents for sites, geoms, actuators, and joints.
PiperOrigin-RevId: 781945497 Change-Id: I5c409f05e6bae33c181a51c273f260daea6004fc
1 parent bbb265d commit 3473e4e

File tree

14 files changed

+234
-24
lines changed

14 files changed

+234
-24
lines changed

include/mujoco/experimental/usd/mjcPhysics/collisionAPI.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SdfAssetPath;
4040

4141
/// \class MjcPhysicsCollisionAPI
4242
///
43-
/// API describing a Mujoco collider.
43+
/// API describing a MuJoCo collider.
4444
///
4545
class MjcPhysicsCollisionAPI : public UsdAPISchemaBase {
4646
public:
@@ -142,6 +142,30 @@ class MjcPhysicsCollisionAPI : public UsdAPISchemaBase {
142142
MJCPHYSICS_API
143143
const TfType &_GetTfType() const override;
144144

145+
public:
146+
// --------------------------------------------------------------------- //
147+
// GROUP
148+
// --------------------------------------------------------------------- //
149+
/// Integer MuJoCo group to which the collider belongs.
150+
///
151+
/// | ||
152+
/// | -- | -- |
153+
/// | Declaration | `uniform int mjc:group = 0` |
154+
/// | C++ Type | int |
155+
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int |
156+
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
157+
MJCPHYSICS_API
158+
UsdAttribute GetGroupAttr() const;
159+
160+
/// See GetGroupAttr(), and also
161+
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
162+
/// If specified, author \p defaultValue as the attribute's default,
163+
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
164+
/// the default for \p writeSparsely is \c false.
165+
MJCPHYSICS_API
166+
UsdAttribute CreateGroupAttr(VtValue const &defaultValue = VtValue(),
167+
bool writeSparsely = false) const;
168+
145169
public:
146170
// --------------------------------------------------------------------- //
147171
// SHELLINERTIA

include/mujoco/experimental/usd/mjcPhysics/jointAPI.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SdfAssetPath;
4040

4141
/// \class MjcPhysicsJointAPI
4242
///
43-
/// API describing a Mujoco joint.
43+
/// API describing a MuJoCo joint.
4444
///
4545
/// For any described attribute \em Fallback \em Value or \em Allowed \em Values
4646
/// below that are text/tokens, the actual token is published and defined in
@@ -146,6 +146,30 @@ class MjcPhysicsJointAPI : public UsdAPISchemaBase {
146146
MJCPHYSICS_API
147147
const TfType &_GetTfType() const override;
148148

149+
public:
150+
// --------------------------------------------------------------------- //
151+
// GROUP
152+
// --------------------------------------------------------------------- //
153+
/// Integer MuJoCo group to which the joint belongs.
154+
///
155+
/// | ||
156+
/// | -- | -- |
157+
/// | Declaration | `uniform int mjc:group = 0` |
158+
/// | C++ Type | int |
159+
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int |
160+
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
161+
MJCPHYSICS_API
162+
UsdAttribute GetGroupAttr() const;
163+
164+
/// See GetGroupAttr(), and also
165+
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
166+
/// If specified, author \p defaultValue as the attribute's default,
167+
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
168+
/// the default for \p writeSparsely is \c false.
169+
MJCPHYSICS_API
170+
UsdAttribute CreateGroupAttr(VtValue const &defaultValue = VtValue(),
171+
bool writeSparsely = false) const;
172+
149173
public:
150174
// --------------------------------------------------------------------- //
151175
// MJCSPRINGDAMPER

include/mujoco/experimental/usd/mjcPhysics/sceneAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SdfAssetPath;
4040

4141
/// \class MjcPhysicsSceneAPI
4242
///
43-
/// API providing global simulation options for Mujoco.
43+
/// API providing global simulation options for MuJoCo.
4444
///
4545
/// For any described attribute \em Fallback \em Value or \em Allowed \em Values
4646
/// below that are text/tokens, the actual token is published and defined in

include/mujoco/experimental/usd/mjcPhysics/siteAPI.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/// \file mjcPhysics/siteAPI.h
1919

2020
#include <mujoco/experimental/usd/mjcPhysics/api.h>
21+
#include <mujoco/experimental/usd/mjcPhysics/tokens.h>
2122
#include <pxr/base/gf/matrix4d.h>
2223
#include <pxr/base/gf/vec3d.h>
2324
#include <pxr/base/gf/vec3f.h>
@@ -39,7 +40,7 @@ class SdfAssetPath;
3940

4041
/// \class MjcPhysicsSiteAPI
4142
///
42-
/// API describing a Mujoco site.
43+
/// API describing a MuJoCo site.
4344
///
4445
class MjcPhysicsSiteAPI : public UsdAPISchemaBase {
4546
public:
@@ -140,6 +141,30 @@ class MjcPhysicsSiteAPI : public UsdAPISchemaBase {
140141
MJCPHYSICS_API
141142
const TfType &_GetTfType() const override;
142143

144+
public:
145+
// --------------------------------------------------------------------- //
146+
// GROUP
147+
// --------------------------------------------------------------------- //
148+
/// Integer MuJoCo group to which the collider belongs.
149+
///
150+
/// | ||
151+
/// | -- | -- |
152+
/// | Declaration | `uniform int mjc:group = 0` |
153+
/// | C++ Type | int |
154+
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int |
155+
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
156+
MJCPHYSICS_API
157+
UsdAttribute GetGroupAttr() const;
158+
159+
/// See GetGroupAttr(), and also
160+
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
161+
/// If specified, author \p defaultValue as the attribute's default,
162+
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
163+
/// the default for \p writeSparsely is \c false.
164+
MJCPHYSICS_API
165+
UsdAttribute CreateGroupAttr(VtValue const &defaultValue = VtValue(),
166+
bool writeSparsely = false) const;
167+
143168
public:
144169
// ===================================================================== //
145170
// Feel free to add custom code below this line, it will be preserved by

include/mujoco/experimental/usd/mjcPhysics/tokens.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ struct MjcPhysicsTokensType {
338338
const TfToken mjcGear;
339339
/// \brief "mjc:group"
340340
///
341-
/// MjcPhysicsTransmission
341+
/// MjcPhysicsSiteAPI, MjcPhysicsImageableAPI, MjcPhysicsCollisionAPI,
342+
/// MjcPhysicsTransmission, MjcPhysicsJointAPI
342343
const TfToken mjcGroup;
343344
/// \brief "mjc:inertia"
344345
///
@@ -589,6 +590,10 @@ struct MjcPhysicsTokensType {
589590
///
590591
/// Schema identifier and family for MjcPhysicsCollisionAPI
591592
const TfToken MjcCollisionAPI;
593+
/// \brief "MjcImageableAPI"
594+
///
595+
/// Schema identifier and family for MjcPhysicsImageableAPI
596+
const TfToken MjcImageableAPI;
592597
/// \brief "MjcJointAPI"
593598
///
594599
/// Schema identifier and family for MjcPhysicsJointAPI

src/experimental/usd/mjcPhysics/collisionAPI.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ const TfType &MjcPhysicsCollisionAPI::_GetTfType() const {
7575
return _GetStaticTfType();
7676
}
7777

78+
UsdAttribute MjcPhysicsCollisionAPI::GetGroupAttr() const {
79+
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcGroup);
80+
}
81+
82+
UsdAttribute MjcPhysicsCollisionAPI::CreateGroupAttr(
83+
VtValue const &defaultValue, bool writeSparsely) const {
84+
return UsdSchemaBase::_CreateAttr(
85+
MjcPhysicsTokens->mjcGroup, SdfValueTypeNames->Int,
86+
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
87+
}
88+
7889
UsdAttribute MjcPhysicsCollisionAPI::GetShellInertiaAttr() const {
7990
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcShellinertia);
8091
}
@@ -101,6 +112,7 @@ static inline TfTokenVector _ConcatenateAttributeNames(
101112
const TfTokenVector &MjcPhysicsCollisionAPI::GetSchemaAttributeNames(
102113
bool includeInherited) {
103114
static TfTokenVector localNames = {
115+
MjcPhysicsTokens->mjcGroup,
104116
MjcPhysicsTokens->mjcShellinertia,
105117
};
106118
static TfTokenVector allNames = _ConcatenateAttributeNames(

src/experimental/usd/mjcPhysics/generatedSchema.usda

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
)
55

66
class "MjcSceneAPI" (
7-
doc = "API providing global simulation options for Mujoco."
7+
doc = "API providing global simulation options for MuJoCo."
88
)
99
{
1010
uniform bool mjc:flag:actuation = 1 (
@@ -221,23 +221,31 @@ class "MjcSceneAPI" (
221221
}
222222

223223
class "MjcSiteAPI" (
224-
doc = "API describing a Mujoco site."
224+
doc = "API describing a MuJoCo site."
225225
)
226226
{
227+
uniform int mjc:group = 0 (
228+
displayName = "Group"
229+
doc = "Integer MuJoCo group to which the collider belongs."
230+
)
227231
}
228232

229233
class "MjcCollisionAPI" (
230-
doc = "API describing a Mujoco collider."
234+
doc = "API describing a MuJoCo collider."
231235
)
232236
{
237+
uniform int mjc:group = 0 (
238+
displayName = "Group"
239+
doc = "Integer MuJoCo group to which the collider belongs."
240+
)
233241
uniform bool mjc:shellinertia = 0 (
234242
displayName = "Shell Inertia"
235243
doc = "Enables handling of the inertia assuming mass is concentrated on the surface."
236244
)
237245
}
238246

239247
class "MjcMeshCollisionAPI" (
240-
doc = "API describing a Mujoco mesh collider."
248+
doc = "API describing a MuJoCo mesh collider."
241249
)
242250
{
243251
uniform token mjc:inertia = "legacy" (
@@ -318,6 +326,10 @@ class MjcTransmission "MjcTransmission" (
318326
uniform double[] mjc:gear = [1, 0, 0, 0, 0, 0] (
319327
doc = "This attribute scales the length (and consequently moment arms, velocity and force) of the actuator, for all transmission types. It is different from the gain in the force generation mechanism, because the gain only scales the force output and does not affect the length, moment arms and velocity. For actuators with scalar transmission, only the first element of this vector is used. The remaining elements are needed for joint, jointinparent and site transmissions where this attribute is used to specify 3D force and torque axes."
320328
)
329+
uniform int mjc:group = 0 (
330+
displayName = "Group"
331+
doc = "Integer MuJoCo group to which the transmission belongs."
332+
)
321333
uniform bool mjc:jointInParent = 0 (
322334
doc = "If true and applied to ball and free joints, the 3d rotation axis given by gear is defined in the parent frame (which is the world frame for free joints) rather than the child frame."
323335
)
@@ -363,7 +375,7 @@ class MjcKeyframe "MjcKeyframe" (
363375
}
364376

365377
class "MjcJointAPI" (
366-
doc = "API describing a Mujoco joint."
378+
doc = "API describing a MuJoCo joint."
367379
)
368380
{
369381
uniform token mjc:actuatorfrclimited = "auto" (
@@ -388,6 +400,10 @@ class "MjcJointAPI" (
388400
uniform double mjc:frictionloss = 0 (
389401
doc = "Friction loss due to dry friction. This value is the same for all degrees of freedom created by this joint. Semantically friction loss does not make sense for free joints, but the compiler allows it. To enable friction loss, set this attribute to a positive value."
390402
)
403+
uniform int mjc:group = 0 (
404+
displayName = "Group"
405+
doc = "Integer MuJoCo group to which the joint belongs."
406+
)
391407
uniform double mjc:margin = 0 (
392408
doc = "The distance threshold below which limits become active. Recall that the Constraint solver normally generates forces as soon as a constraint becomes active, even if the margin parameter makes that happen at a distance. This attribute together with solreflimit and solimplimit can be used to model a soft joint limit."
393409
)

src/experimental/usd/mjcPhysics/jointAPI.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ const TfType &MjcPhysicsJointAPI::_GetTfType() const {
7474
return _GetStaticTfType();
7575
}
7676

77+
UsdAttribute MjcPhysicsJointAPI::GetGroupAttr() const {
78+
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcGroup);
79+
}
80+
81+
UsdAttribute MjcPhysicsJointAPI::CreateGroupAttr(VtValue const &defaultValue,
82+
bool writeSparsely) const {
83+
return UsdSchemaBase::_CreateAttr(
84+
MjcPhysicsTokens->mjcGroup, SdfValueTypeNames->Int,
85+
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
86+
}
87+
7788
UsdAttribute MjcPhysicsJointAPI::GetMjcSpringdamperAttr() const {
7889
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcSpringdamper);
7990
}
@@ -265,6 +276,7 @@ static inline TfTokenVector _ConcatenateAttributeNames(
265276
const TfTokenVector &MjcPhysicsJointAPI::GetSchemaAttributeNames(
266277
bool includeInherited) {
267278
static TfTokenVector localNames = {
279+
MjcPhysicsTokens->mjcGroup,
268280
MjcPhysicsTokens->mjcSpringdamper,
269281
MjcPhysicsTokens->mjcSolreflimit,
270282
MjcPhysicsTokens->mjcSolimplimit,

src/experimental/usd/mjcPhysics/schema.usda

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class "MjcSceneAPI"
9898
customData = {
9999
string className = "SceneAPI"
100100
}
101-
doc = """API providing global simulation options for Mujoco."""
101+
doc = """API providing global simulation options for MuJoCo."""
102102

103103
inherits = </APISchemaBase>
104104
)
@@ -516,22 +516,37 @@ class "MjcSiteAPI"
516516
customData = {
517517
string className = "SiteAPI"
518518
}
519-
doc = """API describing a Mujoco site."""
519+
doc = """API describing a MuJoCo site."""
520520

521521
inherits = </APISchemaBase>
522522
)
523-
{}
523+
{
524+
uniform int mjc:group = 0 (
525+
customData = {
526+
string apiName = "Group"
527+
}
528+
displayName = "Group"
529+
doc = """Integer MuJoCo group to which the collider belongs."""
530+
)
531+
}
524532

525533
class "MjcCollisionAPI"
526534
(
527535
customData = {
528536
string className = "CollisionAPI"
529537
}
530-
doc = """API describing a Mujoco collider."""
538+
doc = """API describing a MuJoCo collider."""
531539

532540
inherits = </APISchemaBase>
533541
)
534542
{
543+
uniform int mjc:group = 0 (
544+
customData = {
545+
string apiName = "Group"
546+
}
547+
displayName = "Group"
548+
doc = """Integer MuJoCo group to which the collider belongs."""
549+
)
535550
uniform bool mjc:shellinertia = False (
536551
customData = {
537552
string apiName = "ShellInertia"
@@ -546,7 +561,7 @@ class "MjcMeshCollisionAPI"
546561
customData = {
547562
string className = "MeshCollisionAPI"
548563
}
549-
doc = """API describing a Mujoco mesh collider."""
564+
doc = """API describing a MuJoCo mesh collider."""
550565

551566
inherits = </APISchemaBase>
552567
)
@@ -579,6 +594,14 @@ class MjcTransmission "MjcTransmission"
579594
inherits = </Typed>
580595
)
581596
{
597+
uniform int mjc:group = 0 (
598+
customData = {
599+
string apiName = "Group"
600+
}
601+
displayName = "Group"
602+
doc = """Integer MuJoCo group to which the transmission belongs."""
603+
)
604+
582605
rel mjc:target (
583606
doc = "Actuator transmission target."
584607
)
@@ -728,11 +751,19 @@ class "MjcJointAPI"
728751
customData = {
729752
string className = "JointAPI"
730753
}
731-
doc = """API describing a Mujoco joint."""
754+
doc = """API describing a MuJoCo joint."""
732755

733756
inherits = </APISchemaBase>
734757
)
735758
{
759+
uniform int mjc:group = 0 (
760+
customData = {
761+
string apiName = "Group"
762+
}
763+
displayName = "Group"
764+
doc = """Integer MuJoCo group to which the joint belongs."""
765+
)
766+
736767
uniform double[] mjc:springdamper = [0, 0] (
737768
doc = "When both numbers are positive, the compiler will override any stiffness and damping values specified with the attributes below, and will instead set them automatically so that the resulting mass-spring-damper for this joint has the desired time constant (first value) and damping ratio (second value). This is done by taking into account the joint inertia in the model reference configuration. Note that the format is the same as the solref parameter of the constraint solver."
738769
)

0 commit comments

Comments
 (0)