Пример #1
0
    def _create_road(self) -> None:

        # Circle lanes: (s)outh/(e)ast/(n)orth/(w)est (e)ntry/e(x)it.
        center = [0, 0]  # [m]

        radius = self.config["derby_radius"]  # [m]
        alpha = 90  # [deg]

        net = RoadNetwork()
        radii = [radius]
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.CONTINUOUS
        line = [[c, s], [n, c]]
        for lane in [0]:

            net.add_lane(
                "se", "ee",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(-90 - alpha),
                             np.deg2rad(alpha + 5),
                             clockwise=True,
                             line_types=line[lane]))
            net.add_lane(
                "ee", "se",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(alpha - 5),
                             np.deg2rad(92 + alpha),
                             clockwise=True,
                             line_types=line[lane]))

        road = Road(network=net,
                    np_random=self.np_random,
                    record_history=self.config["show_trajectories"])
        self.road = road
Пример #2
0
    def _make_road(self):
        """
            Make an 4-way intersection.

            The horizontal road has the right of way. More precisely, the levels of priority are:
                - 3 for horizontal straight lanes and right-turns
                - 1 for vertical straight lanes and right-turns
                - 2 for horizontal left-turns
                - 0 for vertical left-turns
            The code for nodes in the road network is:
            (o:outer | i:inner + [r:right, l:left]) + (0:south | 1:west | 2:north | 3:east)
        :return: the intersection road
        """
        lane_width = AbstractLane.DEFAULT_WIDTH
        right_turn_radius = lane_width + 5  # [m}
        left_turn_radius = right_turn_radius + lane_width  # [m}
        outer_distance = right_turn_radius + lane_width / 2
        access_length = 50 + 50  # [m]

        net = RoadNetwork()
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        for corner in range(4):
            angle = np.radians(90 * corner)
            is_horizontal = corner % 2
            priority = 3 if is_horizontal else 1
            rotation = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
            # Incoming
            start = rotation @ np.array([lane_width / 2, access_length + outer_distance])
            end = rotation @ np.array([lane_width / 2, outer_distance])
            net.add_lane("o" + str(corner), "ir" + str(corner),
                         StraightLane(start, end, line_types=[s, c], priority=priority, speed_limit=10))
            # Right turn
            r_center = rotation @ (np.array([outer_distance, outer_distance]))
            net.add_lane("ir" + str(corner), "il" + str((corner - 1) % 4),
                         CircularLane(r_center, right_turn_radius, angle + np.radians(180), angle + np.radians(270),
                                      line_types=[n, c], priority=priority, speed_limit=10))
            # Left turn
            l_center = rotation @ (np.array([-left_turn_radius + lane_width / 2, left_turn_radius - lane_width / 2]))
            net.add_lane("ir" + str(corner), "il" + str((corner + 1) % 4),
                         CircularLane(l_center, left_turn_radius, angle + np.radians(0), angle + np.radians(-90),
                                      clockwise=False, line_types=[n, n], priority=priority - 1, speed_limit=10))
            # Straight
            start = rotation @ np.array([lane_width / 2, outer_distance])
            end = rotation @ np.array([lane_width / 2, -outer_distance])
            net.add_lane("ir" + str(corner), "il" + str((corner + 2) % 4),
                         StraightLane(start, end, line_types=[s, n], priority=priority, speed_limit=10))
            # Exit
            start = rotation @ np.flip([lane_width / 2, access_length + outer_distance], axis=0)
            end = rotation @ np.flip([lane_width / 2, outer_distance], axis=0)
            net.add_lane("il" + str((corner - 1) % 4), "o" + str((corner - 1) % 4),
                         StraightLane(end, start, line_types=[n, c], priority=priority, speed_limit=10))

        # TODO: double check here change from regulated to general road

        road = RegulatedRoad(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"])
        self.road = road
Пример #3
0
    def _make_road(self):
        lane_width = AbstractLane.DEFAULT_WIDTH
        right_turn_radius = lane_width + 5  # [m}
        left_turn_radius = right_turn_radius + lane_width  # [m}
        outer_distance = right_turn_radius + lane_width / 2
        access_length = 40  # [m]

        # Corners: 0:south, 1:west, 2:north, 3:east. i:inner, o:outer, r:right, l:left
        net = RoadNetwork()
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        for corner in range(4):
            angle = rad(90 * corner)
            rotation = np.array([[np.cos(angle), -np.sin(angle)],
                                 [np.sin(angle), np.cos(angle)]])
            # Incoming
            start = rotation @ np.array(
                [lane_width / 2, access_length + outer_distance])
            end = rotation @ np.array([lane_width / 2, outer_distance])
            net.add_lane("o" + str(corner), "ir" + str(corner),
                         StraightLane(start, end, line_types=[s, c]))
            # Right turn
            r_center = rotation @ (np.array([outer_distance, outer_distance]))
            net.add_lane(
                "ir" + str(corner), "il" + str((corner - 1) % 4),
                CircularLane(r_center,
                             right_turn_radius,
                             angle + rad(180),
                             angle + rad(270),
                             line_types=[n, c]))
            # Left turn
            l_center = rotation @ (np.array([
                -left_turn_radius + lane_width / 2,
                left_turn_radius - lane_width / 2
            ]))
            net.add_lane(
                "ir" + str(corner), "il" + str((corner + 1) % 4),
                CircularLane(l_center,
                             left_turn_radius,
                             angle + rad(0),
                             angle + rad(-90),
                             clockwise=False,
                             line_types=[n, n]))
            # Straight
            start = rotation @ np.array([lane_width / 2, outer_distance])
            end = rotation @ np.array([lane_width / 2, -outer_distance])
            net.add_lane("ir" + str(corner), "il" + str((corner + 2) % 4),
                         StraightLane(start, end, line_types=[s, n]))
            # Exit
            start = rotation @ np.flip(
                [lane_width / 2, access_length + outer_distance], axis=0)
            end = rotation @ np.flip([lane_width / 2, outer_distance], axis=0)
            net.add_lane("il" + str((corner - 1) % 4), "o" + str(
                (corner - 1) % 4), StraightLane(end, start, line_types=[n, c]))

        road = Road(network=net, np_random=self.np_random)
        self.road = road
Пример #4
0
    def _make_road(self) -> None:
        net = RoadNetwork()

        radius = self.config["radius"]  # [m]
        # radius = np.random.choice([50, 500])  # [m]
        # radius = np.random.choice([50, 200, 500, 1000])  # [m]
        center = [0, StraightLane.DEFAULT_WIDTH + radius]  # [m]
        alpha = 0  # [deg]
        radii = [
            radius, radius + StraightLane.DEFAULT_WIDTH,
            radius + 2 * StraightLane.DEFAULT_WIDTH
        ]
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        line = [[c, s], [n, s], [n, c]]

        for lane in [0, 1, 2]:
            net.add_lane(
                "a",
                "b",
                # CircularLane(center, radii[lane], np.deg2rad(90 - alpha), np.deg2rad(-90+alpha),
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(90 - alpha),
                             np.deg2rad(-360 + alpha),
                             clockwise=False,
                             line_types=line[lane]))

        road = Road(network=net,
                    np_random=self.np_random,
                    record_history=self.config["show_trajectories"])
        self.road = road
        self.road.record_history = True
