Add SDF functions to public API.

PiperOrigin-RevId: 757829339
Change-Id: I81ee7c3f33acf234835bf34cbb632e23cb9e284e
This commit is contained in:
Alessio Quaglino
2025-05-12 10:52:41 -07:00
committed by Copybara-Service
parent d77126dc58
commit 8a7c42c747
10 changed files with 232 additions and 16 deletions
+20
View File
@@ -357,6 +357,26 @@ last argument to :ref:`mj_local2global`.
.. mujoco-include:: mjtSameFrame
.. _mjtFlexSelf:
mjtFlexSelf
~~~~~~~~~~~~
Types of flex self-collisions midphase.
.. mujoco-include:: mjtFlexSelf
.. _mjtSDFType:
mjtSDFType
~~~~~~~~~~~
Formulas used to combine SDFs when calling mjc_distance and mjc_gradient.
.. mujoco-include:: mjtSDFType
.. _tyDataEnums:
Data
+19
View File
@@ -766,6 +766,12 @@ typedef enum mjtFlexSelf_ { // mode for flex selfcollide
mjFLEXSELF_SAP, // use SAP in midphase
mjFLEXSELF_AUTO // choose between BVH and SAP automatically
} mjtFlexSelf;
typedef enum mjtSDFType_ { // signed distance function (SDF) type
mjSDFTYPE_SINGLE = 0, // single SDF
mjSDFTYPE_INTERSECTION, // max(A, B)
mjSDFTYPE_MIDSURFACE, // A - B
mjSDFTYPE_COLLISION, // A + B + abs(max(A, B))
} mjtSDFType;
struct mjLROpt_ { // options for mj_setLengthRange()
// flags
int mode; // which actuators to process (mjtLRMode)
@@ -1586,6 +1592,15 @@ struct mjpPlugin_ {
void (*sdf_aabb)(mjtNum aabb[6], const mjtNum* attributes);
};
typedef struct mjpPlugin_ mjpPlugin;
struct mjSDF_ {
const mjpPlugin** plugin;
int* id;
mjtSDFType type;
mjtNum* relpos;
mjtNum* relmat;
mjtGeom* geomtype;
};
typedef struct mjSDF_ mjSDF;
typedef enum mjtGridPos_ { // grid position for overlay
mjGRID_TOPLEFT = 0, // top left
mjGRID_TOPRIGHT, // top right
@@ -3637,6 +3652,10 @@ void mju_insertionSortInt(int* list, int n);
mjtNum mju_Halton(int index, int base);
char* mju_strncpy(char *dst, const char *src, int n);
mjtNum mju_sigmoid(mjtNum x);
const mjpPlugin* mjc_getSDF(const mjModel* m, int id);
mjtNum mjc_distance(const mjModel* m, const mjData* d, const mjSDF* s, const mjtNum x[3]);
void mjc_gradient(const mjModel* m, const mjData* d, const mjSDF* s, mjtNum gradient[3],
const mjtNum x[3]);
void mjd_transitionFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte flg_centered,
mjtNum* A, mjtNum* B, mjtNum* C, mjtNum* D);
void mjd_inverseFD(const mjModel* m, mjData* d, mjtNum eps, mjtByte flg_actuation,
+8
View File
@@ -407,6 +407,14 @@ typedef enum mjtFlexSelf_ { // mode for flex selfcollide
} mjtFlexSelf;
typedef enum mjtSDFType_ { // signed distance function (SDF) type
mjSDFTYPE_SINGLE = 0, // single SDF
mjSDFTYPE_INTERSECTION, // max(A, B)
mjSDFTYPE_MIDSURFACE, // A - B
mjSDFTYPE_COLLISION, // A + B + abs(max(A, B))
} mjtSDFType;
//---------------------------------- mjLROpt -------------------------------------------------------
struct mjLROpt_ { // options for mj_setLengthRange()
+10
View File
@@ -135,6 +135,16 @@ struct mjpPlugin_ {
};
typedef struct mjpPlugin_ mjpPlugin;
struct mjSDF_ {
const mjpPlugin** plugin;
int* id;
mjtSDFType type;
mjtNum* relpos;
mjtNum* relmat;
mjtGeom* geomtype;
};
typedef struct mjSDF_ mjSDF;
#if defined(__has_attribute)
#if __has_attribute(constructor)
+13
View File
@@ -1308,6 +1308,19 @@ MJAPI char* mju_strncpy(char *dst, const char *src, int n);
MJAPI mjtNum mju_sigmoid(mjtNum x);
//---------------------------------- Signed Distance Function --------------------------------------
// get sdf from geom id
MJAPI const mjpPlugin* mjc_getSDF(const mjModel* m, int id);
// signed distance function
MJAPI mjtNum mjc_distance(const mjModel* m, const mjData* d, const mjSDF* s, const mjtNum x[3]);
// gradient of sdf
MJAPI void mjc_gradient(const mjModel* m, const mjData* d, const mjSDF* s, mjtNum gradient[3],
const mjtNum x[3]);
//---------------------------------- Derivatives ---------------------------------------------------
// Finite differenced transition matrices (control theory notation)
+11
View File
@@ -428,6 +428,17 @@ ENUMS: Mapping[str, EnumDecl] = dict([
('mjFLEXSELF_AUTO', 4),
]),
)),
('mjtSDFType',
EnumDecl(
name='mjtSDFType',
declname='enum mjtSDFType_',
values=dict([
('mjSDFTYPE_SINGLE', 0),
('mjSDFTYPE_INTERSECTION', 1),
('mjSDFTYPE_MIDSURFACE', 2),
('mjSDFTYPE_COLLISION', 3),
]),
)),
('mjtTaskStatus',
EnumDecl(
name='mjtTaskStatus',
+93
View File
@@ -8570,6 +8570,99 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
doc='Sigmoid function over 0<=x<=1 using quintic polynomial.',
)),
('mjc_getSDF',
FunctionDecl(
name='mjc_getSDF',
return_type=PointerType(
inner_type=ValueType(name='mjpPlugin', is_const=True),
),
parameters=(
FunctionParameterDecl(
name='m',
type=PointerType(
inner_type=ValueType(name='mjModel', is_const=True),
),
),
FunctionParameterDecl(
name='id',
type=ValueType(name='int'),
),
),
doc='get sdf from geom id',
)),
('mjc_distance',
FunctionDecl(
name='mjc_distance',
return_type=ValueType(name='mjtNum'),
parameters=(
FunctionParameterDecl(
name='m',
type=PointerType(
inner_type=ValueType(name='mjModel', is_const=True),
),
),
FunctionParameterDecl(
name='d',
type=PointerType(
inner_type=ValueType(name='mjData', is_const=True),
),
),
FunctionParameterDecl(
name='s',
type=PointerType(
inner_type=ValueType(name='mjSDF', is_const=True),
),
),
FunctionParameterDecl(
name='x',
type=ArrayType(
inner_type=ValueType(name='mjtNum', is_const=True),
extents=(3,),
),
),
),
doc='signed distance function',
)),
('mjc_gradient',
FunctionDecl(
name='mjc_gradient',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='m',
type=PointerType(
inner_type=ValueType(name='mjModel', is_const=True),
),
),
FunctionParameterDecl(
name='d',
type=PointerType(
inner_type=ValueType(name='mjData', is_const=True),
),
),
FunctionParameterDecl(
name='s',
type=PointerType(
inner_type=ValueType(name='mjSDF', is_const=True),
),
),
FunctionParameterDecl(
name='gradient',
type=ArrayType(
inner_type=ValueType(name='mjtNum'),
extents=(3,),
),
),
FunctionParameterDecl(
name='x',
type=ArrayType(
inner_type=ValueType(name='mjtNum', is_const=True),
extents=(3,),
),
),
),
doc='gradient of sdf',
)),
('mjd_transitionFD',
FunctionDecl(
name='mjd_transitionFD',
+49
View File
@@ -8966,6 +8966,55 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
),
)),
('mjSDF',
StructDecl(
name='mjSDF',
declname='struct mjSDF_',
fields=(
StructFieldDecl(
name='plugin',
type=PointerType(
inner_type=PointerType(
inner_type=ValueType(name='mjpPlugin', is_const=True),
),
),
doc='',
),
StructFieldDecl(
name='id',
type=PointerType(
inner_type=ValueType(name='int'),
),
doc='',
),
StructFieldDecl(
name='type',
type=ValueType(name='mjtSDFType'),
doc='',
),
StructFieldDecl(
name='relpos',
type=PointerType(
inner_type=ValueType(name='mjtNum'),
),
doc='',
),
StructFieldDecl(
name='relmat',
type=PointerType(
inner_type=ValueType(name='mjtNum'),
),
doc='',
),
StructFieldDecl(
name='geomtype',
type=PointerType(
inner_type=ValueType(name='mjtGeom'),
),
doc='',
),
),
)),
('mjrRect',
StructDecl(
name='mjrRect',
+3 -16
View File
@@ -19,27 +19,14 @@
#include <mujoco/mjexport.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjplugin.h>
#include <mujoco/mjtnum.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum mjtSDFType_ { // signed distance function (SDF) type
mjSDFTYPE_SINGLE = 0, // single SDF
mjSDFTYPE_INTERSECTION, // max(A, B)
mjSDFTYPE_MIDSURFACE, // A - B
mjSDFTYPE_COLLISION, // A + B + abs(max(A, B))
} mjtSDFType;
struct mjSDF_ {
const mjpPlugin** plugin;
int* id;
mjtSDFType type;
mjtNum* relpos;
mjtNum* relmat;
mjtGeom* geomtype;
};
typedef struct mjSDF_ mjSDF;
// get sdf from geom id
MJAPI const mjpPlugin* mjc_getSDF(const mjModel* m, int id);
// signed distance function
MJAPI mjtNum mjc_distance(const mjModel* m, const mjData* d, const mjSDF* s, const mjtNum x[3]);
+6
View File
@@ -419,6 +419,12 @@ public enum mjtFlexSelf : int{
mjFLEXSELF_SAP = 3,
mjFLEXSELF_AUTO = 4,
}
public enum mjtSDFType : int{
mjSDFTYPE_SINGLE = 0,
mjSDFTYPE_INTERSECTION = 1,
mjSDFTYPE_MIDSURFACE = 2,
mjSDFTYPE_COLLISION = 3,
}
public enum mjtPluginCapabilityBit : int{
mjPLUGIN_ACTUATOR = 1,
mjPLUGIN_SENSOR = 2,