Skip to content

Commit a4a6ee2

Browse files
[Feat] Render lidar before agents and allow for tuple as color (#115)
* Render lidar before agent, so agent is on top. Adding get render_color function to lidar like in Agent.render so it allows for alpha in colors. * now it is ray and not the circle * added alpha instead of tuple including alpha * Update vmas/simulator/sensors.py Co-authored-by: Matteo Bettini <55539777+matteobettini@users.noreply.github.com> * Update vmas/simulator/sensors.py Co-authored-by: Matteo Bettini <55539777+matteobettini@users.noreply.github.com> * Update vmas/simulator/sensors.py * Update vmas/simulator/sensors.py --------- Co-authored-by: Matteo Bettini <55539777+matteobettini@users.noreply.github.com>
1 parent 3964475 commit a4a6ee2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

vmas/simulator/sensors.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import typing
88
from abc import ABC, abstractmethod
9-
from typing import Callable, List, Union
9+
from typing import Callable, List, Tuple, Union
1010

1111
import torch
1212

1313
import vmas.simulator.core
14-
import vmas.simulator.utils
14+
from vmas.simulator.utils import Color
1515

1616
if typing.TYPE_CHECKING:
1717
from vmas.simulator.rendering import Geom
@@ -52,7 +52,8 @@ def __init__(
5252
n_rays: int = 8,
5353
max_range: float = 1.0,
5454
entity_filter: Callable[[vmas.simulator.core.Entity], bool] = lambda _: True,
55-
render_color: vmas.simulator.utils.Color = vmas.simulator.utils.Color.GRAY,
55+
render_color: Union[Color, Tuple[float, float, float]] = Color.GRAY,
56+
alpha: float = 1.0,
5657
render: bool = True,
5758
):
5859
super().__init__(world)
@@ -71,6 +72,7 @@ def __init__(
7172
self._render = render
7273
self._entity_filter = entity_filter
7374
self._render_color = render_color
75+
self._alpha = alpha
7476

7577
def to(self, device: torch.device):
7678
self._angles = self._angles.to(device)
@@ -85,6 +87,16 @@ def entity_filter(
8587
):
8688
self._entity_filter = entity_filter
8789

90+
@property
91+
def render_color(self):
92+
if isinstance(self._render_color, Color):
93+
return self._render_color.value
94+
return self._render_color
95+
96+
@property
97+
def alpha(self):
98+
return self._alpha
99+
88100
def measure(self):
89101
dists = []
90102
for angle in self._angles.unbind(1):
@@ -123,9 +135,10 @@ def render(self, env_index: int = 0) -> "List[Geom]":
123135
xform.set_translation(*self.agent.state.pos[env_index])
124136
xform.set_rotation(angle)
125137
ray.add_attr(xform)
138+
ray.set_color(r=0, g=0, b=0, alpha=self.alpha)
126139

127140
ray_circ = rendering.make_circle(0.01)
128-
ray_circ.set_color(*self._render_color.value)
141+
ray_circ.set_color(*self.render_color, alpha=self.alpha)
129142
xform = rendering.Transform()
130143
rot = torch.stack([torch.cos(angle), torch.sin(angle)], dim=-1)
131144
pos_circ = (

0 commit comments

Comments
 (0)