Esempio n. 1
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)
Esempio n. 2
0
def main(argv):
    parser = argparse.ArgumentParser(
        description='Update scene descriptions with target visibility info')
    parser.add_argument('--app',
                        metavar='UNITY_MCS_APP',
                        required=True,
                        help='Path to Unity MCS application')
    parser.add_argument('--debug',
                        action='store_true',
                        default=False,
                        help='Enable debugging output')
    parser.add_argument('--backup',
                        action='store_true',
                        default=False,
                        help='Keep backup files')
    parser.add_argument('--loglevel',
                        choices=LOG_LEVELS,
                        help='set logging level')
    parser.add_argument('scene_files',
                        metavar='SCENE_FILE',
                        nargs='+',
                        help='scene file to update')

    args = parser.parse_args(argv[1:])

    if args.loglevel:
        logging.getLogger().setLevel(args.loglevel)
    elif args.debug:
        logging.getLogger().setLevel(logging.DEBUG)

    controller = MCS.create_controller(args.app, args.debug)

    for f in args.scene_files:
        update_file(controller, f, args.backup)
Esempio n. 3
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)
Esempio n. 4
0
def main():
    if len(sys.argv) < 3:
        print('Usage: python mcs_run_scene_timer.py <mcs_unity_build_file> <scene_configuration_dir> <debug=False>')
        sys.exit()

    file_list = [os.path.join(sys.argv[2], file_name) for file_name in os.listdir(sys.argv[2]) if \
            os.path.isfile(os.path.join(sys.argv[2], file_name)) and os.path.splitext(file_name)[1] == '.json']
    file_list.sort()

    debug = sys.argv[3] if len(sys.argv) > 3 else False

    print(f'FOUND {len(file_list)} SCENE CONFIGURATION FILES... STARTING THE MCS UNITY APP...')
    controller = MCS.create_controller(sys.argv[1], debug=(True if debug == 'true' else debug))

    scene_time_list = []
    step_time_list_list = []
    step_time_avg_list = []
    step_time_len_list = []
    step_time_max_list = []
    step_time_min_list = []
    step_time_sum_list = []

    for i in range(0, len(file_list)):
        print('================================================================================')
        print(f'RUNNING FILE {(i + 1)}: {file_list[i]}')
        start = time.perf_counter()
        step_time_list = run_scene(controller, file_list[i])
        end = time.perf_counter()
        scene_time_list.append(end - start)
        step_time_list_list.append(step_time_list)
        step_time_avg_list.append(statistics.mean(step_time_list))
        step_time_len_list.append(len(step_time_list))
        step_time_max_list.append(max(step_time_list))
        step_time_min_list.append(min(step_time_list))
        step_time_sum_list.append(sum(step_time_list))

    print('================================================================================')
    print(f'RAN {len(file_list)} SCENES WITH {sum(step_time_len_list)} TOTAL STEPS IN {sum(scene_time_list):0.4f} SECONDS')
    print(f'Average single step took {statistics.mean(step_time_avg_list):0.4f} seconds')
    print(f'Longest single step took {max(step_time_max_list):0.4f} seconds')
    print(f'Shortest single step took {min(step_time_min_list):0.4f} seconds')
    print(f'Average single scene took {statistics.mean(scene_time_list):0.4f} seconds')
    print(f'Longest single scene took {max(scene_time_list):0.4f} seconds')
    print(f'Shortest single scene took {min(scene_time_list):0.4f} seconds')
Esempio n. 5
0
def main(args):
    if len(args) < 2:
        print(
            'Usage: python image_generator.py <unity_app_file_path> <output_folder=../images/>'
        )
        exit()

    controller = MCS.create_controller(args[1])

    scene_configuration_list = generate_scene_configuration_list(
        simplified_objects.OBJECT_LIST)

    output_folder = (args[2] if len(args) > 2 else '../images') + '/'

    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    for scene_configuration in scene_configuration_list:
        object_config = scene_configuration['objects'][0]
        object_type = object_config['type']
        material_list = object_config[
            'materials'] if 'materials' in object_config else []

        print('type = ' + object_type + ', materials = ' +
              json.dumps(material_list))

        step_output = controller.start_scene(scene_configuration)
        object_screenshot = step_output.image_list[0]

        # Shrink and crop the object's screenshot to reduce its size.
        object_screenshot = object_screenshot.resize((300, 200))
        object_screenshot = object_screenshot.crop(
            ImageOps.invert(object_screenshot).getbbox())

        output_file_name = output_folder + generate_output_file_name(
            object_type, material_list)
        object_screenshot.save(fp=output_file_name + '.png')

        pixels = retrieve_image_pixel_list(object_screenshot)

        with open(output_file_name + '.txt', 'w') as output_text_file:
            output_text_file.write(
                json.dumps(PrettyJsonNoIndent(pixels), cls=PrettyJsonEncoder))
Esempio 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)
Esempio n. 7
0
                             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:]

    # TODO: Read name directly from JSON in config file
    config_data['name'] = config_file_name[0:config_file_name.find('.')]

    run_scene(controller, config_data)
Esempio n. 8
0
    # Move towards apple to pick it up
    output = controller.step('MoveLeft')
    output = controller.step('MoveAhead')

    # Should return OUT_OF_REACH
    output = controller.step('PullObject', objectId="apple_a", force=1)

    output = controller.step('RotateLook', rotation=0, horizon=45)

    # Should return SUCCESSFUL
    output = controller.step('PullObject', objectId="apple_a", force=1)
    output = controller.step('PushObject', objectId="apple_a", force=1)


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

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

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

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

    # TODO: Read name directly from JSON in config file
    config_data['name'] = config_file_name[0:config_file_name.find('.')]

    run_scene(controller, config_data)