google-deepmind / mujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.
https://mujoco.org
Apache License 2.0
8.21k stars 819 forks source link

O2MConverter (Convert OpenSim Models to MuJoCo Models) #823

Closed mertalagozlu closed 10 months ago

mertalagozlu commented 1 year ago

Hi,

I'm a student and I'm trying to use MuJoCo for academic purposes.

I'm looking for some help with O2MConverter, which enables us to convert opensim models to mujoco model format. Even with many attempts, I am having trouble converting generic wrist.osim model file, that can be found in opensim models, using this tool https://github.com/aikkala/O2MConverter A brief summary of what I have done can be found in this stackoverflow question https://stackoverflow.com/questions/75987855/unresolvedpackage-anaconda-conda-environment-o2mconverter. Briefly, I have dependency issues and cannot convert models and I thought that this can be great place to resolve the issue because it could be useful for other people.

Thank you very much!

vikashplus commented 1 year ago

@mertalagozlu -- I just want to bring your attention to the MyoSuite project where we went thought similar pain-points. MyoSuite is an attempt at providing these solutions out of the box so that others don't have to face similar issues. Wrist model was one of the hardest to parse and stabilize, hope it helps - https://sites.google.com/view/myosuite

aikkala commented 1 year ago

I think the wrist.osim file you refer to had some issues during conversion (not related to the dependency issues in the SO question you linked), which is why it wasn't included as a converted model in the O2MConverter repository. I highly recommend using the MyoSuite wrist model, if that is applicable to your research problem.

mertalagozlu commented 1 year ago

Thanks for the heads up @aikkala, @vikashplus, but I am only interested in getting xml model of wrist.osim and further change it if&when necessary in the future. Is there a way to directly get the wrist model for MuJoCo without myosuite. I found models inside myosuite env as binary files, maybe I can change it as xml some way. Additionally, myosuite uses mujoco 2.1 with mujoco_py. How can I use the latest MuJoCO engine while also using myosuite. I also encountered some issues with myosuite stating such that I need to add mujoco_py to the path even though I added to the environment variables of Windows. I am using Pycharm and followed the exact instructions for installing myosuite fyi.

conda create --name MyoSuite python=3.7.1 conda activate MyoSuite pip install -U myosuite

Did not work, and not sure this is correct place to raise the question though

Pouyan97 commented 1 year ago

I have posted a solution to installing myosuite and mujoco on windows using a linux VM HERE

mertalagozlu commented 1 year ago

Thanks @Pouyan97, I will call it as plan B if I cannot manage advanced setup in my wsl. Although I am still interested in importing .mjb models to mujoco without using myosuite. To do that, I think we need _mjloadModel, but mujoco.mj_loadModel does not work on loading .mjb models. In fact, it gives error as "cannot find reference in init.py" --> "AttributeError: module 'mujoco' has no attribute 'mj_loadModel'."

So overall solution is as below to import models as .mjb format. model = mujoco.mj_loadModel(r'C:\ProgramData\Anaconda3\envs\MyoSuite\Lib\site-packages\myosuite\envs\myo\assets\myo_hand_pose.mjb') Why do you think we can't add the model this way?

kevinzakka commented 10 months ago

@mertalagozlu The correct API to load an MJB is:

import mujoco

m = mujoco.MjModel.from_binary_path("model.mjb")
d = mujoco.MjData(m)

Going to mark this issue as resolved for now. If you have further issues, please feel free to re-open.

vikashplus commented 10 months ago

@mertalagozlu -- Please note that the binary models are MuJoCo version-specific.