Skip to content

Commit

Permalink
First tests done
Browse files Browse the repository at this point in the history
  • Loading branch information
ljmanso committed Nov 27, 2024
1 parent 17bad63 commit ec24c01
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 30 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ This repository contains the implementation of our paper [SocNavGym: A Reinforce
## Usage
```python
import socnavgym
import gym
import gymnasium as gym
env = gym.make('SocNavGym-v1', config="<PATH_TO_CONFIG>")
```
## Sample Code
```python
import socnavgym
import gym
import gymnasium as gym
env = gym.make("SocNavGym-v1", config="./environment_configs/exp1_no_sngnn.yaml")
obs, _ = env.reset()
Expand All @@ -64,7 +64,7 @@ for i in range(1000):
```
## About the environment
```SocNavGym-v1``` is a highly customisable environment and the parameters of the environment can be controlled using the config files. There are a few config files in [environment_configs/](https://github.com/gnns4hri/SocNavGym/tree/main/environment_configs). For a better understanding of each parameter refer to [this](https://github.com/gnns4hri/SocNavGym#config-file) section. Other than the robot, the environment supports entities like plants, tables, laptops. The environment also models interactions between humans, and human-laptop. It can also contain moving crowds, and static crowds, and the ability to form new crowds and interactions, as well as disperse existing crowds and interactions. The environment follows the OpenAI Gym format implementing the `step`, `render` and `reset` functions. The environment uses the latest Gym API (gym 0.26.2).
```SocNavGym-v1``` is a highly customisable environment and the parameters of the environment can be controlled using the config files. There are a few config files in [environment_configs/](https://github.com/gnns4hri/SocNavGym/tree/main/environment_configs). For a better understanding of each parameter refer to [this](https://github.com/gnns4hri/SocNavGym#config-file) section. Other than the robot, the environment supports entities like plants, tables, laptops. The environment also models interactions between humans, and human-laptop. It can also contain moving crowds, and static crowds, and the ability to form new crowds and interactions, as well as disperse existing crowds and interactions. The environment follows the Farama foundation format implementing the `step`, `render` and `reset` functions. The environment uses the latest Gymnasium API (gymnasium 0.29.1).
## Conventions
* X-axis points in the direction of zero-angle.
Expand All @@ -74,7 +74,7 @@ for i in range(1000):
## Observation Space
The observation returned when ```env.step(action)``` is called, consists of the following (all in the<b> robot frame</b> unless you're using the [`WorldFrameObservations`](https://github.com/gnns4hri/SocNavGym#wrappers) wrapper):
The observation is of the type `gym.Spaces.Dict`. The dictionary has the following keys:
The observation is of the type `gymnasium.Spaces.Dict`. The dictionary has the following keys:
1. ```"robot"``` : This is a vector of shape (9,) of which the first six values represent the one-hot encoding of the robot, i.e ```[1, 0, 0, 0, 0, 0]```. The next two values represent the goal's x and y coordinates in the robot frame and the last value is the robot's radius.
2. The other keys present in the observation are ```"humans"```, ```"plants"```, ```"laptops"```, ```"tables"``` and ```"walls"```. Every entity (human, plant, laptop, table, or wall) would have an observation vector given by the structure below:
Expand Down Expand Up @@ -628,7 +628,7 @@ The behaviour of the environment is controlled using the config file. The config
</table>
## Wrappers
Gym wrappers are convenient to have changes in the observation-space / action-space. SocNavGym implements 4 wrappers.
Gymnasium wrappers are convenient to have changes in the observation-space / action-space. SocNavGym implements 4 wrappers.
The following are the wrappers implemented by SocNavGym:
1. `DiscreteActions` : To change the environment from a continuous action space environment to a discrete action space environment. The action space consists of 7 discrete actions. They are :
Expand Down
2 changes: 1 addition & 1 deletion manual_control_js.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
import time
import gym
import gymnasium as gym
import numpy as np
import socnavgym
import os
Expand Down
2 changes: 1 addition & 1 deletion sb3_eval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import socnavgym
import torch
from socnavgym.wrappers import DiscreteActions
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
LONG_DESCRIPTION = f.read()

REQUIRED = [
"gym >= 0.26.2",
"gymnasium >= 0.29.1",
"opencv-python",
"numpy",
"matplotlib",
Expand Down
2 changes: 1 addition & 1 deletion socnavgym/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gym.envs.registration import register
from gymnasium.envs.registration import register

register(
id='SocNavGym-v1',
Expand Down
17 changes: 11 additions & 6 deletions socnavgym/envs/socnavenv_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import copy
from importlib.machinery import SourceFileLoader
import cv2
import gym
import gymnasium as gym
import matplotlib.pyplot as plt
import numpy as np
import rvo2
import torch
import yaml
from gym import spaces
from gymnasium import spaces
from shapely.geometry import Point, Polygon
from collections import namedtuple
import math
Expand Down Expand Up @@ -146,14 +146,19 @@ class SocNavEnv_v1(gym.Env):
# human-laptop interaction params
HUMAN_LAPTOP_DISTANCE = None

def __init__(self, config:str=None) -> None:
def __init__(self, config:str=None, render_mode:str=None) -> None:
"""
Args :
config: Path to the environment config file
"""
super().__init__()

assert(config is not None), "Argument config_path is None. Please call gym.make(\"SocNavGym-v1\", config_path=path_to_config)"
assert(config is not None), "Argument config is None. Please call gym.make(\"SocNavGym-v1\", config=path_to_config)"


self.render_mode_ = render_mode
if render_mode is None:
self.render_mode_ = "human"

self.window_initialised = False
self.has_configured = False
Expand Down Expand Up @@ -3605,12 +3610,12 @@ def render_without_showing(self, mode="human", draw_human_gaze=False, draw_human

return self.world_image

def render(self, mode="human", draw_human_gaze=False, draw_human_goal=True):
def render(self, draw_human_gaze=False, draw_human_goal=True):
if not self.window_initialised:
cv2.namedWindow("world", cv2.WINDOW_NORMAL)
cv2.resizeWindow("world", int(self.RESOLUTION_VIEW), int(self.RESOLUTION_VIEW))
self.window_initialised = True
self.world_image = self.render_without_showing(mode, draw_human_gaze, draw_human_goal)
self.world_image = self.render_without_showing(self.render_mode_, draw_human_gaze, draw_human_goal)
cv2.imshow("world", self.world_image)
k = cv2.waitKey(self.MILLISECONDS)
if k%255 == 27:
Expand Down
4 changes: 2 additions & 2 deletions socnavgym/wrappers/discrete_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gym
from gym.spaces import Discrete
import gymnasium as gym
from gymnasium.spaces import Discrete
from socnavgym.envs.socnavenv_v1 import SocNavEnv_v1
import numpy as np

Expand Down
4 changes: 2 additions & 2 deletions socnavgym/wrappers/noisy_observations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gym
from gym import spaces
import gymnasium as gym
from gymnasium import spaces
from socnavgym.envs.socnavenv_v1 import SocNavEnv_v1
from socnavgym.envs.utils.wall import Wall
import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions socnavgym/wrappers/partial_observations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gym
from gym import spaces
import gymnasium as gym
from gymnasium import spaces
from socnavgym.envs.socnavenv_v1 import SocNavEnv_v1
from socnavgym.envs.utils.wall import Wall
from socnavgym.envs.utils.utils import w2px, w2py
Expand Down
4 changes: 2 additions & 2 deletions socnavgym/wrappers/world_frame_observations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gym
from gym import spaces
import gymnasium as gym
from gymnasium import spaces
from socnavgym.envs.socnavenv_v1 import SocNavEnv_v1
from socnavgym.envs.utils.wall import Wall
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion stable_dqn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym
import socnavgym
import torch
import torch.nn as nn
Expand Down
4 changes: 2 additions & 2 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
import os
sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)) + "/..")
import gym
import gymnasium as gym
import socnavgym
from socnavgym.wrappers import WorldFrameObservations, PartialObservations, NoisyObservations, DiscreteActions
from gym.utils.env_checker import check_env
from gymnasium.utils.env_checker import check_env
import numpy as np
from glob import glob

Expand Down
4 changes: 2 additions & 2 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
import os
sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)) + "/..")
import gym
import gymnasium as gym
import socnavgym
from socnavgym.wrappers import WorldFrameObservations, PartialObservations, NoisyObservations, DiscreteActions
from gym.utils.env_checker import check_env
from gymnasium.utils.env_checker import check_env
import numpy as np


Expand Down
2 changes: 1 addition & 1 deletion tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import os
sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)) + "/..")
import gym
import gymnasium as gym
import socnavgym
import yaml
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import os
sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)) + "/..")
import gym
import gymnasium as gym
import socnavgym
import yaml

Expand Down

0 comments on commit ec24c01

Please sign in to comment.