How to add camera definition in MJCF file using C++ library

Discussion in 'Modeling' started by HeikkiCheung, Mar 6, 2018.

  1. Hi guys,

    I am working on a C++ wrapper for MuJoCo, which can transfer URDF file to MJCF file automatically. I used MuJoCo's C++ api, mj_LoadXML() and mj_saveLastXML() to do the basic staff, and it can work. But I also can't find any api to add a camera and actuators to mjModel. Although I can see the definition of mjModel. Any help is appreciated.

    Thanks!
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    mjModel is compiled, you cannot add anything to it. You can add elements to an XML file (by hand or perhaps programmatically) and then call mj_loadXML to invoke the internal compiler which generates mjModel.

    If you want to do this from C++, the best way to do it is link some XML library (such as TinyXML), compose a tree of XML elements in memory, then save to file and pass that file to MuJoCo. You can also pass an XML in a memory buffer, so the file can be avoided -- see Virtual File System in the documentation.
     
  3. Thanks for reply, I will do it using some XML library.
     
  4. Hi Emo, another question is that, after I used mj_saveLastXML to save a pre-loaded urdf file to mjcf file, some meshes elements in urdf file were not in mjcf file like following xml snippets shows
    in urdf file:
    it has a lot more meshes defenition
    in mjcf file:
    <asset>
    <mesh name="base_link_collision" file="base_link_collision.STL"/>
    <mesh name="pedestal_link_collision" file="pedestal_link_collision.STL"/>
    </asset>
     
  5. Emo Todorov

    Emo Todorov Administrator Staff Member

    URDFs have two repeated sets of geometry, one for visualization and the other for collision. Since it doesn't make sense to include meshes twice, the URDF loader has the option to discard visual geoms. For MJCF files this is off by default, while for URDF it is on by default. You can change it in the <mujoco> element that can be inserted in the URDF file. See documentation here:

    http://www.mujoco.org/book/modeling.html#CURDF