Пример #5
0
    def _create_circuit(self):
        circular_radius = 50
        line_types = [LineType.STRIPED, LineType.CONTINUOUS]
        circular_lane_1 = CircularLane(center=(0.0, 0.0),
                                       radius=circular_radius,
                                       start_phase=0,
                                       end_phase=math.pi * 0.5,
                                       speed_limit=self.speed_limit,
                                       width=self.circuit_width,
                                       line_types=line_types)
        circular_lane_2 = CircularLane(
            center=(0.0, 0.0),
            radius=circular_radius,
            start_phase=math.pi * 0.5,
            end_phase=math.pi,
            speed_limit=self.speed_limit,
            width=self.circuit_width,
            line_types=line_types,
        )
        circular_lane_start = circular_lane_1.position(0, 0)
        circular_lane_end = circular_lane_2.position(circular_lane_2.length, 0)
        sine_lane = SineLane(
            circular_lane_end,
            circular_lane_start,
            amplitude=10,
            pulsation=2 * math.pi / (circular_radius * 2),
            phase=0,
            speed_limit=self.speed_limit,
            width=self.circuit_width,
            line_types=line_types,
        )

        self._add_lane('start', 'int1', circular_lane_1)
        self._add_lane('int1', 'int2', circular_lane_2)
        self._add_lane('int2', 'end', sine_lane)
Пример #6
0
    def make_road(self):
        # Circle lanes: (s)outh/(e)ast/(n)orth/(w)est (e)ntry/e(x)it.
        center = [0, 0]  # [m]
        radius = 30  # [m]
        alpha = 20  # [deg]

        net = RoadNetwork()
        radii = [radius, radius+4]
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        line = [[c, s], [n, c]]
        for lane in [0, 1]:
            net.add_lane("se", "ex", CircularLane(center, radii[lane], rad(90-alpha), rad(alpha), line_types=line[lane]))
            net.add_lane("ex", "ee", CircularLane(center, radii[lane], rad(alpha), rad(-alpha), line_types=line[lane]))
            net.add_lane("ee", "nx", CircularLane(center, radii[lane], rad(-alpha), rad(-90+alpha), line_types=line[lane]))
            net.add_lane("nx", "ne", CircularLane(center, radii[lane], rad(-90+alpha), rad(-90-alpha), line_types=line[lane]))
            net.add_lane("ne", "wx", CircularLane(center, radii[lane], rad(-90-alpha), rad(-180+alpha), line_types=line[lane]))
            net.add_lane("wx", "we", CircularLane(center, radii[lane], rad(-180+alpha), rad(-180-alpha), line_types=line[lane]))
            net.add_lane("we", "sx", CircularLane(center, radii[lane], rad(180-alpha), rad(90+alpha), line_types=line[lane]))
            net.add_lane("sx", "se", CircularLane(center, radii[lane], rad(90+alpha), rad(90-alpha), line_types=line[lane]))

        # Access lanes: (r)oad/(s)ine
        access = 200  # [m]
        dev = 120  # [m]
        a = 5  # [m]
        delta_st = 0.20*dev  # [m]

        delta_en = dev-delta_st
        w = 2*np.pi/dev
        net.add_lane("ser", "ses", StraightLane([2, access], [2, dev/2], line_types=[s, c]))
        net.add_lane("ses", "se", SineLane([2+a, dev/2], [2+a, dev/2-delta_st], a, w, -np.pi/2, line_types=[c, c]))
        net.add_lane("sx", "sxs", SineLane([-2-a, -dev/2+delta_en], [-2-a, dev/2], a, w, -np.pi/2+w*delta_en, line_types=[c, c]))
        net.add_lane("sxs", "sxr", StraightLane([-2, dev / 2], [-2, access], line_types=[n, c]))

        net.add_lane("eer", "ees", StraightLane([access, -2], [dev / 2, -2], line_types=[s, c]))
        net.add_lane("ees", "ee", SineLane([dev / 2, -2-a], [dev / 2 - delta_st, -2-a], a, w, -np.pi / 2, line_types=[c, c]))
        net.add_lane("ex", "exs", SineLane([-dev / 2 + delta_en, 2+a], [dev / 2, 2+a], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c]))
        net.add_lane("exs", "exr", StraightLane([dev / 2, 2], [access, 2], line_types=[n, c]))

        net.add_lane("ner", "nes", StraightLane([-2, -access], [-2, -dev / 2], line_types=[s, c]))
        net.add_lane("nes", "ne", SineLane([-2 - a, -dev / 2], [-2 - a, -dev / 2 + delta_st], a, w, -np.pi / 2, line_types=[c, c]))
        net.add_lane("nx", "nxs", SineLane([2 + a, dev / 2 - delta_en], [2 + a, -dev / 2], a, w, -np.pi / 2 + w * delta_en, line_types=[c, c]))
        net.add_lane("nxs", "nxr", StraightLane([2, -dev / 2], [2, -access], line_types=[n, c]))

        road = Road(network=net)
        self.road = road
