Making a gym environment

Discussion in 'Simulation' started by Silverjoda, Oct 19, 2017.

  1. Hi,

    Thanks for this awesome simulator, but I wish it had more extensive tutorials :(

    I'm trying to make an openAI - gym environment (mujoco_py) as a test platform for my diploma thesis,
    and I'm not having luck finding sources to help me do this so far.

    I need to attach a camera to a robot. Do I do this in the XML file by attaching some camera object to
    the correct body? I assume a name is given to the camera and then during simulation I will get the
    image from the camera by calling 'render()' is that right?

    I need to make an environment which has many static cubes of various hights protruding out of the ground so the hexapod
    can navigate over them. How do I do this? Again by generating a list of cubes in the XML file?

    I'm using the older mujoco_py 0.5.7 (because the new version is impossible to install, been trying for days)

    Thanks a lot in advance.
     
  2. You can look at openai-gym mujoco environments like hopper-v0 etc to get an idea on how to get an image from the simulation. Generally you have model which simulates the environment and you have a viewer with a viewpoint which you can change according to your need. You can also attach multiple viewer to your model with a different viewpoint.
    I add a viewer in code instead of the xml file. Here is a python file using mujoco-py 0.5.7 to load a xml file and set a camera parameters. You can change the fullpath variable in the code to your xml file.
     
  3. Thanks a lot for the reply. I think I understand how to handle a camera and get the image from it, but I still don't understand how to firmly attach a camera to a model. When you do viewer.set_model() and then make it track a body it just tracks
    the body as it moves, but what I need is to firmly attach (weld) the camera to a specific body of the robot (for example the ants environments spherical body).

    I'm guessing that I can somehow attach it in the XML file with a given name, and then
    request that camera from mujoco_py, but I can't seem to find how to add the camera.
     
    Last edited: Oct 24, 2017
  4. I think I understand your problem a little bit better now. Have you looked at the body_interaction.py example in mujoco_py-1.50.1 . This is an example of the video of what can be done with the cameras. In the start I record the video from the fixed camera viewpoint and then switch using 'Tab' key to the camera which is attached to the ball frame.
    You can look at the small xml file in the example to see how to attach a camera to a specific part of the model. You can also find a more description here.
     
  5. Thanks for the answer. Yes I have already looked at that example and attached a camera to the torso with a specific name. However, I do not know how to get a render from that camera. In mujoco 1.5 you can pass in
    a camera name into the render method of the Mjsim class but in mujoco 0.5.7 there is none of that. The viewer is attached to the default camera and I don't know how to change it.
     
    Last edited: Oct 24, 2017
  6. Is there an OpenAI Gym environment to develop a line-following robot?
     
  7. jxj

    jxj

    I also meet this problem. I don't know how to pass a camera_name into the render method of the mjsim.pyx. Did you solved this problem?

    def render(self, width=None, height=None, *, camera_name=None, depth=False,
    mode='offscreen', device_id=-1):