Skip to content

Commit

Permalink
Merge pull request #1 from HeyGF/HeyGF-Dev
Browse files Browse the repository at this point in the history
Improve the readability
  • Loading branch information
HeyGF authored Aug 17, 2024
2 parents aabd9fa + a78515c commit 482e3ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 6 additions & 5 deletions car_dreamer/carla_stop_sign_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def calculate_traffic_light_violation_penalty(self):
return 0.0

def violate_traffic_light(self):
if self.is_near_sepecific_stop_sign(self._config.traffic_locations):
if self.is_within_stop_sign_proximity(self._config.traffic_locations):
self._stop_time += 1
self._entered = 1
elif self._entered == 1: # Mark the leaving
Expand All @@ -80,23 +80,24 @@ def violate_traffic_light(self):
if self._entered == 2 and self._stop_time < self._config.stopping_time:
return True
return False

def is_within_stop_sign_proximity(self, sign_location):

def is_near_sepecific_stop_sign(self, sign_location):
"""
Check if the ego vehicle is near the stop sign.
"""
ego_location = np.array([*get_vehicle_pos(self.ego), 0.1])
distance = np.linalg.norm(ego_location - sign_location)

return distance <= self._config.stop_sign_near_threshold
return distance <= self._config.stop_sign_proximity_threshold

def _is_ego_near_stop_sign(self, stop_sign: carla.Actor) -> bool:
"""Check if the ego vehicle is within the proximity threshold of the stop sign."""
ego_location = self.ego.get_location()
stop_sign_location = stop_sign.get_location()
distance = ego_location.distance(stop_sign_location)
return distance < self._config.stop_sign_near_threshold

return distance < self._config.stop_sign_proximity_threshold
def handle_stop_sign(self):
stop_signs = self._world._get_world().get_actors().filter("traffic.stop")
for stop_sign in stop_signs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,6 @@ def _render_stop_signs(self, **env_state):

self._render_stop_sign(self._surface, stop_sign, color)

# def _is_ego_near_stop_sign(self, stop_sign: carla.Actor) -> bool:
# """Check if the ego vehicle is within the proximity threshold of the stop sign."""
# ego_location = self._ego.get_location()
# stop_sign_location = stop_sign.get_location()
# distance = ego_location.distance(stop_sign_location)
# return distance < self._stop_sign_near_threshold

def _render_stop_sign(self, surface, stop_sign: carla.Actor, color: Color):
"""Render a stop sign on the surface."""
world_pos = stop_sign.get_location()
Expand Down

0 comments on commit 482e3ce

Please sign in to comment.