Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Enable to set the number of lidar rays in navigation, discovery and flocking scenarios #141

Merged
merged 6 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions vmas/scenarios/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self._min_dist_between_entities = kwargs.pop("min_dist_between_entities", 0.2)
self._lidar_range = kwargs.pop("lidar_range", 0.35)
self._covering_range = kwargs.pop("covering_range", 0.25)

self.use_agent_lidar = kwargs.pop("use_agent_lidar", False)
if self.use_agent_lidar:
self.n_lidar_rays_entities = kwargs.pop("n_lidar_rays_entities", 15)
else:
if "n_lidar_rays_entities" in kwargs:
raise ValueError(
'Cannot set "n_lidar_rays_entities" when "use_agent_lidar" is False.'
)
self.n_lidar_rays_agents = kwargs.pop("n_lidar_rays_agents", 12)
Giovannibriglia marked this conversation as resolved.
Show resolved Hide resolved

self._agents_per_target = kwargs.pop("agents_per_target", 2)
self.targets_respawn = kwargs.pop("targets_respawn", True)
self.shared_reward = kwargs.pop("shared_reward", False)
Expand Down Expand Up @@ -74,7 +84,7 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
[
Lidar(
world,
n_rays=15,
n_rays=self.n_lidar_rays_entities,
max_range=self._lidar_range,
entity_filter=entity_filter_targets,
render_color=Color.GREEN,
Expand All @@ -86,7 +96,7 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
world,
angle_start=0.05,
angle_end=2 * torch.pi + 0.05,
n_rays=12,
n_rays=self.n_lidar_rays_agents,
max_range=self._lidar_range,
entity_filter=entity_filter_agents,
render_color=Color.BLUE,
Expand Down
4 changes: 3 additions & 1 deletion vmas/scenarios/flocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
n_obstacles = kwargs.pop("n_obstacles", 5)
self._min_dist_between_entities = kwargs.pop("min_dist_between_entities", 0.15)

self.n_lidar_rays = kwargs.pop("n_rays", 12)
Giovannibriglia marked this conversation as resolved.
Show resolved Hide resolved

self.collision_reward = kwargs.pop("collision_reward", -0.1)
self.dist_shaping_factor = kwargs.pop("dist_shaping_factor", 1)
ScenarioUtils.check_kwargs_consumed(kwargs)
Expand Down Expand Up @@ -51,7 +53,7 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
sensors=[
Lidar(
world,
n_rays=12,
n_rays=self.n_lidar_rays,
max_range=0.2,
entity_filter=goal_entity_filter,
)
Expand Down
3 changes: 2 additions & 1 deletion vmas/scenarios/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
self.lidar_range = kwargs.pop("lidar_range", 0.35)
self.agent_radius = kwargs.pop("agent_radius", 0.1)
self.comms_range = kwargs.pop("comms_range", 0)
self.n_lidar_rays = kwargs.pop("n_rays", 12)
Giovannibriglia marked this conversation as resolved.
Show resolved Hide resolved

self.shared_rew = kwargs.pop("shared_rew", True)
self.pos_shaping_factor = kwargs.pop("pos_shaping_factor", 1)
Expand Down Expand Up @@ -115,7 +116,7 @@ def make_world(self, batch_dim: int, device: torch.device, **kwargs):
[
Lidar(
world,
n_rays=12,
n_rays=self.n_lidar_rays,
max_range=self.lidar_range,
entity_filter=entity_filter_agents,
),
Expand Down