예제 #1
0
def cozmo_program(robot: cozmo.robot.Robot):

    global isTakingPicture
    # creates a local directory if its not already there
    if os.path.exists('photos'):
        shutil.rmtree('photos')
    if not os.path.exists('photos'):
        os.makedirs('photos')

    #mute Cozmo while testing. Leave it in case we want it later.
    robot.say_text(f"Somebody just ordered the {targetObject}. I'll go get it for him.").wait_for_completed()
    # reset Cozmo's arms and head
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()

    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)


    while not discoveredObject:
        isTakingPicture = False
        robot.turn_in_place(degrees(90)).wait_for_completed()
        isTakingPicture = True
        time.sleep(5)


    isTakingPicture = False

    if discoveredObject:

        # acknowledge its been found
        robot.say_text(f"Oh yay! I've found {targetObject}").wait_for_completed()
        # robot.play_anim_trigger(cozmo.anim.Triggers.MajorWin).wait_for_completed()

        # go to pick up obj
        cozmo.run_program(get_object(robot))
def cozmo_program(robot: cozmo.robot.Robot):
    global toy
    toy = sys.argv[1]
    global takePicture
    if os.path.exists('photos'):
        shutil.rmtree('photos')
    if not os.path.exists('photos'):
        os.makedirs('photos')
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()

    #time.sleep(10)

    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    while not foundToy:
        takePicture = False
        robot.turn_in_place(degrees(45)).wait_for_completed()
        takePicture = True
        time.sleep(2)
    takePicture = False

    if foundToy:
        print('Found toy: ' + toy + ' !!!')
        robot.drive_straight(distance_mm(200),
                             speed_mmps(300)).wait_for_completed()
        robot.say_text("I have found the " + toy).wait_for_completed()
        anim = robot.play_anim_trigger(
            cozmo.anim.Triggers.MajorWin).wait_for_completed()
예제 #3
0
def cozmo_program(robot: cozmo.robot.Robot):

    # Make sure Cozmo's head and arm are at reasonable levels
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()

    robot.say_text(
        f"I'm going to take photos of {sys.argv[1]}").wait_for_completed()

    # Set directory to the Category that Cozmo is going to photograph
    global directory
    directory = sys.argv[1]
    if not os.path.exists('data'):
        os.makedirs('data')
    if not os.path.exists(f'data/{directory}'):
        os.makedirs(f'data/{directory}')

    # Anytime Cozmo sees a "new" image, take a photo
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    # Initial photo sesh
    robot.drive_straight(distance_mm(-200), speed_mmps(100), False, False,
                         0).wait_for_completed()
    take_photos(robot)

    # Get all the angles
    #for i in range(3):
    #    move_to_next_side(robot)

    # And we're done here
    robot.say_text("All done!").wait_for_completed()
    robot.play_anim_trigger(cozmo.anim.Triggers.MajorWin).wait_for_completed()
예제 #4
0
def cozmo_program(robot: cozmo.robot.Robot):
    global isTakingPicture
    global targetObject
    targetObject = sys.argv[1]
    if os.path.exists('photos'):
        shutil.rmtree('photos')
    if not os.path.exists('photos'):
        os.makedirs('photos')

    robot.say_text(
        f"Somebody lost the {targetObject}. Don't worry, I'll find it."
    ).wait_for_completed()

    # reset Cozmo's arms and head
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()

    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    while not discoveredObject:
        isTakingPicture = False
        robot.turn_in_place(degrees(45)).wait_for_completed()
        isTakingPicture = True
        time.sleep(2)

    isTakingPicture = False

    if discoveredObject:
        robot.drive_straight(distance_mm(200),
                             speed_mmps(300)).wait_for_completed()
        robot.say_text(
            f"Oh yay! I've found the {targetObject}").wait_for_completed()
        robot.play_anim_trigger(
            cozmo.anim.Triggers.MajorWin).wait_for_completed()
예제 #5
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    # define a unique cube (44mm x 44mm x 44mm) (approximately the same size as a light cube)
    # with a 30mm x 30mm Diamonds2 image on every face
    cube_obj = robot.world.define_custom_cube(CustomObjectTypes.CustomType00,
                                              CustomObjectMarkers.Diamonds2,
                                              44, 30, 30, True)

    if (cube_obj is not None):
        print("All objects defined successfully!")
    else:
        print("One or more object definitions failed!")
        return

    print(
        "Show the above markers to Cozmo and you will see the related objects "
        "annotated in Cozmo's view window, you will also see print messages "
        "everytime a custom object enters or exits Cozmo's view.")

    print("Press CTRL-C to quit")
    while True:
        time.sleep(0.1)
