def cozmo_program(robot: cozmo.robot.Robot):
    current_directory = os.path.dirname(os.path.realpath(__file__))
    #get_in_position(robot)
    sdk_png = os.path.join(current_directory, "circles02.png")
    hello_png = os.path.join(current_directory, "circles3.jpg")

    # load some images and convert them for display cozmo's face
    image_settings = [(sdk_png, Image.BICUBIC), (hello_png, Image.NEAREST)]
    face_images = []
    for image_name, resampling_mode in image_settings:
        image = Image.open(image_name)

        # resize to fit on Cozmo's face screen
        resized_image = image.resize((64, 32), resampling_mode)

        # convert the image to the format used by the oled screen
        face_image = cozmo.oled_face.convert_image_to_screen_data(
            resized_image, invert_image=False)
        face_images.append(face_image)

    # display each image on Cozmo's face for duration_s seconds (Note: this
    # is clamped at 30 seconds max within the engine to prevent burn-in)
    # repeat this num_loops times

    num_loops = 10
    duration_s = 100

    print("Press CTRL-C to quit (or wait %s seconds to complete)" %
          int(num_loops * duration_s))

    for _ in range(num_loops):
        for image in face_images:
            robot.display_oled_face_image(image, duration_s * 1000.0)
            time.sleep(duration_s)
示例#2
0
def alarm_clock(robot: cozmo.robot.Robot):
    '''The core of the alarm_clock program'''
    alarm_time = extract_time_from_args()
    if alarm_time:
        print("Alarm set for %s" % alarm_time)
    else:
        print("No Alarm time provided. Usage example: 'alarm_clock.py 17:23' to set alarm for 5:23 PM. (Input uses the 24-hour clock.)")
    print("Press CTRL-C to quit")
    get_in_position(robot)
    was_before_alarm_time = False
    last_displayed_time = None
    while True:
        current_time = datetime.datetime.now().time()
        do_alarm = False
        if alarm_time:
            is_before_alarm_time = current_time < alarm_time
            do_alarm = was_before_alarm_time and not is_before_alarm_time
            was_before_alarm_time = is_before_alarm_time
        if do_alarm:
            robot.abort_all_actions()
            with robot.perform_off_charger():
                short_time_string = str(current_time.hour) + ":" + str(current_time.minute)
                robot.say_text("Wake up lazy human! it's " + short_time_string).wait_for_completed()
        else:
            if (last_displayed_time is None) or (current_time.second != last_displayed_time.second):
                clock_image = make_clock_image(current_time)
                oled_face_data = cozmo.oled_face.convert_image_to_screen_data(clock_image)
                # display for 1 second
                robot.display_oled_face_image(oled_face_data, 1000.0)
                last_displayed_time = current_time
        time.sleep(0.1)
def cozmo_program(robot: cozmo.robot.Robot):
    robot.move_head(-1)
    robot.move_lift(-1)
    time.sleep(10)
    robot.move_head(1)
    time.sleep(.4)
    robot.play_anim(name="id_poked_giggle").wait_for_completed()
    robot.play_anim(name="id_poked_giggle").wait_for_completed()
    robot.play_anim(name="id_poked_giggle").wait_for_completed()
    image_settings = [
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/cozmosdk.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Cozmo The kid.jpg",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Cozmo The King.jpg",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/hello_world.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/ifttt_gmail.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/ifttt_sports.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/ifttt_stocks.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Glowing_Alien_Authorize.jpg",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Glowing_Geo-Sphere.jpg",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/White-Website-Link-Card.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Joey-in-Lights-Web-Small.gif",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Joey-Chroma-Key.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/3D_Award.jpg",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Pure-White-Transparent-Portrait.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Mogie-Works-2T.png",
         Image.NEAREST),
        ("C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Pure-White-Transparent-Dog.png",
         Image.NEAREST),
    ]
    face_images = []
    for image_name, resampling_mode in image_settings:
        image = Image.open(image_name)
        resized_image = image.resize(cozmo.oled_face.dimensions(),
                                     resampling_mode)
        face_image = cozmo.oled_face.convert_image_to_screen_data(
            resized_image, invert_image=True)
        face_images.append(face_image)
    num_loops = 1
    duration_s = 2.0
    for _ in range(num_loops):
        for image in face_images:
            robot.display_oled_face_image(image, duration_s * 1000.0)
            time.sleep(duration_s)
