Esempio n. 1
0
    def __init__(self, config, is_discrete=False, mode="RGBD", 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
        self.flag_timeout = 1

        CameraRobotEnv.__init__(self,
                                config,
                                gpu_count,
                                scene_type="stadium",
                                use_filler=False)
        self.robot_introduce(
            Ant(initial_pos, initial_orn, is_discrete=is_discrete, 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.5, 0.5, 0.5],
                rgbaColor=[1, 0, 0, 0.7])
        self.lastid = None

        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")
Esempio n. 2
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(
            Quadrotor(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")
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 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)
Esempio n. 6
0
    def __init__(self, config, gpu_idx=0):
        """Initialize the minitaur gym environment.
        Args:
            distance_weight: The weight of the distance term in the reward.
            energy_weight: The weight of the energy term in the reward.
            shake_weight: The weight of the vertical shakiness term in the reward.
            drift_weight: The weight of the sideways drift term in the reward.
            distance_limit: The maximum distance to terminate the episode.
            observation_noise_stdev: The standard deviation of observation noise.
            leg_model_enabled: Whether to use a leg motor to reparameterize the action
                space.
            hard_reset: Whether to wipe the simulation and load everything when reset
                is called. If set to false, reset just place the minitaur back to start
                position and set its pose to initial configuration.
            env_randomizer: An EnvRandomizer to randomize the physical properties
                during reset().
        """
    
        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="building",
                                tracking_camera=tracking_camera)

        self.robot_introduce(Minitaur(self.config, env=self, 
                                      pd_control_enabled=self.pd_control_enabled,
                                      accurate_motor_model_enabled=self.accurate_motor_model_enabled))
        self.scene_introduce()
        self.gui = self.config["mode"] == "gui"
        self.total_reward = 0
        self.total_frame = 0

        self.action_repeat = 1
        ## Important: PD controller needs more accuracy
        '''if self.pd_control_enabled or self.accurate_motor_model_enabled:
            self.time_step = self.config["speed"]["timestep"]
            self.time_step /= self.NUM_SUBSTEPS
            self.num_bullet_solver_iterations /= self.NUM_SUBSTEPS
            self.action_repeat *= self.NUM_SUBSTEPS
            pybullet.setPhysicsEngineParameter(physicsClientId=self.physicsClientId,
              numSolverIterations=int(self.num_bullet_solver_iterations))
            pybullet.setTimeStep(self.time_step, physicsClientId=self.physicsClientId)
        '''
        pybullet.setPhysicsEngineParameter(physicsClientId=self.physicsClientId,
              numSolverIterations=int(self.num_bullet_solver_iterations))
        self._observation = []
        self._last_base_position = [0, 0, 0]
        self._action_bound = self.action_bound
        
        self._env_randomizer = self.env_randomizer        
        if self._env_randomizer is not None:
            self._env_randomizer.randomize_env(self)

        self._objectives = []        
        self.viewer = None
        self.Amax = [0] * 8
Esempio n. 7
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
Esempio n. 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)
Esempio n. 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")
    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)
Esempio n. 11
0
    def __init__(self, config, gpu_idx=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_idx,
                                scene_type="building",
                                tracking_camera=tracking_camera)

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

        self.gui = self.config["mode"] == "gui"
        self.total_reward = 0
        self.total_frame = 0
Esempio n. 12
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(JR2(self.config, env=self))
        self.scene_introduce()
        self.total_reward = 0
        self.total_frame = 0
Esempio n. 13
0
 def _reset(self):
     self.total_frame = 0
     self.total_reward = 0
     self.has_collided = 0
     obs = CameraRobotEnv._reset(self)
     self._flag_reposition()
     return obs
Esempio n. 14
0
    def _step(self, action):
        """Step forward the simulation, given the action.

        Args:
          action: A list of desired motor angles for eight motors.

        Returns:
          observations: The angles, velocities and torques of all motors.
          reward: The reward for the current state-action pair.
          done: Whether the episode has ended.
          info: A dictionary that stores diagnostic information.

        Raises:
          ValueError: The action dimension is not the same as the number of motors.
          ValueError: The magnitude of actions is out of bounds.
        """
        #print("Env apply raw action", action)
        action = self._transform_action_to_motor_command(action)
        #print("Env apply action", action)
    
        #for _ in range(self._action_repeat):
        #  self.robot.ApplyAction(action)
        #  pybullet.stepSimulation()
        for i in range(len(self.Amax)):
            if action[i] > self.Amax[i]:
                self.Amax[i] = action[i]
        #print("Action max", self.Amax)
        for _ in range(self.action_repeat):
            state = CameraRobotEnv._step(self, action)
        return state
Esempio n. 15
0
 def  _reset(self):
     self.total_frame = 0
     self.total_reward = 0
     self._randomize_target()
     self._flag_reposition()
     obs = CameraRobotEnv._reset(self)       ## Important: must come after flat_reposition
     return obs
Esempio n. 16
0
    def _step(self, a):
        state, reward, done, meta = CameraRobotEnv._step(self, a)
        if self.flag_timeout <= 0 or (self.flag_timeout < 225
                                      and self.robot.walk_target_dist < 0.4):
            if self.robot.walk_target_dist < 0.4:
                self.waypoint = 1
            self._flag_reposition()
        self.flag_timeout -= 1

        depth_size = 16
        if "depth" in self.config["output"]:
            depth_obs = self.get_observations()["depth"]
            x_start = int(self.windowsz / 2 - depth_size)
            x_end = int(self.windowsz / 2 + depth_size)
            y_start = int(self.windowsz / 2 - depth_size)
            y_end = int(self.windowsz / 2 + depth_size)
            self.obstacle_dist = (np.mean(depth_obs[x_start:x_end,
                                                    y_start:y_end, -1]))

        # state, reward, done, meta = CameraRobotEnv._step(self, a)
        # if self.flag_timeout <= 0 or (self.flag_timeout < FLAG_LIMIT and self.robot.walk_target_dist < 0.8):
        #    self._flag_reposition()
        # self.flag_timeout -= 1

        debug = 0
        if debug:
            print(
                "Frame: {}, FlagTimeOut: {}, Reward: {:.3f}, Distance: {:.3f}, "
                .format(self.nframe, self.flag_timeout, reward,
                        self.robot.walk_target_dist), done)

        return state, reward, done, meta
Esempio n. 17
0
    def _step(self, a):
        state, reward, done, meta = CameraRobotEnv._step(self, a)
        if self.flag_timeout <= 0:
            self._flag_reposition()
        self.flag_timeout -= 1

        return state, reward, done, meta
Esempio n. 18
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()
    def __init__(self, config, gpu_idx=0, gravity=9.8, collision_enabled=True):
        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(Turtlebot(self.config, env=self))
        self.scene_introduce(gravity=gravity,
                             collision_enabled=collision_enabled)
        self.total_reward = 0
        self.total_frame = 0
Esempio n. 20
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(AntClimber(self.config, env=self))
        self.scene_introduce()
        self.gui = self.config["mode"] == "gui"
        self.total_reward = 0
        self.total_frame = 0
        self.visual_flagId = None
        assert (self.config["envname"] == self.__class__.__name__
                or self.config["envname"] == "TestEnv")
Esempio n. 21
0
    def _step(self, a):
        state, reward, done, meta = CameraRobotEnv._step(self, a)
        if self.flag_timeout <= 0 or (self.flag_timeout < 225
                                      and self.robot.walk_target_dist < 0.8):
            self._flag_reposition()
        self.flag_timeout -= 1

        self.obstacle_dist = (np.mean(state[16:48, 16:48, -1]))

        return state, reward, done, meta
Esempio n. 22
0
    def _reset(self):
        self.total_frame = 0
        self.total_reward = 0
        obs = CameraRobotEnv._reset(self)
        self._flag_reposition()

        [p.removeBody(i) for i in self.marker_ids]
        self.markers = []
        self.marker_ids = []
        [j.reset_joint_state(0, 0) for j in self.nonWheelJoints]
        return obs
Esempio n. 23
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(Hamstirbot(self.config, env=self))
        self.scene_introduce()
        self.total_reward = 0
        self.total_frame = 0
        self.electricity_cost = 0
        self.stall_torque_cost = -0.01
        self.wall_collision_cost = -1.0
        self.collision_penalty = -10.0
        self.has_collided = 0
Esempio n. 24
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:
Esempio n. 25
0
    def _step(self, a):
        state, reward, done, meta = CameraRobotEnv._step(self, a)
        if self.flag_timeout <= 0 or (self.flag_timeout < 225 and self.robot.walk_target_dist < 0.8):
            self._flag_reposition()
        self.flag_timeout -= 1

        if "depth" in self.config["output"]:
            depth_obs = self.get_observations()["depth"]
            x_start = int(self.windowsz/2-16)
            x_end   = int(self.windowsz/2+16)
            y_start = int(self.windowsz/2-16)
            y_end   = int(self.windowsz/2+16)
            self.obstacle_dist = (np.mean(depth_obs[x_start:x_end, y_start:y_end, -1]))

        return state, reward, done, meta
Esempio n. 26
0
    def __init__(self,
                 config,
                 is_discrete=False,
                 use_filler=True,
                 gpu_count=0,
                 resolution=512):
        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 = 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"]

        CameraRobotEnv.__init__(self,
                                config,
                                gpu_count,
                                scene_type="building",
                                use_filler=self.config["use_filler"])

        self.robot_introduce(
            Humanoid(initial_pos,
                     initial_orn,
                     is_discrete=is_discrete,
                     target_pos=target_pos,
                     resolution=self.resolution,
                     env=self))

        self.scene_introduce()

        self.total_reward = 0
        self.total_frame = 0
Esempio n. 27
0
    def _reset(self):
        self.total_frame = 0
        self.total_reward = 0
        obs = CameraRobotEnv._reset(self)
        self._flag_reposition()

        # initial_pos:
        quat_orientation = p.getQuaternionFromEuler([0, 0, 3.14 / 2])
        base_position = [-14.3, 5, 1.2]
        base_position = [0, 0, 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)

        return obs
Esempio n. 28
0
 def _reset(self):
     CameraRobotEnv._reset(self)
     for flagId in self.semantic_flagIds:
         p.changeVisualShape(flagId, -1, rgbaColor=[1, 0, 0, 1])
Esempio n. 29
0
 def _reset(self):
     obs = CameraRobotEnv._reset(self)
     return obs
Esempio n. 30
0
 def step(self, a):
     obs, rew, done, info = CameraRobotEnv.step(self, a)
     return obs["rgb_filled"], rew, done, info