赞
踩
在本篇博客中,我们将深入探讨一个具体的MuJoCo模型,通过其XML配置文件来解析模型的组成、设计理念及其在模拟环境中的作用。MuJoCo(Multi-Joint dynamics with Contact)是一种用于机器人学、生物力学、仿生学和其他领域的物理引擎,它支持精确的力学模拟和复杂交互的创建。
<compiler inertiafromgeom='true' angle='degree'/>
此行定义了整个模型的编译器设置,inertiafromgeom='true'
表示从几何形状自动计算惯性,而 angle='degree'
则指定了角度单位为度。这些设置是为了简化模型的定义过程,并使其更加直观。
<asset>
<material name="matplane" reflectance="0.3" texture="texplane" texrepeat="1 1" texuniform="true"/>
<material name="matgeom" texture="texgeom" texuniform="true" rgba="0.8 0.6 .4 1"/>
<texture name="texplane" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2" width="512" height="512" mark="cross" markrgb=".8 .8 .8"/>
<texture name="texgeom" type="cube" builtin="flat" mark="cross" width="127" height="1278" rgb1="0.8 0.6 0.4" rgb2="0.8 0.6 0.4" markrgb="1 1 1" random="0.01"/>
<texture type="skybox" builtin="gradient" rgb1="1 1 1" rgb2=".6 .8 1" width="256" height="256"/>
</asset>
资产部分定义了模型中使用的所有材料、纹理等资源。例如,material
定义了材料属性如反射率和纹理,而 texture
则定义了具体的纹理特征,包括类型、颜色、大小等。这里定义的材料和纹理在模型的其他部分中被引用,以实现视觉上的效果。
<worldbody>
<geom name="floor" pos="0 0 0" size="10 10 0.1" type="plane" material="matplane"/>
<light directional="false" diffuse=".2 .2 .2" specular="0 0 0" pos="0 0 5" dir="0 0 -1"/>
<light mode="targetbodycom" directional="false" diffuse=".8 .8 .8" specular="0.3 0.3 0.3" pos="0 0 4.0" dir="0 0 -1"/>
<body name='base' pos='0 0 1.2'>
<!-- <geom type='cylinder' size='.1 .1' euler="90 0 0" rgba='1 0 0 1'/> -->
<joint name='joint1' type='hinge' axis='0 1 0' pos='0 0 0'/>
<body name='arm1' pos='0 0 -0.3'>
<geom type='capsule' size='.1 .2' rgba='0 1 0 1'/>
<body name='arm2' pos='0 0 -0.4'>
<!-- <geom type='cylinder' size='.1 .1' euler="90 0 0" rgba='1 0 0 1'/> -->
<joint name='joint2' type='hinge' axis='0 1 0' pos='0 0 0'/>
<body name='linkjoint2' pos='0 0 -0.2'>
<geom type='capsule' size='.1 .2' rgba='0 0 1 1'/>
</body>
</body>
</body>
</body>
<body name="point_marker1" pos="0 0 0">
<geom type="sphere" size="0.05" rgba="1 0 0 1"/>
</body>
<body name="point_marker2" pos="1.2 0 1.2">
<geom type="sphere" size="0.05" rgba="1 0 0 1"/>
</body>
<body name="point_marker3" pos="0.0 0 2.4">
<geom type="sphere" size="0.05" rgba="1 0 0 1"/>
</body>
<body name="point_marker4" pos="-1.2 0 1.2">
<geom type="sphere" size="0.05" rgba="1 0 0 1"/>
</body>
<!-- <body name="point_marker5" pos="1.0 0 0.8">
<geom type="sphere" size="0.05" rgba="1 0 0 1"/>
</body> -->
</worldbody>
worldbody
部分构造了模型的物理世界,包括地面、灯光和所有的物理体。例如,geom
标签定义了各种几何形状如地面平面、胶囊和球体。每个几何体都可以指定材料、位置、大小等属性。body
标签则用于定义具有层次结构的物理体,如本例中的机械臂组件,每个 body
可以包含多个几何体(geom
)和关节(joint
)。
<actuator>
<motor joint='joint1' name='joint1' gear='101'/>
<motor joint='joint2' name='joint2' gear='11' />
</actuator>
执行器部分定义了如何控制模型中的动作。在这个例子中,通过两个 motor
来控制关节的运动,gear
属性定义了力矩的大小。这使得我们可以模拟机械臂的运动控制。
在执行器配置中有很多中配置方法,比如可以设定其速度、位置等,但是经过尝试发现,效果都非常不好,甚至无法使用的程度,(可能是笔者能力有限的原因,亦或是参数调不好的原因导致),但是查阅各类开源文件,不论是角度还是速度大多都是定义的力矩控制,后续再在控制器中加入PID控制器实现角度或速度控制,所以在此定义为力矩控制。
经过上述建模,就可以得到一个简单的机械臂模型。
如下图所示(图中红点为后续控制点暂时可以忽略)
通过上述解析,我们可以看到MuJoCo模型的XML文件如何详细地描述了一个复杂的模拟环境,包括其物理特性、视觉效果和控制机制。这种详细程度的配置为模拟提供了高度的灵活性和精确度,使得MuJoCo成为复杂动态系统模拟的有力工具。
后续将更新如何使用mujoco_py实现控制该机械臂的简单教程。
引用需要标明出处,违者必究
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。