Ejemplo n.º 1
0
def run_scene(controller, file_name):
    config_data, status = MCS.load_config_json_file(file_name)

    if status is not None:
        print(status)
        return

    config_file_path = file_name
    config_file_name = config_file_path[config_file_path.rfind('/')+1:]

    if 'name' not in config_data.keys():
        config_data['name'] = config_file_name[0:config_file_name.find('.')]

    last_step = DEFAULT_STEP_COUNT
    if 'goal' in config_data.keys():
        if 'last_step' in config_data['goal'].keys():
            last_step = config_data['goal']['last_step']

    step_time_list = []

    output = controller.start_scene(config_data)

    for i in range(output.step_number + 1, last_step + 1):
        start = time.perf_counter()
        output = controller.step('Pass')
        end = time.perf_counter()
        step_time_list.append(end - start)

    output = controller.end_scene("", "")

    return step_time_list
Ejemplo n.º 2
0
def main():
    if len(sys.argv) < 3:
        print(
            'Usage: python run_mcs_human_input.py <mcs_unity_build_file> <mcs_config_json_file> <debug_files> <enable_noise>'
        )
        sys.exit()

    config_data, status = MCS.load_config_json_file(sys.argv[2])

    if status is not None:
        print(status)
        exit()

    debug = True
    if len(sys.argv) >= 4:
        debug = sys.argv[3].lower() == 'true'

    enable_noise = False
    if len(sys.argv) >= 5:
        enable_noise = sys.argv[4].lower() == 'true'

    controller = MCS.create_controller(sys.argv[1],
                                       debug=debug,
                                       enable_noise=enable_noise)

    config_file_path = sys.argv[2]
    config_file_name = config_file_path[config_file_path.rfind('/') + 1:]

    if 'name' not in config_data.keys():
        config_data['name'] = config_file_name[0:config_file_name.find('.')]

    run_scene(controller, config_data)
Ejemplo n.º 3
0
def update_file(controller, filename, keep_backups):
    config_data, err_status = MCS.load_config_json_file(filename)
    if err_status is not None:
        logging.error(f'could not load scene file "{filename}": {err_status}')
        return False

    if 'name' not in config_data:
        base = os.path.basename(filename)
        config_data['name'] = base.rsplit('.', 1)[-1]

    output = controller.start_scene(config_data)

    metadata = config_data['goal']['metadata']
    target_ids = [
        metadata[key]['id'] for key in ('target', 'target_1', 'target_2')
        if key in metadata
    ]
    logging.debug(f'target_ids: {target_ids}')
    logging.debug(f'num objects = {len(output.object_list)}')

    targets_visible = False
    targets_not_visible = False
    for obj in output.object_list:
        if obj.uuid in target_ids:
            # If it's in the object list to begin with, it should be visible, but just to make sure...
            if obj.visible:
                targets_visible = True
                target_ids.remove(obj.uuid)
                logging.debug(f'target visible: {obj.uuid}')
            else:
                targets_not_visible = True
                logging.debug(f'target not visible: {obj.uuid}')
        if targets_visible and targets_not_visible:
            break
    if targets_visible:
        config_data['goal']['type_list'].append('target_starts_visible')
    if targets_not_visible or len(target_ids) > 0:
        config_data['goal']['type_list'].append('target_starts_invisible')

    backup_name = filename + '.backup'
    os.replace(filename, backup_name)
    try:
        write_file(filename, config_data)
    except Exception as e:
        logging.error(f'error writing file "{filename}": {e}')
        logging.error(f'backup file is at "{backup_name}"')
        return
    if not keep_backups:
        os.remove(backup_name)
Ejemplo n.º 4
0
def main():
    args = parse_args()

    unity_exe_path = find_unity_executable()
    if unity_exe_path is None:
        print("Unity executable not found in /mcs", file=sys.stderr)
        exit(1)

    scene_config, status = MCS.load_config_json_file(args.scene)
    if status is not None:
        print(status, file=sys.stderr)
        exit(1)

    controller = MCS.create_controller(unity_exe_path, debug=False)
    run_playroom(controller, scene_config)
Ejemplo n.º 5
0
def run_scene(file_name, action_list):
    config_data, status = MCS.load_config_json_file(file_name)

    if status is not None:
        print(status)
        return

    config_file_path = file_name
    config_file_name = config_file_path[config_file_path.rfind('/') + 1:]

    if 'name' not in config_data.keys():
        config_data['name'] = config_file_name[0:config_file_name.find('.')]

    output = controller.start_scene(config_data)

    output = controller.step('Pass')

    for action in action_list:
        output = controller.step(action)
