def _reset(self):
        if self.eps_count % self.switch_frequency == 0:
            # kill the scene
            p.resetSimulation()
            self.r_camera_mul.terminate()
            self.r_camera_rgb._close()
            print("Garbage collection", gc.collect())
            
            snapshot = tracemalloc.take_snapshot()
            if self.old_snapshot is not None:
                top_stats = snapshot.compare_to(self.old_snapshot, 'lineno')
                print("[ Top 20 ]")
                for stat in top_stats[:20]:
                    print(stat)
            self.old_snapshot = snapshot


            
            # select new scene
            self.switch_model(self.model_selection)
            self.scene = None
            self._robot_introduced = False
            self._scene_introduced = False
            self.robot_introduce(Husky(self.config, env=self))
            self.scene_introduce()
        return HuskyCoordinateNavigateEnv._reset(self)
예제 #2
0
    def __init__(self, config, gpu_count=0):
        self.config = self.parse_config(config)
        print(self.config["envname"])
        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")
        CameraRobotEnv.__init__(self,
                                self.config,
                                gpu_count,
                                scene_type="building",
                                tracking_camera=tracking_camera)

        self.robot_introduce(Husky(self.config, env=self))
        self.scene_introduce()

        self.total_reward = 0
        self.total_frame = 0
        self.flag_timeout = 1
        self.visualid = -1
        self.lastid = None
        self.gui = self.config["mode"] == "gui"

        if self.gui:
            self.visualid = p.createVisualShape(
                p.GEOM_MESH,
                fileName=os.path.join(pybullet_data.getDataPath(), 'cube.obj'),
                meshScale=[0.2, 0.2, 0.2],
                rgbaColor=[1, 0, 0, 0.7])
        self.colisionid = p.createCollisionShape(
            p.GEOM_MESH,
            fileName=os.path.join(pybullet_data.getDataPath(), 'cube.obj'),
            meshScale=[0.2, 0.2, 0.2])

        self.lastid = None
        self.obstacle_dist = 100
예제 #3
0
    def __init__(self, config, is_discrete=False, gpu_count=0):

        self.config = self.parse_config(config)
        self.gui = self.config["mode"] == "gui"
        self.model_id = self.config["model_id"]
        self.timestep = self.config["speed"]["timestep"]
        self.frame_skip = self.config["speed"]["frameskip"]
        self.resolution = self.config["resolution"]
        self.tracking_camera = tracking_camera
        target_orn, target_pos = self.config["target_orn"], self.config[
            "target_pos"]
        initial_orn, initial_pos = self.config["initial_orn"], self.config[
            "initial_pos"]
        self.total_reward = 0
        self.total_frame = 0

        CameraRobotEnv.__init__(self,
                                config,
                                gpu_count,
                                scene_type="building",
                                use_filler=self.config["use_filler"])
        self.robot_introduce(
            Husky(
                #HuskyHighCamera(
                is_discrete=is_discrete,
                initial_pos=initial_pos,
                initial_orn=initial_orn,
                target_pos=target_pos,
                resolution=self.resolution,
                env=self))
        self.scene_introduce()

        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")
예제 #4
0
    def __init__(self, config, gpu_idx=0):
        self.config = self.parse_config(config)
        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")

        CameraRobotEnv.__init__(self,
                                self.config,
                                gpu_idx,
                                scene_type="stadium" if self.config["model_id"]
                                == "stadium" else "building",
                                tracking_camera=tracking_camera)

        self.robot_introduce(Husky(self.config, env=self))
        #WARNING:Robot tanımının yapıldığı yer devam etmeli, aksi taktirde 'Bad inertia hatası'
        self.scene_introduce()
        self.total_reward = 0
        self.total_frame = 0
        self.eps_so_far = 0
        self.hold_rew = 0
        self.success = 0
        self.SR = 0
        self.SPL = 0

        self.position = []
        self.old_pos = []
        self.shortest_path = 0
        self.actual_path = 0
예제 #5
0
    def __init__(self, config, gpu_idx=0):
        self.config = self.parse_config(config)
        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")

        CameraRobotEnv.__init__(self,
                                self.config,
                                gpu_idx,
                                scene_type="stadium" if self.config["model_id"]
                                == "stadium" else "building",
                                tracking_camera=tracking_camera)

        self.robot_introduce(Husky(self.config, env=self))
        self.scene_introduce()
        self.total_reward = 0
        self.total_frame = 0

        quat_orientation = p.getQuaternionFromEuler([0, 0, 3.14 / 2])
        base_position = [-14.3, 5, 1.2]
        base_position = [1, 1, 3.2]
        obj_file_name = 'TeaCup.urdf'

        self._ballUniqueId = p.loadURDF(
            obj_file_name,
            basePosition=base_position,
            baseOrientation=quat_orientation,
            #flags=p.URDF_USE_MATERIAL_COLORS_FROM_MTL,
            globalScaling=0.25)
예제 #6
0
 def introduce_custom_robot(self):
     if self.config["robot"] == 'Husky':
         self.robot_introduce(Husky(self.config, env=self))
         print("Robot camera pos", self.robot.eyes.get_position())
     elif self.config["robot"] == 'Turtlebot':
         self.robot_introduce(Turtlebot(self.config, env=self))
         print("Robot camera pos", self.robot.eyes.get_position())
예제 #7
0
    def __init__(self, config, gpu_count=0):
        #assert(self.config["envname"] == self.__class__.__name__ or self.config["envname"] == "TestEnv")
        self.config = self.parse_config(config)
        SemanticRobotEnv.__init__(self, self.config, gpu_count, 
                                  scene_type="building",
                                  tracking_camera=tracking_camera)
        self.robot_introduce(Husky(self.config, env=self))
        self.scene_introduce()

        self.total_reward = 0
        self.total_frame = 0
        self.flag_timeout = 1
        self.visualid = -1
        self.lastid = None
        self.gui = self.config["mode"] == "gui"
        
        if self.gui:
            self.visualid = p.createVisualShape(p.GEOM_MESH, fileName=os.path.join(pybullet_data.getDataPath(), 'cube.obj'), meshScale=[0.2, 0.2, 0.2], rgbaColor=[1, 0, 0, 0.7])
        self.colisionid = p.createCollisionShape(p.GEOM_MESH, fileName=os.path.join(pybullet_data.getDataPath(), 'cube.obj'), meshScale=[0.2, 0.2, 0.2])

        self.lastid = None
        self.obstacle_dist = 100

        self.semantic_flagIds = []

        debug_semantic = 1
        if debug_semantic:
            for i in range(self.semantic_pos.shape[0]):
                pos = self.semantic_pos[i]
                pos[2] += 0.2   # make flag slight above object 
                visualId = p.createVisualShape(p.GEOM_MESH, fileName=os.path.join(pybullet_data.getDataPath(), 'cube.obj'), meshScale=[0.1, 0.1, 0.1], rgbaColor=[1, 0, 0, 0.7])
                flagId = p.createMultiBody(baseVisualShapeIndex=visualId, baseCollisionShapeIndex=-1, basePosition=pos)
                self.semantic_flagIds.append(flagId)
예제 #8
0
 def __init__(self, config, gpu_count=0):
     self.config = self.parse_config(config)
     assert (self.config["envname"] == self.__class__.__name__
             or self.config["envname"] == "TestEnv")
     CameraRobotEnv.__init__(self,
                             self.config,
                             gpu_count,
                             scene_type="building",
                             tracking_camera=tracking_camera)
     self.robot_introduce(Husky(self.config, env=self))
     self.scenarios = self.get_scenarios(self.config["scenarios"])
     self.n_scenarios = len(self.scenarios)
예제 #9
0
    def __init__(self,
                 config,
                 is_discrete=False,
                 gpu_count=0,
                 scene_type="building"):

        self.config = self.parse_config(config)
        target_orn, target_pos = self.config["target_orn"], self.config[
            "target_pos"]
        initial_orn, initial_pos = self.config["initial_orn"], self.config[
            "initial_pos"]

        self.gui = self.config["mode"] == "gui"
        self.timestep = self.config["speed"]["timestep"]
        self.frame_skip = self.config["speed"]["frameskip"]
        self.model_id = self.config["model_id"]
        ## Mode initialized with mode=SENSOR
        self.tracking_camera = tracking_camera
        self.flag_timeout = 1
        self.visualid = -1
        self.lastid = None
        self.resolution = self.config["resolution"]
        CameraRobotEnv.__init__(
            self,
            config,
            gpu_count,
            scene_type="building",
            use_filler=self.config["use_filler"],
        )
        self.robot_introduce(
            Husky(is_discrete,
                  initial_pos=initial_pos,
                  initial_orn=initial_orn,
                  target_pos=target_pos,
                  resolution=self.resolution,
                  env=self))
        self.scene_introduce()

        if self.gui:
            self.visualid = p.createVisualShape(
                p.GEOM_MESH,
                fileName=os.path.join(pybullet_data.getDataPath(), 'cube.obj'),
                meshScale=[0.2, 0.2, 0.2],
                rgbaColor=[1, 0, 0, 0.7])
        self.colisionid = p.createCollisionShape(
            p.GEOM_MESH,
            fileName=os.path.join(pybullet_data.getDataPath(), 'cube.obj'),
            meshScale=[0.2, 0.2, 0.2])

        self.lastid = None
        self.obstacle_dist = 100
        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")
