How to use the ai2thor.controller function in ai2thor

To help you get started, we’ve selected a few ai2thor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TheMTank / cups-rl / tests / test_ai2thor_wrapper.py View on Github external
def test_simple_example():
        """
        Taken from here: http://ai2thor.allenai.org/tutorials/examples
        """
        controller = ai2thor.controller.Controller()
        controller.start()

        # Kitchens: FloorPlan1 - FloorPlan30
        # Living rooms: FloorPlan201 - FloorPlan230
        # Bedrooms: FloorPlan301 - FloorPlan330
        # Bathrooms: FloorPLan401 - FloorPlan430

        controller.reset('FloorPlan28')
        controller.step(dict(action='Initialize', gridSize=0.25))

        event = controller.step(dict(action='MoveAhead'))

        # Numpy Array - shape (width, height, channels), channels are in RGB order
        event.frame

        # Numpy Array in BGR order suitable for use with OpenCV
github allenai / ai2thor / test_controllers.py View on Github external
import ai2thor.controller
import ai2thor.robot_controller
import random
import time
import numpy as np
from pprint import pprint

fps = ["FloorPlan311"]

runs = [
    {'id': 'unity', 'port': 8200, 'controller': ai2thor.controller.Controller()},
    {'id': 'robot', 'port': 9200, 'controller': ai2thor.robot_controller.Controller()}
    #{'id': 'robot', 'port': 9000, 'controller': ai2thor.robot_controller.Controller()}
]

for run_config in runs:
    port = run_config['port']
    controller = run_config['controller']
    event = controller.start(start_unity=False, host='127.0.0.1', port=port)
    # event = controller.step({'action': 'ChangeQuality', 'quality': 'High'})
    # event = controller.step({"action": "ChangeResolution", "x": 300, "y": 300})

    for fp in fps:
        print(fp)
        for i in range(1):
            event = controller.reset(fp)
            # event = controller.step(dict(action='Initialize', gridSize=0.25, fieldOfView=90, renderObjectImage=True))
github TheMTank / cups-rl / tests / bounding_boxes_and_test_reward.py View on Github external
return False

    return True

def close_enough(distance):
    if distance < 1.0:
        return True
    return False

if __name__ == '__main__':
    # Kitchens: FloorPlan1 - FloorPlan30
    # Living rooms: FloorPlan201 - FloorPlan230
    # Bedrooms: FloorPlan301 - FloorPlan330
    # Bathrooms: FloorPLan401 - FloorPlan430

    controller = ai2thor.controller.Controller()
    controller.start()
    controller.reset('FloorPlan28')
    event = controller.step(dict(action='Initialize', gridSize=0.25,
                                     renderDepthImage=True,
                                     renderClassImage=True,
                                     renderObjectImage=True))

    # Numpy Array - shape (width, height, channels), channels are in RGB order
    print(event.frame)
    print(event.frame.shape)

    # event = controller.step(dict(action='MoveAhead'))
    event = controller.step(dict(action='RotateRight'))
    event = controller.step(dict(action='RotateRight'))
    event = controller.step(dict(action='MoveAhead'))
    event = controller.step(dict(action='MoveAhead'))
github allenai / ai2thor / tests / test_unity.py View on Github external
def test_rectangle_aspect():
    controller = ai2thor.controller.Controller()
    controller.releases_dir = releases_dir.__get__(controller, ai2thor.controller.Controller)
    print("trying to start unity")
    controller.start(player_screen_width=600, player_screen_height=300)
    print("started")
    controller.reset('FloorPlan28')
    event = controller.step(dict(action='Initialize', gridSize=0.25))
    assert event.frame.shape == (300, 600, 3)
github TheMTank / cups-rl / examples / ai2thor_examples.py View on Github external
def run(thread_num):
        """
        Runs 5 iterations of 10 steps of the environment with the different rendering options
        :param thread_num: (int) Number of threads to launch
        """
        env = ai2thor.controller.Controller()
        env.start()

        render_depth_image, render_class_image, render_object_image = False, False, False

        for i in range(5):
            t_start = time.time()
            env.reset('FloorPlan1')
            env.step({'action': 'Initialize', 'gridSize': 0.25})

            # Compare the performance with all the extra added information
            # Big take away is that Object instance information makes it much slower
            if i == 2:
                render_class_image = True
                print('Thread num: {}. Added Class info'.format(thread_num))
            elif i == 3:
                render_object_image = True
github metalbubble / RLexample / navigation_agent.py View on Github external
# install AI2THOR at https://github.com/allenai/ai2thor
import ai2thor.controller
import random
import matplotlib.pyplot as plt
import time

# Kitchens:       FloorPlan1 - FloorPlan30
# Living rooms:   FloorPlan201 - FloorPlan230
# Bedrooms:       FloorPlan301 - FloorPlan330
# Bathrooms:      FloorPLan401 - FloorPlan430
room_id = 205
agent_id = 1 # 1 is random agent, 2 is keyboard agent (control by you)

