예제 #1
0
    def dump_all_maps(self):
        assert not engine_initialized(), \
            "We assume you generate map files in independent tasks (not in training). " \
            "So you should run the generating script without calling reset of the " \
            "environment."

        self.lazy_init()  # it only works the first time when reset() is called to avoid the error when render
        assert engine_initialized()

        for seed in range(self.start_seed, self.start_seed + self.env_num):
            all_config = self.config.copy()
            all_config["map_config"]["seed"] = seed
            # map_config = copy.deepcopy(self.config["map_config"])
            # map_config.update({"seed": seed})
            # set_global_random_seed(seed)

            self.engine.map_manager.update_map(all_config, current_seed=seed)
            # new_map = self.engine.map_manager.spawn_object(PGMap, map_config=map_config, random_seed=None)
            # self.pg_maps[current_seed] = new_map
            # self.engine.map_manager.unload_map(new_map)
            print("Finish generating map with seed: {}".format(seed))

        map_data = dict()
        for seed, map in self.maps.items():
            assert map is not None
            map_data[seed] = map.save_map()

        return_data = dict(map_config=self.config["map_config"].copy().get_dict(), map_data=copy.deepcopy(map_data))
        return return_data
예제 #2
0
 def __init__(self):
     from pgdrive.engine.engine_utils import get_engine, engine_initialized
     assert engine_initialized(
     ), "You should not create manager before the initialization of BaseEngine"
     self.engine = get_engine()
     Randomizable.__init__(self, self.engine.global_random_seed)
     self.spawned_objects = {}
예제 #3
0
 def __init__(self):
     assert engine_initialized(
     ), "You should initialize engine before adding camera to vehicle"
     config = get_global_config()["vehicle_config"]["rgb_camera"]
     self.BUFFER_W, self.BUFFER_H = config[0], config[1]
     super(RGBCamera, self).__init__()
     cam = self.get_cam()
     lens = self.get_lens()
     cam.lookAt(0, 2.4, 1.3)
     lens.setFov(60)
     lens.setAspectRatio(2.0)
예제 #4
0
    def __init__(self):
        assert engine_initialized(
        ), "You should initialize engine before adding camera to vehicle"
        config = get_global_config()["vehicle_config"]["depth_camera"]
        self.BUFFER_W, self.BUFFER_H = config[0], config[1]
        self.VIEW_GROUND = config[2]
        super(DepthCamera, self).__init__()
        cam = self.get_cam()
        lens = self.get_lens()

        cam.lookAt(0, 2.4, 1.3)
        lens.setFov(60)
        lens.setAspectRatio(2.0)
        if get_engine(
        ).mode == RENDER_MODE_NONE or not AssetLoader.initialized():
            return
        # add shader for it
        if get_global_config()["headless_machine_render"]:
            vert_path = AssetLoader.file_path("shaders",
                                              "depth_cam_gles.vert.glsl")
            frag_path = AssetLoader.file_path("shaders",
                                              "depth_cam_gles.frag.glsl")
        else:
            from pgdrive.utils import is_mac
            if is_mac():
                vert_path = AssetLoader.file_path("shaders",
                                                  "depth_cam_mac.vert.glsl")
                frag_path = AssetLoader.file_path("shaders",
                                                  "depth_cam_mac.frag.glsl")
            else:
                vert_path = AssetLoader.file_path("shaders",
                                                  "depth_cam.vert.glsl")
                frag_path = AssetLoader.file_path("shaders",
                                                  "depth_cam.frag.glsl")
        custom_shader = Shader.load(Shader.SL_GLSL,
                                    vertex=vert_path,
                                    fragment=frag_path)
        cam.node().setInitialState(
            RenderState.make(ShaderAttrib.make(custom_shader, 1)))

        if self.VIEW_GROUND:
            self.GROUND = GeoMipTerrain("mySimpleTerrain")

            self.GROUND.setHeightfield(
                AssetLoader.file_path("textures", "height_map.png"))
            # terrain.setBruteforce(True)
            # # Since the terrain is a texture, shader will not calculate the depth information, we add a moving terrain
            # # model to enable the depth information of terrain
            self.GROUND_MODEL = self.GROUND.getRoot()
            self.GROUND_MODEL.setPos(-128, 0, self.GROUND_HEIGHT)
            self.GROUND_MODEL.hide(CamMask.AllOn)
            self.GROUND_MODEL.show(CamMask.DepthCam)
            self.GROUND.generate()