예제 #10
0
    def __init__(self, config, gpu_count=0):
        self.config = self.parse_config(config)
        assert(self.config["envname"] == self.__class__.__name__ or self.config["envname"] == "TestEnv")

        CameraRobotEnv.__init__(self, self.config, gpu_count, 
                                scene_type="building",
                                tracking_camera=tracking_camera)

        self.robot_introduce(Husky(self.config, env=self))
        self.scene_introduce()
        self.total_reward = 0
        self.total_frame = 0
    def __init__(self, config, gpu_count=0, render_map=False, fixed_endpoints=False, switch_frequency=None):
        tracemalloc.start()
        self.old_snapshot = None
        self.config = self.parse_config(config)
        CameraRobotEnv.__init__(self, self.config, gpu_count, scene_type='building', tracking_camera=tracking_camera)

        self.fixed_endpoints = fixed_endpoints
        self.target_radius = 0.5
        self.render_map = render_map
        self.render_resolution = 256
        if switch_frequency is not None:
            self.switch_frequency = switch_frequency
        else:
            self.switch_frequency = self.config["switch_frequency"]

        
        # configure environment
        self.model_selection = self.config["model_selection"]
        assert self.model_selection in ['in_order', 'random']

        self.target_mu = self.config["target_distance_mu"]
        self.target_sigma = self.config["target_distance_sigma"]

        self.model_ids = self.config["model_ids"]
        self.z_coordinates = {}
        for model_id, z in zip(self.model_ids, self.config["z_coordinates"]):
            self.z_coordinates[model_id] = z

        self.all_locations = self.get_valid_locations()
        
        self.model_index = -1
        if not self.fixed_endpoints:
            self.switch_model(self.model_selection)
        else:
            self.model_id = self.config["model_id"]
            self.default_z = self.config["initial_pos"][2]

        self.start_location = self.select_agent_location()
        self.config["initial_pos"] = [self.start_location[0], self.start_location[1], self.default_z]
        self.target_location = self.select_target()

        # introduce robot and scene
        self.robot_introduce(Husky(self.config, env=self))
        self.scene_introduce()

        self.eps_count = 1

        
        if render_map:
            mesh_file = os.path.join(get_model_path(self.model_id), "mesh_z_up.obj")
            self.map_renderer = NavigationMapRenderer(mesh_file, self.default_z, 0.1, render_resolution=self.render_resolution)
예제 #12
0
    def __init__(self, config, gpu_count=0):
        self.config = self.parse_config(config)
        assert(self.config["envname"] == self.__class__.__name__ or self.config["envname"] == "TestEnv")

        CameraRobotEnv.__init__(self, self.config, gpu_count, 
                                scene_type="stadium" if self.config["model_id"]=="stadium" else "building",
                                tracking_camera=tracking_camera)
        if "robot" in self.config.keys():
            self.introduce_custom_robot()
        else:
            self.robot_introduce(Husky(self.config, env=self))
        self.scene_introduce()
        self.total_reward = 0
        self.total_frame = 0
        if self.config["ideal_position_control"]:
            for _ in range(100):
                self.scene.global_step()
예제 #13
0
    def __init__(self, config, gpu_idx=0):
        self.config = self.parse_config(config)
        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")

        CameraRobotEnv.__init__(self,
                                self.config,
                                gpu_idx,
                                scene_type="stadium" if self.config["model_id"]
                                == "stadium" else "building",
                                tracking_camera=tracking_camera)

        self.robot_introduce(Husky(self.config, env=self))
        self.scene_introduce()
        self.total_reward = 0
        self.total_frame = 0

        #self.flag_timeout = 1
        #self.visualid = -1
        #self.lastid = None
        self.gui = self.config["mode"] == "gui"
        '''if self.gui: