Agent

Agent

class habitat_sim.Agent(agent_config: habitat_sim.agent.agent.AgentConfiguration = NOTHING, sensors: habitat_sim.sensors.sensor_suite.SensorSuite = NOTHING, controls: habitat_sim.agent.controls.ObjectControls = NOTHING, body: habitat_sim._ext.habitat_sim_bindings.AttachedObject = NOTHING)[source]

Implements an agent with multiple sensors

Parameters

agent_config (AgentConfiguration) – The configuration of the agent

Warning

Agents are given controls over a node in the scene graph, but do not own this node. This means that errors will occur if the owner of the scene graph is deallocated. Generally the owner of the scene graph is the Simulator.

If you’d like to have an agent to control without loading up the simulator, see unit tests for the agent in tests/test_agent.py. We recommend letting the simulator create the agent and own the scene graph in almost all cases. Using the scene graph in python is dangerous due to differences in c++ and python memory management

act(action_id: Any)[source]

Take the action specified by action_id

Parameters

action_id (Any) – ID of the action. Retreives the action from agent_config.action_space

attach(scene_node: habitat_sim._ext.habitat_sim_bindings.SceneNode)[source]

Gives the agent control over the specified scene node (but not ownership)

The agent will recursively call attach for the sensors

Parameters

scene_node (hsim.SceneNode) –

detach()[source]

Detaches the agent from the its current scene_node

Recursively calls detach on any sensors

get_state() → habitat_sim.agent.agent.AgentState[source]
reconfigure(agent_config: habitat_sim.agent.agent.AgentConfiguration, reconfigure_sensors: bool = True)[source]

Re-create the agent with a new configuration :param agent_config: New config :type agent_config: AgentConfiguration :param reconfigure_sensors: Whether or not to also reconfigure the sensors, there

are specific cases where false makes sense, but most cases are covered by true

property scene_node
set_state(state: habitat_sim.agent.agent.AgentState, reset_sensors: bool = True)[source]

Sets the agents state

Parameters
  • state (AgentState) – The state to set the agent to

  • reset_sensors (bool) – Whether or not to reset the sensors to their default intrinsic/extrinsic parameters before setting their extrinsic state

property state
class habitat_sim.AgentConfiguration(height: float = 1.5, radius: float = 0.1, mass: float = 32.0, linear_acceleration: float = 20.0, angular_acceleration: float = 12.566370614359172, linear_friction: float = 0.5, angular_friction: float = 1.0, coefficient_of_restitution: float = 0.0, sensor_specifications: List[habitat_sim._ext.habitat_sim_bindings.SensorSpec] = NOTHING, action_space: Dict[Any, habitat_sim.agent.agent.ActionSpec] = NOTHING, body_type: str = 'cylinder')[source]
action_space
angular_acceleration
angular_friction
body_type
coefficient_of_restitution
height
linear_acceleration
linear_friction
mass
radius
sensor_specifications
class habitat_sim.AgentState(position: numpy.array = array([0., 0., 0.]), rotation: Union[quaternion, List] = quaternion(1, 0, 0, 0), velocity: numpy.array = array([0., 0., 0.]), angular_velocity: numpy.array = array([0., 0., 0.]), force: numpy.array = array([0., 0., 0.]), torque: numpy.array = array([0., 0., 0.]), sensor_states: Dict[str, habitat_sim.agent.agent.SixDOFPose] = NOTHING)[source]
angular_velocity
force
position
rotation
sensor_states
torque
velocity
class habitat_sim.SixDOFPose(position: numpy.array = array([0., 0., 0.]), rotation: Union[quaternion, List] = quaternion(1, 0, 0, 0))[source]

Specifies a position with 6 degrees of freedom

Parameters
  • position (np.array) – xyz position

  • rotation (np.quaternion) – unit quaternion rotation

position
rotation

Actions

class habitat_sim.ActionSpec(name: str, actuation: habitat_sim.agent.controls.ActuationSpec = None)[source]

Defines how a specific action is implemented

