Identify landlet direction of travel from lanelet_id or position

In the Lanelet class there are some attributes that are related to the road’s permitted direction of travel. e.g. adjacent_left_same_direction, adjacent_right_same_direction, user_one_way, but nothing I see indicates the actual allowed direction of travel. Is there a function like LaneletNetwork.find_lanelet_by_position() that could easily check if the ego vehicle is in the correct lane? My solutions would occasionally have the ego vehicle swerve into the opposite lane whenever there’s space.

Hi tk,

there is no such function implemented at the moment. What you can easily do is that you first compute a route leading from the initial lanelet to the goal lanelet, then for each lanelet in the route, iteratively add their adjacent lanelets with the same driving direction. This way you obtain a set of lanelets that have the same driving direction as your route.

Something like this

set_ids_lanelets = set(route.list_ids_lanelets)
# obtain lanelets in the same direction as the route
terminate = False
while not terminate:
    num_ids_lanelets = len(set_ids_lanelets)
    for id_lanelet in list(set_ids_lanelets):
        lanelet = self.config.scenario.lanelet_network.find_lanelet_by_id(id_lanelet)

        # if left lanelet is in the same direction
        if lanelet.adj_left and lanelet.adj_left_same_direction:
            set_ids_lanelets.add(lanelet.adj_left)

        # if right lanelet is in the same direction
        if lanelet.adj_right and lanelet.adj_right_same_direction:
            set_ids_lanelets.add(lanelet.adj_right)

    terminate = (num_ids_lanelets == len(set_ids_lanelets))

set_ids_lanelets_same_direction = set_ids_lanelets.copy()
1 Like