HighwayEnv icon indicating copy to clipboard operation
HighwayEnv copied to clipboard

Lane index and location

Open AHPUymhd opened this issue 3 months ago • 2 comments

Let's say I'm in the middle lane, how can I get the index of the left and right lanes and the current lane first, and then how can I find out which cars are in these three lanes based on the lane index, and how to get their speed and coordinates,I noticed that the official tutorial doesn't seem to have this information, how can I get it? Thank you so much

AHPUymhd avatar Mar 11 '24 08:03 AHPUymhd

@eleurent Thank you very much

AHPUymhd avatar Mar 11 '24 08:03 AHPUymhd

Let's say I'm in the middle lane, how can I get the index of the left and right lanes and the current lane first

You can access the ego-vehicle's lane index with env.vehicle.lane_index. It is a (from: str, to: str, lane: int) tuple, and the adjacent lanes are those with the same from/to bounds but +/-1 "lane" index.

and then how can I find out which cars are in these three lanes based on the lane index

You can iterate vehicles in env.road.vehicles and check that their lane_index matches env.vehicle.lane_index (+/-1 on last tuple item).

and how to get their speed and coordinates

With vehicle.speed and vehicle.position

eleurent avatar Mar 16 '24 14:03 eleurent