Пример #7
0
    def _make_road(self, length=128):
        """
        Making double lane road with counter-clockwise U-Turn.
        :return: the road
        """
        net = RoadNetwork()

        # Defining upper starting lanes after the U-Turn.
        # These Lanes are defined from x-coordinate 'length' to 0.
        net.add_lane("c", "d", StraightLane([length, StraightLane.DEFAULT_WIDTH], [0, StraightLane.DEFAULT_WIDTH],
                                            line_types=(LineType.CONTINUOUS_LINE, LineType.STRIPED)))
        net.add_lane("c", "d", StraightLane([length, 0], [0, 0],
                                            line_types=(LineType.NONE, LineType.CONTINUOUS_LINE)))

        # Defining counter-clockwise circular U-Turn lanes.
        center = [length, StraightLane.DEFAULT_WIDTH + 20]  # [m]
        radius = 20  # [m]
        alpha = 0  # [deg]

        radii = [radius, radius+StraightLane.DEFAULT_WIDTH]
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        line = [[c, s], [n, c]]
        for lane in [0, 1]:
            net.add_lane("b", "c",
                         CircularLane(center, radii[lane], np.deg2rad(90 - alpha), np.deg2rad(-90+alpha),
                                      clockwise=False, line_types=line[lane]))

        offset = 2*radius

        # Defining lower starting lanes before the U-Turn.
        # These Lanes are defined from x-coordinate 0 to 'length'.
        net.add_lane("a", "b", StraightLane([0, ((2 * StraightLane.DEFAULT_WIDTH + offset) - StraightLane.DEFAULT_WIDTH)],
                                            [length, ((2 * StraightLane.DEFAULT_WIDTH + offset) - StraightLane.DEFAULT_WIDTH)],
                                            line_types=(LineType.CONTINUOUS_LINE,
                                                        LineType.STRIPED)))
        net.add_lane("a", "b", StraightLane([0, (2 * StraightLane.DEFAULT_WIDTH + offset)],
                                            [length, (2 * StraightLane.DEFAULT_WIDTH + offset)],
                                            line_types=(LineType.NONE,
                                                        LineType.CONTINUOUS_LINE)))

        road = Road(network=net, np_random=self.np_random, record_history=self.config["show_trajectories"])
        self.road = road