示例#4
0
def setup_position(robot: cozmo.robot.Robot):
 if robot.lift_height.distance_mm > 45:
    with robot.perform_off_charger():
       robot.set_lift_height(0,20).wait_for_completed()
 resampling_mode = Image.NEAREST
 image_name= "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Cozmo_Primary_Gradient_Logo-2.png"
 image = Image.open(image_name)
 resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode) 
 face_image = cozmo.oled_face.convert_image_to_screen_data(resized_image,invert_image=False) 
 duration_s = 3.0 
 robot.display_oled_face_image(face_image, duration_s * 1000.0) 
 time.sleep(duration_s)
示例#5
0
def singDayman(robot: cozmo.robot.Robot):
    get_in_position(robot)

    # load some images and convert them for display cozmo's face
    image_settings = [("images/sun.png", Image.NEAREST),
                      ("images/nightman.png", Image.NEAREST), ("images/hearts.png", Image.NEAREST)]

    face_images = []
    for image_name, resampling_mode in image_settings:
        image = Image.open(image_name)

        # resize to fit on Cozmo's face screen
        resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)

        # convert the image to the format used by the oled screen
        face_image = cozmo.oled_face.convert_image_to_screen_data(resized_image,
                                                                 invert_image=True)
        face_images.append(face_image)

        
    # getting formatted images out
    sunImg = face_images[0]
    nightManImg = face_images[1]
    heartsImg = face_images[2]


    robot.say_text("day man", duration_scalar= .5,in_parallel=True).wait_for_completed()
        
##    robot.play_anim_trigger(Surprise).wait_for_completed()
    harmony(robot)
    
    a1 = robot.say_text("fighter of the night man", duration_scalar= .7,in_parallel=True)
    a2 = robot.display_oled_face_image(nightManImg, .5 * 1000.0, in_parallel=True)

    syncThisShit([a1,a2], 0 )

    harmony(robot)
    
    a3 = robot.say_text("champion of the sun", duration_scalar= .7,in_parallel=True)
    a4 = robot.display_oled_face_image(sunImg, .5 * 1000.0, in_parallel=True)

    syncThisShit([a3,a4], 0 )

    harmony(robot)

    a5 = robot.say_text("master of karate and friendship for everyone!", duration_scalar= .7,in_parallel=True)
    a6 = robot.display_oled_face_image(heartsImg, 1.5 * 1000.0, in_parallel=True)

    syncThisShit([a5,a6], 0 )
示例#6
0
def example3_abort_one_action(robot: cozmo.robot.Robot):
    cozmo.logger.info("----------------------------------------")
    cozmo.logger.info("Example 3: Abort some parallel actions.")
    cozmo.logger.info("Start multiple parallel actions:")
    action1 = robot.set_lift_height(0.0, in_parallel=True)
    action2 = robot.set_head_angle(cozmo.robot.MIN_HEAD_ANGLE,
                                   duration=6.0,
                                   in_parallel=True)
    action3 = robot.drive_straight(distance_mm(75),
                                   speed_mmps(25),
                                   should_play_anim=False,
                                   in_parallel=True)
    action4 = robot.display_oled_face_image(
        face_image, 30000.0)  # Note: face image is in_parallel by default
    # Lift-lowering is aborted immediately
    action1.abort(log_abort_messages=True)
    # Head-lowering is aborted shortly afterwards
    time.sleep(0.1)
    action2.abort(log_abort_messages=True)
    # Image on Cozmo's face is aborted another 2 seconds later
    time.sleep(2)
    action4.abort(log_abort_messages=True)
    # We wait for the one remaining action to complete
    action3.wait_for_completed()
    # Only action3 should succeed (as long as Cozmo had enough space to drive)
    cozmo.logger.info("action1 = %s", action1)
    cozmo.logger.info("action2 = %s", action2)
    cozmo.logger.info("action3 = %s", action3)
    cozmo.logger.info("action4 = %s", action4)