예제 #5
0
    def __init__(self):
        assert engine_initialized(), "You should initialize engine before adding camera to vehicle"
        config = get_global_config()["vehicle_config"]["mini_map"]
        self.BUFFER_W, self.BUFFER_H = config[0], config[1]
        height = config[2]
        super(MiniMap, self).__init__()

        cam = self.get_cam()
        lens = self.get_lens()

        cam.setZ(height)
        cam.lookAt(Vec3(0, 20, 0))
        lens.setAspectRatio(2.0)
예제 #6
0
 def lazy_init(self):
     """
     Only init once in runtime, variable here exists till the close_env is called
     :return: None
     """
     # It is the true init() func to create the main vehicle and its module, to avoid incompatible with ray
     if engine_initialized():
         return
     self.engine = initialize_engine(self.config)
     # engine setup
     self.setup_engine()
     # other optional initialization
     self._after_lazy_init()
예제 #7
0
    def __init__(
        self,
        vehicle_config: Union[dict, Config] = None,
        name: str = None,
        random_seed=None,
    ):
        """
        This Vehicle Config is different from self.get_config(), and it is used to define which modules to use, and
        module parameters. And self.physics_config defines the physics feature of vehicles, such as length/width
        :param vehicle_config: mostly, vehicle module config
        :param random_seed: int
        """
        # check
        assert vehicle_config is not None, "Please specify the vehicle config."
        assert engine_initialized(
        ), "Please make sure game engine is successfully initialized!"

        # NOTE: it is the game engine, not vehicle drivetrain
        self.engine = get_engine()
        BaseObject.__init__(self, name, random_seed,
                            self.engine.global_config["vehicle_config"])
        BaseVehicleState.__init__(self)
        self.update_config(vehicle_config)
        am_i_the_special_one = self.config["am_i_the_special_one"]

        # build vehicle physics model
        vehicle_chassis = self._create_vehicle_chassis()
        self.add_body(vehicle_chassis.getChassis())
        self.system = vehicle_chassis
        self.chassis = self.origin
        self.wheels = self._create_wheel()

        # powertrain config
        self.increment_steering = self.config["increment_steering"]
        self.enable_reverse = self.config["enable_reverse"]
        self.max_speed = self.config["max_speed"]
        self.max_steering = self.config["max_steering"]

        # visualization
        color = sns.color_palette("colorblind")
        idx = get_np_random().randint(len(color))
        rand_c = color[idx]
        if am_i_the_special_one:
            rand_c = color[2]  # A pretty green
        self.top_down_color = (rand_c[0] * 255, rand_c[1] * 255,
                               rand_c[2] * 255)
        self.panda_color = rand_c
        self._add_visualization()

        # modules, get observation by using these modules
        self.lane: Optional[AbstractLane] = None
        self.lane_index = None
        self.navigation: Optional[Navigation] = None
        self.lidar: Optional[Lidar] = None  # detect surrounding vehicles
        self.side_detector: Optional[SideDetector] = None  # detect road side
        self.lane_line_detector: Optional[
            LaneLineDetector] = None  # detect nearest lane lines
        self.image_sensors = {}

        # state info
        self.throttle_brake = 0.0
        self.steering = 0
        self.last_current_action = deque([(0.0, 0.0), (0.0, 0.0)], maxlen=2)
        self.last_position = (0, 0)
        self.last_heading_dir = self.heading
        self.dist_to_left_side = None
        self.dist_to_right_side = None

        # step info
        self.out_of_route = None
        self.on_lane = None
        self.spawn_place = (0, 0)
        self._init_step_info()

        # others
        self._add_modules_for_vehicle()
        self.takeover = False
        self.expert_takeover = False
        self.energy_consumption = 0
        self.action_space = self.get_action_space_before_init(
            extra_action_dim=self.config["extra_action_dim"])
        self.break_down = False

        # overtake_stat
        self.front_vehicles = set()
        self.back_vehicles = set()

        if self.engine.current_map is not None:
            self.reset()