How to get names of bodies and joints in order? #342
Answered
by
yuvaltassa
rohit-kumar-j
asked this question in
Asking for Help
-
Intention: # Creating functions that return:
names = getBodyNames() # type(names) == <class List[str]>
joints = getJointNames() # type(joints) == <class List[int]> XML File<mujoco model="4_bar_assemlby">
<compiler angle="radian" />
<option gravity="0 0 0" collision="predefined" />
<size njmax="500" nconmax="100" />
<asset>
<mesh name="m_base_link" file="base_link.stl" scale="0.001 0.001 0.001" />
<mesh name="m_link_1_1" file="link_1_1.stl" scale="0.001 0.001 0.001" />
<mesh name="m_link_2_1" file="link_2_1.stl" scale="0.001 0.001 0.001" />
<mesh name="m_link_3_1" file="link_3_1.stl" scale="0.001 0.001 0.001" />
</asset>
<worldbody>
<light name="l_light_1" diffuse=".5 .5 .5" pos="0 -2 2" dir="0 1 -1" />
<body name="b_base_link">
<geom name="g_base_link" type="mesh" mesh="m_base_link" />
<body name="b_link_1_1" pos="0 -0.025 0">
<inertial pos="0.5 -0.025 0" quat="0 0.707107 0 0.707107" mass="16.3006" diaginertia="1.51622 1.51617 0.005188" />
<joint name="j_Rev1" pos="0 0 0" axis="0 -1 0" />
<geom name="g_link_1_1" pos="0 0.025 0" type="mesh" mesh="m_link_1_1" />
<body name="b_link_2_1" pos="1 0 0">
<inertial pos="0 0.025 0.5" mass="16.3006" diaginertia="1.51622 1.51617 0.005188" />
<joint name="j_Rev2" pos="0 0 0" axis="0 1 0" />
<geom name="g_link_2_1" pos="-1 0.025 0" type="mesh" mesh="m_link_2_1" />
<body name="b_link_3_1" pos="0 0.05 1">
<inertial pos="-0.5 0.025 0" quat="0 0.707107 0 0.707107" mass="16.3006" diaginertia="1.51622 1.51617 0.005188" />
<joint name="j_Rev3" pos="0 0 0" axis="0 1 0" />
<geom name="g_link_3_1" pos="-1 -0.025 -1" type="mesh" mesh="m_link_3_1" />
</body>
</body>
</body>
</body>
</worldbody>
</mujoco> # print(model.names)
b'4_bar_assemlby\x00world\x00b_base_link\x00b_link_1_1\x00b_link_2_1\x00b_link_3_1\x00j_Rev1\x00j_Rev2\x00j_Rev3\x00g_base_link\x00g_link_1_1\x00g_link_2_1\x00g_link_3_1\x00l_light_1\x00m_base_link\x00m_link_1_1\x00m_link_2_1\x00m_link_3_1\x00'
# j_ is joint
# g_ is geom
# b_ is body
# m_ is mesh
# Split and convert to string
['4_bar_assemlby', 'world', 'b_base_link', 'b_link_1_1',
'b_link_2_1', 'b_link_3_1', 'j_Rev1', 'j_Rev2', 'j_Rev3',
'g_base_link', 'g_link_1_1', 'g_link_2_1', 'g_link_3_1', 'l_light_1',
'm_base_link', 'm_link_1_1', 'm_link_2_1', 'm_link_3_1', ''] # <- empty ''
len(model.names) = 19 It seems like name of model > worldbody > body > joint > geoms > mesh |
Beta Was this translation helpful? Give feedback.
Answered by
yuvaltassa
Jun 12, 2022
Replies: 1 comment 1 reply
-
I think you are using Python, but it is not entire clear. Please make that explicit in the future :) We have an internal open feature request to add a more convenient way to do it, in the meantime you should be able to use a comprehension like geom_names = [mujoco.mj_id2name(model, mujoco.mjtObj.mjOBJ_GEOM, i) for i in range(model.ngeom)] |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rohit-kumar-j
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you are using Python, but it is not entire clear. Please make that explicit in the future :)
We have an internal open feature request to add a more convenient way to do it, in the meantime you should be able to use a comprehension like