metadriverse / metadrive

MetaDrive: Open-source driving simulator
https://metadriverse.github.io/metadrive/
Apache License 2.0
746 stars 107 forks source link

Spawning vehicles #731

Open EhsanSabouni opened 4 months ago

EhsanSabouni commented 4 months ago

Hi

I want to use ramp in MARL. But I do not know how to spawn car on side road (in ramp). Does anyone know how to spawn car in an arbitrary position?

I checked the website and found this but I am not sure how to find these values including navigation module, spawn_lane_index and so on.

    # A BaseNavigation instance. It should match the road network type.
    navigation_module=None,
    # A lane id specifies which lane to spawn this vehicle
    spawn_lane_index=None,
    # destination lane id. Required only when navigation module is not None.
    destination=None,
    # the longitudinal and lateral position on the spawn lane
    spawn_longitude=5.0,
    spawn_lateral=0.0,

Thanks

QuanyiLi commented 3 months ago

Hi @EhsanSabouni,

All lanes will have its corresponding ID, which can be retrieved by lane.id. And you can find all lanes from env.engine.current_map.road_network which also records the connectivity information for all lanes. Usually speaking, the lane id is generated following some rules. This line is for creating the merging lane: https://github.com/metadriverse/metadrive/blob/05ec6c8ea9a9fc77742b8af9967e63b43b4abaae/metadrive/component/pgblock/ramp.py#L139 Checking the properties of 'straight_road' would tell you the lane ID in style (node1, node2, lane_index). If you are connecting multiple ramps, the ID of this merging lane only differs at the first digit which indicates the block order.