Ejemplo n.º 6
0
def main():
    if len(sys.argv) < 3:
        print('Usage: python run_mcs_human_input.py <mcs_unity_build_file> <mcs_config_json_file> <debug_files>')
        sys.exit()

    config_data, status = MCS.load_config_json_file(sys.argv[2])

    if status is not None:
        print(status)
        exit()

    debug = 'terminal' if len(sys.argv) < 4 else True

    controller = MCS.create_controller(sys.argv[1], debug=debug)

    config_file_path = sys.argv[2]
    config_file_name = config_file_path[config_file_path.rfind('/'):]

    if 'name' not in config_data.keys():
        config_data['name'] = config_file_name[0:config_file_name.find('.')]

    run_scene(controller, config_data)
Ejemplo n.º 7
0
def run_scene(file_name):
    config_data, status = MCS.load_config_json_file(file_name)

    if status is not None:
        print(status)
        return

    config_file_path = file_name
    config_file_name = config_file_path[config_file_path.rfind('/')+1:]

    if 'name' not in config_data.keys():
        config_data['name'] = config_file_name[0:config_file_name.find('.')]

    last_step = 30
    if 'goal' in config_data.keys():
        if 'last_step' in config_data['goal'].keys():
            last_step = config_data['goal']['last_step']

    output = controller.start_scene(config_data)

    for i in range(1, last_step + 1):
        action = output.action_list[len(output.action_list) - 1]
        output = controller.step(action, **params)
Ejemplo n.º 8
0
 def test_load_config_file_json(self):
     actual, status = MCS.load_config_json_file("test/test_scene.json")
     expected = {
         "ceilingMaterial": "Walls/WallDrywallWhite",
         "floorMaterial": "Fabrics/RUG4",
         "wallMaterial": "Walls/YellowDrywall",
         "objects": [{
             "id": "testBall",
             "type": "sphere",
             "materialFile": "Plastics/BlueRubber",
             "physics": True,
             "shows": [{
                 "stepBegin": 0,
                 "position": {
                     "x": 0,
                     "y": 0.5,
                     "z": 3
                 },
                 "scale": {
                     "x": 0.25,
                     "y": 0.25,
                     "z": 0.25
                 }   
             }],     
             "forces": [{
                 "stepBegin": 1,
                 "stepEnd": 1,
                 "vector": {
                     "x": 50,
                     "y": 0,
                     "z": 0
                 }
             }]  
         }]      
     }
     self.assertEqual(actual, expected)
     self.assertEqual(status, None)
Ejemplo n.º 9
0
    output = controller.step('Pass')
    output = controller.step('RotateLook', rotation=0, horizon=-30)
    output = controller.step('ThrowObject',
                             objectId="apple_a",
                             force=1,
                             objectDirectionX=1,
                             objectDirectionY=0,
                             objectDirectionZ=2)
    output = controller.step('RotateLook', rotation=20, horizon=0)
    output = controller.step('Pass')
    output = controller.step('Pass')
    output = controller.step('Pass')


if __name__ == "__main__":
    config_data, status = MCS.load_config_json_file(sys.argv[2])

    if status is not None:
        print(status)
        exit()

    debug = 'terminal' if sys.argv[3] is None else True
    enable_noise = 'terminal' if sys.argv[4] is None else False

    controller = MCS.create_controller(sys.argv[1],
                                       debug=debug,
                                       enable_noise=enable_noise)

    config_file_path = sys.argv[2]
    config_file_name = config_file_path[config_file_path.rfind('/') + 1:]
Ejemplo n.º 10
0
 def test_load_config_file_json_is_missing(self):
     actual, status = MCS.load_config_json_file("test/test_scene_missing.json")
     self.assertEqual(actual, {})
     self.assertEqual(status, "The given file 'test/test_scene_missing.json' cannot be found.")
Ejemplo n.º 11
0
 def test_load_config_file_json_is_invalid(self):
     actual, status = MCS.load_config_json_file("test/test_scene_invalid.json")
     self.assertEqual(actual, {})
     self.assertEqual(status, "The given file 'test/test_scene_invalid.json' does not contain valid JSON.")