Mujoco核心数据结构-mjData mjModel

Defined in mjdata.h
This is the data structure holding information about one solver iteration. mjData.solver is a preallocated array of mjSolverStat data structures, one for each iteration of the solver, up to a maximum of mjNSOLVER. The actual number of solver iterations is given by mjData.solver_iter.

struct _mjData
{
   
   
    // constant sizes
    int nstack;                     // number of mjtNums that can fit in stack
    int nbuffer;                    // size of main buffer in bytes

    // stack pointer
    int pstack;                     // first available mjtNum address in stack

    // memory utilization stats
    int maxuse_stack;               // maximum stack allocation
    int maxuse_con;                 // maximum number of contacts
    int maxuse_efc;                 // maximum number of scalar constraints

    // diagnostics
    mjWarningStat warning[mjNWARNING]; // warning statistics
    mjTimerStat timer[mjNTIMER];       // timer statistics
    mjSolverStat solver[mjNSOLVER];    // solver statistics per iteration
    int solver_iter;                // number of solver iterations
    int solver_nnz;                 // number of non-zeros in Hessian or efc_AR
    mjtNum solver_fwdinv[2];        // forward-inverse comparison: qfrc, efc

    // variable sizes
    int ne;                         // number of equality constraints
    int nf;                         // number of friction constraints
    int nefc;                       // number of constraints
    int ncon;                       // number of detected contacts

    // global properties
    mjtNum time;                    // simulation time
    mjtNum energy[2];               // potential, kinetic energy

    //-------------------------------- end of info header

    // buffers
    void*     buffer;               // main buffer; all pointers point in it    (nbuffer bytes)
    mjtNum*   stack;                // stack buffer                             (nstack mjtNums)

    //-------------------------------- main inputs and outputs of the computation

    // state
    mjtNum*   qpos;                 // position                                 (nq x 1)
    mjtNum*   qvel;                 // velocity                                 (nv x 1)
    mjtNum*   act;                  // actuator activation                      (na x 1)
    mjtNum*   qacc_warmstart;       // acceleration used for warmstart          (nv x 1)

    // control
    //0 = torque actuator,1=position servo,2= velocity servo
    mjtNum*   ctrl;                 // control                                  (nu x 1)
    mjtNum*   qfrc_applied;         // applied ge`neralized force`                (nv x 1)
    mjtNum*   xfrc_applied;         // applied Cartesian force/torque           (nbody x 6)

    // dynamics
    //M*qacc + qfrc_bias = qfrc_applied + ctrl中的qacc,加速度
    mjtNum*   qacc;                 // acceleration                             (nv x 1)
    mjtNum*   act_dot;              // time-derivative of actuator activation   (na x 1)

    // mocap data
    mjtNum*  mocap_pos;             // positions of mocap bodies                (nmocap x 3)
    mjtNum*  mocap_quat;            // orientations of mocap bodies             (nmocap x 4)

    // user data
    mjtNum*  userdata;              // user data, not touched by engine         (nuserdata x 1)

    // sensors
    //传感器是3x1,即一个传感器就有3个数据x,y,z,如果感应的是速度,则是dx,dy,dz
    //传感器类型:framepos=感应位置,framelinvel感应速度
    mjtNum*  sensordata;            // sensor data array                        (nsensordata x 1)

    //-------------------------------- POSITION dependent

    // computed by mj_fwdPosition/mj_kinematics
    mjtNum*   xpos;                 // Cartesian position of body frame         (nbody x 3)
    mjtNum*   xquat;                // Cartesian orientation of body frame      (nbody x 4)
    mjtNum*   xmat;                 // Cartesian orientation of body frame      (nbody x 9)
    mjtNum*   xipos;                // Cartesian position of body com           (nbody x 3)
    mjtNum*   ximat;                // Cartesian orientation of body inertia    (nbody x 9)
    mjtNum*   xanchor;              // Cartesian position of joint anchor       (njnt x 3)
    mjtNum*   xaxis;                // Cartesian joint axis                     (njnt x 3)
    mjtNum*   geom_xpos;            // Cartesian geom position                  (ngeom x 3)
    mjtNum*   geom_xmat;            // Cartesian geom orientation               (ngeom x 9)
    mjtNum*   site_xpos;            // Cartesian site position                  (nsite x 3)
    mjtNum*   site_xmat;            // Cartesian site orientation               (nsite x 9)
    mjtNum*   cam_xpos;             // Cartesian camera position                (ncam x 3)
    mjtNum*   cam_xmat;             // Cartesian camera orientation             (ncam x 9)
    mjtNum*   light_xpos;           // Cartesian light position                 (nlight x 3)
    mjtNum*   light_xdir;           // Cartesian light direction                (nlight x 3)

    
03-08
### Mujoco 物理仿真软件使用教程 #### 安装与配置环境 为了开始使用 MuJoCo 进行物理仿真,首先需要安装必要的依赖项并设置工作环境。MuJoCo 是一款专为高效、精确的多体动力学模拟设计的工具,在 Linux 下尤其受欢迎[^1]。 对于初次使用者来说,建议按照官方文档中的指导完成安装过程。通常情况下,这涉及到下载许可证密钥文件、解压预编译二进制包到指定位置,并将路径添加至系统的环境变量中以便调用命令行工具或 Python API 接口[^2]。 #### 基础概念理解 熟悉几个核心术语有助于更好地掌握 MuJoCo 的功能特性: - **模型定义**:通过 XML 文件描述要仿真的对象及其属性; - **关节坐标系**:用于表示刚体之间的相对运动关系; - **几何形状(Geoms)**:负责碰撞检测及接触力计算; - **位点(Sites)**:标记特定空间位置供传感器或其他组件关联使用; - **软度和滑移参数**:控制表面间的摩擦行为,影响交互效果的真实性。 这些基本要素共同构成了复杂场景的基础框架,使得开发者能够构建逼真且高效的虚拟实验场。 #### 编写第一个程序实例 下面给出一段简单的 Python 代码片段作为入门练习,展示如何加载默认的人形模特模型并执行一次完整的仿真循环: ```python import mujoco as mj from mujoco import MjModel, MjData from mujoco.glfw import glfw def init_simulation(): xml_path = 'humanoid.xml' # 替换为你自己的XML路径 model = MjModel.from_xml_path(xml_path) data = MjData(model) if not glfw.init(): raise RuntimeError('Failed to initialize GLFW') window = glfw.create_window(800, 600, "Demo", None, None) while not glfw.window_should_close(window): mj.mj_step(model, data) # 渲染逻辑... glfw.poll_events() glfw.swap_buffers(window) if __name__ == '__main__': try: init_simulation() finally: glfw.terminate() ``` 此脚本展示了初始化渲染窗口、读取外部 XML 配置文件创建 `MjModel` 对象的过程,接着利用该模型生成相应的状态数据结构 `MjData` 实例化当前时刻的所有动态量值。最后进入主事件处理循环直至用户关闭应用程序为止。 #### 调试技巧分享 当遇到问题时,除了查阅手册外还可以尝试以下几种方法来定位错误原因: - 利用内置的日志记录机制追踪异常信息; - 启用可视化调试模式观察实际运行状况是否符合预期设定; - 参考社区论坛上的讨论帖获取更多实战经验交流机会。 以上便是关于 MuJoCo 工具链的一个简短概述,希望可以帮助有兴趣探索这一领域的朋友快速上手操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值