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
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
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)
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")
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")
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
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): 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)
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)
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
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
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
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")
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
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:
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
def __init__(self, config, gpu_idx=0, depth_render_port=5556, use_filler=None): self.config = config assert (self.config["envname"] == self.__class__.__name__ or self.config["envname"] == "TestEnv") if isinstance(use_filler, bool): self._use_filler = use_filler else: self._use_filler = config["use_filler"] CameraRobotEnv.__init__(self, self.config, gpu_idx, scene_type="stadium" if self.config["model_id"] == "stadium" else "building", tracking_camera=tracking_camera, start_port=depth_render_port, use_filler=use_filler) # print("Finished setting up camera_env") self.window_width = self.config['window_width'] self.window_height = self.config['window_height'] self._render_width = self.config['window_width'] self._render_height = self.config['window_height'] self._target_labels = self.config['target_labels'] self.keys_to_action = { (ord('s'), ): [-0.05, 0] + [0] * 13, # backward (ord('w'), ): [0.05, 0] + [0] * 13, # forward (ord('d'), ): [0, 0.05] + [0] * 13, # turn right (ord('a'), ): [0, -0.05] + [0] * 13, # turn left (): [0] * 15 } # print("[{} {}] Fetch init'd".format(getframeinfo(currentframe()).filename, getframeinfo(currentframe()).lineno)) fetch = Fetch(self.config, env=self) # print("[{} {}] Introducing robot".format(getframeinfo(currentframe()).filename, getframeinfo(currentframe()).lineno)) self.robot_introduce(fetch) # print("[{} {}] Introducing scene".format(getframeinfo(currentframe()).filename, # getframeinfo(currentframe()).lineno)) self.scene_introduce() # print("[{} {}] Scene Introduced".format(getframeinfo(currentframe()).filename, # getframeinfo(currentframe()).lineno)) self.total_reward = 0 self.total_frame = 0 self.goal_img = None self.initial_pos = config['initial_pos'] self.initial_orn = config['initial_orn'] self.step = self._step self.reset = self._reset self.nonWheelJoints = [ j for j in self.robot.ordered_joints if 'wheel' not in j.joint_name ] self.markers = [] self.marker_ids = [] # Initialize camera to point top down if self.gui: pos = self.robot._get_scaled_position() # orn = self.robot.get_orientation() pos = (pos[0], pos[1], pos[2] + self.tracking_camera['z_offset']) pos = np.array(pos) # dist = self.tracking_camera['distance'] / self.robot.mjcf_scaling # [yaw, pitch, dist] = p.getDebugVisualizerCamera()[8:11] p.resetDebugVisualizerCamera(3, 0, 269, pos)
def __init__( self, distance_weight=1.0, energy_weight=0.005, shake_weight=0.0, drift_weight=0.0, distance_limit=float("inf"), observation_noise_stdev=0.0, leg_model_enabled=False, hard_reset=False, render=False, env_randomizer=None, ## Cambria specific human=True, timestep=MINITAUR_TIMESTEP, frame_skip=MINITAUR_FRAMESKIP, is_discrete=False, mode="RGBD", use_filler=True, gpu_count=0, resolution="NORMAL"): """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. render: Whether to render the simulation. env_randomizer: An EnvRandomizer to randomize the physical properties during reset(). """ self._time_step = 0.01 self._observation = [] #self._is_render = render self._last_base_position = [0, 0, 0] self._distance_weight = distance_weight self._energy_weight = energy_weight self._drift_weight = drift_weight self._shake_weight = shake_weight self._distance_limit = distance_limit self._observation_noise_stdev = observation_noise_stdev self._action_bound = 1 self._leg_model_enabled = leg_model_enabled self._env_randomizer = env_randomizer self._time_step = timestep target_orn, target_pos = configs.TASK_POSE[ configs.NAVIGATE_MODEL_ID]["navigate"][-1] initial_orn, initial_pos = configs.TASK_POSE[ configs.NAVIGATE_MODEL_ID]["navigate"][0] self.robot = Minitaur(time_step=self._time_step, initial_pos=initial_pos, initial_orn=initial_orn) if self._env_randomizer is not None: self._env_randomizer.randomize_env(self) self._last_base_position = [0, 0, 0] self._objectives = [] self.viewer = None self._hard_reset = hard_reset # This assignment need to be after reset() self.human = human self.model_id = configs.NAVIGATE_MODEL_ID self.timestep = timestep self.frame_skip = frame_skip self.resolution = resolution self.tracking_camera = tracking_camera CameraRobotEnv.__init__(self, mode, gpu_count, scene_type="building", use_filler=use_filler) self.total_reward = 0 self.total_frame = 0