Skip to content

Commit 89882a6

Browse files
[Feature] Navigation: kwargs for spawning ranges (#139)
* Introduce x_semidim and y_semidim parameters for managing environment dimensions * [discovery]introduce x_semidim and y_semidim parameters for managing environment dimensions * [navigation]introduce x_semidim and y_semidim parameters for managing environment dimensions * [environment rendering] implementing boundary visualization for limited environments * [navigation] ensure entity placement within constrained environment boundaries * [environment rendering] implementing boundary visualization for limited environments * [Features] world_spawning_x, world_spawning_y and enforce_bounds * [Bug Fix] world_spawning_x, world_spawning_y and enforce_bounds * Update vmas/scenarios/navigation.py * Update vmas/scenarios/navigation.py * [Bug Fix] world_spawning_x, world_spawning_y and enforce_bounds * [Bug Fix] world_spawning_x, world_spawning_y and enforce_bounds --------- Co-authored-by: Matteo Bettini <[email protected]>
1 parent ff58363 commit 89882a6

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

vmas/scenarios/navigation.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
2424
self.n_agents = kwargs.pop("n_agents", 4)
2525
self.collisions = kwargs.pop("collisions", True)
2626

27-
self.x_semidim = kwargs.pop("x_semidim", None)
28-
self.y_semidim = kwargs.pop("y_semidim", None)
27+
self.world_spawning_x = kwargs.pop(
28+
"world_spawning_x", 1
29+
) # X-coordinate limit for entities spawning
30+
self.world_spawning_y = kwargs.pop(
31+
"world_spawning_y", 1
32+
) # Y-coordinate limit for entities spawning
33+
self.enforce_bounds = kwargs.pop(
34+
"enforce_bounds", False
35+
) # If False, the world is unlimited; else, constrained by world_spawning_x and world_spawning_y.
2936

3037
self.agents_with_same_goal = kwargs.pop("agents_with_same_goal", 1)
3138
self.split_goals = kwargs.pop("split_goals", False)
@@ -43,9 +50,15 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
4350
ScenarioUtils.check_kwargs_consumed(kwargs)
4451

4552
self.min_distance_between_entities = self.agent_radius * 2 + 0.05
46-
self.world_semidim = 1
4753
self.min_collision_distance = 0.005
4854

55+
if self.enforce_bounds:
56+
self.x_semidim = self.world_spawning_x
57+
self.y_semidim = self.world_spawning_y
58+
else:
59+
self.x_semidim = None
60+
self.y_semidim = None
61+
4962
assert 1 <= self.agents_with_same_goal <= self.n_agents
5063
if self.agents_with_same_goal > 1:
5164
assert (
@@ -135,8 +148,8 @@ def reset_world_at(self, env_index: int = None):
135148
self.world,
136149
env_index,
137150
self.min_distance_between_entities,
138-
(-self.world_semidim, self.world_semidim),
139-
(-self.world_semidim, self.world_semidim),
151+
(-self.world_spawning_x, self.world_spawning_x),
152+
(-self.world_spawning_y, self.world_spawning_y),
140153
)
141154

142155
occupied_positions = torch.stack(
@@ -152,8 +165,8 @@ def reset_world_at(self, env_index: int = None):
152165
env_index=env_index,
153166
world=self.world,
154167
min_dist_between_entities=self.min_distance_between_entities,
155-
x_bounds=(-self.world_semidim, self.world_semidim),
156-
y_bounds=(-self.world_semidim, self.world_semidim),
168+
x_bounds=(-self.world_spawning_x, self.world_spawning_x),
169+
y_bounds=(-self.world_spawning_y, self.world_spawning_y),
157170
)
158171
goal_poses.append(position.squeeze(1))
159172
occupied_positions = torch.cat([occupied_positions, position], dim=1)

0 commit comments

Comments
 (0)