def test_straight_road(self): TF = Transform([1, 1], math.pi / 2) LENGTH = 4 MIDDLE_LINE = Line([[1, 1], [1, 5]]) sr = StraightRoad(length=LENGTH, transform=TF) self.assertEqual(sr.__class__.TYPE, road_section_type.STRAIGHT_ROAD) self.assertEqual(sr.middle_line, MIDDLE_LINE)
StraightRoad, ) def env_as_bool(name, default: bool): e = os.environ.get(name) if e is None: return default return e == "True" or e == "1" PARKING_LOT_RIGHT = env_as_bool("PARKING_LOT_RIGHT", True) PARKING_LOT_LEFT = env_as_bool("PARKING_LOT_LEFT", True) road = Road() road.append(StraightRoad(length=2)) right_lots = ([ ParkingLot( start=1, spots=[ ParkingSpot(width=0.3, kind=ParkingSpot.OCCUPIED, obstacle=ParkingObstacle()), ParkingSpot(width=0.4, kind=ParkingSpot.BLOCKED), ParkingSpot(width=1), ParkingSpot(width=0.3, kind=ParkingSpot.OCCUPIED, obstacle=ParkingObstacle()), ], )
BlockedArea, Intersection, LeftCircularArc, ParkingArea, ParkingLot, ParkingObstacle, ParkingSpot, RightCircularArc, StaticObstacle, StraightRoad, TrafficIsland, ZebraCrossing, ) road = Road() road.append(StraightRoad(length=1)) ROAD_WIDTH = 0.4 def get_random_parking() -> ParkingArea: """Create a randomized parking area.""" def get_spot(side=0): width = (0.5 + random.random()) * (0.2 + ROAD_WIDTH * side) obs_width = (random.random() / 2 + 0.5) * width return ParkingSpot( width=width, kind=random.choice([ParkingSpot.FREE, ParkingSpot.BLOCKED]), obstacle=random.choice([ ParkingObstacle( width=obs_width,
from simulation.utils.road.road import Road from simulation.utils.road.sections import ( Intersection, LeftCircularArc, ParkingArea, ParkingLot, ParkingObstacle, ParkingSpot, RightCircularArc, StraightRoad, ) road = Road() road.append(ParkingArea(length=0.06, start_line=True)) road.append(StraightRoad(length=0.62)) road.append( ParkingArea( length=2.9, right_lots=[ ParkingLot( depth=0.32, spots=[ ParkingSpot(width=1.15), ParkingSpot( width=0.25, kind=ParkingSpot.OCCUPIED, obstacle=ParkingObstacle() ), ParkingSpot(width=0.045), ParkingSpot(width=0.56, kind=ParkingSpot.BLOCKED), ParkingSpot(width=0.32), ],
import math import os from simulation.utils.road.road import Road from simulation.utils.road.sections import Intersection, StraightRoad speed_limit = int(os.environ.get("SPEED_LIMIT", 30)) road = Road() road.append(StraightRoad(length=4)) road.append(Intersection(turn=Intersection.RIGHT, angle=math.radians(90))) s = StraightRoad(length=4) s.add_speed_limit(0, speed=speed_limit) road.append(s)
from simulation.utils.road.road import Road # Definition of the road class from simulation.utils.road.sections import ( BlockedArea, Intersection, LeftCircularArc, ParkingArea, ParkingLot, ParkingObstacle, ParkingSpot, StraightRoad, TrafficIsland, ZebraCrossing, ) # - Beginning sphinx straight_road - straight_road = StraightRoad(length=2) # - Ending sphinx straight_road - # - Beginning sphinx straight_road_obs - straight_road_obs = StraightRoad(length=2) straight_road_obs.add_obstacle(arc_length=1, y_offset=0, width=0.2, length=0.1) # - Ending sphinx straight_road_obs - # - Beginning sphinx parking_area - parking_area = ParkingArea( length=4, start_line=True, left_lots=[ ParkingLot(spots=[ ParkingSpot(kind=ParkingSpot.OCCUPIED, obstacle=ParkingObstacle()), ParkingSpot(kind=ParkingSpot.BLOCKED),
from simulation.utils.road.sections import RightCircularArc, StraightRoad, TrafficSign SIZE = int(os.environ.get("SIZE", 1)) EDGES = int(os.environ.get("EDGES", 9)) signs_dict = TrafficSign.__dict__ signs = SIZE * [signs_dict[s] for s in signs_dict if not s.startswith("__")] random.shuffle(signs) signs_list = np.array_split(signs, EDGES) straight_length = len(signs_list[0]) y = 0.5 road = Road() for s, signs in enumerate(signs_list): straight = StraightRoad(length=straight_length) for i, sign in enumerate(signs): y *= -1 straight.traffic_signs.append( TrafficSign( kind=sign, arc_length=i, angle=0, normalize_x=False, y=y, )) road.append(straight) if s != len(signs_list) - 1: road.append( RightCircularArc(radius=2.81, angle=math.radians(360 / EDGES)))
import os from simulation.utils.road.road import Road from simulation.utils.road.sections import StraightRoad speed_limit = int(os.environ.get("SPEED_LIMIT", 30)) road = Road() s = StraightRoad(length=8) s.add_speed_limit(4, speed_limit) road.append(s)
import math from simulation.utils.road.road import Road # Definition of the road class from simulation.utils.road.sections import ( LeftCircularArc, RightCircularArc, StaticObstacle, StraightRoad, ) road = Road() road.append(StraightRoad(length=4)) road.append( LeftCircularArc(radius=3, angle=math.radians(60), obstacles=[StaticObstacle()])) road.append(StraightRoad(length=2, obstacles=[StaticObstacle()])) road.append( RightCircularArc(radius=2, angle=math.radians(60), obstacles=[StaticObstacle()])) road.append(StraightRoad(length=2))
"""The default road when launching this simulation.""" from simulation.utils.road.road import Road # Definition of the road class from simulation.utils.road.sections import StraightRoad, ZebraCrossing road = Road() road.append(StraightRoad(length=3)) road.append(ZebraCrossing(length=0.4)) road.append(StraightRoad(length=3)) road.append(ZebraCrossing(length=0.45)) road.append(StraightRoad(length=1))
import math from simulation.utils.road.road import Road # Definition of the road class from simulation.utils.road.sections import ( Intersection, LeftCircularArc, ParkingArea, ParkingLot, ParkingObstacle, ParkingSpot, RightCircularArc, StraightRoad, ) road = Road() road.append(StraightRoad()) parking_area = ParkingArea( length=3.5, start_line=True, left_lots=[ ParkingLot( start=0.5, depth=0.5, spots=[ ParkingSpot(kind=ParkingSpot.BLOCKED), ParkingSpot(), ParkingSpot(kind=ParkingSpot.OCCUPIED, obstacle=ParkingObstacle()), ], ), ],
"""Convert a rule env variable to an Intersection attribute. This allows to specify "equal, yield, stop, priority_yield, priority_stop" as rule options through environment variables. """ rule = os.environ.get(env, "equal") return getattr(Intersection, rule.upper()) # Read environment variables: first_turn = direction_str_to_int("FIRST_TURN") second_turn = direction_str_to_int("SECOND_TURN") first_rule = rule_str_to_int("FIRST_RULE") second_rule = rule_str_to_int("SECOND_RULE") first_angle = math.radians(float(os.environ.get("FIRST_ANGLE", 90))) second_angle = math.radians(float(os.environ.get("SECOND_ANGLE", 90))) distance = float(os.environ.get("INTERSECTION_DISTANCE", 1)) """Definition of the actual road. Just a straight beginning and then two intersections with a short straight in between. """ road = Road() road.append(StraightRoad(length=2)) road.append(Intersection(turn=first_turn, angle=first_angle, rule=first_rule)) road.append(StraightRoad(length=distance)) road.append(Intersection(turn=second_turn, angle=second_angle, rule=second_rule)) road.append(StraightRoad(length=2))
from simulation.utils.road.road import Road # Definition of the road class from simulation.utils.road.sections import ( Intersection, LeftCircularArc, ParkingArea, ParkingLot, ParkingObstacle, ParkingSpot, StaticObstacle, StraightRoad, ZebraCrossing, ) from simulation.utils.road.sections.road_section import RoadSection road = Road() road.append(StraightRoad(length=1)) # Create a parking area with different kinds of parking spots road.append( ParkingArea( length=4, start_line=True, left_lots=[ ParkingLot( start=1, spots=[ParkingSpot(), ParkingSpot(kind=ParkingSpot.BLOCKED)]) ], right_lots=[ ParkingLot( start=0.2,
from simulation.utils.road.road import Road # Definition of the road class from simulation.utils.road.sections import ( CubicBezier, CustomSection, Intersection, RightCircularArc, StraightRoad, ) road = Road() custom_part_one: CustomSection = CustomSection.from_yaml( os.path.join(os.path.dirname(__file__), "./cc20_scans/training_part1.yaml") ) road.append(custom_part_one) road.append(StraightRoad(length=0.1)) road.append(RightCircularArc(radius=3, angle=math.radians(17))) road.append(StraightRoad(length=0.08)) road.append( CubicBezier( p1=Point(0.1, 0), p2=Point(0.9, -0.05), p3=Point(1.0, -0.05), left_line_marking=StraightRoad.MISSING_LINE_MARKING, right_line_marking=StraightRoad.MISSING_LINE_MARKING, middle_line_marking=StraightRoad.MISSING_LINE_MARKING, ) ) road.append( CustomSection.from_yaml( os.path.join(os.path.dirname(__file__), "./cc20_scans/training_loop.yaml")
import os import random from simulation.utils.road.road import Road from simulation.utils.road.sections import StraightRoad, TrafficSign from simulation.utils.road.sections.traffic_sign import get_all_signs SIZE = int(os.environ.get("SIZE", 1)) signs = SIZE * get_all_signs() random.shuffle(signs) y = 0.5 road = Road() straight = StraightRoad(length=len(signs)) for i, sign in enumerate(signs): y *= -1 straight.traffic_signs.append( TrafficSign(kind=sign, arc_length=i, angle=0, normalize_x=False, y=y, visible=True)) road.append(straight)