Пример #1
0
def dock_with_cube(robot: cozmo.robot.Robot):
    cube1 = robot.world.get_light_cube(LightCube1Id)

    robot.set_head_angle(degrees(44.0)).wait_for_completed()

    robot.say_text("All right kids. Who's thirsty").wait_for_completed()

    robot.set_head_angle(degrees(0.0)).wait_for_completed()

    print("Cozmo is waiting until he sees a cube.")
    robot.world.wait_for_observed_light_cube()

    print("Cozmo found a cube, and will now attempt to dock with it:")
    robot.dock_with_cube(cube1,
                         approach_angle=cozmo.util.degrees(0),
                         num_retries=2).wait_for_completed()
Пример #2
0
def cozmo_program(coz: cozmo.robot.Robot):

    # look for all three cubes
    lookaround = coz.start_behavior(
        cozmo.behavior.BehaviorTypes.LookAroundInPlace)
    cubes = coz.world.wait_until_observe_num_objects(
        num=1, object_type=cozmo.objects.LightCube, timeout=60)
    lookaround.stop()

    if len(cubes) < 1:
        print('Coulnd' 't locate cube.. aborting')

    elif len(cubes) == 1:
        print('found cube... proceeding')

        #drive to first cube
        cube = cubes[0]
        cube.set_lights(cozmo.lights.red_light)
        coz.say_text('Cube found').wait_for_completed()

        action = coz.dock_with_cube(cube,
                                    approach_angle=cozmo.util.degrees(0),
                                    num_retries=2)
        action.wait_for_completed()

        if action.has_succeeded:
            cube.set_lights(cozmo.lights.red_light)
def intent_pass_butter(robot: cozmo.robot.Robot):
    robot.set_lift_height(height=0.7).wait_for_completed()
    robot.set_head_angle(cozmo.robot.MIN_HEAD_ANGLE).wait_for_completed()

    robot.say_text('oh my god').wait_for_completed()

    robot.set_lift_height(height=0.0).wait_for_completed()
    robot.set_head_angle(cozmo.robot.MAX_HEAD_ANGLE).wait_for_completed()

    look_around = robot.start_behavior(
        cozmo.behavior.BehaviorTypes.LookAroundInPlace)
    cube = None

    try:
        cube = robot.world.wait_for_observed_light_cube(timeout=30)
    except asyncio.TimeoutError:
        robot.say_text('I cannot find the butter. I have failed my purpose.')
        robot.play_anim_trigger(
            cozmo.anim.Triggers.CubeMovedUpset).wait_for_completed()
    finally:
        look_around.stop()

    if cube:
        action = robot.dock_with_cube(cube,
                                      approach_angle=degrees(0),
                                      num_retries=3)
        action.wait_for_completed()

        robot.drive_straight(distance_mm(150),
                             speed_mmps(50)).wait_for_completed()
        robot.drive_straight(distance_mm(-150),
                             speed_mmps(50)).wait_for_completed()
        robot.say_text('oh my god', duration_scalar=1.8).wait_for_completed()
Пример #4
0
async def dock_with_cube(robot: cozmo.robot.Robot):
    await robot.set_head_angle(degrees(-5.0)).wait_for_completed()

    print("Cozmo is waiting until he sees a cube.")
    cube = await robot.world.wait_for_observed_light_cube()

    print("Cozmo found a cube, and will now attempt to dock with it:")
    # Cozmo will approach the cube he has seen
    # using a 180 approach angle will cause him to drive past the cube and approach from the opposite side
    # num_retries allows us to specify how many times Cozmo will retry the action in the event of it failing
    action = robot.dock_with_cube(cube, approach_angle=cozmo.util.degrees(180), num_retries=2)
    await action.wait_for_completed()
    print("result:", action.result)
Пример #5
0
def dock_with_cube(robot: cozmo.robot.Robot):
    robot.say_text("This is dock with cube.").wait_for_completed()
    time.sleep(2)

    #this puts his head in the right position
    robot.move_lift(-1)
    time.sleep(1)
    robot.move_head(-0.1)
    time.sleep(0.1)
    cube1 = robot.world.get_light_cube(LightCube1Id)

    robot.say_text("All right kids. Who's thirsty").wait_for_completed()

    print("Cozmo is waiting until he sees a cube.")
    robot.world.wait_for_observed_light_cube()

    print("Cozmo found a cube, and will now attempt to dock with it:")
    cube1 = robot.world.get_light_cube(LightCube1Id)
    robot.dock_with_cube(cube1,
                         approach_angle=cozmo.util.degrees(0),
                         num_retries=2).wait_for_completed()
    time.sleep(3)
Пример #6
0
async def dock_with_cube(robot: cozmo.robot.Robot):
    talkie(robot)
    await robot.set_head_angle(degrees(44.0)).wait_for_completed()

    await robot.say_text("All right kids. Who's thirsty").wait_for_completed()

    await robot.set_head_angle(degrees(0.0)).wait_for_completed()

    print("Cozmo is waiting until he sees a cube.")
    cubeMy = await robot.world.wait_for_observed_light_cube()

    print("Cozmo found a cube, and will now attempt to dock with it:")
    action = robot.dock_with_cube(cubeMy,
                                  approach_angle=cozmo.util.degrees(0),
                                  num_retries=2)
    await action.wait_for_completed()