示例#7
0
def cozmo_face_mirror(robot: cozmo.robot.Robot):
    robot.camera.image_stream_enabled = True
    get_in_position(robot)
    face_dimensions = cozmo.oled_face.SCREEN_WIDTH, cozmo.oled_face.SCREEN_HALF_HEIGHT
    print("Press CTRL-C to quit")
    while True:
        duration_s = 0.1
        latest_image = robot.world.latest_image
        if latest_image is not None:
            # Scale the camera image down to fit on Cozmo's face
            resized_image = latest_image.raw_image.resize(
                face_dimensions, Image.BICUBIC)
            resized_image = resized_image
            pixel_threshold = calc_pixel_threshold(resized_image)
            screen_data = cozmo.oled_face.convert_image_to_screen_data(
                resized_image, pixel_threshold=pixel_threshold)
            robot.display_oled_face_image(screen_data, duration_s * 1000.0)
        time.sleep(duration_s)
示例#8
0
def cozmo_program(robot: cozmo.robot.Robot):
    setup_position(robot)
    raw_images = [('../images/animal.jpg', Image.BICUBIC),
                  ('../images/male.jpg', Image.BICUBIC),
                  ('../images/star.jpg', Image.BICUBIC)]
    face_images = []
    for name, mode in raw_images:
        img = Image.open(name)
        resize = img.resize(cozmo.oled_face.dimensions(), mode)
        face = cozmo.oled_face.convert_image_to_screen_data(resize,
                                                            invert_image=True)
        face_images.append(face)

    num_loops = 10
    duration = 2
    for _ in range(num_loops):
        for image in face_images:
            robot.display_oled_face_image(image, duration * 1000.0)
            time.sleep(duration)
示例#9
0
def cozmo_boost_face(robot: cozmo.robot.Robot):
    setup_position(robot)
    raw_images = [
        ('C:\\Users\\Alexa\\OneDrive\\Desktop\\Year 10\\EPM\\logo.jpg',
         Image.BICUBIC)
    ]
    face_images = []
    for name, mode in raw_images:
        img = Image.open(name)
        resize = img.resize(cozmo.oled_face.dimensions(), mode)
        face = cozmo.oled_face.convert_image_to_screen_data(resize,
                                                            invert_image=True)
        face_images.append(face)

    num_loops = 10
    duration = 2
    for _ in range(num_loops):
        for image in face_images:
            robot.display_oled_face_image(image, duration * 1000.0)
            time.sleep(duration)
示例#10
0
        def cozmo_face_response(robot: cozmo.robot.Robot):
            print("Running cozmo face response")
            try:

                robot.move_lift(-3)
                robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE).wait_for_completed()
                robot.enable_facial_expression_estimation(True)
                face = None
                face = robot.world.wait_for_observed_face(timeout=30)
                if face and face.is_visible:
                    robot.set_all_backpack_lights(cozmo.lights.blue_light)
                else:
                    robot.set_backpack_lights_off()
                print(face.expression)
                print(face.name)
                print(face.face_id)
                print(face.expression_score)
                # Cozmo responds based on happy facial expression (transitioned from negative tone)
                # and a smiley face is displayed on his OLED screen
                face_response = f"I see your face with an {face.expression} expression. But I think you look happy!"
                robot.say_text(face_response).wait_for_completed()
                if face.expression == 'happy':
                    robot.say_text(f"Yay I am so glad you have a {face.expression} face!").wait_for_completed()
                # time.sleep(.1)
                image = Image.open("cozmo_smiley_2.jpg")
                image = image.resize(cozmo.oled_face.dimensions(), Image.NEAREST)
                image = cozmo.oled_face.convert_image_to_screen_data(image)
                seconds = 10

                for i in range(seconds):
                    robot.display_oled_face_image(image, 1000.0)
                    time.sleep(1.0)

            except asyncio.TimeoutError:
                print("did not find a face")
                pass
