// Copyright 2024 DeepMind Technologies Limited // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef MUJOCO_SRC_USER_USER_API_H_ #define MUJOCO_SRC_USER_USER_API_H_ #include #include #include #include // this is a C-API #ifdef __cplusplus extern "C" { #endif //---------------------------------- handles to internal objects ----------------------------------- typedef struct _mjElement* mjElement; typedef struct _mjString* mjString; typedef struct _mjStringVec* mjStringVec; typedef struct _mjIntVec* mjIntVec; typedef struct _mjIntVecVec* mjIntVecVec; typedef struct _mjFloatVec* mjFloatVec; typedef struct _mjFloatVecVec* mjFloatVecVec; typedef struct _mjDoubleVec* mjDoubleVec; //---------------------------------- enum types (mjt) ---------------------------------------------- typedef enum _mjtGeomInertia { // type of inertia inference mjINERTIA_VOLUME, // mass distributed in the volume mjINERTIA_SHELL, // mass distributed on the surface } mjtGeomInertia; typedef enum _mjtBuiltin { // type of built-in procedural texture mjBUILTIN_NONE = 0, // no built-in texture mjBUILTIN_GRADIENT, // gradient: rgb1->rgb2 mjBUILTIN_CHECKER, // checker pattern: rgb1, rgb2 mjBUILTIN_FLAT // 2d: rgb1; cube: rgb1-up, rgb2-side, rgb3-down } mjtBuiltin; typedef enum _mjtMark { // mark type for procedural textures mjMARK_NONE = 0, // no mark mjMARK_EDGE, // edges mjMARK_CROSS, // cross mjMARK_RANDOM // random dots } mjtMark; typedef enum _mjtLimited { // type of limit specification mjLIMITED_FALSE = 0, // not limited mjLIMITED_TRUE, // limited mjLIMITED_AUTO, // limited inferred from presence of range } mjtLimited; typedef enum _mjtInertiaFromGeom { mjINERTIAFROMGEOM_FALSE = 0, // do not use; inertial element required mjINERTIAFROMGEOM_TRUE, // always use; overwrite inertial element mjINERTIAFROMGEOM_AUTO // use only if inertial element is missing } mjtInertiaFromGeom; //---------------------------------- attribute structs (mjm) --------------------------------------- typedef struct _mjSpec { // model specification mjElement element; // internal, do not modify mjStatistic stat; // statistics override (if defined) // compiler settings mjtByte autolimits; // infer "limited" attribute based on range double boundmass; // enforce minimum body mass double boundinertia; // enforce minimum body diagonal inertia double settotalmass; // rescale masses and inertias; <=0: ignore mjtByte balanceinertia; // automatically impose A + B >= C rule mjtByte strippath; // automatically strip paths from mesh files mjtByte fitaabb; // meshfit to aabb instead of inertia box mjtByte degree; // angles in radians or degrees char euler[3]; // sequence for euler rotations mjString meshdir; // mesh and hfield directory mjString texturedir; // texture directory mjtByte discardvisual; // discard visual geoms in parser mjtByte convexhull; // compute mesh convex hulls mjtByte usethread; // use multiple threads to speed up compiler mjtByte fusestatic; // fuse static bodies with parent int inertiafromgeom; // use geom inertias (mjtInertiaFromGeom) int inertiagrouprange[2]; // range of geom groups used to compute inertia mjtByte exactmeshinertia; // if false, use old formula mjLROpt LRopt; // options for lengthrange computation // engine data mjString modelname; // model name mjOption option; // options mjVisual visual; // visual options size_t memory; // size of arena+stack memory in bytes int nemax; // max number of equality constraints int njmax; // max number of constraints (Jacobian rows) int nconmax; // max number of detected contacts (mjContact array size) size_t nstack; // (deprecated) number of fields in mjData stack int nuserdata; // number extra fields in mjData int nuser_body; // number of mjtNums in body_user int nuser_jnt; // number of mjtNums in jnt_user int nuser_geom; // number of mjtNums in geom_user int nuser_site; // number of mjtNums in site_user int nuser_cam; // number of mjtNums in cam_user int nuser_tendon; // number of mjtNums in tendon_user int nuser_actuator; // number of mjtNums in actuator_user int nuser_sensor; // number of mjtNums in sensor_user // sizes int nkey; // number of keyframes // global data mjString comment; // comment at top of XML mjString modelfiledir; // path to model file // other bool hasImplicitPluginElem; // already encountered an implicit plugin sensor/actuator } mjSpec; typedef struct _mjmOrientation { // alternative orientation specifiers double axisangle[4]; // rotation axis and angle double xyaxes[6]; // x and y axes double zaxis[3]; // z axis (use minimal rotation) double euler[3]; // euler angles } mjmOrientation; typedef struct _mjmPlugin { // plugin specification mjElement instance; // internal, do not modify mjString name; // name mjString instance_name; // instance name int plugin_slot; // global registered slot number of the plugin mjtByte active; // is the plugin active mjString info; // message appended to compiler errors } mjmPlugin; typedef struct _mjmBody { // body specification mjElement element; // internal, do not modify mjString name; // name mjString childclass; // childclass name // body frame double pos[3]; // frame position double quat[4]; // frame orientation mjmOrientation alt; // frame alternative orientation // inertial frame double mass; // mass double ipos[3]; // inertial frame position double iquat[4]; // inertial frame orientation double inertia[3]; // diagonal inertia (in i-frame) mjmOrientation ialt; // inertial frame alternative orientation double fullinertia[6]; // non-axis-aligned inertia matrix // other mjtByte mocap; // is this a mocap body double gravcomp; // gravity compensation mjDoubleVec userdata; // user data mjtByte explicitinertial; // whether to save the body with explicit inertial clause mjmPlugin plugin; // passive force plugin mjString info; // message appended to compiler errors } mjmBody; typedef struct _mjmFrame { // frame specification mjElement element; // internal, do not modify mjString name; // name mjString childclass; // childclass name double pos[3]; // position double quat[4]; // orientation mjmOrientation alt; // alternative orientation mjString info; // message appended to compiler errors } mjmFrame; typedef struct _mjmJoint { // joint specification mjElement element; // internal, do not modify mjString name; // name mjString classname; // class name mjtJoint type; // joint type // kinematics double pos[3]; // anchor position double axis[3]; // joint axis double ref; // value at reference configuration: qpos0 // stiffness double stiffness; // stiffness coefficient double springref; // spring reference value: qpos_spring double springdamper[2]; // timeconst, dampratio // limits int limited; // does joint have limits (mjtLimited) double range[2]; // joint limits double margin; // margin value for joint limit detection mjtNum solref_limit[mjNREF]; // solver reference: joint limits mjtNum solimp_limit[mjNIMP]; // solver impedance: joint limits int actfrclimited; // are actuator forces on joint limited (mjtLimited) double actfrcrange[2]; // actuator force limits // dof properties double armature; // armature inertia (mass for slider) double damping; // damping coefficient double frictionloss; // friction loss mjtNum solref_friction[mjNREF]; // solver reference: dof friction mjtNum solimp_friction[mjNIMP]; // solver impedance: dof friction // other int group; // group double urdfeffort; // effort (urdf) mjDoubleVec userdata; // user data mjString info; // message appended to compiler errors } mjmJoint; typedef struct _mjmGeom { // geom specification mjElement element; // internal, do not modify mjString name; // name mjString classname; // classname mjtGeom type; // geom type // frame, size double pos[3]; // position double quat[4]; // orientation mjmOrientation alt; // alternative orientation double fromto[6]; // alternative for capsule, cylinder, box, ellipsoid double size[3]; // type-specific size // contact related int contype; // contact type int conaffinity; // contact affinity int condim; // contact dimensionality int priority; // contact priority double friction[3]; // one-sided friction coefficients: slide, roll, spin double solmix; // solver mixing for contact pairs mjtNum solref[mjNREF]; // solver reference mjtNum solimp[mjNIMP]; // solver impedance double margin; // margin for contact detection double gap; // include in solver if dist < margin-gap // inertia inference double mass; // used to compute density double density; // used to compute mass and inertia from volume or surface mjtGeomInertia typeinertia; // selects between surface and volume inertia // fluid forces mjtNum fluid_ellipsoid; // whether ellipsoid-fluid model is active mjtNum fluid_coefs[5]; // ellipsoid-fluid interaction coefs // visual mjString material; // name of material float rgba[4]; // rgba when material is omitted int group; // group // other mjString hfieldname; // heightfield attached to geom mjString meshname; // mesh attached to geom double fitscale; // scale mesh uniformly mjDoubleVec userdata; // user data mjmPlugin plugin; // sdf plugin mjString info; // message appended to compiler errors } mjmGeom; typedef struct _mjmSite { // site specification mjElement element; // internal, do not modify mjString name; // name mjString classname; // class name // frame, size double pos[3]; // position double quat[4]; // orientation mjmOrientation alt; // alternative orientation double fromto[6]; // alternative for capsule, cylinder, box, ellipsoid double size[3]; // geom size // visual mjtGeom type; // geom type mjString material; // name of material int group; // group float rgba[4]; // rgba when material is omitted // other mjDoubleVec userdata; // user data mjString info; // message appended to compiler errors } mjmSite; typedef struct _mjmCamera { // camera specification mjElement element; // internal, do not modify mjString name; // name mjString classname; // class name // extrinsics double pos[3]; // position double quat[4]; // orientation mjmOrientation alt; // alternative orientation mjtCamLight mode; // tracking mode mjString targetbody; // target body for tracking/targeting // intrinsics double fovy; // y-field of view double ipd; // inter-pupilary distance float intrinsic[4]; // camera intrinsics (length) float sensor_size[2]; // sensor size (length) float resolution[2]; // resolution (pixel) float focal_length[2]; // focal length (length) float focal_pixel[2]; // focal length (pixel) float principal_length[2]; // principal point (length) float principal_pixel[2]; // principal point (pixel) // other mjDoubleVec userdata; // user data mjString info; // message appended to compiler errors } mjmCamera; typedef struct _mjmLight { // light specification mjElement element; // internal, do not modify mjString name; // name mjString classname; // class name // frame double pos[3]; // position double dir[3]; // direction mjtCamLight mode; // tracking mode mjString targetbody; // target body for targeting // intrinsics mjtByte active; // is light active mjtByte directional; // is light directional or spot mjtByte castshadow; // does light cast shadows float attenuation[3]; // OpenGL attenuation (quadratic model) float cutoff; // OpenGL cutoff float exponent; // OpenGL exponent float ambient[3]; // ambient color float diffuse[3]; // diffuse color float specular[3]; // specular color // other mjString info; // message appended to compiler errors } mjmLight; typedef struct _mjmFlex { mjElement element; // internal, do not modify mjString name; // name mjString classname; // class name // contact properties int contype; // contact type int conaffinity; // contact affinity int condim; // contact dimensionality int priority; // contact priority double friction[3]; // one-sided friction coefficients: slide, roll, spin double solmix; // solver mixing for contact pairs mjtNum solref[mjNREF]; // solver reference mjtNum solimp[mjNIMP]; // solver impedance double margin; // margin for contact detection double gap; // include in solver if distfullinertia. MJAPI const char* mjm_setFullInertia(mjmBody* body, double quat[4], double inertia[3]); //---------------------------------- Initialization functions -------------------------------------- // Default model attributes. MJAPI void mjm_defaultSpec(mjSpec& model); // Default body attributes. MJAPI void mjm_defaultBody(mjmBody& body); // Default frame attributes. MJAPI void mjm_defaultFrame(mjmFrame& frame); // Default joint attributes. MJAPI void mjm_defaultJoint(mjmJoint& joint); // Default geom attributes. MJAPI void mjm_defaultGeom(mjmGeom& geom); // Default site attributes. MJAPI void mjm_defaultSite(mjmSite& site); // Default camera attributes. MJAPI void mjm_defaultCamera(mjmCamera& camera); // Default light attributes. MJAPI void mjm_defaultLight(mjmLight& light); // Default flex attributes. MJAPI void mjm_defaultFlex(mjmFlex& flex); // Default mesh attributes. MJAPI void mjm_defaultMesh(mjmMesh& mesh); // Default height field attributes. MJAPI void mjm_defaultHField(mjmHField& hfield); // Default skin attributes. MJAPI void mjm_defaultSkin(mjmSkin& skin); // Default texture attributes. MJAPI void mjm_defaultTexture(mjmTexture& texture); // Default material attributes. MJAPI void mjm_defaultMaterial(mjmMaterial& material); // Default pair attributes. MJAPI void mjm_defaultPair(mjmPair& pair); // Default equality attributes. MJAPI void mjm_defaultEquality(mjmEquality& equality); // Default tendon attributes. MJAPI void mjm_defaultTendon(mjmTendon& tendon); // Default actuator attributes. MJAPI void mjm_defaultActuator(mjmActuator& actuator); // Default sensor attributes. MJAPI void mjm_defaultSensor(mjmSensor& sensor); // Default numeric attributes. MJAPI void mjm_defaultNumeric(mjmNumeric& numeric); // Default text attributes. MJAPI void mjm_defaultText(mjmText& text); // Default tuple attributes. MJAPI void mjm_defaultTuple(mjmTuple& tuple); // Default keyframe attributes. MJAPI void mjm_defaultKey(mjmKey& key); // Default plugin attributes. MJAPI void mjm_defaultPlugin(mjmPlugin& plugin); //------------------------- Cache functions ------------------------------------ typedef struct _mjCache* mjCache; // Set the size of the cache in bytes. MJAPI void mj_setCacheSize(mjCache cache, size_t size); // Get internal global cache context. MJAPI mjCache mj_globalCache(); #ifdef __cplusplus } #endif #endif // MUJOCO_SRC_USER_USER_API_H_