Пример #7
0
def cozmo_program(robot: cozmo.robot.Robot):
    # create an origin point where Cozmo's charger is. When he picks up objects he will return here.
    # If the robot was on the charger, drive them forward and clear of the charger
    if robot.is_on_charger:
        robot.drive_off_charger_contacts().wait_for_completed()
        robot.drive_straight(distance_mm(100), speed_mmps(50)).wait_for_completed()
        robot.move_lift(-3)
        robot.turn_in_place(degrees(180)).wait_for_completed()
        robot.set_head_angle(degrees(0)).wait_for_completed()
        time.sleep(0.5)

    # try to find the charger
    charger = None

    if robot.world.charger:
        if robot.world.charger.pose.is_comparable(robot.pose):
            # Cozmo knows where the charger is
            charger = robot.world.charger
        else:
            pass

    if not charger:
        # Tell Cozmo to look around for the charger
        look_around = robot.start_behavior(cozmo.behavior.BehaviorTypes.LookAroundInPlace)
        try:
            charger = robot.world.wait_for_observed_charger(timeout=30)
        except asyncio.TimeoutError:
            print("Didn't see the charger")
        finally:
            look_around.stop()

    origin = charger
    robot.go_to_object(origin, 70)

    # on boot up show loading screen

    # locate all cubes
    look_around = robot.start_behavior(cozmo.behavior.BehaviorTypes.LookAroundInPlace)

    look_around.stop()

    # define light colours
    red_light = cozmo.lights.Light(cozmo.lights.Color(rgb=(255, 0, 0)))
    blue_light = cozmo.lights.Light(cozmo.lights.Color(rgb=(0, 0, 255)))
    yellow__light = cozmo.lights.Light(cozmo.lights.Color(rgb=(255, 255, 0)))

    # tag each cube found as a different colour
    red_cube = robot.world.get_light_cube(LightCube1Id)
    blue_cube = robot.world.get_light_cube(LightCube2Id)
    yellow_cube = robot.world.get_light_cube(LightCube3Id)

    red_cube.set_lights(red_light)
    blue_cube.set_lights(blue_light)
    yellow_cube.set_lights(yellow__light)

    # Pass found objects to GUI for selection

    robot.say_text("Ready when you are").wait_for_completed()

    # user selects which cube they want
    robot.say_text("When you are sure that's the one you want. Press the tick, if you want to select another, "
                   "just press on another object").wait_for_completed()

    # Wait for conformation
    robot.say_text("OK, I'll be right back.").wait_for_completed()

    # cozmo goes and gets cube
    action = robot.go_to_object(red_cube, distance_mm(70.0))
    action.wait_for_completed()
    action = robot.dock_with_cube(red_cube, approach_angle=cozmo.util.degrees(0), num_retries=2)
    action.wait_for_completed()
    action = robot.pickup_object(red_cube, num_retries=3)
    action.wait_for_completed()
    robot.say_text("Got it").wait_for_completed()

    # Cozmo returns cube to user
    action = robot.go_to_object(origin, 70)
    action.wait_for_completed()
    robot.say_text("Is this one the right one?").wait_for_completed()

    # Object is confirmed

    robot.say_text("Yay")

    # get dat fist bump
    robot.say_text("Do you want me to fetch anything else")

    # user says no

    # cozmo returns to base

    # wait for five minutes of inactivity

    robot.say_text("I'm going to have a nap now, let me know if you need anything?")
Пример #8
0
def cozmo_program(robot: cozmo.robot.Robot):

    # Définir la couleur jaune
    light_yellow = Light(Color(name='yellow', rgb=(255, 255, 0)))
    light_cyan = Light(Color(name='cyan', rgb=(0, 255, 255)))

    # Tourner jusqu'a détecter un visage
    lookaround = robot.start_behavior(cozmo.behavior.BehaviorTypes.FindFaces)
    face = robot.world.wait_for_observed_face()
    lookaround.stop()

    # Jouer l'animation du Chien
    robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLabDog).wait_for_completed()

    # Se connecter aux différents cubes et les faire clignoter en jaune
    robot.world.get_light_cube(LightCube1Id).set_lights(light_yellow.flash())
    robot.world.get_light_cube(LightCube2Id).set_lights(light_yellow.flash())
    robot.world.get_light_cube(LightCube3Id).set_lights(light_yellow.flash())

    # Attendre jusqu'a ce qu'un cube soit touché
    target = robot.world.wait_for(cozmo.objects.EvtObjectTapped)
    cube = robot.world.get_light_cube(target.obj.cube_id)
    robot.world.get_light_cube(LightCube1Id).set_lights(light_cyan)
    robot.world.get_light_cube(LightCube2Id).set_lights(light_cyan)
    robot.world.get_light_cube(LightCube3Id).set_lights(light_cyan)
    cube.set_lights(light_yellow)

    # Tourner jusqu'a détecter le cube
    found = False
    lookaround = robot.start_behavior(
        cozmo.behavior.BehaviorTypes.LookAroundInPlace)
    while found is False:
        tcube = robot.world.wait_for_observed_light_cube(
            include_existing=False)
        found = tcube is cube
    lookaround.stop()

    # Rammasser le cube
    robot.dock_with_cube(cube,
                         approach_angle=cozmo.util.degrees(180),
                         num_retries=3).wait_for_completed()
    robot.move_lift(0.2)

    # Tourner jusqu'a détecter de nouvea le visage précédent
    found = False
    lookaround = robot.start_behavior(cozmo.behavior.BehaviorTypes.FindFaces)
    while found is False:
        tface = robot.world.wait_for_observed_face()
        found = tface is face
    lookaround.stop()

    # Se déplacer vers le visage poser le cube
    robot.drive_straight(distance_mm(200), speed_mmps(50)).wait_for_completed()
    robot.move_lift(-3)
    robot.move_lift(0)
    robot.drive_straight(distance_mm(-100),
                         speed_mmps(50)).wait_for_completed()
    robot.play_anim_trigger(
        cozmo.anim.Triggers.CodeLabDog).wait_for_completed()