Mujoco 中的位置控制

问题描述 投票:0回答:1

作为 Mujoco 的新手,我刚刚在 mujoco 中创建了一个虚拟场景,现在我尝试控制其中的一些对象。场景包含一个固定桌子,上面放置一本可移动的书,可以通过控制驱动的抹刀框架来移动书本:

xml = """
<mujoco>
  <worldbody>
    <light name="top" pos="0 0 1"/>
    
    <body name="table" pos="0 0 0.025">
      <geom name="plate" type="box" size="0.25 0.2 0.025" rgba=".8 .8 .8 1"/>
      <geom name="bound0" type="box" size=".25 .01 .05" pos="0 -.19 .075"/>
      <geom name="bound1" type="box" size=".01 .19 .05" pos="-.24 .01 .075"/>
    </body>

    <body name="booklink" pos="0 0 0.065">
      <freejoint/>
      <geom name="book" type="box" size=".1 .05 .0125" rgba="0 1 0 1" mass=".1"/>
    </body>  

    <body name="spatulalink" pos="0 0 .2">
        <joint name="transX" type="slide" axis="1 0 0" limited="true" range="-.6 .6"/>
        <joint name="transY" type="slide" axis="0 1 0" limited="true" range="-.6 .6"/>
        <joint name="transZ" type="slide" axis="0 0 1" limited="true" range="-.6 .6"/>
        <joint name="hingeX" type="hinge" axis="1 0 0" limited="true" range="-3.2 3.2"/>
        <joint name="hingeY" type="hinge" axis="0 1 0" limited="true" range="-3.2 3.2"/>
        <joint name="hingeZ" type="hinge" axis="0 0 1" limited="true" range="-3.2 3.2"/>
        <geom name="spatula" type="box" size=".05 .05 5e-4" rgba="1 1 0 1" friction=".1 .1 .1" mass=".1"/>
    </body>
  </worldbody>
  <actuator>
    <position ctrllimited="true" ctrlrange="-.6 .6" joint="transX"/>
    <position ctrllimited="true" ctrlrange="-.6 .6" joint="transY"/>
    <position ctrllimited="true" ctrlrange="-.6 .6" joint="transZ"/>
    <position ctrllimited="true" ctrlrange="-3.2 3.2" joint="hingeX"/>
    <position ctrllimited="true" ctrlrange="-3.2 3.2" joint="hingeY"/>
    <position ctrllimited="true" ctrlrange="-3.2 3.2" joint="hingeZ"/>
  </actuator>
</mujoco>
"""
model = mujoco.MjModel.from_xml_string(xml)
data = mujoco.MjData(model)

现在我的问题是如何在我控制机器人的环境中正确运行轨迹。天真地,我尝试通过直接写入

data.qpos
data.qvel
来放置一些控件。这会产生所需的运动,但对象会相互穿过,即存在几何形状的碰撞,这当然是我不希望的。您可以在这里看到这样的图片(您可以看到黄色抹刀对象在碰撞中穿过边界):

现在,经过一些阅读,我现在了解到在 Mujoco 中控制执行器/关节的正确方法是直接设置控件,在我的例子中是

data.crtl = some_position_vector
。我这样做如下:

# Construct a BSpline to interpolate the via-points
spline_ref = BSpline_reference(data.qpos[7:], data.qvel[6:], data.time)
spline_ref.append(path, times, data.time)

with mujoco.viewer.launch_passive(model, data) as viewer:
  # Close the viewer automatically after 30 wall-seconds.
  start = time.time()
  sim_steps = int(n_steps // tau)
  i = 0
  while viewer.is_running(): #and i < sim_steps:
    # Get a target position from the reference spline using current sim state
    qreal = data.qpos[7:]
    qDot_real = data.qvel[6:]
    qref, qDotref = spline_ref.getReference(qreal, qDot_real, data.time)
    data.ctrl = q_ref
    mujoco.mj_step(model, data)

    # Pick up changes to the physics state, apply perturbations, update options from GUI.
    viewer.sync()

    # Slow down sim. for visualization
    time.sleep(1e-2)
    i += 1

不知怎的,我由此得到的运动与我直接设置

data.qpos
时完全不同。有人可以向我解释如何正确设置控件吗?

simulation robotics mujoco
1个回答
0
投票

模型中的位置执行器可施加

kp * (q_desired - q) - kv * qdot
的扭矩或力。所以位置并不是像直接设置 qpos 那样神奇地设置的。

默认值

kp="1"
kv="0"
kp
对于您的系统来说可能太小。

与真正的机器人类似,您应该调整位置执行器的增益,以便获得所需的响应能力,而不会引入不必要的振荡。

© www.soinside.com 2019 - 2024. All rights reserved.