Przeglądaj źródła

Fixed issue causing dynamic obstacles env to crash

Maxime Chevalier-Boisvert 6 lat temu
rodzic
commit
ba8b8e2316

+ 2 - 1
README.md

@@ -141,6 +141,7 @@ position for each episode, while the regular variants have the agent always
 starting in the corner opposite to the goal.
 starting in the corner opposite to the goal.
 
 
 ### Dynamic obstacles environment
 ### Dynamic obstacles environment
+
 Registered configurations:
 Registered configurations:
 - `MiniGrid-Dynamic-Obstacles-5x5-v0`
 - `MiniGrid-Dynamic-Obstacles-5x5-v0`
 - `MiniGrid-Dynamic-Obstacles-Random-5x5-v0`
 - `MiniGrid-Dynamic-Obstacles-Random-5x5-v0`
@@ -150,7 +151,7 @@ Registered configurations:
 - `MiniGrid-Dynamic-Obstacles-16x16-v0`
 - `MiniGrid-Dynamic-Obstacles-16x16-v0`
 
 
 <p align="center">
 <p align="center">
-<img src="https://media.giphy.com/media/NUvVVRNTW4cG0NoQBr/giphy.gif">
+<img src="/figures/dynamic_obstacles.gif">
 </p>
 </p>
 
 
 This environment is an empty room with moving obstacles. The goal of the agent is to reach the green goal square without colliding with any obstacle. A large penalty is subtracted if the agent collides with an obstacle and the episode finishes. This environment is useful to test Dynamic Obstacle Avoidance for mobile robots with Reinforcement Learning in Partial Observability.
 This environment is an empty room with moving obstacles. The goal of the agent is to reach the green goal square without colliding with any obstacle. A large penalty is subtracted if the agent collides with an obstacle and the episode finishes. This environment is useful to test Dynamic Obstacle Avoidance for mobile robots with Reinforcement Learning in Partial Observability.

BIN
figures/dynamic_obstacles.gif


+ 4 - 10
gym_minigrid/envs/dynamicobstacles.py

@@ -2,10 +2,9 @@ from gym_minigrid.minigrid import *
 from gym_minigrid.register import register
 from gym_minigrid.register import register
 from operator import add
 from operator import add
 
 
-
 class DynamicObstaclesEnv(MiniGridEnv):
 class DynamicObstaclesEnv(MiniGridEnv):
     """
     """
-    Empty grid environment with moving obstacles
+    Single-room square grid environment with moving obstacles
     """
     """
 
 
     def __init__(
     def __init__(
@@ -68,39 +67,34 @@ class DynamicObstaclesEnv(MiniGridEnv):
             for i_obst in range(len(self.obstacles)):
             for i_obst in range(len(self.obstacles)):
                 old_pos = self.obstacles[i_obst].cur_pos
                 old_pos = self.obstacles[i_obst].cur_pos
                 top = tuple(map(add, old_pos, (-1, -1)))
                 top = tuple(map(add, old_pos, (-1, -1)))
+                self.grid.set(*old_pos, None)
                 self.place_obj(self.obstacles[i_obst], top=top, size=(3,3), max_tries=100)
                 self.place_obj(self.obstacles[i_obst], top=top, size=(3,3), max_tries=100)
-                self.grid.set(old_pos[0], old_pos[1], None)
                 if np.array_equal(self.obstacles[i_obst].cur_pos, self.agent_pos):
                 if np.array_equal(self.obstacles[i_obst].cur_pos, self.agent_pos):
                     reward = -1
                     reward = -1
                     done = True
                     done = True
-        return obs, reward, done, info
 
 
+        return obs, reward, done, info
 
 
 class DynamicObstaclesEnv5x5(DynamicObstaclesEnv):
 class DynamicObstaclesEnv5x5(DynamicObstaclesEnv):
     def __init__(self):
     def __init__(self):
         super().__init__(size=5, n_obstacles=2)
         super().__init__(size=5, n_obstacles=2)
 
 
-
 class DynamicObstaclesRandomEnv5x5(DynamicObstaclesEnv):
 class DynamicObstaclesRandomEnv5x5(DynamicObstaclesEnv):
     def __init__(self):
     def __init__(self):
         super().__init__(size=5, agent_start_pos=None, n_obstacles=2)
         super().__init__(size=5, agent_start_pos=None, n_obstacles=2)
 
 
-
 class DynamicObstaclesEnv6x6(DynamicObstaclesEnv):
 class DynamicObstaclesEnv6x6(DynamicObstaclesEnv):
     def __init__(self):
     def __init__(self):
         super().__init__(size=6, n_obstacles=3)
         super().__init__(size=6, n_obstacles=3)
 
 
-
 class DynamicObstaclesRandomEnv6x6(DynamicObstaclesEnv):
 class DynamicObstaclesRandomEnv6x6(DynamicObstaclesEnv):
     def __init__(self):
     def __init__(self):
         super().__init__(size=6, agent_start_pos=None, n_obstacles=3)
         super().__init__(size=6, agent_start_pos=None, n_obstacles=3)
 
 
-
 class DynamicObstaclesEnv16x16(DynamicObstaclesEnv):
 class DynamicObstaclesEnv16x16(DynamicObstaclesEnv):
     def __init__(self):
     def __init__(self):
         super().__init__(size=16, n_obstacles=8)
         super().__init__(size=16, n_obstacles=8)
 
 
-
 register(
 register(
     id='MiniGrid-Dynamic-Obstacles-5x5-v0',
     id='MiniGrid-Dynamic-Obstacles-5x5-v0',
     entry_point='gym_minigrid.envs:DynamicObstaclesEnv5x5'
     entry_point='gym_minigrid.envs:DynamicObstaclesEnv5x5'
@@ -129,4 +123,4 @@ register(
 register(
 register(
     id='MiniGrid-Dynamic-Obstacles-16x16-v0',
     id='MiniGrid-Dynamic-Obstacles-16x16-v0',
     entry_point='gym_minigrid.envs:DynamicObstaclesEnv16x16'
     entry_point='gym_minigrid.envs:DynamicObstaclesEnv16x16'
-)
+)