Пример #8
0
    def _make_road(self) -> None:
        # Circle lanes: (s)outh/(e)ast/(n)orth/(w)est (e)ntry/e(x)it.
        center = [0, 0]  # [m]
        radius = 20  # [m]
        alpha = 24  # [deg]

        net = RoadNetwork()
        radii = [radius, radius + 4]
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        line = [[c, s], [n, c]]
        for lane in [0, 1]:
            net.add_lane(
                "se", "ex",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(90 - alpha),
                             np.deg2rad(alpha),
                             clockwise=False,
                             line_types=line[lane]))
            net.add_lane(
                "ex", "ee",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(alpha),
                             np.deg2rad(-alpha),
                             clockwise=False,
                             line_types=line[lane]))
            net.add_lane(
                "ee", "nx",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(-alpha),
                             np.deg2rad(-90 + alpha),
                             clockwise=False,
                             line_types=line[lane]))
            net.add_lane(
                "nx", "ne",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(-90 + alpha),
                             np.deg2rad(-90 - alpha),
                             clockwise=False,
                             line_types=line[lane]))
            net.add_lane(
                "ne", "wx",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(-90 - alpha),
                             np.deg2rad(-180 + alpha),
                             clockwise=False,
                             line_types=line[lane]))
            net.add_lane(
                "wx", "we",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(-180 + alpha),
                             np.deg2rad(-180 - alpha),
                             clockwise=False,
                             line_types=line[lane]))
            net.add_lane(
                "we", "sx",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(180 - alpha),
                             np.deg2rad(90 + alpha),
                             clockwise=False,
                             line_types=line[lane]))
            net.add_lane(
                "sx", "se",
                CircularLane(center,
                             radii[lane],
                             np.deg2rad(90 + alpha),
                             np.deg2rad(90 - alpha),
                             clockwise=False,
                             line_types=line[lane]))

        # Access lanes: (r)oad/(s)ine
        access = 170  # [m]
        dev = 85  # [m]
        a = 5  # [m]
        delta_st = 0.2 * dev  # [m]

        delta_en = dev - delta_st
        w = 2 * np.pi / dev
        net.add_lane(
            "ser", "ses",
            StraightLane([2, access], [2, dev / 2], line_types=(s, c)))
        net.add_lane(
            "ses", "se",
            SineLane([2 + a, dev / 2], [2 + a, dev / 2 - delta_st],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=(c, c)))
        net.add_lane(
            "sx", "sxs",
            SineLane([-2 - a, -dev / 2 + delta_en], [-2 - a, dev / 2],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=(c, c)))
        net.add_lane(
            "sxs", "sxr",
            StraightLane([-2, dev / 2], [-2, access], line_types=(n, c)))

        net.add_lane(
            "eer", "ees",
            StraightLane([access, -2], [dev / 2, -2], line_types=(s, c)))
        net.add_lane(
            "ees", "ee",
            SineLane([dev / 2, -2 - a], [dev / 2 - delta_st, -2 - a],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=(c, c)))
        net.add_lane(
            "ex", "exs",
            SineLane([-dev / 2 + delta_en, 2 + a], [dev / 2, 2 + a],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=(c, c)))
        net.add_lane(
            "exs", "exr",
            StraightLane([dev / 2, 2], [access, 2], line_types=(n, c)))

        net.add_lane(
            "ner", "nes",
            StraightLane([-2, -access], [-2, -dev / 2], line_types=(s, c)))
        net.add_lane(
            "nes", "ne",
            SineLane([-2 - a, -dev / 2], [-2 - a, -dev / 2 + delta_st],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=(c, c)))
        net.add_lane(
            "nx", "nxs",
            SineLane([2 + a, dev / 2 - delta_en], [2 + a, -dev / 2],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=(c, c)))
        net.add_lane(
            "nxs", "nxr",
            StraightLane([2, -dev / 2], [2, -access], line_types=(n, c)))

        net.add_lane(
            "wer", "wes",
            StraightLane([-access, 2], [-dev / 2, 2], line_types=(s, c)))
        net.add_lane(
            "wes", "we",
            SineLane([-dev / 2, 2 + a], [-dev / 2 + delta_st, 2 + a],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=(c, c)))
        net.add_lane(
            "wx", "wxs",
            SineLane([dev / 2 - delta_en, -2 - a], [-dev / 2, -2 - a],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=(c, c)))
        net.add_lane(
            "wxs", "wxr",
            StraightLane([-dev / 2, -2], [-access, -2], line_types=(n, c)))

        road = Road(network=net,
                    np_random=self.np_random,
                    record_history=self.config["show_trajectories"])
        self.road = road
