MuJoCo 学习笔记:概述 Overview

MuJoCo 官方文档给出了详细介绍 MuJoCo Overview 。下面截取部分相对重要的内容翻译记录。

参考:Mujoco官方文档中文翻译1-概述


1. 关键特性 Key Feature

1.1 广义坐标 + 现代接触动力学 Generalized coordinates combined with modern contact dynamics

物理引擎传统上分为两类。1. 机器人学和生物力学引擎通常在广义坐标关节坐标中使用高效准确的递归算法。然而,它们要么省略了接触动力学,要么依赖于早期的弹簧-阻尼器方法(这在仿真中需要非常小的时间步长)。2. 游戏引擎则使用一种更现代的方法,通过求解优化问题来模拟接触力。然而,它们通常采用笛卡尔坐标(注:over-specified Cartesian represenation,大概是说,仿真场景中物体的自由度大于真实世界中的自由度,再通过约束来限定关节/减小自由度),其中关节约束是数值施加的,当涉及复杂的运动学结构时,会导致仿真结果不准确、不稳定。MuJoCo 是结合了上述两类中各自优点的通用引擎:广义坐标中的仿真基于优化的接触动力学。最近几年,其他引擎也加入了类似MuJoCo的方法(可能就是在点名PhysX),但也不太容易与它们原有的功能很好的兼容,因为这与他们最初的设计不一致(注:大概是说,其他引擎最开始是采用笛卡尔坐标的,虽然最近也支持了广义坐标下的仿真,但很难与原有的功能很好的兼容)。习惯了游戏引擎的用户,最初可能会觉得广义坐标不符合直觉(我也是这样的>_<)。

Physics engines have traditionally separated in two categories. Robotics and biomechanics engines use efficient and accurate recursive algorithms in generalized or joint coordinates. However they either leave out contact dynamics, or rely on the earlier spring-damper approach which requires very small time-steps. Gaming engines use a more modern approach where contact forces are found by solving an optimization problem. However, they often resort to the over-specified Cartesian representation where joint constraints are imposed numerically, causing inaccuracies and instabilities when elaborate kinematic structures are involved. MuJoCo was the first general-purpose engine to combine the best of both worlds: simulation in generalized coordinates and optimization-based contact dynamics. Other simulators have more recently been adapted to use MuJoCo’s approach, but that is not usually compatible with all of their functionality because they were not designed to do this from the start. Users accustomed to gaming engines may find the generalized coordinates counterintuitive at first; see Clarifications section below.

1.2 柔性、凸形和逆可解析的接触动力学 Soft, convex and analytically-invertible contact dynamics

在现代接触动力学方法中,计算由摩擦接触引起的力或冲量,通常将其定义为线性或非线性互补问题(LCP或NCP),这两者都是 NP-hard 问题。MuJoCo 则基于一种不同的接触物理,它将接触动力学简化为一个凸优化问题。该方法允许柔性接触和其他约束,并具有唯一定义的逆,有助于数据分析和控制应用。对于优化问题的求解,有多种算法可供选择,包括投影高斯-塞德尔方法等,其可以处理椭圆摩擦锥。这类求解器提供统一处理摩擦接触的方法,包括扭转和滚动摩擦、无摩擦接触、关节和肌腱限制、关节和肌腱中的干摩擦,以及各种等式约束。

In the modern approach to contact dynamics, the forces or impulses caused by frictional contacts are usually defined as the solution to a linear or non-linear complementarity problem (LCP or NCP), both of which are NP-hard. MuJoCo is based on a different formulation of the physics of contact which reduces to a convex optimization problem, as explained in detail in the Computation chapter. Our model allows soft contacts and other constraints, and has a uniquely-defined inverse facilitating data analysis and control applications. There is a choice of optimization algorithms, including a generalization to the projected Gauss-Seidel method that can handle elliptic friction cones. The solver provides unified treatment of frictional contacts including torsional and rolling friction, frictionless contacts, joint and tendon limits, dry friction in joints and tendons, as well as a variety of equality constraints.

1.3 通用驱动模型 General actuation model

