Iohannes
发布于 2025-01-17 / 15 阅读 / 0 评论 / 0 点赞

mujoco获取关节的位置、速度、执行力

获取关节位置(滑动关节slide或铰链关节hinge)

<sensor>
    <jointpos name="FR_hip_pos" joint="FR_hip_joint" />
    <jointpos name="FR_thigh_pos" joint="FR_thigh_joint" />
    <jointpos name="FR_calf_pos" joint="FR_calf_joint" />
    <jointpos name="FL_hip_pos" joint="FL_hip_joint" />
    <jointpos name="FL_thigh_pos" joint="FL_thigh_joint" />
    <jointpos name="FL_calf_pos" joint="FL_calf_joint" />
    <jointpos name="RR_hip_pos" joint="RR_hip_joint" />
    <jointpos name="RR_thigh_pos" joint="RR_thigh_joint" />
    <jointpos name="RR_calf_pos" joint="RR_calf_joint" />
    <jointpos name="RL_hip_pos" joint="RL_hip_joint" />
    <jointpos name="RL_thigh_pos" joint="RL_thigh_joint" />
    <jointpos name="RL_calf_pos" joint="RL_calf_joint" />
</sensor>
import mujoco

# 加载模型和数据
model = mujoco.MjModel.from_xml_path('path/to/your/model.xml')
data = mujoco.MjData(model)

# 模拟环境并获取关节位置
while True:
    mujoco.mj_step(model, data)
    joint_pos = data.qpos
    print(joint_pos)

获取关节速度(滑动关节slide或铰链关节hinge)

<sensor>
    <jointvel name="FR_hip_vel" joint="FR_hip_joint" />
    <jointvel name="FR_thigh_vel" joint="FR_thigh_joint" />
    <jointvel name="FR_calf_vel" joint="FR_calf_joint" />
    <jointvel name="FL_hip_vel" joint="FL_hip_joint" />
    <jointvel name="FL_thigh_vel" joint="FL_thigh_joint" />
    <jointvel name="FL_calf_vel" joint="FL_calf_joint" />
    <jointvel name="RR_hip_vel" joint="RR_hip_joint" />
    <jointvel name="RR_thigh_vel" joint="RR_thigh_joint" />
    <jointvel name="RR_calf_vel" joint="RR_calf_joint" />
    <jointvel name="RL_hip_vel" joint="RL_hip_joint" />
    <jointvel name="RL_thigh_vel" joint="RL_thigh_joint" />
    <jointvel name="RL_calf_vel" joint="RL_calf_joint" />
</sensor>
import mujoco

model = mujoco.MjModel.from_xml_path('path/to/your/model.xml')
data = mujoco.MjData(model)

while True:
    mujoco.mj_step(model, data)
    joint_vel = data.qvel
    print(joint_vel)

获取关节执行力(各种类型的关节)

<sensor>
    <jointactuatorfrc name="FR_hip_torque" joint="FR_hip_joint" noise="0.01" />
    <jointactuatorfrc name="FR_thigh_torque" joint="FR_thigh_joint" noise="0.01" />
    <jointactuatorfrc name="FR_calf_torque" joint="FR_calf_joint" noise="0.01" />
    <jointactuatorfrc name="FL_hip_torque" joint="FL_hip_joint" noise="0.01" />
    <jointactuatorfrc name="FL_thigh_torque" joint="FL_thigh_joint" noise="0.01" />
    <jointactuatorfrc name="FL_calf_torque" joint="FL_calf_joint" noise="0.01" />
    <jointactuatorfrc name="RR_hip_torque" joint="RR_hip_joint" noise="0.01" />
    <jointactuatorfrc name="RR_thigh_torque" joint="RR_thigh_joint" noise="0.01" />
    <jointactuatorfrc name="RR_calf_torque" joint="RR_calf_joint" noise="0.01" />
    <jointactuatorfrc name="RL_hip_torque" joint="RL_hip_joint" noise="0.01" />
    <jointactuatorfrc name="RL_thigh_torque" joint="RL_thigh_joint" noise="0.01" />
    <jointactuatorfrc name="RL_calf_torque" joint="RL_calf_joint" noise="0.01" />
</sensor>
import mujoco

model = mujoco.MjModel.from_xml_path('path/to/your/model.xml')
data = mujoco.MjData(model)

while True:
    mujoco.mj_step(model, data)
    joint_actuator_frc = data.qfrc_actuator
    print(joint_actuator_frc)

评论