-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++ ways to get MjDataBodyViews #251
Comments
I'm not 100% clear on what you're asking here. Are you trying to replicate the Python API of the |
I'm trying to replicate gym's way of using mujoco in C++. For example, this is Ant-v4 env written in pure C++: https://github.com/Trinkle23897/mjc-mwe/blob/master/cc/ant.cc |
In that case my current recommendation would be to code against MuJoCo's C API directly. You can use If you want nice syntactic sugar for named access (e.g. |
Thanks for the answer! |
Hi,
First, thanks for this great project!
I'm going to translate the existing python bindings in gym to C++, to get the best performance for vectorized environments envpool and minimize the overhead. openai/gym#2762 has made huge progress in integrating the newest version of mujoco. However, I cannot find a related document for MjDataBodyViews.
In short, https://github.com/openai/gym/blob/0e2077bb636fbac979a4edd0c8608235742a8f2a/gym/envs/mujoco/mujoco_env.py#L268-L272
self.data
is amjData
structure. But I cannot find a related pybind binding function of mjData that has abody
method. Later on I expand theindexers.[h|cc]
to see the code after expansion, byindexer_expand.txt
However, after going through the expanded code, I'm still quite confused about how to write the same functionality (
data.body(body_name).xpos
) in C++. Could you please kindly provide some help? Thanks in advance!Update:
For Ant Env (sail-sg/envpool#74):
data.xpos[1]
isdata.body("torso").xpos
,mj_name2id(model_, mjOBJ_BODY, "torso")
For Reacher Env (sail-sg/envpool#81):
data.xpos[-2]
isdata.body("fingertip").xpos
,mj_name2id(model_, mjOBJ_BODY, "fingertip")
data.xpos[-1]
isdata.body("target").xpos
,mj_name2id(model_, mjOBJ_BODY, "target")
For Pusher Env (sail-sg/envpool#82):
data.xpos[-3]
isdata.body("tips_arm").xpos
,mj_name2id(model_, mjOBJ_BODY, "tips_arm")
data.xpos[-2]
isdata.body("object").xpos
,mj_name2id(model_, mjOBJ_BODY, "object")
data.xpos[-1]
isdata.body("goal").xpos
,mj_name2id(model_, mjOBJ_BODY, "goal")
The text was updated successfully, but these errors were encountered: