How to load .c files into MuJoCo simulation?

Discussion in 'Simulation' started by Chris Richards, Jun 9, 2016.

  1. I'm working on OSX.
    I've been trying to load some of the tutorial files (e.g. hello.c) into a MuJoCo simulation so that I can experiment with input forces, etc. Is there a specific way to load .c files from the XML model file? Or is the XML loaded from a compiled .c file?

    As an example, I'm trying to modify the simulate.cpp code to do the following:
    1. load a specific XML model (hello.xml, in this case)
    2. run the simulation for 10 seconds only

    I've (sort-of) achieved #1, but my inserted code in the main function doesn't work. I.e. it opens, but closes immediately. Here's an excerpt of my modified simulate.cpp code (starting line 810 from the original simulate.cpp code):

    Code:
        // main loop
        //while( !glfwWindowShouldClose(window) )
        while( d->time<10 )
            mj_step(m, d);
        {
            // simulate and render
            render(window);
            // run simulation for 10 seconds
    
            // finalize
            glfwSwapBuffers(window);
            glfwPollEvents();
        }
    Am I going about this correctly? I.e. should I modify the simulate.cpp to make my own simulation conditions?

    thanks for your time,
    Chirs
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    You have to compile the .c or .cpp file into an executable - which becomes your custom simulator. Then run it and load the XML model file in it. This is what the code sample simulate.cpp does.

    In your code above, the while loop only runs the function mj_step(m, d). Perhaps you wanted to run the code inside the curly braces in the loop as well? Currently it only runs once, after the loop is finished. If you move the mj_step function inside the braces, everything will execute in the loop.

    Note also that simulate.cpp is a fairly complex program, running an event loop using the GLFW library and advancing the simulation from within the render() function. I should write a simpler code sample with the minimal functionality needed to show an animation...
     
  3. OK, that's great, very helpful. Thanks again for responding so quickly to all of my questions.
    Best,
    Chris