def get(self): return { HabitatSimActions.STOP: habitat_sim.ActionSpec("stop"), HabitatSimActions.MOVE_FORWARD: habitat_sim.ActionSpec( "pyrobot_noisy_move_forward", habitat_sim.PyRobotNoisyActuationSpec( amount=self.config.FORWARD_STEP_SIZE, robot=self.config.NOISE_MODEL.ROBOT, controller=self.config.NOISE_MODEL.CONTROLLER, noise_multiplier=self.config.NOISE_MODEL.NOISE_MULTIPLIER, ), ), HabitatSimActions.TURN_LEFT: habitat_sim.ActionSpec( "pyrobot_noisy_turn_left", habitat_sim.PyRobotNoisyActuationSpec( amount=self.config.TURN_ANGLE, robot=self.config.NOISE_MODEL.ROBOT, controller=self.config.NOISE_MODEL.CONTROLLER, noise_multiplier=self.config.NOISE_MODEL.NOISE_MULTIPLIER, ), ), HabitatSimActions.TURN_RIGHT: habitat_sim.ActionSpec( "pyrobot_noisy_turn_right", habitat_sim.PyRobotNoisyActuationSpec( amount=self.config.TURN_ANGLE, robot=self.config.NOISE_MODEL.ROBOT, controller=self.config.NOISE_MODEL.CONTROLLER, noise_multiplier=self.config.NOISE_MODEL.NOISE_MULTIPLIER, ), ), HabitatSimActions.LOOK_UP: habitat_sim.ActionSpec( "look_up", habitat_sim.ActuationSpec(amount=self.config.TILT_ANGLE), ), HabitatSimActions.LOOK_DOWN: habitat_sim.ActionSpec( "look_down", habitat_sim.ActuationSpec(amount=self.config.TILT_ANGLE), ), # The perfect actions are needed for the oracle planner "_forward": habitat_sim.ActionSpec( "move_forward", habitat_sim.ActuationSpec( amount=self.config.FORWARD_STEP_SIZE), ), "_left": habitat_sim.ActionSpec( "turn_left", habitat_sim.ActuationSpec(amount=self.config.TURN_ANGLE), ), "_right": habitat_sim.ActionSpec( "turn_right", habitat_sim.ActuationSpec(amount=self.config.TURN_ANGLE), ), }
def test_pyrobot_noisy_actions(noise_multiplier, robot, controller): np.random.seed(0) scene_graph = hsim.SceneGraph() agent_config = habitat_sim.AgentConfiguration() agent_config.action_space = dict( noisy_move_backward=habitat_sim.ActionSpec( "pyrobot_noisy_move_backward", habitat_sim.PyRobotNoisyActuationSpec( amount=1.0, robot=robot, controller=controller, noise_multiplier=noise_multiplier, ), ), noisy_move_forward=habitat_sim.ActionSpec( "pyrobot_noisy_move_forward", habitat_sim.PyRobotNoisyActuationSpec( amount=1.0, robot=robot, controller=controller, noise_multiplier=noise_multiplier, ), ), noisy_turn_left=habitat_sim.ActionSpec( "pyrobot_noisy_turn_left", habitat_sim.PyRobotNoisyActuationSpec( amount=90.0, robot=robot, controller=controller, noise_multiplier=noise_multiplier, ), ), noisy_turn_right=habitat_sim.ActionSpec( "pyrobot_noisy_turn_right", habitat_sim.PyRobotNoisyActuationSpec( amount=90.0, robot=robot, controller=controller, noise_multiplier=noise_multiplier, ), ), move_backward=habitat_sim.ActionSpec( "move_backward", habitat_sim.ActuationSpec(amount=1.0)), move_forward=habitat_sim.ActionSpec( "move_forward", habitat_sim.ActuationSpec(amount=1.0)), turn_left=habitat_sim.ActionSpec( "turn_left", habitat_sim.ActuationSpec(amount=90.0)), turn_right=habitat_sim.ActionSpec( "turn_right", habitat_sim.ActuationSpec(amount=90.0)), ) agent = habitat_sim.Agent(scene_graph.get_root_node().create_child(), agent_config) for base_action in { act.replace("noisy_", "") for act in agent_config.action_space }: state = agent.state state.rotation = np.quaternion(1, 0, 0, 0) agent.state = state agent.act(base_action) base_state = agent.state delta_translations = [] delta_rotations = [] for _ in range(300): agent.state = state agent.act(f"noisy_{base_action}") noisy_state = agent.state delta_translations.append( _delta_translation(base_state, noisy_state)) delta_rotations.append(_delta_rotation(base_state, noisy_state)) delta_translations_arr = np.stack(delta_translations) delta_rotations_arr = np.stack(delta_rotations) if "move" in base_action: noise_model = pyrobot_noise_models[robot][controller].linear_motion else: noise_model = pyrobot_noise_models[robot][ controller].rotational_motion EPS = 5e-2 assert (np.linalg.norm(noise_model.linear.mean * noise_multiplier - np.abs(delta_translations_arr.mean(0))) < EPS) assert (np.linalg.norm(noise_model.rotation.mean * noise_multiplier - np.abs(delta_rotations_arr.mean(0))) < EPS) assert (np.linalg.norm(noise_model.linear.cov * noise_multiplier - np.diag(delta_translations_arr.std(0)**2)) < EPS) assert (np.linalg.norm(noise_model.rotation.cov * noise_multiplier - (delta_rotations_arr.std(0)**2)) < EPS)
def make_cfg(self, settings): sim_cfg = habitat_sim.SimulatorConfiguration() sim_cfg.gpu_device_id = 0 sim_cfg.scene.id = settings["scene"] # Note: all sensors must have the same resolution sensors = { "color_sensor": { "sensor_type": habitat_sim.SensorType.COLOR, "resolution": [settings["height"], settings["width"]], "position": [0.0, settings["sensor_height"], 0.0], }, "depth_sensor": { "sensor_type": habitat_sim.SensorType.DEPTH, "resolution": [settings["height"], settings["width"]], "position": [0.0, settings["sensor_height"], 0.0], }, "semantic_sensor": { "sensor_type": habitat_sim.SensorType.SEMANTIC, "resolution": [settings["height"], settings["width"]], "position": [0.0, settings["sensor_height"], 0.0], }, } sensor_specs = [] for sensor_uuid, sensor_params in sensors.items(): if settings[sensor_uuid]: sensor_spec = habitat_sim.SensorSpec() sensor_spec.uuid = sensor_uuid sensor_spec.sensor_type = sensor_params["sensor_type"] sensor_spec.resolution = sensor_params["resolution"] sensor_spec.position = sensor_params["position"] sensor_specs.append(sensor_spec) # Here you can specify the amount of displacement in a forward action and the turn angle agent_cfg = habitat_sim.agent.AgentConfiguration() agent_cfg.sensor_specifications = sensor_specs agent_cfg.action_space = { "do_nothing": habitat_sim.agent.ActionSpec( "move_forward", habitat_sim.agent.ActuationSpec(amount=0.)), "move_forward": habitat_sim.agent.ActionSpec( "move_forward", habitat_sim.agent.ActuationSpec(amount=0.25)), "turn_left": habitat_sim.agent.ActionSpec( "turn_left", habitat_sim.agent.ActuationSpec(amount=self.rot_interval)), "turn_right": habitat_sim.agent.ActionSpec( "turn_right", habitat_sim.agent.ActuationSpec(amount=self.rot_interval)), "look_up": habitat_sim.ActionSpec( "look_up", habitat_sim.ActuationSpec(amount=self.rot_interval)), "look_down": habitat_sim.ActionSpec( "look_down", habitat_sim.ActuationSpec(amount=self.rot_interval)), "look_down_init": habitat_sim.ActionSpec("look_down", habitat_sim.ActuationSpec(amount=100.0)) } return habitat_sim.Configuration(sim_cfg, [agent_cfg])
def create_sim_config( self, _sensor_suite: SensorSuite) -> habitat_sim.Configuration: sim_config = habitat_sim.SimulatorConfiguration() sim_config.scene.id = self.config.SCENE sim_config.gpu_device_id = self.config.HABITAT_SIM_V0.GPU_DEVICE_ID agent_config = habitat_sim.AgentConfiguration() overwrite_config(config_from=self._get_agent_config(), config_to=agent_config) sensor_specifications = [] for sensor in _sensor_suite.sensors.values(): sim_sensor_cfg = habitat_sim.SensorSpec() sim_sensor_cfg.uuid = sensor.uuid sim_sensor_cfg.resolution = list( sensor.observation_space.shape[:2]) sim_sensor_cfg.parameters["hfov"] = str(sensor.config.HFOV) sim_sensor_cfg.position = sensor.config.POSITION # TODO(maksymets): Add configure method to Sensor API to avoid # accessing child attributes through parent interface sim_sensor_cfg.sensor_type = sensor.sim_sensor_type # type: ignore sensor_specifications.append(sim_sensor_cfg) # If there is no sensors specified create a dummy sensor so simulator # won't throw an error if not _sensor_suite.sensors.values(): sim_sensor_cfg = habitat_sim.SensorSpec() sim_sensor_cfg.resolution = [1, 1] sensor_specifications.append(sim_sensor_cfg) agent_config.sensor_specifications = sensor_specifications agent_config.action_space = { SimulatorActions.STOP.value: habitat_sim.ActionSpec("stop"), SimulatorActions.MOVE_FORWARD.value: habitat_sim.ActionSpec( "move_forward", habitat_sim.ActuationSpec( amount=self.config.FORWARD_STEP_SIZE), ), SimulatorActions.TURN_LEFT.value: habitat_sim.ActionSpec( "turn_left", habitat_sim.ActuationSpec(amount=self.config.TURN_ANGLE), ), SimulatorActions.TURN_RIGHT.value: habitat_sim.ActionSpec( "turn_right", habitat_sim.ActuationSpec(amount=self.config.TURN_ANGLE), ), SimulatorActions.LOOK_UP.value: habitat_sim.ActionSpec( "look_up", habitat_sim.ActuationSpec(amount=self.config.TILT_ANGLE), ), SimulatorActions.LOOK_DOWN.value: habitat_sim.ActionSpec( "look_down", habitat_sim.ActuationSpec(amount=self.config.TILT_ANGLE), ), } return habitat_sim.Configuration(sim_config, [agent_config])