Skip to content

Commit

Permalink
Docs and linter update
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliusMiller committed Sep 26, 2024
1 parent 41f2038 commit 657c97f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
2 changes: 0 additions & 2 deletions examples/demo_pedestrian.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Simulate the trained robot and a trained pedestrian."""
import os
from pathlib import Path

from stable_baselines3 import PPO
import loguru
Expand Down
5 changes: 5 additions & 0 deletions robot_sf/gym_env/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def simple_ped_reward(meta: dict, max_episode_step_discount: float=-0.1,
Parameters:
meta (dict): Metadata containing information about the pedestrian's current state.
max_episode_step_discount (float): Discount factor for each step in the episode.
ped_coll_penalty (float): Penalty for colliding with a pedestrian.
obst_coll_penalty (float): Penalty for colliding with an obstacle.
robot_coll_reward (float): Reward for colliding with a robot.
robot_at_goal_penalty (float): Penalty if the robot reaches his goal.
Returns:
float: The calculated reward.
Expand All @@ -76,6 +80,7 @@ def simple_ped_reward(meta: dict, max_episode_step_discount: float=-0.1,
if meta["is_robot_collision"]:
reward += robot_coll_reward

# If the robot has reached its goal, apply penalty
if meta["is_robot_at_goal"]:
reward += robot_at_goal_penalty

Expand Down
29 changes: 29 additions & 0 deletions robot_sf/nav/occupancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,35 @@ def is_in_bounds(self, world_x: float, world_y: float) -> bool:

@dataclass
class EgoPedContinuousOccupancy(ContinuousOccupancy):
"""
A class, which extends the continuous occupancy for the ego pedestrian.
Attributes
----------
width : float
The width of the occupancy.
height : float
The height of the occupancy.
get_agent_coords : Callable[[], Vec2D]
A function to get the agent coordinates.
get_goal_coords : Callable[[], Vec2D]
A function to get the goal coordinates.
get_obstacle_coords : Callable[[], np.ndarray]
A function to get the obstacle coordinates.
get_pedestrian_coords : Callable[[], np.ndarray]
A function to get the pedestrian coordinates.
agent_radius : float, optional
The robot radius, by default 1.0.
ped_radius : float, optional
The pedestrian radius, by default 0.4.
goal_radius : float, optional
The goal radius, by default 1.0.
get_enemy_coords : Optional[Callable[[], Vec2D]]
The coordinates of the opposing agent.
enemy_radius : optional, float=1.0
The radius of the opposing agent.
"""

get_enemy_coords: Optional[Callable[[], Vec2D]] = None
enemy_radius: float=1.0

Expand Down
19 changes: 9 additions & 10 deletions robot_sf/render/sim_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def render(self, state: VisualizableSimState):
# static objects
if self.map_def.obstacles:
self._draw_obstacles()

# debugging objects
# if self.map_def.robot_routes:
# self._draw_robot_routes()
Expand Down Expand Up @@ -296,7 +296,7 @@ def _draw_robot(self, pose: RobotPose):
ROBOT_COLOR,
self._scale_tuple(pose[0]),
self.robot_radius * self.scaling)

def _draw_ego_ped(self, pose: PedPose):
# TODO: display robot with an image instead of a circle
pygame.draw.circle(
Expand Down Expand Up @@ -468,16 +468,16 @@ def _add_text(self, timestep: int, state: VisualizableSimState):
for i, text in enumerate(text_lines):
text_render = self.font.render(text, True, TEXT_COLOR)
text_outline = self.font.render(text, True, TEXT_OUTLINE_COLOR)

pos = (5, i * self.font.get_linesize() + 5)

# Draw text outline
for dx, dy in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
text_surface.blit(text_outline, (pos[0] + dx, pos[1] + dy))

# Draw main text
text_surface.blit(text_render, pos)

self.screen.blit(text_surface, self._timestep_text_pos)

def _add_help_text(self):
Expand All @@ -496,7 +496,6 @@ def _add_help_text(self):

# Determine max width of the text
text_surface = self.font.render(text_lines[1], False, TEXT_COLOR)
width = text_surface.get_width() + 10

max_width = max(self.font.size(line)[0] for line in text_lines)
text_height = len(text_lines) * self.font.get_linesize()
Expand All @@ -506,13 +505,13 @@ def _add_help_text(self):
for i, text in enumerate(text_lines):
text_render = self.font.render(text, True, TEXT_COLOR)
text_outline = self.font.render(text, True, TEXT_OUTLINE_COLOR)

pos = (5, i * self.font.get_linesize() + 5)

# Draw text outline
for dx, dy in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
text_surface.blit(text_outline, (pos[0] + dx, pos[1] + dy))

# Draw main text
text_surface.blit(text_render, pos)

Expand Down
9 changes: 8 additions & 1 deletion robot_sf/sim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ def init_simulators(

@dataclass
class PedSimulator(Simulator):
"""
A pedestrian simulator, whic extends the base simulator.
Args:
ego_ped (UnicycleDrivePedestrian): The ego pedestrian in the environment.
"""
ego_ped: UnicycleDrivePedestrian

@property
Expand Down Expand Up @@ -246,7 +253,7 @@ def get_proximity_point(self, fixed_point: Tuple[float, float],

def is_obstacle_collision(self, x: float, y: float) -> bool:
"""
TODO: copy from occupancy.py
TODO: this method is copied from occupancy.py
"""
if not (0 <= x <= self.map_def.width and 0 <= y <= self.map_def.height):
return True
Expand Down
3 changes: 0 additions & 3 deletions scripts/debug_ped_discrete.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""Simulate a hardcoded deterministic policy with four actions."""
import os
from pathlib import Path
from math import pi

from stable_baselines3 import PPO
import loguru
Expand Down

0 comments on commit 657c97f

Please sign in to comment.