controller = ai2thor.controller.Controller()
controller.start()

controller.reset('FloorPlan' + str(room_id))

# gridSize specifies the coarseness of the grid that the agent navigates on
controller.step(dict(action='Initialize', gridSize=0.25))

actions = ['MoveAhead','MoveLeft','MoveRight','MoveBack','RotateLeft','RotateRight']

for i in range(200):
    if agent_id == 1:
        action_id = random.randint(0, len(actions)-1) # random action
    elif agent_id == 2:
        # input your action
        key = int(input('press 1,2,3,4,5,6\n')) # type 1,2,3,4,5
        action_id = key-1
github TheMTank / cups-rl / gym_ai2thor / envs / ai2thor_env.py View on Github external
self.gridSize = self.config.get('gridSize', 0.1)
        
        # Create task from config
        self.task = TaskFactory.create_task(self.config)
        # set scene_id
        if self.task.random_scene_ids_on_reset:
            self.scene_id = random.choice(self.task.random_scene_ids_on_reset)
        else:
            self.scene_id = self.config.get('scene_id')
        if not self.scene_id:
            raise ValueError('Need to specify scene_id in config')
        # todo check for self.config['task'].get('list_of_xyz_starting_positions')
        # todo and implement random.choice of starting position for specific task/scene with teleport
        # todo precompute all valid locations for all scenes and avoid objects too?
        # Start ai2thor
        self.controller = ai2thor.controller.Controller()
        if self.config.get('build_file_name'):
            # file must be in gym_ai2thor/build_files
            self.build_file_path = os.path.abspath(os.path.join(__file__, '../../build_files',
                                                   self.config['build_file_name']))
            print('Build file path at: {}'.format(self.build_file_path))
            if not os.path.exists(self.build_file_path):
                raise ValueError('Unity build file at:\n{}\n does not exist'.format(
                    self.build_file_path))
            self.controller.local_executable_path = self.build_file_path
        self.controller.start()

        self.reset_ever = False
github hsvgbkhgbv / SQDDPG / environments / ai2thor / ai2thor_env.py View on Github external
'lastObjectPickedUp', 'lastObjectOpened',
                                                'lastObjectClosed']
        self.cameraY = self.config.get('cameraY', 0.0)
        self.gridSize = self.config.get('gridSize', 0.1)
        # Rendering options. Set segmentation and bounding box options off as default
        self.render_options = defaultdict(lambda: False)
        if 'render_options' in self.config:
            for option, value in self.config['render_options'].items():
                self.render_options[option] = value
        # Create task from config
        try:
            self.task = getattr(tasks, self.config['task']['task_name'])(**self.config)
        except Exception as e:
            raise ValueError('Error occurred while creating task. Exception: {}'.format(e))
        # Start ai2thor
        self.controller = ai2thor.controller.Controller()
        if self.config.get('build_file_name'):
            # file must be in gym_ai2thor/build_files
            self.build_file_path = os.path.abspath(os.path.join(__file__, '../../build_files',
                                                                self.config['build_file_name']))
            print('Build file path at: {}'.format(self.build_file_path))
            if not os.path.exists(self.build_file_path):
                raise ValueError('Unity build file at:\n{}\n does not exist'.format(
                    self.build_file_path))
            self.controller.local_executable_path = self.build_file_path

        self.controller.start()
        print("AI2Thor Server starts!")
github TheMTank / cups-rl / examples / ai2thor_inbuilt_interactive_mode.py View on Github external
Only works from terminal!
"""

import argparse
import os

import ai2thor.controller

parser = argparse.ArgumentParser(description='Run ai2thor in interactive mode')
parser.add_argument('--unity-build-name', type=str,
                    default='build_bowls_vs_cups_fp1_201_301_4011_v_0.1.x86_64',
                    help='Path to a unity build with file ending in .x86_64')
args = parser.parse_args()

controller = ai2thor.controller.Controller()
# file must be in gym_ai2thor/build_files
unity_build_abs_file_path = os.path.abspath(os.path.join(__file__, '../../gym_ai2thor/build_files',
                                                         args.unity_build_name))
print('Build file path at: {}'.format(unity_build_abs_file_path))
if not os.path.exists(unity_build_abs_file_path):
    raise ValueError('Unity build file does not exist')
controller.local_executable_path = unity_build_abs_file_path
controller.start()

controller.reset('FloorPlan201')
controller.step(dict(action='Initialize', gridSize=0.05, cameraY=-0.8, continuous=True))
controller.interact()
github jkulhanek / visual-navigation-agent-pytorch / agent / environment / __init__.py View on Github external
def __init__(self, name = "FloorPlan28", grid_size = 0.25):
        import ai2thor.controller
        self.name = name
        self.grid_size = grid_size
        self.controller = ai2thor.controller.Controller()
        self.state = None