Parameters
  • name (str) – Name of the function implementing the action in the move_func_map

  • actuation (ActuationSpec) – Arguements that will be passed to the function

actuation = None
class habitat_sim.ActuationSpec(amount: float)[source]

Struct to hold parameters for the default actions

The default actions only have one parameters, the amount they move the scene node by, however other actions may have any number of parameters and can define different structs to hold those parameters

Parameters

amount (float) – The amount the control moves the scene node by

class habitat_sim.agent.controls.SceneNodeControl(body_action: bool = False)[source]

Base class for all controls

Control classes are used to implement agent actions. Any new control must subclass this class.

See default_controls.py for an example of adding new actions (note that this can be done _outside_ the core habitat_sim codebase in exactly the same way)

@habitat_sim.agent.controls.register_move_fn(controller: Optional[Type[habitat_sim.agent.controls.SceneNodeControl]] = None, *, name: Optional[str] = None, body_action: bool = None)[source]

Registers a new control with Habitat-Sim

See default_controls.py for an example of adding new actions (note that this can be done _outside_ the core habitat_sim codebase in exactly the same way)

Parameters
  • controller (Optional[Type[SceneNodeControl]]) – The class of the controller to register If none, will return a wrapper for use with decorator syntax

  • name (Optional[str]) – The name to register the control with If none, will register with the name of the controller converted to snake case i.e. a controller with class name MoveForward will be registered as move_forward

  • body_action (bool) – Whether or not this action manipulates the agent’s body (thereby also moving the sensors) or manipulates just the sensors. This is a non-optional keyword arguement and must be set (this is done for readability)

We currently have the following actions added by default. Any action not registered with an explict name is given the snake case version of the class name, i.e. MoveForward can be accessed with the name move_forward

#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import numpy as np

import habitat_sim.bindings as hsim
from habitat_sim import utils

from .controls import ActuationSpec, SceneNodeControl, register_move_fn

__all__ = []


_x_axis = 0
_y_axis = 1
_z_axis = 2


def _move_along(scene_node: hsim.SceneNode, distance: float, axis: int):
    ax = scene_node.absolute_transformation()[0:3, axis]
    scene_node.translate_local(ax * distance)


def _rotate_local(scene_node: hsim.SceneNode, theta: float, axis: int):
    ax = np.zeros(3, dtype=np.float32)
    ax[axis] = 1

    scene_node.rotate_local(np.deg2rad(theta), ax)
    scene_node.normalize()


@register_move_fn(body_action=True)
class MoveBackward(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _move_along(scene_node, actuation_spec.amount, _z_axis)


@register_move_fn(body_action=True)
class MoveForward(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _move_along(scene_node, -actuation_spec.amount, _z_axis)


@register_move_fn(body_action=True)
class MoveRight(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _move_along(scene_node, actuation_spec.amount, _x_axis)


@register_move_fn(body_action=True)
class MoveLeft(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _move_along(scene_node, -actuation_spec.amount, _x_axis)


@register_move_fn(body_action=False)
class MoveUp(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _move_along(scene_node, actuation_spec.amount, _y_axis)


@register_move_fn(body_action=False)
class MoveDown(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _move_along(scene_node, -actuation_spec.amount, _y_axis)


@register_move_fn(body_action=False)
class LookLeft(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _rotate_local(scene_node, actuation_spec.amount, _y_axis)


@register_move_fn(body_action=False)
class LookRight(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _rotate_local(scene_node, -actuation_spec.amount, _y_axis)


register_move_fn(LookLeft, name="turn_left", body_action=True)
register_move_fn(LookRight, name="turn_right", body_action=True)


@register_move_fn(body_action=False)
class LookUp(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _rotate_local(scene_node, actuation_spec.amount, _x_axis)


@register_move_fn(body_action=False)
class LookDown(SceneNodeControl):
    def __call__(self, scene_node: hsim.SceneNode, actuation_spec: ActuationSpec):
        _rotate_local(scene_node, -actuation_spec.amount, _x_axis)

Action space path finding