This is a custom environment for the POSGGym library that extends the existing DrivingContinuous environment by adding random circular obstacles instead of the hard-coded block obstacles.
The DrivingContinuousRandom environment is based on the DrivingContinuous-v0 environment but allows for more flexible obstacle configurations. Instead of using predefined block obstacles, this environment generates random circular obstacles based on specified parameters.
- Random circular obstacles with configurable size range and density
- All the features of the original DrivingContinuous environment
- Customizable obstacle field for different difficulty levels
- Reproducible obstacle generation with random seed
The environment is included in the POSGGym package. No additional installation is required if you have POSGGym installed.
import posggym
# Create the environment with default parameters
env = posggym.make("DrivingContinuousRandom-v0")
# Create the environment with custom parameters
env = posggym.make(
"DrivingContinuousRandom-v0",
world="14x14Empty", # Use the empty world layout
num_agents=2, # Number of agents
obs_dist=5.0, # Observation distance
n_sensors=16, # Number of sensors
obstacle_radius_range=(0.3, 0.7), # Min and max obstacle radius
obstacle_density=0.1, # Density of obstacles (0.0 to 1.0)
random_seed=42, # Random seed for reproducibility
render_mode="human", # Render mode (optional)
)
# Reset the environment
obs, info = env.reset()
# Run a simulation with random actions
for _ in range(100):
actions = {agent: env.action_spaces[agent].sample() for agent in env.agents}
next_obs, rewards, terminations, truncations, infos = env.step(actions)
# Check if episode is done
if all(terminations.values()) or all(truncations.values()):
obs, info = env.reset()
# Close the environment
env.close()world(str or RandomDrivingWorld): The world layout to use. Default is "14x14Empty".num_agents(int): The number of agents in the environment. Default is 2.obs_dist(float): The sensor observation distance. Default is 5.0.n_sensors(int): The number of sensor lines eminating from the agent. Default is 16.obstacle_radius_range(tuple): A tuple (min_radius, max_radius) specifying the range of possible obstacle radii. Default is (0.3, 0.7).obstacle_density(float): A float between 0 and 1 specifying the density of obstacles in the environment. Default is 0.1. Higher values mean more obstacles.random_seed(int, optional): A seed for the random number generator to ensure reproducible obstacle generation. Default is None.render_mode(str, optional): The render mode to use. Can be "human" or "rgb_array". Default is None.
14x14Empty: An empty 14x14 world with start positions at the corners and destinations in the middle.
You can also use any of the standard world layouts from the original DrivingContinuous environment:
6x6Intersection7x7Blocks7x7CrissCross7x7RoundAbout14x14Blocks14x14CrissCross14x14RoundAbout
Here's a simple example of using the environment:
import posggym
import time
# Create the environment
env = posggym.make(
"DrivingContinuousRandom-v0",
render_mode="human",
obstacle_density=0.2, # Increase density for more obstacles
obstacle_radius_range=(0.2, 0.8), # Vary the size of obstacles
random_seed=42, # Set seed for reproducibility
)
# Reset the environment
obs, info = env.reset()
# Run a few random steps
for _ in range(100):
# Sample random actions for all agents
actions = {agent: env.action_spaces[agent].sample() for agent in env.agents}
# Step the environment
next_obs, rewards, terminations, truncations, infos = env.step(actions)
# Slow down the rendering
time.sleep(0.1)
# Check if all agents are done
if all(terminations.values()) or all(truncations.values()):
obs, info = env.reset()
# Close the environment
env.close()You can create your own custom world layouts by defining a new world string in the SUPPORTED_RANDOM_WORLDS dictionary in the driving_continuous_random.py file.
This environment is released under the same license as the POSGGym library.