예제 #1
0
def main():
    global safe_file
    global verbose

    # Parse command-line.
    args = parse_args()

    safe_file = args.safe_file
    verbose = args.verbose

    # Verify .safe file.
    verify_safe(safe_file, args.signature)

    # Update robot.
    try:
        pycozmo.run_program(update,
                            protocol_log_level="INFO",
                            robot_log_level="DEBUG",
                            auto_initialize=False)
    except Exception as e:
        print("ERROR: {}".format(e))
        sys.exit(3)
예제 #2
0
import time

import pycozmo


def on_camera_image(cli, image):
    del cli
    image.save("camera.png", "PNG")


def pycozmo_program(cli):

    angle = (pycozmo.robot.MAX_HEAD_ANGLE_RAD - pycozmo.robot.MIN_HEAD_ANGLE_RAD) / 2
    pkt = pycozmo.protocol_encoder.SetHeadAngle(angle_rad=angle)
    cli.send(pkt)

    pkt = pycozmo.protocol_encoder.EnableCamera(enable=True)
    cli.send(pkt)

    # Wait for image to stabilize.
    time.sleep(1.5)

    cli.add_handler(pycozmo.client.EvtNewRawCameraImage, on_camera_image, one_shot=True)

    # Wait for image to be captured.
    time.sleep(1)


pycozmo.run_program(pycozmo_program)
예제 #3
0
#!/usr/bin/env python

import time

import pycozmo


def pycozmo_program(cli: pycozmo.client.Client):

    # Load animations - one time.
    cli.load_anims("com.anki.cozmo/files/cozmo/cozmo_resources/assets/animations/")

    # Print the names of all available animations.
    names = cli.get_anim_names()
    for name in sorted(names):
        print(name)

    time.sleep(2)

    # Play an animation.
    cli.play_anim("anim_launch_wakeup_01")


pycozmo.run_program(pycozmo_program, protocol_log_level="DEBUG")
예제 #4
0
파일: nvram.py 프로젝트: v1ckxy/pycozmo
import pycozmo

e = Event()


def on_nv_storage_op_result(cli: pycozmo.client.Client,
                            pkt: pycozmo.protocol_encoder.NvStorageOpResult):
    del cli
    print(pkt.result)
    print(pkt.data)

    if pkt.result != pycozmo.protocol_encoder.NvResult.NV_MORE:
        e.set()


def pycozmo_program(cli: pycozmo.client.Client):
    cli.conn.add_handler(pycozmo.protocol_encoder.NvStorageOpResult,
                         on_nv_storage_op_result)

    pkt = pycozmo.protocol_encoder.NvStorageOp(
        tag=pycozmo.protocol_encoder.NvEntryTag.NVEntry_CameraCalib,
        length=1,
        op=pycozmo.protocol_encoder.NvOperation.NVOP_READ)
    cli.conn.send(pkt)

    e.wait(timeout=20.0)


pycozmo.run_program(pycozmo_program, log_level="DEBUG")
예제 #5
0
            # (0, 0) coordinate. 
            display_surface.blit(cv2ImageToSurface(im), (0, 0))
            display_surface.blit(cv2ImageToSurface(cropped), (0,240))

            # draw the distance detecting image
            display_surface.blit(cv2ImageToSurface(boxImg), (0, 480)) 

            # Draws the surface object to the screen.   
            pygame.display.update()  

        # iterate over the list of Event objects 
        # that was returned by pygame.event.get() method. 
        for event in pygame.event.get() : 
    
            # if event object type is QUIT 
            # then quitting the pygame 
            # and program both. 
            if event.type == pygame.QUIT : 
    
                # deactivates the pygame library 
                pygame.quit() 
    
                # quit the program. 
                quit()  

        # Run with 25 FPS.
        time.sleep(1 / 25)


pycozmo.run_program(pycozmo_program, protocol_log_level="INFO", robot_log_level="DEBUG")
예제 #6
0
파일: events.py 프로젝트: v1ckxy/pycozmo
        print("Stopped moving.")


def pycozmo_program(cli: pycozmo.client.Client):

    cli.conn.add_handler(pycozmo.protocol_encoder.RobotState,
                         on_robot_state,
                         one_shot=True)
    cli.conn.add_handler(pycozmo.protocol_encoder.RobotPoked, on_robot_poked)
    cli.conn.add_handler(pycozmo.protocol_encoder.FallingStarted,
                         on_robot_falling_started)
    cli.conn.add_handler(pycozmo.protocol_encoder.FallingStopped,
                         on_robot_falling_stopped)
    cli.conn.add_handler(pycozmo.protocol_encoder.ButtonPressed,
                         on_button_pressed)
    cli.add_handler(pycozmo.event.EvtRobotPickedUpChange, on_robot_picked_up)
    cli.add_handler(pycozmo.event.EvtRobotChargingChange, on_robot_charging)
    cli.add_handler(pycozmo.event.EvtCliffDetectedChange, on_cliff_detected)
    cli.add_handler(pycozmo.event.EvtRobotWheelsMovingChange,
                    on_robot_wheels_moving)

    while True:
        try:
            time.sleep(0.1)
        except KeyboardInterrupt:
            break


# Change the robot log level to DEBUG to see robot debug messages related to events.
pycozmo.run_program(pycozmo_program, robot_log_level="INFO")