示例#11
0
def cozmo_program(robot: cozmo.robot.Robot):
    time.sleep(10)
    robot.move_head(-1)
    robot.move_lift(-1)
    time.sleep(5)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Cozmo_Primary_Gradient_Logo-2.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/cozmosdk.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/hello_world.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Cozmo The kid.jpg"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Cozmo The King.jpg"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/ifttt_gmail.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/ifttt_sports.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/ifttt_stocks.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Star-Two-Tone-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Planet-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Space-Station-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/UFO-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Alien-Head-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Atom-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Nuke-Symble-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Round-Squaer-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Squaers-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Hexago-Pattern-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Heart-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Diamond-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Club-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Spade-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Tittle Mask.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Pure-White-Transparent-Skull-Mask.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Yen-Yan-Shape-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Joey-Tittle-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/3D_Award.jpg"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=True)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Award-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Joey-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Pure-White-Transparent-Portrait.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Mogie-Works-2T.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Youtube Thumbnail.jpg"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Pure-White-Transparent-Dog.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Teardrop-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Spaceuphoria-Logo-Chroma-Ke.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Mascot-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Clear-Website-Link-Card-Mas.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/Spaceuphoria-Link-Chroma-Ke.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    resampling_mode = Image.NEAREST
    image_name = "C:/Users/MI700T/Documents/cozmo_sdk_examples_1.2.1/face_images/The-Joshua-Logo-Chroma-Key.png"
    image = Image.open(image_name)
    resized_image = image.resize(cozmo.oled_face.dimensions(), resampling_mode)
    face_image = cozmo.oled_face.convert_image_to_screen_data(
        resized_image, invert_image=False)
    duration_s = 3.0
    robot.display_oled_face_image(face_image, duration_s * 1000.0)
    time.sleep(duration_s)
    robot.move_head(-1)
    time.sleep(20)