既要为未知模型提供 API,又要使其能设计出足够丰富的驱动模型,是十分具有挑战性的。MuJoCo 通过采用一个抽象的驱动模型来实现这一目标。该模型可以具有不同类型的 transmission、force generation 和 internal dynamics(即,使动力学状态三阶可导)。这些组件可以实例化,以统一的方式模拟电机、气动和液压缸、PD控制器、生物肌肉和许多其他驱动器。

Designing a sufficiently rich actuation model while using a model-agnostic API is challenging. MuJoCo achieves this goal by adopting an abstract actuation model that can have different types of transmission, force generation, and internal dynamics (i.e., state variables which make the overall dynamics 3rd order). These components can be instantiated so as to model motors, pneumatic and hydraulic cylinders, PD controllers, biological muscles and many other actuators in a unified way.

1.4 可重配置的计算流水线 Reconfigurable computation pipeline

MuJoCo 有一个顶层的仿真步函数 mj_step,它实现了完整的正向动力学计算并更新仿真场景的状态。然而,在仿真之外的许多应用中,往往期望能够运行计算流水线的部分环节。为此,MuJoCo 提供了大量可以以组合设置的标志位,允许用户根据需要重新配置流水线。此外,提供了许多低级别函数直接调用。用户定义的回调函数可以实现自定义力场、驱动器、碰撞例程和反馈控制器。

MuJoCo has a top-level stepper function mj_step which runs the entire forward dynamics and advances the state of the simulation. In many applications beyond simulation, however, it is beneficial to be able to run selected parts of the computation pipeline. To this end MuJoCo provides a large number of flags which can be set in any combination, allowing the user to reconfigure the pipeline as needed, beyond the selection of algorithms and algorithm parameters via options. Furthermore many lower-level functions can be called directly. User-defined callbacks can implement custom force fields, actuators, collision routines, and feedback controllers.


2. 模型元素 Model elements

本章节简要介绍 MuJoCo 中相对重要的模型元素,其他的不做重点介绍了。

2.1 选项 Options

在 MuJoCo 中,每个模型都包含以下三组选项。如果在 XML 文件中没有指定它们的值,则使用默认值。用户可以在每个仿真时间步之前更改这些选项的值,但在一个时间步内用户不能修改这些值。
mjOption:这个结构体包含所有物理仿真相关的选项。它用于选择算法并设置它们的参数,启用和禁用仿真流水线的不同部分,并设定系统级的物理属性,如重力。
mjVisual:这个结构体包含所有可视化相关的选项。此外也包含额外的 OpenGL 渲染选项,但这些是 session-dependent,并不是模型的一部分。
mjStatistic:这个结构体包含由编译器计算的模型统计信息,例如平均体质量、模型的空间范围等。这个选项主要是为了提供信息,也可以帮助渲染器自动调整缩放(视角等)。

2.2 资产 Assets

资产本身不是模型元素。模型元素可以引用资产,这种情况下资产以某种方式改变了引用元素的属性。一个资产可以被多个模型元素引用。由于包含资产的唯一目的是引用它,而引用只能通过名称完成,因此每个资产都有一个名称(在适用时,名称可能从文件名推断而来)。相比之下,普通元素的名称可以不定义。

网格 Mesh

MuJoCo 可以从 OBJ 文件或二进制 STL 中加载三角网格。虽然任何三角形集合都可以作为网格加载和可视化,但在 MuJoCo 的碰撞检测器仅支持凸包。通过设定选项,可以在编译阶段缩放网格,以及将原始几何形状拟合到网格上。网格也可以用于自动估计刚体的惯性属性(通过将网格视为三角金字塔的联合,并结合它们的质量和惯性)。注意,网格没有颜色,网格的颜色使用引用 geom 的材料属性着色。相比之下,所有空间属性都由网格数据决定。MuJoCo 支持 OBJ 和自定义的二进制文件格式用于法线和纹理坐标。网格也可以直接嵌入在XML中。

