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

Fixed bubble rendering issue, added ConfigurableZone #1693

Merged
merged 13 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Copy and pasting the git commit messages is __NOT__ enough.
- Added ego's mission details into the `FormatObs` wrapper.
- Added `SmartsLaneChangingModel` and `SmartsJunctionModel` to types available for use with the new smarts traffic engine within Scenario Studio.
- Added option to `AgentInterface` to include traffic signals (lights) in `EgoVehicleObservation` objects.
- Added `ConfigurableZone` for `Zone` object to types which enable users to build bubble by providing coordinates of the polygon.

### Deprecated
- Deprecated a few things related to traffic in the `Scenario` class, including the `route` argument to the `Scenario` initializer, the `route`, `route_filepath` and `route_files_enabled` properties, and the `discover_routes()` static method. In general, the notion of "route" (singular) here is being replaced with "`traffic_specs`" (plural) that allow for specifying traffic controlled by the SMARTS engine as well as Sumo.
Expand Down
6 changes: 3 additions & 3 deletions envision/web/src/helpers/state_unpacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const WorldState = Object.freeze({
SCENARIO_ID: 1,
SCENARIO_NAME: 2,
TRAFFIC: 3,
BUBBLES: 4,
SCORES: 5,
EGO_AGENT_IDS: 6,
BUBBLES: 5,
SCORES: 6,
EGO_AGENT_IDS: 7,
AisenGinn marked this conversation as resolved.
Show resolved Hide resolved
});

const Traffic = Object.freeze({
Expand Down
56 changes: 54 additions & 2 deletions smarts/sstudio/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from dataclasses import dataclass, field
from enum import IntEnum
from sys import maxsize
from typing import Any, Callable, Dict, NewType, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, NewType, Optional, Sequence, Tuple, Union, List

import numpy as np
from shapely.affinity import rotate as shapely_rotate
Expand All @@ -38,6 +38,7 @@
MultiPolygon,
Point,
Polygon,
box,
)
from shapely.ops import split, unary_union

Expand Down Expand Up @@ -653,7 +654,7 @@ class GroupedLapMission:
class Zone:
"""The base for a descriptor that defines a capture area."""

def to_geometry(self, road_map: RoadMap) -> Polygon:
def to_geometry(self, road_map: Optional[RoadMap] = None) -> Polygon:
"""Generates the geometry from this zone."""
raise NotImplementedError

Expand Down Expand Up @@ -814,6 +815,51 @@ def to_geometry(self, road_map: Optional[RoadMap] = None) -> Polygon:
return shapely_translate(poly, xoff=x, yoff=y)


@dataclass(frozen=True)
class ConfigurableZone(Zone):
"""A descripter that defines a specific configurableZone defined by user"""
AisenGinn marked this conversation as resolved.
Show resolved Hide resolved

ext_coordinates: List[Tuple[float, float]]
AisenGinn marked this conversation as resolved.
Show resolved Hide resolved
"""external coordinates of the polygon
< 2 points provided: error
= 2 points provided: generates a box using these two points as diagonal
> 2 points provided: generates a polygons according to the coordinates"""
AisenGinn marked this conversation as resolved.
Show resolved Hide resolved
rotation: Optional[float] = None
"""The heading direction of the bubble(radians, clock-wise rotation)"""

def __post_init__(self):
if not self.ext_coordinates or not isinstance(self.ext_coordinates[0], tuple):
raise ValueError(
"Two points or more are needed to create a polygon. (less than two points are provided)"
)

x_set = set(point[0] for point in self.ext_coordinates)
y_set = set(point[1] for point in self.ext_coordinates)
if len(x_set) == 1 or len(y_set) == 1:
raise ValueError(
"Parallel line cannot form a polygon. (points provided form a parallel line)"
)
AisenGinn marked this conversation as resolved.
Show resolved Hide resolved

def to_geometry(self, road_map: Optional[RoadMap] = None) -> Polygon:
"""Generate a polygon according to given coordinates"""
poly = None
if (
len(self.ext_coordinates) == 2
): # if user only specified two points, create a box
x_min = min(self.ext_coordinates[0][0], self.ext_coordinates[1][0])
x_max = max(self.ext_coordinates[0][0], self.ext_coordinates[1][0])
y_min = min(self.ext_coordinates[0][1], self.ext_coordinates[1][1])
y_max = max(self.ext_coordinates[0][1], self.ext_coordinates[1][1])
poly = box(x_min, y_min, x_max, y_max)

else: # else create a polygon according to the coordinates
poly = Polygon(self.ext_coordinates)

if self.rotation is not None:
poly = shapely_rotate(poly, self.rotation, use_radians=True)
return
AisenGinn marked this conversation as resolved.
Show resolved Hide resolved


@dataclass(frozen=True)
class BubbleLimits:
"""Defines the capture limits of a bubble."""
Expand Down Expand Up @@ -890,6 +936,12 @@ def __post_init__(self):
"Only boids can have keep_alive enabled (for persistent boids)"
)

poly = None
if not isinstance(self.zone, MapZone):
poly = self.zone.to_geometry(road_map=None)
if poly is not None and (poly.is_valid == False):
raise ValueError("The Zone Polygon is not a valid closed loop")
AisenGinn marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def to_actor_id(actor, mission_group):
"""Mashes the actor id and mission group to create what needs to be a unique id."""
Expand Down