示例#12
0
async def run(robot: cozmo.robot.Robot):
    '''The run method runs once the Cozmo SDK is connected.'''

    # add annotators for battery level and ball bounding box
    robot.world.image_annotator.add_annotator('battery', BatteryAnnotator)
    robot.world.image_annotator.add_annotator('ball', BallAnnotator)

    try:
        await robot.set_lift_height(0.0, in_parallel=True).wait_for_completed()
        await robot.set_head_angle(degrees(-17),
                                   in_parallel=True).wait_for_completed()

        focalLength = 132.7
        actualBallHeight = 40
        isNotFinished = 1
        state = "initial"
        prevBall = [0, 0, 0]
        robot.set_robot_volume(0.3)
        myCozmo = cozmoFSM("myCozmo")

        while isNotFinished:
            oled_face_data = cozmo.oled_face.convert_image_to_screen_data(
                make_text_image(myCozmo.state, 8, 6, _clock_font))
            robot.display_oled_face_image(oled_face_data,
                                          1000.0,
                                          in_parallel=True)
            # get camera image
            event = await robot.world.wait_for(
                cozmo.camera.EvtNewRawCameraImage, timeout=30)

            # convert camera image to opencv format
            opencv_image = cv2.cvtColor(np.asarray(event.image),
                                        cv2.COLOR_RGB2GRAY)
            height, width = opencv_image.shape[:2]

            # look for ball
            ball = find_ball.find_ball(opencv_image)

            if ball[0] != 0 or ball[1] != 0 or ball[2] != 0:

                ballDetected = 1
                prevBall = ball
            else:
                ball = None
                ballDetected = 0
            BallAnnotator.ball = ball

            if myCozmo.state == "initial":
                print("Starting state: initial")
                # print('\a')

                if ballDetected == 1:
                    print("Previous state: initial, new state: drive")
                    myCozmo.ballDetected()

                else:
                    print("Previous state: initial, new state: search")
                    myCozmo.ballLost()

                # print('\a')

            elif myCozmo.state == "search":

                # robot.stop_all_motors()

                if ballDetected == 1:
                    robot.stop_all_motors()
                    print("Previous state: search, new state: drive")
                    myCozmo.ballDetected()
                    # print('\a')
                    continue
                else:
                    if prevBall[0] != 0 or prevBall[1] != 0 or prevBall[2] != 0:
                        offset = width / 2 - prevBall[0]
                        if offset < 0:
                            await robot.drive_wheels(35, -35)
                        else:
                            await robot.drive_wheels(-35, 35)
                    else:
                        await robot.drive_wheels(-35, 35)

            elif myCozmo.state == "drive":

                if not ballDetected:
                    print("Previous state: drive, new state: search")
                    myCozmo.ballLost()
                    # print('\a')
                    continue
                if ballDetected:
                    distance = actualBallHeight * focalLength / ball[2]

                    leftConst = 70
                    rightConst = 70

                    offset = width / 2 - ball[0]

                    leftSpeed = leftConst - 0.333 * offset
                    rightSpeed = rightConst + 0.333 * offset

                    if distance < 54 or ball[2] > 98:

                        print("Previous state: drive, new state: hit ball")
                        myCozmo.ballInReach()
                        # print(state)
                        # print('\a')
                    else:
                        await robot.drive_wheels(leftSpeed, rightSpeed)

            elif myCozmo.state == "hitball":
                await robot.set_lift_height(
                    0.5, in_parallel=True).wait_for_completed()
                await robot.set_lift_height(
                    0.1, in_parallel=True).wait_for_completed()
                print("Previous state: hit ball, new state: drive")
                myCozmo.ballDetected()
                # print('\a')

                # isNotFinished = 0

    except KeyboardInterrupt:
        print("")
        print("Exit requested by user")
    except cozmo.RobotBusy as e:
        print(e)