예제 #6
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    default_position_upon_start(robot)

    # define a unique wall (150mm x 120mm (x10mm thick for all walls)
    # with a 50mm x 30mm Circles2 image on front and back
    wall_obj1 = robot.world.define_custom_wall(CustomObjectTypes.CustomType01,
                                               CustomObjectMarkers.Hexagons5,
                                               150, 120, 50, 30, True)
    wall_obj2 = robot.world.define_custom_wall(CustomObjectTypes.CustomType00,
                                               CustomObjectMarkers.Diamonds2,
                                               150, 120, 50, 30, True)

    if ((wall_obj1 is not None) and (wall_obj2 is not None)):
        print("All objects defined successfully!")
    else:
        print("One or more object definitions failed!")

    print("Press CTRL-C to quit")
    while True:
        #time.sleep(0.1)
        action_on_seeing_object(robot)
예제 #7
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)
    default_position_upon_start(robot)

    #wall_obj1.object_id = 123456

    wall_obj1 = robot.world.define_custom_wall(CustomObjectTypes.CustomType00,
                                               CustomObjectMarkers.Circles5,
                                               38, 38, 38, 38, True)
    wall_obj2 = robot.world.define_custom_wall(CustomObjectTypes.CustomType01,
                                               CustomObjectMarkers.Diamonds2,
                                               38, 38, 38, 38, True)

    if ((wall_obj1 is not None) and (wall_obj2 is not None)):
        print("All objects defined successfully!")

    else:
        print("One or more object definitions failed!")

    print("Press CTRL-C to quit")
    while True:
        #time.sleep(0.1)
        action_on_seeing_object(robot)
def cozmo_program(robot: cozmo.robot.Robot):
    robot.camera.color_image_enabled = True
    robot.add_event_handler(cozmo.camera.EvtNewRawCameraImage, handle_image)
    robot.set_lift_height(1.0)
    print("Added event handler")
    while True:
        time.sleep(0.1)
예제 #9
0
파일: robot.py 프로젝트: Aurametrix/Alg
def cozmo_program(robot: cozmo.robot.Robot):
    global isTakingPicture
    global targetObject
    targetObject = sys.argv[1]
    if os.path.exists('photos'):
        shutil.rmtree('photos')
    if not os.path.exists('photos'):
        os.makedirs('photos')

    robot.say_text(f"Somebody lost the {targetObject}. Don't worry, I'll find it.").wait_for_completed()
    
    # reset Cozmo's arms and head
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()

    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    while not discoveredObject:
        isTakingPicture = False
        robot.turn_in_place(degrees(45)).wait_for_completed()
        isTakingPicture = True
        time.sleep(2)

    isTakingPicture = False

    if discoveredObject:
        robot.drive_straight(distance_mm(200), speed_mmps(300)).wait_for_completed()
        robot.say_text(f"Oh yay! I've found the {targetObject}").wait_for_completed()
        robot.play_anim_trigger(cozmo.anim.Triggers.MajorWin).wait_for_completed()
async def cozmo_program(robot: cozmo.robot.Robot):
    robot.camera.image_stream_enabled = True
    robot.camera.color_image_enabled = True
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_img)
    robot.set_head_angle(cozmo.util.Angle(degrees=0))

    while True:
        await asyncio.sleep(1)
