benelot / pybullet-gym

Open-source implementations of OpenAI Gym MuJoCo environments for use with the OpenAI Gym Reinforcement Learning Research Platform.
https://pybullet.org/
Other
814 stars 124 forks source link

How to set the environment status manually? #59

Closed cookiegg closed 3 years ago

cookiegg commented 3 years ago

I want to run the InvertedPendulumPyBulletEnv-v0 from a different initial position and angle each time. Could you tell me how to set the status value manually?

benelot commented 3 years ago

Each env is made from a robot (the actor) and its actual environment. This is built to allow defining new environments/settings with robots used in other settings.

To reset the initial position and angle manually, you need to access the robot of the environment (here the pendulum) and reset its hinges as the robot itself does (https://github.com/benelot/pybullet-gym/blob/1d239f55b62b4f3ac8e6e2f193cb379e604d8661/pybulletgym/envs/roboschool/robots/pendula/inverted_double_pendulum.py#L9)

So, it should be possible to call:

u = self.np_random.uniform(low=-.1, high=.1, size=[2])
env.robot.jdict["hinge"].reset_current_position(float(u[0], 0)
env.robot.jdict["hinge2"].reset_current_position(float(u[1], 0)

Edit: sorry, wrong robot, but this serves as a sufficient example because pendulum is the same.

cookiegg commented 3 years ago

Thank you very much for your patience in answering my questions, it was a great help.