示例#13
0
def cozmo_program(robot: cozmo.robot.Robot):

    global face_images
    global gaze_type
    global gaze_side

    get_in_position(robot)

    # load some images and convert them for display cozmo's face

    setup_images("eyes_image/%s.png" % (gaze_type))
    setup_images("eyes_image/%s.png" % (gaze_type))

    for i in range(1, 7, 1):
        #print("close %d" %i)
        setup_images("%s/%s%d.png" % (gaze_type, gaze_side, i))
    for i in range(6, 0, -1):
        #print("open %d" %i)
        setup_images("%s/%s%d.png" % (gaze_type, gaze_side, i))

    # display each image on Cozmo's face for duration_s seconds (Note: this
    # is clamped at 30 seconds max within the engine to prevent burn-in)
    # repeat this num_loops times
    num_loops = 2  # Increase the number of blinks here. This is 5 blinks in a loop
    duration_s = 0.02  # Increase time here to make it slower

    #robot.play_audio(cozmo.audio.AudioEvents.Sfx_Flappy_Increase)

    print("Press CTRL-C to quit (or wait %s seconds to complete)" %
          int(num_loops * duration_s))
    ts = time.time()
    print(ts)
    #for _ in range(num_loops):
    face_to_follow = None
    while True:
        turn_action = None
        if face_to_follow:
            # start turning towards the face
            turn_action = robot.turn_towards_face(face_to_follow,
                                                  in_parallel=True)
            robot.display_oled_face_image(face_images[1],
                                          5000.0,
                                          in_parallel=True)

        if not (face_to_follow and face_to_follow.is_visible):
            # find a visible face, timeout if nothing found after a short while
            robot.display_oled_face_image(face_images[1],
                                          10000.0,
                                          in_parallel=True)
            try:
                robot.display_oled_face_image(face_images[1],
                                              10000.0,
                                              in_parallel=True)
                face_to_follow = robot.world.wait_for_observed_face(timeout=30)
            except asyncio.TimeoutError:
                print("Didn't find a face")
                robot.display_oled_face_image(face_images[1],
                                              10000.0,
                                              in_parallel=True)
                #return

        if turn_action:
            # Complete the turn action if one was in progress
            turn_action.wait_for_completed()

        time.sleep(.1)

        for image in face_images:
            robot.display_oled_face_image(image, duration_s * 1000.0)
            time.sleep(duration_s)
        robot.display_oled_face_image(face_images[-1], 2000.0)
        time.sleep(2)
        if keyboard.is_pressed("t"):
            print("You pressed t")
            ts = time.time()
            print(ts)
        if keyboard.is_pressed("w"):
            print("You pressed w")
            ts = time.time()
            print(ts)
            action1 = robot.say_text("Yeaaaaaaaaaaaaaahhh",
                                     voice_pitch=1,
                                     in_parallel=True)
            action2 = robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE,
                                           in_parallel=True)
            action3 = robot.set_lift_height(0.0, in_parallel=True)
            action4 = robot.display_oled_face_image(face_images[6],
                                                    5000.0,
                                                    in_parallel=True)
            action5 = robot.turn_in_place(degrees(360), in_parallel=True)
            break
        if keyboard.is_pressed("l"):
            print("You pressed l")
            ts = time.time()
            print(ts)
            action1 = robot.say_text("Nooooooooh",
                                     voice_pitch=-1,
                                     in_parallel=True)
            action2 = robot.set_head_angle(cozmo.robot.MIN_HEAD_ANGLE,
                                           in_parallel=True)
            action3 = robot.set_lift_height(1.0, in_parallel=True)
            action4 = robot.display_oled_face_image(face_images[6],
                                                    5000.0,
                                                    in_parallel=True)
            action5 = robot.drive_straight(distance_mm(-50),
                                           speed_mmps(10),
                                           in_parallel=True)
            break

    robot.display_oled_face_image(face_images[6], 5000.0)

    while True:
        for image in face_images:
            robot.set_lift_height(0.0, in_parallel=True)
            robot.display_oled_face_image(image, duration_s * 1000.0)
            time.sleep(duration_s)
        robot.display_oled_face_image(face_images[-1], 2000.0)
        time.sleep(2)
        if keyboard.is_pressed("q"):
            print("You pressed q")
            ts = time.time()
            print(ts)
            break
