1import gymnasium as gym
2import fancy_gym
3
4
5def example_mp(env_name, seed=1, render=True):
6 """
7 Example for running a movement primitive based version of a OpenAI-gym environment, which is already registered.
8 For more information on movement primitive specific stuff, look at the traj_gen examples.
9 Args:
10 env_name: ProMP env_id
11 seed: seed
12 render: boolean
13 Returns:
14
15 """
16 env = gym.make(env_name)
17
18 returns = 0
19 obs = env.reset(seed=seed)
20 # number of samples/full trajectories (multiple environment steps)
21 for i in range(10):
22 if render and i % 2 == 0:
23 env.render(mode="human")
24 else:
25 env.render()
26 ac = env.action_space.sample()
27 obs, reward, terminated, truncated, info = env.step(ac)
28 returns += reward
29
30 if terminated or truncated:
31 print(returns)
32 obs = env.reset()
33
34
35if __name__ == '__main__':
36 example_mp("gym_ProMP/Reacher-v2")