MuJoCo can load triangulated meshes from OBJ files and binary STL. Software such as MeshLab can be used to convert from other formats. While any collection of triangles can be loaded and visualized as a mesh, the collision detector works with the convex hull. There are compile-time options for scaling the mesh, as well as fitting a primitive geometric shape to it. The mesh can also be used to automatically infer inertial properties – by treating it as a union of triangular pyramids and combining their masses and inertias. Note that meshes have no color, instead the mesh is colored using the material properties of the referencing geom. In contrast, all spatial properties are determined by the mesh data. MuJoCo supports both OBJ and a custom binary file format for normals and texture coordinates. Meshes can also be embedded directly in the XML.

高度场 Height field

高度场可以从 PNG 文件加载(内部转换为灰度),或从自定义的二进制格式文件中加载。高度场是一系列高度数据的矩形网格,编译器将数据归一化到 [0-1] 的范围。高度场的实际空间范围由引用 geom 的大小参数确定,且高度场只能从附加到世界坐标系的 geom 引用。为了渲染和碰撞检测的目的,高度场的网格矩形会自动三角化,因此高度场实际上由一系列三角棱柱组合而成。与这种复合对象的碰撞检测理论上可以为单个geom对生成大量接触点,如果发生这种情况,只保留前64个接触点。理由是,高度场通常用于模拟地形图,其空间特征与仿真中的其他对象相比较大,因此对于设计良好的模型,接触点的数量将很少。

2.3 运动学树 Kinematic tree

MuJoCo 通常模拟一组运动受限的刚体的动力学。系统状态以关节坐标表示,并且刚体被组织成运动学树。除了顶层的“世界”刚体之外(类似于基座),每个刚体都有一个唯一的父刚体。在 MuJoCo 中,不允搭建环状的运动树;如果需要环状的链,则应该使用等式约束来建模(即通过等式约束把首位连接起来)。因此,MuJoCo 模型的骨干是由嵌套的刚体定义形成的一个或多个运动学树;一个孤立的刚体也被视为一棵树。下面列出的几类元素是在 body 内部定义并属于该 body。

刚体 Body

刚体具有质量和惯性属性,但没有几何属性。几何形状(geoms)被附加到刚体上。每个刚体有两个坐标系:一个用于定义自身位置、以及其他元素相对于该刚体的位置;一个以刚体质心为中心、并与其主惯性轴对齐的惯性坐标系(因此,刚体惯性矩阵在这个坐标系中是对角的)。在每个时间步,MuJoCo 递归地计算(运动树的)正向运动学,得出所有刚体在全局笛卡尔坐标中的位置和方向。

Bodies have mass and inertial properties but do not have any geometric properties. Instead geometric shapes (or geoms) are attached to the bodies. Each body has two coordinate frames: the frame used to define it as well as to position other elements relative to it, and an inertial frame centered at the body’s center of mass and aligned with its principal axes of inertia. The body inertia matrix is therefore diagonal in this frame. At each time step MuJoCo computes the forward kinematics recursively, yielding all body positions and orientations in global Cartesian coordinates. This provides the basis for all subsequent computations.

关节 Joint

关节在刚体内定义(隶属于)。关节在刚体和其父刚体之间创建运动自由度(DOF)。如果没有关节,刚体就焊接在其父刚体上。这与游戏引擎使用的笛卡尔坐标相反,在游戏引擎中,关节是移除自由度而不是增加自由度。(注:大概是说,MuJoCo 使用广义坐标系,新建关节即增加自由度。而传统游戏引擎使用笛卡尔坐标,通过关节约束限定自由度/移除自由度。)在 MuJoCo 中,有四种类型的关节:球关节、滑动环节、铰链和“自由关节”(它创建浮动刚体)。刚体可以有多个关节,这样可以创建复合关节,而无需定义虚拟刚体。球关节和自由关节的方向分量表示为单位四元数,MuJoCo 中的所有计算大都兼容四元数。

Joints are defined within bodies. They create motion degrees of freedom (DOFs) between the body and its parent. In the absence of joints the body is welded to its parent. This is the opposite of gaming engines which use over-complete Cartesian coordinates, where joints remove DOFs instead of adding them. There are four types of joints: ball, slide, hinge, and a “free joint” which creates floating bodies. A single body can have multiple joints. In this way composite joints are created automatically, without having to define dummy bodies. The orientation components of ball and free joints are represented as unit quaternions, and all computations in MuJoCo respect the properties of quaternions.

