Skip to content

Commit

Permalink
PGMap: customizable starting point (#667)
Browse files Browse the repository at this point in the history
* Ability to configure pg map starting position

Add this to global config

Run format.sh

* Remove constant from base_map
  • Loading branch information
fredyshox authored Mar 1, 2024
1 parent 65d17aa commit 27f5e71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions metadrive/component/map/pg_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def _config_generate(self, blocks_config: List, parent_node_path: NodePath, phys
render_root_np=parent_node_path,
physics_world=physics_world,
length=self._config.get("exit_length", 50),
start_point=self._config.get("start_position", [0, 0]),
ignore_intersection_checking=True
)
self.blocks.append(last_block)
Expand Down
12 changes: 11 additions & 1 deletion metadrive/component/pgblock/first_block.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Sequence, Union
from panda3d.core import NodePath

import numpy as np

from metadrive.component.lane.straight_lane import StraightLane
from metadrive.component.pg_space import ParameterSpace
from metadrive.component.pgblock.create_pg_block_utils import CreateRoadFrom, CreateAdverseRoad, ExtendStraightLane
Expand Down Expand Up @@ -30,6 +33,7 @@ def __init__(
render_root_np: NodePath,
physics_world: PhysicsWorld,
length: float = 30,
start_point: Union[np.ndarray, Sequence[float]] = [0, 0],
ignore_intersection_checking=False,
remove_negative_lanes=False,
side_lane_line_type=None,
Expand All @@ -48,9 +52,15 @@ def __init__(
)
if length < self.ENTRANCE_LENGTH:
print("Warning: first block length is two small", length, "<", self.ENTRANCE_LENGTH)
if not isinstance(start_point, np.ndarray):
start_point = np.array(start_point)

self._block_objects = []
basic_lane = StraightLane(
[0, 0], [self.ENTRANCE_LENGTH, 0], line_types=(PGLineType.BROKEN, PGLineType.SIDE), width=lane_width
start_point,
start_point + [self.ENTRANCE_LENGTH, 0],
line_types=(PGLineType.BROKEN, PGLineType.SIDE),
width=lane_width
)
ego_v_spawn_road = Road(self.NODE_1, self.NODE_2)
CreateRoadFrom(
Expand Down
1 change: 1 addition & 0 deletions metadrive/envs/metadrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
BaseMap.LANE_WIDTH: 3.5,
BaseMap.LANE_NUM: 3,
"exit_length": 50,
"start_position": [0, 0],
},
store_map=True,

Expand Down

0 comments on commit 27f5e71

Please sign in to comment.