当前位置:   article > 正文

【MUJOCO控制篇-1】建一个简单的模型_mujoco 控制

mujoco 控制

MUJOCO控制篇-1】建一个简单的模型

在本篇博客中,我们将深入探讨一个具体的MuJoCo模型,通过其XML配置文件来解析模型的组成、设计理念及其在模拟环境中的作用。MuJoCo(Multi-Joint dynamics with Contact)是一种用于机器人学、生物力学、仿生学和其他领域的物理引擎,它支持精确的力学模拟和复杂交互的创建。

目录

编译器设置

<compiler inertiafromgeom='true' angle='degree'/>
  • 1

此行定义了整个模型的编译器设置,inertiafromgeom='true' 表示从几何形状自动计算惯性,而 angle='degree' 则指定了角度单位为度。这些设置是为了简化模型的定义过程,并使其更加直观。

asset定义

<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

资产部分定义了模型中使用的所有材料、纹理等资源。例如,material 定义了材料属性如反射率和纹理,而 texture 则定义了具体的纹理特征,包括类型、颜色、大小等。这里定义的材料和纹理在模型的其他部分中被引用,以实现视觉上的效果。

worldbody定义

<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

worldbody 部分构造了模型的物理世界,包括地面、灯光和所有的物理体。例如,geom 标签定义了各种几何形状如地面平面、胶囊和球体。每个几何体都可以指定材料、位置、大小等属性。body 标签则用于定义具有层次结构的物理体,如本例中的机械臂组件,每个 body 可以包含多个几何体(geom)和关节(joint)。

执行器配置

<actuator>
    <motor joint='joint1' name='joint1' gear='101'/>
    <motor joint='joint2' name='joint2' gear='11' />
</actuator>
  • 1
  • 2
  • 3
  • 4

执行器部分定义了如何控制模型中的动作。在这个例子中,通过两个 motor 来控制关节的运动,gear 属性定义了力矩的大小。这使得我们可以模拟机械臂的运动控制。

在执行器配置中有很多中配置方法,比如可以设定其速度、位置等,但是经过尝试发现,效果都非常不好,甚至无法使用的程度,(可能是笔者能力有限的原因,亦或是参数调不好的原因导致),但是查阅各类开源文件,不论是角度还是速度大多都是定义的力矩控制,后续再在控制器中加入PID控制器实现角度或速度控制,所以在此定义为力矩控制。

模型

经过上述建模,就可以得到一个简单的机械臂模型。
如下图所示(图中红点为后续控制点暂时可以忽略)
简单机械臂建模

总结

通过上述解析,我们可以看到MuJoCo模型的XML文件如何详细地描述了一个复杂的模拟环境,包括其物理特性、视觉效果和控制机制。这种详细程度的配置为模拟提供了高度的灵活性和精确度,使得MuJoCo成为复杂动态系统模拟的有力工具。

后续将更新如何使用mujoco_py实现控制该机械臂的简单教程。

引用需要标明出处,违者必究

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/929785
推荐阅读
相关标签
  

闽ICP备14008679号