예제 #11
0
파일: main.py 프로젝트: wwj718/cozmo_pets
async def custom_objects(robot: cozmo.robot.Robot):
    robot.add_event_handler(cozmo.objects.EvtObjectTapped,
                            handle_object_tapped)
    # 拿到loop ._loop
    loop = robot._loop
    # create comumer
    t1 = loop.create_task(worker(robot, queue))
    await t1
    '''
	def __init__(self, robot: cozmo.robot.Robot):
		self._robot = robot
		self.cubes = None
		self.game_state = GAME_STATE
		self.url = 'http://api-fr3.akinator.com/ws/new_session?callback=&partner=1&player=desktopPlayer&constraint='
		self.global_answer = 'Erreur'
		self.step = 0
		self.step2 = 0
		robot.add_event_handler(cozmo.objects.EvtObjectTapped, self.on_cube_tap)
예제 #13
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    # define a unique cube (44mm x 44mm x 44mm) (approximately the same size as a light cube)
    # with a 30mm x 30mm Diamonds2 image on every face
    cube_obj = robot.world.define_custom_cube(CustomObjectTypes.CustomType00,
                                              CustomObjectMarkers.Diamonds2,
                                              44, 30, 30, True)

    # define a unique cube (88mm x 88mm x 88mm) (approximately 2x the size of a light cube)
    # with a 50mm x 50mm Diamonds3 image on every face
    big_cube_obj = robot.world.define_custom_cube(
        CustomObjectTypes.CustomType01, CustomObjectMarkers.Diamonds3, 88, 50,
        50, True)

    # define a unique wall (150mm x 120mm (x10mm thick for all walls)
    # with a 50mm x 30mm Circles2 image on front and back
    wall_obj = robot.world.define_custom_wall(CustomObjectTypes.CustomType02,
                                              CustomObjectMarkers.Circles2,
                                              150, 120, 50, 30, True)

    # define a unique box (60mm deep x 140mm width x100mm tall)
    # with a different 30mm x 50mm image on each of the 6 faces
    box_obj = robot.world.define_custom_box(
        CustomObjectTypes.CustomType03,
        CustomObjectMarkers.Hexagons2,  # front
        CustomObjectMarkers.Circles3,  # back
        CustomObjectMarkers.Circles4,  # top
        CustomObjectMarkers.Circles5,  # bottom
        CustomObjectMarkers.Triangles2,  # left
        CustomObjectMarkers.Triangles3,  # right
        60,
        140,
        100,
        30,
        50,
        True)

    if ((cube_obj is not None) and (big_cube_obj is not None)
            and (wall_obj is not None) and (box_obj is not None)):
        print("All objects defined successfully!")
    else:
        print("One or more object definitions failed!")
        return

    print(
        "Show the above markers to Cozmo and you will see the related objects "
        "annotated in Cozmo's view window, you will also see print messages "
        "everytime a custom object enters or exits Cozmo's view.")

    print("Press CTRL-C to quit")
    while True:
        time.sleep(0.1)
예제 #14
0
def cozmo_program(robot: cozmo.robot.Robot):
    robot.set_lift_height(1.0)
    exposure_amount = 0.3  # Range: [0,1]
    gain_amount = 0.9  # Range: [0,1]
    configure_camera(robot, exposure_amount, gain_amount)
    robot.add_event_handler(cozmo.camera.EvtNewRawCameraImage, handle_image)
    print("Added event handler")
    while True:
        time.sleep(0.1)
예제 #15
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared, handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared, handle_object_disappeared)





    custom_box = robot.world.define_custom_box(custom_object_type=cozmo.objects.CustomObjectTypes.CustomType00, \
                                                       marker_front=cozmo.objects.CustomObjectMarkers.Circles2, \
                                                       marker_back=cozmo.objects.CustomObjectMarkers.Circles3, \
                                                       marker_top=cozmo.objects.CustomObjectMarkers.Circles4, \
                                                       marker_bottom=cozmo.objects.CustomObjectMarkers.Circles5, \
                                                       marker_left=cozmo.objects.CustomObjectMarkers.Diamonds2, \
                                                       marker_right=cozmo.objects.CustomObjectMarkers.Diamonds3, \
                                                       depth_mm=60, \
                                                       width_mm=60, \
                                                       height_mm=45, \
                                                       marker_width_mm=24.892, \
                                                       marker_height_mm=24.892, \
                                                       is_unique=True)

    if (custom_box is not None):
        print("All objects defined successfully!")
    else:
        print("One or more object definitions failed!")
        return

    print("Show the above markers to Cozmo and you will see the related objects "
          "annotated in Cozmo's view window, you will also see print messages "
          "everytime a custom object enters or exits Cozmo's view.")

    print("Press CTRL-C to quit")


    cubes = lookForCubes(robot, 45, 0)
    old_pose = robot.pose
    print("looking for cubes!") 
    if len(cubes) == 1:
        print("found object")
        robot.set_lift_height(height = 0, accel = 6, max_speed = 500, duration = 1, in_parallel = False, num_retries = 3).wait_for_completed()
        robot.go_to_pose(cubes[0].pose,relative_to_robot=False).wait_for_completed()
        pickupObject(robot)
        robot.drive_wheels(-50,-50)
        time.sleep(3)
        robot.drive_wheels(0,0)
        robot.go_to_pose(old_pose,relative_to_robot=False).wait_for_completed()
        robot.set_lift_height(height = 0, accel = 6, max_speed = 500, duration = 1, in_parallel = False, num_retries = 3).wait_for_completed()
    else:
        print("Cannot locate custom box")


    while True:
        time.sleep(0.1)
예제 #16
0
def setup_camera(robot: cozmo.robot.Robot):
    # Chaque fois que Cozmo voit une "nouvelle" image, prends une photo
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    # Indiquer le dossier pour stocker les photos
    global directory
    directory = f"{strftime('%y%m%d')}"
    if not os.path.exists('photos'):
        os.makedirs('photos')
    if not os.path.exists(f'photos/{directory}'):
        os.makedirs(f'photos/{directory}')
예제 #17
0
def workloop(robot: cozmo.robot.Robot):
    global ZielmaschVar
    global Zielmaschine
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    Maschine1 = robot.world.define_custom_cube(CustomObjectTypes.CustomType00,
                                               CustomObjectMarkers.Circles2,
                                               50, 50, 50, True)
    Maschine2 = robot.world.define_custom_cube(CustomObjectTypes.CustomType01,
                                               CustomObjectMarkers.Circles3,
                                               50, 50, 50, True)
    Maschine3 = robot.world.define_custom_cube(CustomObjectTypes.CustomType02,
                                               CustomObjectMarkers.Circles4,
                                               50, 50, 50, True)
    Maschine4 = robot.world.define_custom_cube(CustomObjectTypes.CustomType03,
                                               CustomObjectMarkers.Circles5,
                                               50, 50, 50, True)
    Maschine5 = robot.world.define_custom_cube(CustomObjectTypes.CustomType04,
                                               CustomObjectMarkers.Diamonds2,
                                               50, 50, 50, True)
    robot.set_head_angle(degrees(7)).wait_for_completed()

    # dreh dich und such nach der maschine

    lookaround = robot.start_behavior(
        cozmo.behavior.BehaviorTypes.LookAroundInPlace)
    targ = robot.world.wait_for_observed_light_cube()
    lookaround.stop()
    robot.pickup_object(targ, num_retries=3).wait_for_completed()
    robot.set_head_angle(degrees(7)).wait_for_completed()
    lookForMachine(robot)
    robot.turn_in_place(degrees(5)).wait_for_completed()
    #Masch = robot.world.wait_until_observe_num_objects(num=1, object_type=cozmo.objects.CustomObject, timeout=5)
    robot.drive_straight(distance_mm(150), speed_mmps(50)).wait_for_completed()
    robot.place_object_on_ground_here(targ).wait_for_completed()
    MAschinenwechsler()

    # such den würfel

    # lade den Würfel auf

    # fahr zutrück zur Mitte

    # dreh und scanne nach der nächsten maschine

    # positioniere dich zur maschine

    # lad den würfel ab

    while True:
        time.sleep(0.5)
예제 #18
0
def cozmo_program(robot: cozmo.robot.Robot):
    global isTakingPicture

    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    straight(robot, 130)
    conn.send("Location:130,0\n".encode())

    turn(robot, -90)
def cozmo_program(robot: cozmo.robot.Robot):
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()
    global directory
    directory = sys.argv[1]
    if not os.path.exists('pictures'):
        os.makedirs('pictures')
    if not os.path.exists('pictures/' + directory):
        os.makedirs('pictures/' + directory)
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)
    time.sleep(10)
    print("Done: Taking Pictures")
def cozmo_program(robot: cozmo.robot.Robot):
    robot.set_lift_height(1.0).wait_for_completed()
    robot.camera.color_image_enabled = True
    robot.add_event_handler(cozmo.camera.EvtNewRawCameraImage, handle_image)
    print("Added event handler")
    #robot.say_text("purple").wait_for_completed()
    while True:
        global speak
        if speak == True:
            robot.say_text(prediction).wait_for_completed()
            speak = False
        time.sleep(0.1)
예제 #21
0
def cozmo_program(robot: cozmo.robot.Robot):
    # Reset head
    robot.set_head_angle(degrees(0.0)).wait_for_completed()
    # Reset lift
    robot.set_lift_height(0.0).wait_for_completed()
    # Announce activity
    robot.say_text("Stage 1").wait_for_completed()

    # Create images directory if it doesn't exists
    global directory
    directory = sys.argv[1]
    if not os.path.exists('images'):
        os.makedirs('images')

    # Drive to 1st Location
    robot.drive_straight(distance_mm(340), speed_mmps(90), False, False,
                         0).wait_for_completed()
    # Initialise Camera
    take_photos(robot)
    # new image == new pic
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)
    shoot_sequence(robot)

    # Announce activity
    robot.say_text("Stage 2").wait_for_completed()

    # Drive to 2nd Location
    robot.drive_straight(distance_mm(-50), speed_mmps(90), False, False,
                         0).wait_for_completed()
    robot.turn_in_place(degrees(90)).wait_for_completed()
    robot.drive_straight(distance_mm(250), speed_mmps(90), False, False,
                         0).wait_for_completed()
    robot.turn_in_place(degrees(-90)).wait_for_completed()
    robot.drive_straight(distance_mm(300), speed_mmps(90), False, False,
                         0).wait_for_completed()
    robot.turn_in_place(degrees(-90)).wait_for_completed()
    robot.drive_straight(distance_mm(230), speed_mmps(90), False, False,
                         0).wait_for_completed()
    robot.turn_in_place(degrees(-90)).wait_for_completed()
    robot.drive_straight(distance_mm(50), speed_mmps(90), False, False,
                         0).wait_for_completed()
    # new image == new pic
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)
    shoot_sequence(robot)

    upload()

    #  And we're done here
    robot.say_text("Images sent to Oracle Cloud").wait_for_completed()
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    #robot.add_event_handler(cozmo.objects.EvtObjectDisappeared, handle_object_disappeared)

    # define a unique wall (150mm x 120mm (x10mm thick for all walls)
    # with a 50mm x 30mm Circles2 image on front and back
    wall_obj = robot.world.define_custom_wall(CustomObjectTypes.CustomType02,
                                              CustomObjectMarkers.Circles2,
                                              140, 130, 65, 65, False)
    wall_obj1 = robot.world.define_custom_wall(CustomObjectTypes.CustomType03,
                                               CustomObjectMarkers.Diamonds2,
                                               140, 130, 64, 64, False)

    #    if ((cube_obj is not None) and (big_cube_obj is not None) and
    #           (wall_obj is not None) and (box_obj is not None)):
    #       print("All objects defined successfully!")
    #    else:
    #        print("One or more object definitions failed!")
    #       return

    print(
        "Show the above markers to Cozmo and you will see the related objects "
        "annotated in Cozmo's view window, you will also see print messages "
        "everytime a custom object enters or exits Cozmo's view.")

    print("Press CTRL-C to quit")

    # Move lift down and tilt the head up
    robot.move_lift(100)
    robot.set_head_angle(degrees(-25))
    while True:
        global found_wall
        global found_wall1
        if found_wall == True:
            robot.drive_straight(distance_mm(150),
                                 speed_mmps(50)).wait_for_completed()
            robot.turn_in_place(degrees(90)).wait_for_completed()
            found_wall = False
            robot.set_head_angle(degrees(-25))
        if found_wall1 == True:
            robot.drive_straight(distance_mm(150),
                                 speed_mmps(50)).wait_for_completed()
            robot.turn_in_place(degrees(-90)).wait_for_completed()
            found_wall1 = False
            robot.set_head_angle(degrees(-25))
        time.sleep(0.1)
def cozmo_program(robot: cozmo.robot.Robot):
    global takePicture
    # Make sure Cozmo's head and arm are at reasonable levels
    robot.set_head_angle(degrees(1)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()

    # Anytime Cozmo sees a "new" image, take a photo
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    # And we're done here
    #robot.say_text("All done!").wait_for_completed()
    #robot.camera.enable_auto_exposure(False)
    #robot.camera.set_manual_exposure( 5, .5)

    while takePicture == True:
        pass
예제 #24
0
def init_cubes(robot: cozmo.robot.Robot):
    global cube1,cube2,cube3,ev_cube,ev_id,ev_command,ev_light
    cube1 = robot.world.get_light_cube(LightCube1Id)  # looks like a paperclip
    cube2 = robot.world.get_light_cube(LightCube2Id)  # looks like a lamp / heart
    cube3 = robot.world.get_light_cube(LightCube3Id)  # looks like the letters 'ab' over 'T'

    # Make sure each cube is off
    switch_cubes_off()
    # Add listener to control initialisation
    handler = robot.add_event_handler(cozmo.objects.EvtObjectTapped, handle_tap_init)

    seq = ['red','green','blue']
    light_seq = [cozmo.lights.red_light,cozmo.lights.green_light,cozmo.lights.blue_light]
    cube_seq = [cube1,cube2,cube3]
    comm_seq = ['g','c','s'] # greater,correct,smaller
    for i in range(0,3):
        print('Tap the ',seq[i],' cube')
        switch_cube_on(cube_seq[i],light_seq[i])
        while(True):
            if(ev_id):
                # Map event to cube
                ev_cube[ev_id] = cube_seq[i]
                ev_command[ev_id] = comm_seq[i]
                ev_light[ev_id] = light_seq[i]
                make_selected_cube_blink(ev_cube[ev_id],light_seq[i])
                switch_cubes_off()
                ev_id = 0
                break
    handler.disable()
예제 #25
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    # define a unique cube (44mm x 44mm x 44mm) (approximately the same size as a light cube)
    # with a 30mm x 30mm Diamonds2 image on every face
    cube_obj = robot.world.define_custom_cube(CustomObjectTypes.CustomType00,
                                              CustomObjectMarkers.Diamonds2,
                                              44, 30, 30, True)

    #state machine initializaion
    #machine_state = CozmoStates()

    while True:
        time.sleep(0.1)
예제 #26
0
def cozmo_program(robot: cozmo.robot.Robot):
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()
    global directory
    # directory = sys.argv[1]
    if not os.path.exists('pictures'):
        os.makedirs('pictures')

    robot.add_event_handler(cozmo.pets.EvtPetAppeared, on_new_pet_detected)
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)

    while not detected:
        pass
    #   robot.turn_in_place(degrees(45))
    #   time.sleep(5)

    if detected == True:    
        robot.drive_straight(distance_mm(250), speed_mmps(150)).wait_for_completed()
예제 #27
0
def cozmo_program(robot: cozmo.robot.Robot):
    robot.set_head_angle(degrees(10.0)).wait_for_completed()
    robot.set_lift_height(0.0).wait_for_completed()
    robot.add_event_handler(cozmo.world.EvtNewCameraImage, on_new_camera_image)
    print("press q to exit, press p to take a photo")

    while 1:
        if msvcrt.kbhit():
            c = msvcrt.getch()
            print(c)
            if c == b'p':
                print("saving photo")
                global savePhoto
                savePhoto = 1
            if c == b'q':
                print("quiting")
                break  #exit when 'q' is hit, take a photo when 'p' is hit
        time.sleep(0.2)
예제 #28
0
async def cozmo_program(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    # Connect to the pre-defined cubes
    await robot.world.connect_to_cubes()

    # Make sure Cozmo's head and arm are at reasonable levels
    await robot.set_head_angle(degrees(5.0)).wait_for_completed()
    await robot.set_lift_height(0.0).wait_for_completed()

    # Searches for the cubes for a defined time in seconds
    search_cubes = robot.start_behavior(
        cozmo.behavior.BehaviorTypes.LookAroundInPlace)
    found_cubes = await robot.world.wait_until_observe_num_objects(
        num=1, object_type=cozmo.objects.LightCube, timeout=6)
    search_cubes.stop()

    found_cubes[0] = robot.world.get_light_cube(LightCube2Id)

    # Approach the object (pre-defined function used since its a defined object)
    go_to_cube = robot.go_to_object(found_cubes[0], distance_mm(100.0))
    await go_to_cube.wait_for_completed()
    # Code for objects that weren't pre-defined (we drive manually)
    # await robot.drive_straight(distance_mm(140), speed_mmps(100), False, False, 0).wait_for_completed()

    await robot.drive_wheels(-200,
                             -200,
                             l_wheel_acc=4000,
                             r_wheel_acc=4000,
                             duration=1)

    # Explore all sides of the object
    for sides in range(15):
        await explore_sides(robot, found_cubes)

    await robot.say_text("Exploration complete!").wait_for_completed()

    # Disconnects from the cubes
    robot.world.disconnect_from_cubes()
예제 #29
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    # define a unique cube (44mm x 44mm x 44mm) (approximately the same size as a light cube)
    # with a 30mm x 30mm Diamonds2 image on every face
    custom_obj = robot.world.define_custom_cube(CustomObjectTypes.CustomType00,
                                                CustomObjectMarkers.Diamonds2,
                                                25, 25, 25, True)

    #   custom_obj_fixed = robot.world.create_custom_fixed_object(
    #                                             25,
    #                                             25, 25, True)

    while True:
        time.sleep(0.1)
예제 #30
0
    def __init__(self, robot: cozmo.robot.Robot):
        self.robot = robot
        self.player = QuickTapPlayer()
        self.cozmo_player = CozmoQuickTapPlayer(robot)
        robot.add_event_handler(cozmo.anim.EvtAnimationCompleted,
                                self.on_anim_completed)
        robot.add_event_handler(cozmo.objects.EvtObjectTapped,
                                self.on_cube_tap)

        self.cubes = None
        self.countdown_cube = None

        self.buzzer_display_type = None

        self.round_start_time = time.time()
        self.quick_tap_player_1 = None
        self.quick_tap_player_2 = None
        self.round_over = False

        self.quick_tap_state = CHOOSE_CUBES_STATE
예제 #31
0
def custom_objects(robot: cozmo.robot.Robot):
    # Add event handlers for whenever Cozmo sees a new object
    robot.add_event_handler(cozmo.objects.EvtObjectAppeared,
                            handle_object_appeared)
    robot.add_event_handler(cozmo.objects.EvtObjectDisappeared,
                            handle_object_disappeared)

    # define a unique wall (150mm x 120mm (x10mm thick for all walls)
    # with a 50mm x 30mm Circles2 image on front and back
    north_wall = robot.world.define_custom_wall(CustomObjectTypes.CustomType02,
                                                CustomObjectMarkers.Circles2,
                                                300, 150, 63, 63, True)

    # define a unique wall (150mm x 120mm (x10mm thick for all walls)
    # with a 50mm x 30mm Circles2 image on front and back
    east_wall = robot.world.define_custom_wall(CustomObjectTypes.CustomType03,
                                               CustomObjectMarkers.Circles3,
                                               300, 150, 63, 63, True)

    # define a unique wall (150mm x 120mm (x10mm thick for all walls)
    # with a 50mm x 30mm Circles2 image on front and back
    south_wall = robot.world.define_custom_wall(CustomObjectTypes.CustomType04,
                                                CustomObjectMarkers.Circles4,
                                                300, 150, 63, 63, True)

    # define a unique wall (150mm x 120mm (x10mm thick for all walls)
    # with a 50mm x 30mm Circles2 image on front and back
    west_wall = robot.world.define_custom_wall(CustomObjectTypes.CustomType05,
                                               CustomObjectMarkers.Circles5,
                                               300, 150, 63, 63, True)

    if ((north_wall is not None) and (east_wall is not None)
            and (south_wall is not None) and (west_wall is not None)):
        print("All objects defined successfully!")
    else:
        print("One or more object definitions failed!")
        return

    while True:
        time.sleep(0.1)
예제 #32
0
def get_answer_from_cubes(robot: cozmo.robot.Robot):
    global cube1,cube2,cube3,ev_cube,ev_id,ev_command,ev_light
    timeOut = 30
    timer = 0
    
    switch_cubes_on()
    handler = robot.add_event_handler(cozmo.objects.EvtObjectTapped, handle_tapped)

    while(True):
        time.sleep(0.5)
        timer += 0.5
        if(ev_id):
            switch_cubes_off()
            make_selected_cube_blink(ev_cube[ev_id],ev_light[ev_id])
            local_id = ev_id
            ev_id = 0 # Deactivate selection
            handler.disable()
            return ev_command[local_id]
        elif(timer > timeOut):
            handler.disable()
            return 'timeOut'