Пример #9
0
    def _make_road(self) -> None:
        net = RoadNetwork()

        # Set Speed Limits for Road Sections - Straight, Turn20, Straight, Turn 15, Turn15, Straight, Turn25x2, Turn18
        speedlimits = [None, 10, 10, 10, 10, 10, 10, 10, 10]

        # Initialise First Lane
        lane = StraightLane([42, 0], [100, 0],
                            line_types=(LineType.CONTINUOUS, LineType.STRIPED),
                            width=5,
                            speed_limit=speedlimits[1])
        self.lane = lane

        # Add Lanes to Road Network - Straight Section
        net.add_lane("a", "b", lane)
        net.add_lane(
            "a", "b",
            StraightLane([42, 5], [100, 5],
                         line_types=(LineType.STRIPED, LineType.CONTINUOUS),
                         width=5,
                         speed_limit=speedlimits[1]))

        # 2 - Circular Arc #1
        center1 = [100, -20]
        radii1 = 20
        net.add_lane(
            "b", "c",
            CircularLane(center1,
                         radii1,
                         np.deg2rad(90),
                         np.deg2rad(-1),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.CONTINUOUS, LineType.NONE),
                         speed_limit=speedlimits[2]))
        net.add_lane(
            "b", "c",
            CircularLane(center1,
                         radii1 + 5,
                         np.deg2rad(90),
                         np.deg2rad(-1),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.STRIPED, LineType.CONTINUOUS),
                         speed_limit=speedlimits[2]))

        # 3 - Vertical Straight
        net.add_lane(
            "c", "d",
            StraightLane([120, -20], [120, -30],
                         line_types=(LineType.CONTINUOUS, LineType.NONE),
                         width=5,
                         speed_limit=speedlimits[3]))
        net.add_lane(
            "c", "d",
            StraightLane([125, -20], [125, -30],
                         line_types=(LineType.STRIPED, LineType.CONTINUOUS),
                         width=5,
                         speed_limit=speedlimits[3]))

        # 4 - Circular Arc #2
        center2 = [105, -30]
        radii2 = 15
        net.add_lane(
            "d", "e",
            CircularLane(center2,
                         radii2,
                         np.deg2rad(0),
                         np.deg2rad(-181),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.CONTINUOUS, LineType.NONE),
                         speed_limit=speedlimits[4]))
        net.add_lane(
            "d", "e",
            CircularLane(center2,
                         radii2 + 5,
                         np.deg2rad(0),
                         np.deg2rad(-181),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.STRIPED, LineType.CONTINUOUS),
                         speed_limit=speedlimits[4]))

        # 5 - Circular Arc #3
        center3 = [70, -30]
        radii3 = 15
        net.add_lane(
            "e", "f",
            CircularLane(center3,
                         radii3 + 5,
                         np.deg2rad(0),
                         np.deg2rad(136),
                         width=5,
                         clockwise=True,
                         line_types=(LineType.CONTINUOUS, LineType.STRIPED),
                         speed_limit=speedlimits[5]))
        net.add_lane(
            "e", "f",
            CircularLane(center3,
                         radii3,
                         np.deg2rad(0),
                         np.deg2rad(137),
                         width=5,
                         clockwise=True,
                         line_types=(LineType.NONE, LineType.CONTINUOUS),
                         speed_limit=speedlimits[5]))

        # 6 - Slant
        net.add_lane(
            "f", "g",
            StraightLane([55.7, -15.7], [35.7, -35.7],
                         line_types=(LineType.CONTINUOUS, LineType.NONE),
                         width=5,
                         speed_limit=speedlimits[6]))
        net.add_lane(
            "f", "g",
            StraightLane([59.3934, -19.2], [39.3934, -39.2],
                         line_types=(LineType.STRIPED, LineType.CONTINUOUS),
                         width=5,
                         speed_limit=speedlimits[6]))

        # 7 - Circular Arc #4 - Bugs out when arc is too large, hence written in 2 sections
        center4 = [18.1, -18.1]
        radii4 = 25
        net.add_lane(
            "g", "h",
            CircularLane(center4,
                         radii4,
                         np.deg2rad(315),
                         np.deg2rad(170),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.CONTINUOUS, LineType.NONE),
                         speed_limit=speedlimits[7]))
        net.add_lane(
            "g", "h",
            CircularLane(center4,
                         radii4 + 5,
                         np.deg2rad(315),
                         np.deg2rad(165),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.STRIPED, LineType.CONTINUOUS),
                         speed_limit=speedlimits[7]))
        net.add_lane(
            "h", "i",
            CircularLane(center4,
                         radii4,
                         np.deg2rad(170),
                         np.deg2rad(56),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.CONTINUOUS, LineType.NONE),
                         speed_limit=speedlimits[7]))
        net.add_lane(
            "h", "i",
            CircularLane(center4,
                         radii4 + 5,
                         np.deg2rad(170),
                         np.deg2rad(58),
                         width=5,
                         clockwise=False,
                         line_types=(LineType.STRIPED, LineType.CONTINUOUS),
                         speed_limit=speedlimits[7]))

        # 8 - Circular Arc #5 - Reconnects to Start
        center5 = [43.2, 23.4]
        radii5 = 18.5
        net.add_lane(
            "i", "a",
            CircularLane(center5,
                         radii5 + 5,
                         np.deg2rad(240),
                         np.deg2rad(270),
                         width=5,
                         clockwise=True,
                         line_types=(LineType.CONTINUOUS, LineType.STRIPED),
                         speed_limit=speedlimits[8]))
        net.add_lane(
            "i", "a",
            CircularLane(center5,
                         radii5,
                         np.deg2rad(238),
                         np.deg2rad(268),
                         width=5,
                         clockwise=True,
                         line_types=(LineType.NONE, LineType.CONTINUOUS),
                         speed_limit=speedlimits[8]))

        road = Road(network=net,
                    np_random=self.np_random,
                    record_history=self.config["show_trajectories"])
        self.road = road
    def _make_road(self) -> None:
        """
        Make an 4-way intersection.

        The horizontal road has the right of way. More precisely, the levels of priority are:
            - 3 for horizontal straight lanes and right-turns
            - 1 for vertical straight lanes and right-turns
            - 2 for horizontal left-turns
            - 0 for vertical left-turns

        The code for nodes in the road network is:
        (o:outer | i:inner + [r:right, l:left]) + (0:south | 1:west | 2:north | 3:east)

        :return: the intersection road
        """
        lane_width = AbstractLane.DEFAULT_WIDTH
        right_turn_radius = lane_width  # + 5   # [m}
        left_turn_radius = right_turn_radius + lane_width  # [m}
        outer_distance = right_turn_radius + lane_width / 2  # 7.5
        access_length = 50 + 50  # [m]

        net = RoadNetwork()
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED

        if self.config["scenario"] in [9, 10]:
            # 2nd lane for this scenario (and 3rd invisible lane)
            # incoming from south
            rotation = np.array([[1, 0], [0, 1]])
            start = rotation @ np.array(
                [3 * lane_width / 2, access_length + outer_distance])
            end = rotation @ np.array(
                [3 * lane_width / 2, outer_distance + lane_width])
            net.add_lane(
                "o0", "ir0",
                StraightLane(start,
                             end,
                             line_types=[s, c],
                             priority=0,
                             speed_limit=10,
                             forbidden=True))
            if self.config["scenario"] == 10:
                start = rotation @ np.array(
                    [5 * lane_width / 2, access_length + outer_distance])
                end = rotation @ np.array(
                    [5 * lane_width / 2, outer_distance + lane_width])
                net.add_lane(
                    "o0", "ir0",
                    StraightLane(start,
                                 end,
                                 line_types=[n, n],
                                 priority=0,
                                 speed_limit=10,
                                 forbidden=True))
            # intersection
            r_center = rotation @ (np.array(
                [outer_distance + lane_width, outer_distance + lane_width]))
            net.add_lane(
                "ir0", "il3",
                CircularLane(r_center,
                             right_turn_radius,
                             0 + np.radians(180),
                             0 + np.radians(270),
                             line_types=[n, c],
                             priority=0,
                             speed_limit=10))
            # outgoing east
            start = rotation @ np.flip(
                [3 * lane_width / 2, access_length + outer_distance], axis=0)
            end = rotation @ np.flip(
                [3 * lane_width / 2, outer_distance + lane_width], axis=0)
            net.add_lane(
                "il3", "o3",
                StraightLane(end,
                             start,
                             line_types=[s, c],
                             priority=0,
                             speed_limit=10))

        for corner in range(4):
            angle = np.radians(90 * corner)
            is_horizontal = corner % 2
            priority = 3 if is_horizontal else 1
            rotation = np.array([[np.cos(angle), -np.sin(angle)],
                                 [np.sin(angle), np.cos(angle)]])
            # Incoming
            lt = [
                c, s
            ] if self.config["scenario"] in [9, 10] and corner == 0 else [
                s, c
            ]
            start = rotation @ np.array(
                [lane_width / 2, access_length + outer_distance])
            end = rotation @ np.array([lane_width / 2, outer_distance])
            net.add_lane(
                "o" + str(corner), "ir" + str(corner),
                StraightLane(start,
                             end,
                             line_types=lt,
                             priority=priority,
                             speed_limit=10,
                             forbidden=True))

            # replace s by n to hide ped lanes
            ped_display = s
            if self.config["scenario"] in [9]:
                # Pedestrian lanes (other direction and further from intersection)
                start = rotation @ np.array(
                    [lane_width * 2.5, outer_distance * 2])
                end = rotation @ np.array(
                    [lane_width * 2.5, -outer_distance * 2])
                net.add_lane(
                    "p" + str(corner), "p" + str(corner) + "_end",
                    StraightLane(end,
                                 start,
                                 line_types=[ped_display, ped_display],
                                 priority=1234,
                                 width=AbstractLane.DEFAULT_WIDTH / 2,
                                 speed_limit=2))
            elif self.config["scenario"] in [10]:
                # Pedestrian lanes (other direction and further from intersection)
                start = rotation @ np.array(
                    [lane_width * 8, outer_distance * 2.5])
                end = rotation @ np.array(
                    [lane_width * 8, -outer_distance * 2.5])
                net.add_lane(
                    "p" + str(corner), "p" + str(corner) + "_end",
                    StraightLane(end,
                                 start,
                                 line_types=[ped_display, ped_display],
                                 priority=1234,
                                 width=AbstractLane.DEFAULT_WIDTH / 2,
                                 speed_limit=2))
            else:
                # Pedestrian lanes
                start = rotation @ np.array(
                    [lane_width * 1.5, outer_distance * 2])
                end = rotation @ np.array(
                    [lane_width * 1.5, -outer_distance * 2])
                net.add_lane(
                    "p" + str(corner), "p" + str(corner) + "_end",
                    StraightLane(start,
                                 end,
                                 line_types=[ped_display, ped_display],
                                 priority=1234,
                                 width=AbstractLane.DEFAULT_WIDTH / 2,
                                 speed_limit=2))

            # Right turn
            lt = [
                c, s
            ] if self.config["scenario"] in [9, 10] and corner == 0 else [
                n, c
            ]
            r_center = rotation @ (np.array([outer_distance, outer_distance]))
            net.add_lane(
                "ir" + str(corner), "il" + str((corner - 1) % 4),
                CircularLane(r_center,
                             right_turn_radius,
                             angle + np.radians(180),
                             angle + np.radians(270),
                             line_types=[n, c],
                             priority=priority,
                             speed_limit=10))
            # Left turn
            l_center = rotation @ (np.array([
                -left_turn_radius + lane_width / 2,
                left_turn_radius - lane_width / 2
            ]))
            net.add_lane(
                "ir" + str(corner), "il" + str((corner + 1) % 4),
                CircularLane(l_center,
                             left_turn_radius,
                             angle + np.radians(0),
                             angle + np.radians(-90),
                             clockwise=False,
                             line_types=[n, n],
                             priority=priority - 1,
                             speed_limit=10))
            # Straight
            start = rotation @ np.array([lane_width / 2, outer_distance])
            end = rotation @ np.array([lane_width / 2, -outer_distance])
            net.add_lane(
                "ir" + str(corner), "il" + str((corner + 2) % 4),
                StraightLane(start,
                             end,
                             line_types=[s, n],
                             priority=priority,
                             speed_limit=10))
            # Exit
            lt = [
                c, s
            ] if self.config["scenario"] in [9, 10] and corner == 0 else [
                s, c
            ]
            start = rotation @ np.flip(
                [lane_width / 2, access_length + outer_distance], axis=0)
            end = rotation @ np.flip([lane_width / 2, outer_distance], axis=0)
            net.add_lane(
                "il" + str((corner - 1) % 4), "o" + str((corner - 1) % 4),
                StraightLane(end,
                             start,
                             line_types=lt,
                             priority=priority,
                             speed_limit=10))

        road = RegulatedRoad(network=net,
                             np_random=self.np_random,
                             record_history=self.config["show_trajectories"])
        self.road = road