关节参考 Joint Reference

参考位姿是一组关节位置向量,存储在 mjModel.qpos0 中,它对应于模型处于初始配置时的关节位置。在我们早期的例子中,肘部以 90° 角的弯曲配置创建。但 MuJoCo 不知道什么是肘部,因此,默认情况下它将这个关节配置视为数值为 0。我们可以通过关节的参考属性覆盖默认行为,并指定初始配置对应于 90° (即设置 Joint Reference 为 90°)。所有关节的参考值被组装成向量 mjModel.qpos0 。每次重置仿真时,关节配置 mjData.qpos 被设置为 mjModel.qpos0 。在运行仿真时,关节位置向量的值是相对于参考位姿的(大概是说,关节真实位置 = 关节位置 + 参考位置)。特别是,关节应用的空间变换量是 mjData.qpos - mjModel.qpos0。这个变换是除了存储在 mjModel 中的 body 元素中的父子平移和旋转偏移之外的。参考属性仅适用于标量关节(滑块和铰链)。对于球关节,存储在 mjModel.qpos0 中的四元数始终是(1,0,0,0),对应于零旋转。对于自由关节,浮动刚体的全局3D位置和四元数保存在 mjModel.qpos0 中。
(感觉还是没有特别理解这段。需要列举一些例子吧。)

The reference pose is a vector of joint positions stored in mjModel.qpos0. It corresponds to the numeric values of the joints when the model is in its initial configuration. In our earlier example the elbow was created in a bent configuration at 90° angle. But MuJoCo does not know what an elbow is, and so by default it treats this joint configuration as having numeric value of 0. We can override the default behavior and specify that the initial configuration corresponds to 90°, using the ref attribute of joint. The reference values of all joints are assembled into the vector mjModel.qpos0. Whenever the simulation is reset, the joint configuration mjData.qpos is set to mjModel.qpos0. At runtime the joint position vector is interpreted relative to the reference pose. In particular, the amount of spatial transformation applied by the joints is mjData.qpos - mjModel.qpos0. This transformation is in addition to the parent-child translation and rotation offsets stored in the body elements of mjModel. The ref attribute only applies to scalar joints (slide and hinge). For ball joints, the quaternion saved in mjModel.qpos0 is always (1,0,0,0) which corresponds to the null rotation. For free joints, the global 3D position and quaternion of the floating body are saved in mjModel.qpos0.

弹簧参考 Spring Reference

这是所有关节和肌腱弹簧达到其初始长度的位姿。当关节配置偏离弹簧参考姿势时,会产生弹簧力,并且与偏离量成线性关系。弹簧参考姿势保存在 mjModel.qpos_spring 中。对于滑动关节和铰链关节,弹簧参考用 springref 属性指定。对于球关节和自由关节,弹簧参考对应于初始模型配置。

自由度 DOF

自由度与关节密切相关,但它们不是一一对应的,因为球关节和自由关节有多个自由度。将关节视为指定位置信息,而自由度指定速度和力信息。更正式地说,关节位置是系统配置流形上的坐标,而关节速度是当前位置处该流形切空间上的坐标。自由度具有与速度相关的属性,如摩擦损失、阻尼、电机惯性。作用于系统的所有广义力都在自由度空间中表示。相比之下,关节具有与位置相关的属性,如限制和弹簧刚度。用户不直接指定自由度。相反,它们是由编译器根据关节自动创建的。

Degrees of freedom are closely related to joints, but are not in one-to-one correspondence because ball and free joints have multiple DOFs. Think of joints as specifying positional information, and of DOFs as specifying velocity and force information. More formally, the joint positions are coordinates over the configuration manifold of the system, while the joint velocities are coordinates over the tangent space to this manifold at the current position. DOFs have velocity-related properties such as friction loss, damping, armature inertia. All generalized forces acting on the system are expressed in the space of DOFs. In contrast, joints have position-related properties such as limits and spring stiffness. DOFs are not specified directly by the user. Instead they are created by the compiler given the joints.

posted @ 2024-08-30 09:50  wghou09  阅读(1083)  评论(0)    收藏  举报