def test_init_picture_folder_mkdir(init_test):
    output, session_file, session_template = init_test
    init.init_picture_folder(output)
    assert output.is_dir() is True
    assert session_file.is_file() is True
    session_file.unlink()
    output.rmdir()
def test_init_picture_folder_file_exist(init_test):
    output, session_file, session_template = init_test
    output.mkdir()
    with session_file.open(mode='w', encoding='utf-8') as fp:
        json.dump(session_template, fp)
    init.init_picture_folder(output)
    with session_file.open(mode='r', encoding='utf-8') as fp:
        created_template = json.load(fp)
    assert created_template == session_template
    session_file.unlink()
    output.rmdir()
Ejemplo n.º 3
0
def run_manual():
    """
    Run the car in manual mode (control with xbox pad), record pictures and create associated labels. You can use a
    non-existing directory for automatic creation of the picture directory along with its session template.
    """
    args = get_args(str(run_manual.__doc__))
    init.init_picture_folder(picture_dir=args.picture_dir)
    session = ts.TrainingSession(args.delay, output_dir=args.picture_dir)

    print("Are you ready to drive?")
    starting_prompt = """Press 'go' + enter to start.
    Press 'show' + enter to start with the printing mode.
    Press 'q' + enter to totally stop the race.
    """
    racing_prompt = """Press 'q' + enter to totally stop the race\n"""
    keep_going = True
    started = False

    try:
        while keep_going:
            user_input = input(racing_prompt) if started else input(starting_prompt)
            if user_input == "go" and not started:
                print("Race is on.")
                session.run(show_mode=False)
                started = True
            elif user_input == "show" and not started:
                print("Race is on. test mode")
                session.run(show_mode=True)
                started = True
            elif user_input == "q":
                keep_going = False
    except KeyboardInterrupt:
        pass
    finally:
        if session:
            session.joy.close()
            session.camera.close()
        print("Race is over.")
Ejemplo n.º 4
0
        q = Queue()

        starting_prompt = f"""Type 'go' to start.
        Type 'debug=$LEVEL_VAL' to start in debug mode of level LEVEL_VAL (LEVEL_VAL can be {debug_mode_list})
        Type 'q' to totally stop the race.\n"""

        while True:
            user_input = input(starting_prompt)
            if user_input == "go":
                print("Race is on.")
                input_thread = Thread(target=get_input_queue, args=(q,))
                race_thread = Thread(target=race_on.race, kwargs={'debug': 0, 'queue_input': q})
                run_threads(input_thread, race_thread)
                break
            elif user_input[:6] == "debug=":
                init.init_picture_folder(options.output_dir)
                debug_lvl = int(user_input.split("=")[1])
                if debug_lvl not in debug_mode_list:
                    print("'{}' is not a valid debug mode. Please choose between:{}".format(debug_lvl, debug_mode_list))
                else:
                    print("Race is on in Debug mode level {}".format(debug_lvl))
                    input_thread = Thread(target=get_input_queue, args=(q,))
                    race_thread = Thread(target=race_on.race, kwargs={'debug': debug_lvl, 'queue_input': q,
                                                                      'picture_dir': options.output_dir})
                    run_threads(input_thread, race_thread)
                    break
            elif user_input == "q":
                break
    except KeyboardInterrupt:
        pass
    finally: