Exemplo n.º 1
0
    def _mission2trap(self, road_network, mission, default_zone_dist=6):
        if not (hasattr(mission, "start") and hasattr(mission, "goal")):
            raise ValueError(f"Value {mission} is not a mission!")

        activation_delay = mission.start_time
        patience = mission.entry_tactic.wait_to_hijack_limit_s
        zone = mission.entry_tactic.zone
        default_entry_speed = mission.entry_tactic.default_entry_speed
        n_lane = None

        if default_entry_speed is None:
            n_lane = n_lane or road_network.nearest_lane(
                mission.start.position)
            default_entry_speed = n_lane.getSpeed()

        if zone is None:
            n_lane = n_lane or road_network.nearest_lane(
                mission.start.position)
            lane_speed = n_lane.getSpeed()
            start_edge_id = n_lane.getEdge().getID()
            start_lane = n_lane.getIndex()
            lane_length = n_lane.getLength()
            start_pos = mission.start.position
            vehicle_offset_into_lane = road_network.offset_into_lane(
                n_lane, (start_pos[0], start_pos[1]))
            vehicle_offset_into_lane = clip(vehicle_offset_into_lane, 1e-6,
                                            lane_length - 1e-6)

            drive_distance = lane_speed * default_zone_dist

            start_offset_in_lane = vehicle_offset_into_lane - drive_distance
            start_offset_in_lane = clip(start_offset_in_lane, 1e-6,
                                        lane_length - 1e-6)
            length = max(1e-6, vehicle_offset_into_lane - start_offset_in_lane)

            zone = MapZone(
                start=(start_edge_id, start_lane, start_offset_in_lane),
                length=length,
                n_lanes=1,
            )

        trap = Trap(
            geometry=zone.to_geometry(road_network),
            # TODO: Make reactivation and activation delay configurable through
            #   scenario studio
            reactivation_time=-1,
            remaining_time_to_reactivation=activation_delay,
            patience=patience,
            mission=mission,
            exclusion_prefixes=mission.entry_tactic.exclusion_prefixes,
            default_entry_speed=default_entry_speed,
        )

        return trap
Exemplo n.º 2
0
    def _mission2trap(self, road_map, mission, default_zone_dist=6):
        if not (hasattr(mission, "start") and hasattr(mission, "goal")):
            raise ValueError(f"Value {mission} is not a mission!")

        activation_delay = mission.start_time
        patience = mission.entry_tactic.wait_to_hijack_limit_s
        zone = mission.entry_tactic.zone
        default_entry_speed = mission.entry_tactic.default_entry_speed
        n_lane = None

        if default_entry_speed is None:
            n_lane = road_map.nearest_lane(mission.start.point)
            assert n_lane, "mission must start in a lane"
            default_entry_speed = n_lane.speed_limit

        if zone is None:
            n_lane = n_lane or road_map.nearest_lane(mission.start.point)
            assert n_lane, "mission must start in a lane"
            lane_speed = n_lane.speed_limit
            start_road_id = n_lane.road.road_id
            start_lane = n_lane.index
            lane_length = n_lane.length
            start_pos = mission.start.position
            vehicle_offset_into_lane = n_lane.offset_along_lane(
                MapPoint(x=start_pos[0], y=start_pos[1]))
            vehicle_offset_into_lane = clip(vehicle_offset_into_lane, 1e-6,
                                            lane_length - 1e-6)

            drive_distance = lane_speed * default_zone_dist

            start_offset_in_lane = vehicle_offset_into_lane - drive_distance
            start_offset_in_lane = clip(start_offset_in_lane, 1e-6,
                                        lane_length - 1e-6)
            length = max(1e-6, vehicle_offset_into_lane - start_offset_in_lane)

            zone = MapZone(
                start=(start_road_id, start_lane, start_offset_in_lane),
                length=length,
                n_lanes=1,
            )

        trap = Trap(
            geometry=zone.to_geometry(road_map),
            remaining_time_to_activation=activation_delay,
            patience=patience,
            mission=mission,
            exclusion_prefixes=mission.entry_tactic.exclusion_prefixes,
            default_entry_speed=default_entry_speed,
        )

        return trap