Пример #11
0
    def _make_road(self):
        # Circle lanes: (s)outh/(e)ast/(n)orth/(w)est (e)ntry/e(x)it.
        center = [0, 0]  # [m]
        radius = 30  # [m]
        alpha = 20  # [deg]
        net = RoadNetwork()
        radii = [radius, radius + 4]
        n, c, s = LineType.NONE, LineType.CONTINUOUS, LineType.STRIPED
        line = [[c, s], [n, c]]
        # r = []
        # bounds = [30 * 50 * np.pi / 180, 30 * 40 * np.pi / 180, 34 * 50 * np.pi / 180, 34 * 40 * np.pi / 180]
        # bounds = [30 * 2 * np.pi, 34 * 2 * np.pi ]

        for lane in [0, 1]:
            net.add_lane(
                "se", "ex",
                CircularLane(center,
                             radii[lane],
                             rad(90 - alpha),
                             rad(alpha),
                             line_types=line[lane]))
            net.add_lane(
                "ex", "ee",
                CircularLane(center,
                             radii[lane],
                             rad(alpha),
                             rad(-alpha),
                             line_types=line[lane]))
            net.add_lane(
                "ee", "nx",
                CircularLane(center,
                             radii[lane],
                             rad(-alpha),
                             rad(-90 + alpha),
                             line_types=line[lane]))
            net.add_lane(
                "nx", "ne",
                CircularLane(center,
                             radii[lane],
                             rad(-90 + alpha),
                             rad(-90 - alpha),
                             line_types=line[lane]))
            net.add_lane(
                "ne", "wx",
                CircularLane(center,
                             radii[lane],
                             rad(-90 - alpha),
                             rad(-180 + alpha),
                             line_types=line[lane]))
            net.add_lane(
                "wx", "we",
                CircularLane(center,
                             radii[lane],
                             rad(-180 + alpha),
                             rad(-180 - alpha),
                             line_types=line[lane]))
            net.add_lane(
                "we", "sx",
                CircularLane(center,
                             radii[lane],
                             rad(180 - alpha),
                             rad(90 + alpha),
                             line_types=line[lane]))
            net.add_lane(
                "sx", "se",
                CircularLane(center,
                             radii[lane],
                             rad(90 + alpha),
                             rad(90 - alpha),
                             line_types=line[lane]))
        """
        lane = 0
        net.add_lane("se", "ex",
                     CircularLane(center, radii[lane], rad(90 - alpha), rad(alpha), line_types=line[lane]))
        net.add_lane("ex", "ee", CircularLane(center, radii[lane], rad(alpha), rad(-alpha), line_types=line[lane]))
        net.add_lane("ee", "nx",
                     CircularLane(center, radii[lane], rad(-alpha), rad(-90 + alpha), line_types=line[lane]))
        net.add_lane("nx", "ne",
                     CircularLane(center, radii[lane], rad(-90 + alpha), rad(-90 - alpha), line_types=line[lane]))
        net.add_lane("ne", "wx",
                     CircularLane(center, radii[lane], rad(-90 - alpha), rad(-180 + alpha), line_types=line[lane]))
        net.add_lane("wx", "we",
                     CircularLane(center, radii[lane], rad(-180 + alpha), rad(-180 - alpha), line_types=line[lane]))
        net.add_lane("we", "sx",
                     CircularLane(center, radii[lane], rad(180 - alpha), rad(90 + alpha), line_types=line[lane]))
        net.add_lane("sx", "se",
                     CircularLane(center, radii[lane], rad(90 + alpha), rad(90 - alpha),
                                  line_types=line[lane]))
        lane = 1
        # net.add_lane("se", "ex",
        # CircularLane(center, radii[lane], rad(90 - alpha), rad(alpha), line_types=line[lane]))
        net.add_lane("ser", "exb",
                     CircularLane(center, radii[lane], rad(90 - alpha + 8), rad(alpha - 2), line_types=line[lane]))
        net.add_lane("exb", "exl",
                     CircularLane(center, radii[lane], rad(alpha - 2), rad(alpha - 7),
                                  line_types=line[lane]))
        net.add_lane("eel", "exr",
                     CircularLane(center, radii[lane], rad(-180 + alpha + 165), rad(-180 + alpha + 155),
                                  line_types=line[lane]))
        # net.add_lane("ex", "ee", CircularLane(center, radii[lane], rad(alpha), rad(-alpha), line_types=line[lane]))
        # net.add_lane("ee", "nx",
        # CircularLane(center, radii[lane], rad(-alpha), rad(-90 + alpha), line_types=line[lane]))
        net.add_lane("eer", "nxb",
                     CircularLane(center, radii[lane], rad(-180 + alpha + 147), rad(-180 + alpha + 65),
                                  line_types=line[lane]))
        net.add_lane("nxb", "nxl",
                     CircularLane(center, radii[lane], rad(-180 + alpha + 65), rad(-180 + alpha + 60),
                                  line_types=line[lane]))
        # net.add_lane("nx", "ne",
        # CircularLane(center, radii[lane], rad(-90 + alpha), rad(-90 - alpha), line_types=line[lane]))
        net.add_lane("nxr", "nel",
                     CircularLane(center, radii[lane], rad(-180 + alpha + 58), rad(-180 + alpha + 48),
                                  line_types=line[lane]))
        net.add_lane("ner", "wxb",
                     CircularLane(center, radii[lane], rad(-180 + alpha + 45), rad(-180 + alpha + 5),
                                  line_types=line[lane]))
        # net.add_lane("ner", "wxb",
        # CircularLane(center, radii[lane], rad(-90 - alpha), rad(-180 + alpha), line_types=line[lane]))
        net.add_lane("wxb", "wxl",
                     CircularLane(center, radii[lane], rad(-180 + alpha + 5), rad(-180 + alpha - 7),
                                  line_types=line[lane]))
        # net.add_lane("wx", "we",
        # CircularLane(center, radii[lane], rad(-180 + alpha), rad(-180 - alpha), line_types=line[lane]))
        net.add_lane("wxr", "wel",
                     CircularLane(center, radii[lane], rad(-180 + alpha - 15), rad(-180 - alpha + 15),
                                  line_types=line[lane]))
        # net.add_lane("we", "sx",
        # CircularLane(center, radii[lane], rad(180 - alpha), rad(90 + alpha - 5), line_types=line[lane]))
        net.add_lane("wer", "sxb",
                     CircularLane(center, radii[lane], rad(180 - alpha + 7), rad(90 + alpha + 5),
                                  line_types=line[lane]))
        net.add_lane("sxb", "sxl",
                     CircularLane(center, radii[lane], rad(95 + alpha), rad(90 + alpha - 7), line_types=line[lane]))
        net.add_lane("sxr", "sel",
                     CircularLane(center, radii[lane], rad(90 + alpha - 15), rad(90 - alpha + 15),
                                  line_types=line[lane]))
        """
        # Access lanes: (r)oad/(s)ine
        access = 200  # [m]
        dev = 120  # [m]
        a = 5  # [m]
        delta_st = 0.20 * dev  # [m]

        delta_en = dev - delta_st
        w = 2 * np.pi / dev

        net.add_lane(
            "ser", "ses",
            StraightLane([2, access], [2, dev / 2], line_types=[s, c]))
        net.add_lane(
            "ses", "se",
            SineLane([2 + a, dev / 2], [2 + a, dev / 2 - delta_st],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=[c, c]))
        net.add_lane(
            "sx", "sxs",
            SineLane([-2 - a, -dev / 2 + delta_en], [-2 - a, dev / 2],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=[c, c]))
        net.add_lane(
            "sxs", "sxr",
            StraightLane([-2, dev / 2], [-2, access], line_types=[n, c]))

        net.add_lane(
            "eer", "ees",
            StraightLane([access, -2], [dev / 2, -2], line_types=[s, c]))
        net.add_lane(
            "ees", "ee",
            SineLane([dev / 2, -2 - a], [dev / 2 - delta_st, -2 - a],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=[c, c]))
        net.add_lane(
            "ex", "exs",
            SineLane([-dev / 2 + delta_en, 2 + a], [dev / 2, 2 + a],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=[c, c]))
        net.add_lane(
            "exs", "exr",
            StraightLane([dev / 2, 2], [access, 2], line_types=[n, c]))

        net.add_lane(
            "ner", "nes",
            StraightLane([-2, -access], [-2, -dev / 2], line_types=[s, c]))
        net.add_lane(
            "nes", "ne",
            SineLane([-2 - a, -dev / 2], [-2 - a, -dev / 2 + delta_st],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=[c, c]))
        net.add_lane(
            "nx", "nxs",
            SineLane([2 + a, dev / 2 - delta_en], [2 + a, -dev / 2],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=[c, c]))
        net.add_lane(
            "nxs", "nxr",
            StraightLane([2, -dev / 2], [2, -access], line_types=[n, c]))

        net.add_lane(
            "wer", "wes",
            StraightLane([-access, 2], [-dev / 2, 2], line_types=[s, c]))
        net.add_lane(
            "wes", "we",
            SineLane([-dev / 2, 2 + a], [-dev / 2 + delta_st, 2 + a],
                     a,
                     w,
                     -np.pi / 2,
                     line_types=[c, c]))
        net.add_lane(
            "wx", "wxs",
            SineLane([dev / 2 - delta_en, -2 - a], [-dev / 2, -2 - a],
                     a,
                     w,
                     -np.pi / 2 + w * delta_en,
                     line_types=[c, c]))
        net.add_lane(
            "wxs", "wxr",
            StraightLane([-dev / 2, -2], [-access, -2], line_types=[n, c]))

        road = Road(network=net, np_random=self.np_random)
        self.road = road