示例#14
0
async def main(robot: cozmo.robot.Robot):
    #initialize the machine state
    state_machine = CozmoStates()
    state_machine.set_cozmo_coords(robot.pose.position)
    #event handlers
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            state_machine.handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            state_machine.handle_object_disappeared)

    #are we looking for cube 2?
    look_for_cube_2 = False

    #cube1 definition
    await robot.world.define_custom_cube(
        CustomObjectTypes.CustomType00,
        state_machine.cube_arr[state_machine.current_cube], 44, 30, 30, False)

    while True:
        print('######looping#####')
        #get camera image
        event = await robot.world.wait_for(cozmo.camera.EvtNewRawCameraImage,
                                           timeout=30)

        #refresh the coords
        state_machine.set_cozmo_coords(robot.pose)

        #triggers when we want the first cube
        if state_machine.current_cube == 1:
            print('cube = 1')
            if state_machine.cube_coords == False:
                state_machine.cube_not_found()
            else:
                state_machine.calc_goto_coords()
                if (state_machine.calc_dist_from_cozmo() >
                        state_machine.proximity_distance):
                    if state_machine.goto_y >= 20:
                        state_machine.found_cube_left()
                    elif state_machine.goto_y < -20:
                        state_machine.found_cube_right()
                    else:
                        print('Cube ahead!')
                        state_machine.found_cube_ahead()
                else:
                    robot.stop_all_motors()
                    state_machine.on_enter_near_cube()

        #triggers when we want cube 2
        if state_machine.current_cube == 2:
            print('cube = 2')
            #reset the data if this is the first instance
            if look_for_cube_2 == False:
                robot.stop_all_motors()
                print('\nPART 1 DONE! GO TO CUBE 2\n')
                await robot.say_text('Look for cube 2',
                                     in_parallel=True).wait_for_completed()
                state_machine.set_cozmo_coords(robot.pose)
                state_machine.calc_goto_coords()
                print(state_machine.calc_dist_from_cozmo())
                look_for_cube_2 = True
                state_machine.cube_not_found()
                state_machine.cube_coords = False

                #define the second cube
                await robot.world.define_custom_cube(
                    CustomObjectTypes.CustomType00,
                    state_machine.cube_arr[state_machine.current_cube], 44, 30,
                    30, False)

            #where does cozmo need to move?
            if (state_machine.cube_coords == False) or (state_machine.see_cube
                                                        == False):
                if state_machine.get_current_state() == 'drive_straight':
                    if state_machine.goto_y < state_machine.mid_screen:
                        state_machine.found_cube_left()
                    elif state_machine.goto_y < -20:
                        state_machine.found_cube_right()
                    else:
                        print('Cube ahead!')
                        state_machine.found_cube_ahead()
                else:

                    state_machine.cube_not_found()
            #cozmo sees cube
            else:
                state_machine.calc_goto_coords()
                if (state_machine.calc_dist_from_cozmo() >
                        state_machine.proximity_distance):
                    if state_machine.goto_y < -20:
                        state_machine.found_cube_right()
                    elif state_machine.goto_y > 20:
                        state_machine.found_cube_left()
                    else:
                        state_machine.found_cube_ahead()
                else:
                    robot.stop_all_motors()
                    state_machine.on_enter_near_cube()

        #update states
        last_state = state_machine.get_last_state()
        current_state = state_machine.get_current_state()

        #was there a state transition? WIll only trigger if a cube was detected
        if last_state is not current_state:
            #audio cue, takes a long time, need to comment out
            #await robot.say_text('b', in_parallel = True).wait_for_completed()
            #print the state transition to terminal & reset the state
            print('Last state: ' + last_state)
            print('Current state: ' + current_state)
            print('Coords to cube: ')
            #some reason, cant print this with the Coords to cube: print statement
            print(state_machine.calc_goto_coords())
            #update the state
            state_machine.set_last_state(current_state)

            # the anki victor text stuff, taken and modified
            #
            faceImage = Image.new('RGBA', (128, 64), (0, 0, 0, 255))
            dc = ImageDraw.Draw(faceImage)
            try:
                font_file = ImageFont.truetype('arial.ttf', 20)
            except IOError:
                print('IoError')
                try:
                    font_file = ImageFont.truetype(
                        '/usr/share/fonts/noto/NotoSans-Medium.ttf', 20)
                except IOError:
                    print('IoError 2')
                    pass
            dc.text((0, 0),
                    current_state,
                    fill=(255, 255, 255, 255),
                    font=font_file)
            screen_data = cozmo.oled_face.convert_image_to_screen_data(
                faceImage)
            robot.display_oled_face_image(screen_data,
                                          600000000.0,
                                          in_parallel=True)

        #update how robot should move
        await robot.drive_wheels(state_machine.get_l_motor_speed(),
                                 state_machine.get_r_motor_speed())
示例#15
0
async def run(robot: cozmo.robot.Robot):
    '''The run method runs once the Cozmo SDK is connected.'''

    #add annotators for battery level and ball bounding box
    robot.world.image_annotator.add_annotator('battery', BatteryAnnotator)
    robot.world.image_annotator.add_annotator('ball', BallAnnotator)

    try:
        state = State()
        robot.display_oled_face_image(image(state.cur),
                                      20000,
                                      in_parallel=True)
        trigger = True
        isBallFound = False
        isRobotAtBall = False
        left = False
        right = False
        robot.set_head_angle(radians(-0.23), in_parallel=True)
        # prevPos = None
        # direction = None
        while trigger:

            #get camera image
            event = await robot.world.wait_for(
                cozmo.camera.EvtNewRawCameraImage, timeout=30)

            #convert camera image to opencv format
            opencv_image = cv2.cvtColor(np.asarray(event.image),
                                        cv2.COLOR_RGB2GRAY)
            h, w = opencv_image.shape
            # print(w)
            #find the ball
            ball = find_ball.find_ball(opencv_image)
            distance = calcDistance(ball)
            # if prevPos

            #set annotator ball
            BallAnnotator.ball = ball
            BallAnnotator.distance = distance
            # BallAnnotator.direction = direction
            if state.isCurState("START"):
                robot.set_lift_height(0, in_parallel=True)
                # robot.display_oled_face_image(image(state.cur), 10.0, in_parallel=True)

                #spin around and search for ball
                #Make a sound and print something on screen

                # display for 1 second

                if ball is None:
                    await robot.drive_wheels(17, -17)
                else:
                    await robot.drive_wheels(0, 0, 0.5)
                    state.next()
                    robot.display_oled_face_image(image(state.cur),
                                                  20000,
                                                  in_parallel=True)

            if state.isCurState("TRAVELING"):
                # robot.display_oled_face_image(image(state.cur), 10.0, in_parallel=True)
                #Print and sound off
                # move towards ball
                if distance is None:
                    if left:
                        lspeed = 5
                        rspeed = 2 * base
                    if right:
                        lspeed = 2 * base
                        rspeed = 5
                    await robot.drive_wheels(lspeed, rspeed)
                if distance is not None:
                    if distance > 85:
                        base = 25
                        adj = (ball[0] - (w / 2)) / (distance**0.5)
                        # print(distance)
                        # print("adj:", adj)
                        left = adj < -0.75
                        right = adj > 0.75

                        if left:
                            lspeed = base
                            rspeed = base - adj
                            # print("LEFT")
                        elif right:
                            lspeed = base + adj
                            rspeed = base
                            # print("RIGHT")
                        else:
                            lspeed = base + 20
                            rspeed = base + 20

                        await robot.drive_wheels(lspeed, rspeed)
                    else:
                        state.next()
                        robot.display_oled_face_image(image(state.cur),
                                                      20000,
                                                      in_parallel=True)

            if state.isCurState("END"):
                # robot.display_oled_face_image(image(state.cur), 10.0, in_parallel = True)
                #tap ball
                #Screen and sound off
                robot.set_lift_height(1, in_parallel=True).wait_for_completed()
                robot.set_lift_height(0, in_parallel=True).wait_for_completed()
                if distance is None:
                    if left or right:
                        state.next()
                        robot.display_oled_face_image(image(state.cur),
                                                      20000,
                                                      in_parallel=True)
                elif distance > 85:
                    state.next()
                    robot.display_oled_face_image(image(state.cur),
                                                  20000,
                                                  in_parallel=True)

            if state.isCurState("PAUSE"):
                #pause for a moment
                await robot.drive_wheels(0, 0, 0.05)
                state.next()
                robot.display_oled_face_image(image(state.cur),
                                              100,
                                              in_parallel=True)

    except KeyboardInterrupt:
        print("")
        print("Exit requested by user")
    except cozmo.RobotBusy as e:
        print(e)