コード例 #1
0
    def __init__(self, *a, **kw):

        #init cozmo
        cozmo.setup_basic_logging()
        cozmo.connect(self.run)
        while True:
            self.take_input()
コード例 #2
0
    def __init__(self, *a, **kw):
        CozGame.__init__(self)

        # init cozmo
        cozmo.world.World.light_cube_factory = CustomCube
        cozmo.setup_basic_logging()
        cozmo.connect(self.run)
コード例 #3
0
    def start(self, code):
        def run(sdk_conn):
            '''The run method runs once Cozmo SDK is connected.'''
            self._robot = sdk_conn.wait_for_robot()
            self._origin = self._robot.pose
            self.cubes_to_numbers = {}
            for key in self._robot.world.light_cubes:
                self.cubes_to_numbers[self._robot.world.light_cubes.get(
                    key).object_id] = key
            self.resetCubes()

            self._robot.camera.image_stream_enabled = True

            bot = self

            highlighter = Highlighter()
            highlighter.start()

            import cozmo
            exec(code, locals(), locals())

        self._dataPubThread = threading.Thread(
            target=self.feedRobotDataInThread)
        self._dataPubThread.daemon = True
        self._dataPubThread.start()

        cozmo.setup_basic_logging()
        cozmo.robot.Robot.drive_off_charger_on_connect = False
        cozmo.connect(run)
        self._robot = None
コード例 #4
0
 def __init__(self):
     self.board_length = 250
     self.board_breadth = 200
     self.objects = None
     self.cube_id = [0, 0, 0]
     self.robot = None
     cozmo.connect(self.run)
コード例 #5
0
ファイル: cozmobot.py プロジェクト: wwj718/cozmo-blockly
    def start(self, code):
        def run(sdk_conn):
            '''The run method runs once Cozmo SDK is connected.'''
            self._robot = sdk_conn.wait_for_robot()
            self._origin = self._robot.pose
            self.cubes_to_numbers = {}
            for key in self._robot.world.light_cubes:
                self.cubes_to_numbers[self._robot.world.light_cubes.get(
                    key).object_id] = key
            self.resetCubes()
            self.resetCustomObjects()

            self._robot.camera.image_stream_enabled = True

            bot = self

            import cozmo
            exec(code, locals(), locals())

        from ws4py.client.threadedclient import WebSocketClient
        self._camClient = WebSocketClient('ws://localhost:9090/camPub')
        self._camClient.connect()

        self._wsClient = WebSocketClient('ws://localhost:9090/WsPub')
        self._wsClient.connect()

        self._dataPubThread = threading.Thread(
            target=self.feedRobotDataInThread)
        self._dataPubThread.daemon = True
        self._dataPubThread.start()

        cozmo.setup_basic_logging()
        cozmo.robot.Robot.drive_off_charger_on_connect = False
        cozmo.connect(run)
        self._robot = None
コード例 #6
0
 def __init__(self, *a, **kw):
     self.robot = None
     self.dictDraw = {
         'a': self.drawA,
         'b': self.drawB,
         'c': self.drawC,
         'd': self.drawD,
         'e': self.drawE,
         'f': self.drawF,
         'g': self.drawG,
         'h': self.drawH,
         'i': self.drawI,
         'j': self.drawJ,
         'k': self.drawK,
         'l': self.drawL,
         'm': self.drawM,
         'n': self.drawN,
         'o': self.drawO,
         'p': self.drawP,
         'q': self.drawQ,
         'r': self.drawR,
         's': self.drawS,
         't': self.drawT,
         'u': self.drawU,
         'v': self.drawV,
         'w': self.drawW,
         'x': self.drawX,
         'y': self.drawY,
         'z': self.drawZ
     }
     cozmo.connect(self.run)
    def __init__(self):
        self._robot = None

        # Initialize variables for tkinter
        self._tk_root = 0
        self._tk_label_output = 0

        self.min_object_radius = 10
        # Image size is 320x240 with tkinter, might want to adjust these
        self.left_of_screen = 75
        self.right_of_screen = 225

        self.first_kick = False  # Keeps track of robot being in its initial kick state
        self.search_for_ball = False  # Keeps track of robot being in its searching for ball state
        self.go_to_ball = False  # Keeps track of robot being in its moving to ball state
        self.setup_turn = False
        self.find_goal = False  # Keeps track of robot being in its goal finding state
        self.orange_on = True  # Keeps track of what color robot is looking for (orange or black)
        self.goal_radius = 30  # Radius threshold for objects ball is tracking, used to trigger specific actions
        self.global_radius = 0  # Stores the current radius of an object being track, initialized at 0
        self.turn_angle = 0  # Keeps track of the current turn angle when searching for ball
        self.left_turn = False  # Keeps track of robot being in a left turn state (used when moving towards ball)
        self.go_straight = False  # Keeps track of robot being in a driving straight state (used when moving towards ball)
        self.first_angle = True  # Keeps track of robot being in state where it adjusts to kick the ball initially at an angle
        self.rand_angle = randint(
            -10, 10)  # Random angle calculation for initial kick

        cozmo.connect(self.run)
コード例 #8
0
 def __init__(self, robot=None, instance=None):
     self.thresh = 5
     self.dizzy = 0  #0 = normal, 1 = tipsy, 2 = drunk, 3 = throwing up, 4 = out of order
     self.robot = robot
     self.mainInstance = instance
     self.END = False
     if self.robot is None:
         cozmo.connect(self.run)
コード例 #9
0
    def ButtonPressed(self):
        global server_ip

        server_ip = self.serverentry.get()

        self.root.destroy()
        cozmo.setup_basic_logging()
        cozmo.connect(run)
コード例 #10
0
    def __init__(self, *a, **kw):

        sys.setrecursionlimit(0x100000)

        self.weatherObj = OpenWeather(PYOWM_API_KEY, self.city)

        cozmo.setup_basic_logging()
        cozmo.connect(self.startResponding)
コード例 #11
0
 def __init__(self):
     self._robot = None
     self._tk_root = 0
     self._tk_label_input = 0
     self._tk_label_output = 0
     if USE_LOGGING:
         cozmo.setup_basic_logging()
     cozmo.connect(self.run)
コード例 #12
0
 def __init__(self, *a, **kw):
     
     sys.setrecursionlimit(0x100000)
     
     self.setUpFitBit()
     
     cozmo.setup_basic_logging()
     cozmo.connect(self.startResponding)
コード例 #13
0
 def cozmo_main(self):
     if self._use_logging:
         cozmo.setup_basic_logging()
     try:
         cozmo.connect(self.cozmo_run, connector=cozmo.run.FirstAvailableConnector())
         self._cozmo_conn.shutdown()
         self._cozmo_loop.stop()
     except cozmo.ConnectionError as e:
         ue.log('No Cozmo :(')
コード例 #14
0
def run_cozmo():
    def run(sdk_conn):
        #The run method runs once Cozmo is connected.

        robot = sdk_conn.wait_for_robot()
        robot.say_text("Hello World").wait_for_completed()
        robot.say_text("Hello World Again").wait_for_completed()
        global cozmo_command
        while True:
            if cozmo_command.value == 1:
                robot.turn_in_place(degrees(90)).wait_for_completed()
                cozmo_command.value = 0
                time.sleep(1)
            if cozmo_command.value == 2:
                robot.turn_in_place(degrees(-90)).wait_for_completed()
                cozmo_command.value = 0
            if cozmo_command.value == 3:
                robot.drive_straight(distance_mm(150),
                                     speed_mmps(50)).wait_for_completed()
                cozmo_command.value = 0
            if cozmo_command.value == 4:
                robot.drive_straight(distance_mm(-150),
                                     speed_mmps(50)).wait_for_completed()
                cozmo_command.value = 0
            if cozmo_command.value == 5:

                lookaround = robot.start_behavior(
                    cozmo.behavior.BehaviorTypes.LookAroundInPlace)
                cubes = robot.world.wait_until_observe_num_objects(
                    num=2, object_type=cozmo.objects.LightCube, timeout=60)
                lookaround.stop()
                if len(cubes) < 2:
                    print("Error: need 2 Cubes but only found", len(cubes),
                          "Cube(s)")
                else:
                    robot.pickup_object(cubes[0]).wait_for_completed()
                    robot.place_on_object(cubes[1]).wait_for_completed()
            if cozmo_command.value == 6:
                anim = robot.play_anim_trigger(cozmo.anim.Triggers.MajorWin)
                anim.wait_for_completed()
                cozmo_command.value = 0
            if cozmo_command.value == 7:
                robot.set_all_backpack_lights(cozmo.lights.green_light)
                time.sleep(1)
                robot.set_all_backpack_lights(cozmo.lights.red_light)
                time.sleep(1)
                robot.set_all_backpack_lights(cozmo.lights.blue_light)
                time.sleep(1)
                robot.set_all_backpack_lights(cozmo.lights.white_light)
                time.sleep(1)
                robot.set_all_backpack_lights(cozmo.lights.off_light)

    cozmo.setup_basic_logging()
    try:
        cozmo.connect(run)
    except cozmo.ConnectionError as e:
        sys.exit("A connection error occurred: %s" % e)
コード例 #15
0
    def __init__(self, *a, **kw):

        sys.setrecursionlimit(0x100000)

        self.questions = Questions()

        cozmo.setup_basic_logging()
        #         cozmo.connect_with_tkviewer(self.startResponding)
        cozmo.connect(self.startResponding)
コード例 #16
0
    def __init__(self, *a, **kw):
        CozGame.__init__(self)

        self._answer = None
        self._coz = None
        self._cubes = None

        cozmo.setup_basic_logging()
        cozmo.connect(self.run)
コード例 #17
0
def main(args=None):
    #rospy.init_node('cozmo_driver')
    rclpy.init(args=args)
    cozmo.setup_basic_logging()
    try:
        cozmo.connect(cozmo_app)
    except cozmo.ConnectionError as err:
        sys.exit('A connection error occurred: {}'.format(err))
        rclpy.shutdown()
コード例 #18
0
 def __init__(self):
     self._count = 0
     self._cube = 0
     self._robot = None
     self._is_busy = False
     if USE_LOGGING:
         cozmo.setup_basic_logging()
     if USE_VIEWER:
         cozmo.connect_with_tkviewer(self.run)
     else:
         cozmo.connect(self.run)
コード例 #19
0
def main():
    try:
        # cozmo.connect(run)
        rs = RobotState()
        sm = StateMachine(rs.IDLE, robot: cozmo.robot.Robot)
        cozmo.connect(sm.run_robot())

        # cozmo.run_program(run)

    except cozmo.ConnectionError as e:
        sys.exit("A connection error occurred: %s" % e)
コード例 #20
0
    def __init__(self):
        self.light = True  #true = green; false = red
        self.thresh = 100
        self.timeout = None
        self.previous_frame = None
        self.current_frame = None

        #Cozmo view window - motion detection
        cv2.namedWindow('Diff')
        cv2.createTrackbar('thresh', 'Diff', 100, 255, self.update_values)
        cozmo.connect(self.run)
コード例 #21
0
 def __init__(self):
     self.pubnub = Pubnub(publish_key=DatingCozmo.PUBLISH_KEY,
                          subscribe_key=DatingCozmo.SUBSCRIBE_KEY)
     self.pubnub.subscribe(channels=DatingCozmo.SUBSCRIBE_CHANNEL,
                           callback=self.on_message_received,
                           error=self.error,
                           connect=self.connect,
                           reconnect=self.reconnect,
                           disconnect=self.disconnect)
     cozmo.setup_basic_logging()
     cozmo.connect(self.run)
コード例 #22
0
    def __init__(self, *a, **kw):
        WOC.__init__(self)

        cozmo.setup_basic_logging()
        try:
            cozmo.connect(self.run)
        except cozmo.ConnectionError as e:
            print("A connection error occurred: %s" % e)
            loop = asyncio.new_event_loop()
            asyncio.set_event_loop(loop)
            loop.run_until_complete(self.run())
コード例 #23
0
def reconnect():
    global logging_is_setup
    if not logging_is_setup:
        cozmo.setup_basic_logging()
        logging_is_setup = True
    cozmo.robot.Robot.drive_off_charger_on_connect = False
    try:
        if len(sys.argv) <= 1:
            cozmo.connect_with_tkviewer(run)
        else:
            cozmo.connect(run)
    except cozmo.ConnectionError as e:
        sys.exit("A connection error occurred: %s" % e)
コード例 #24
0
    def __init__(self, *a, **kw):
        WOC.__init__(self)

        if os.path.exists(self.OUTPUT_VIDEO_NAME):
            os.remove(self.OUTPUT_VIDEO_NAME)

        if self.INSTAGRAM_PASSWORD == "":
            with open(self.INSTAGRAM_FILE_NAME) as f:
                self.INSTAGRAM_PASSWORD = f.readlines()[0];

        self.insta = InstagramAPI(self.INSTAGRAM_USER_NAME, self.INSTAGRAM_PASSWORD)
        self.insta.login()  # login

        cozmo.setup_basic_logging()
        cozmo.connect(self.run)
コード例 #25
0
    def __init__(self):
        super(DetectTags, self).__init__()
        self._tk_label_input = 0
        self.is_moving = False
        self.img1 = None  # trainImage
        self.sift = cv2.xfeatures2d.SIFT_create()
        self.index_params = dict(algorithm=0, trees=5)
        self.search_params = dict(checks=50)
        self.flann = cv2.FlannBasedMatcher(self.index_params, self.search_params)
        #self.img2 = cv2.imread('Selection/15.png', 0)   # <= the image viewed by the robot
        self.img2 = None
        self.match_found = False
        self.image = ''

        cozmo.connect(self.run_cozmo)
コード例 #26
0
    def post(self, request, *args, **kwargs):

        # Abrimos la conexión con Cozmo
        cozmo.setup_basic_logging()
        # Leemos los comandos, los parámetros y ejecutamos la orden.
        data = JSONParser().parse(request)
        print(data)
        global commands_to_cozmo
        commands_to_cozmo = data
        try:
            cozmo.connect(run_commands,
                          connector=cozmo.run.FirstAvailableConnector())
        except cozmo.ConnectionError as e:
            sys.exit("Connection Error: %s" % e)

        return JsonResponse("ACTION COMPLETED", status=200, safe=False)
コード例 #27
0
    def __init__(self):
        self._robot = None
        self._cubes = []

        # initial setting ensures we don't first randomize to PRIMARY_GOAL
        self._goal = PRIMARY_GOAL

        self._sfx_success = pygame.mixer.Sound('./sfx/success.wav')
        self._sfx_tick = pygame.mixer.Sound('./sfx/tick.wav')

        if USE_LOGGING:
            cozmo.setup_basic_logging()
        if USE_VIEWER:
            cozmo.connect_with_tkviewer(self.run)
        else:
            cozmo.connect(self.run)
コード例 #28
0
 def __init__(self):
     # self.startBoard = []
     self.startBoard = [["." for x in range(9)] for y in range(9)]
     self.solveList = []
     self._count = 0
     self._cube = 0
     self._cubes = []  #list of lists
     self._robot = None
     self._is_busy = False
     self.boardSide = 609.6
     self.squareSide = 67.73
     if USE_LOGGING:
         cozmo.setup_basic_logging()
     if USE_VIEWER:
         cozmo.connect_with_tkviewer(self.run)
     else:
         cozmo.connect(self.run)
コード例 #29
0
ファイル: high_five.py プロジェクト: Wizards-of-Coz/HighFive
    def __init__(self):
        self.cozmo_idle = True                          # Cozmo state - idle or waiting for user to high five
        self.frames_hand_visible_thresh = 20            # Number of frames Cozmo sees a hand continuously before acknowledging it
        self.frames_wait_for_high_five_thresh = 35      # Number of frames Cozmo waits for a user to high five
        self.norm_thresh = 0.85                         # Threshold for successful high five         
        self.cnt1 = 0
        self.cnt2 = 0
        self.blur = 5
        self.kernel = 11

        #Cozmo's view window
        cv2.namedWindow('Thresholded')
        cv2.createTrackbar('blur', 'Thresholded', 1, 5, self.update_values)
        cv2.createTrackbar('kernel', 'Thresholded', 1, 9, self.update_values)

        #Connect Cozmo and start
        self.robot = None
        cozmo.connect(self.run)
コード例 #30
0
ファイル: Cozmo.py プロジェクト: Heinenn/CozmoProject
    def __init__(self):
        # Set-up logging
        formatter = logging.Formatter(
            '%(asctime)s %(name)s %(levelname)-8s %(message)s')
        handler = logging.StreamHandler()
        handler.setLevel(logging.INFO)
        handler.setFormatter(formatter)
        log.setLevel(logging.INFO)
        log.addHandler(handler)
        # variables
        self.endProgramm = False
        self._robot = None
        self._tk_root = 0
        self._tk_label_input = 0
        self._tk_label_output = 0
        cozmo.connect(self.run)

        self._robot.add_event_handler(cozmo.world.EvtNewCameraImage,
                                      self.on_img)
コード例 #31
0
ファイル: lookaround.py プロジェクト: theycallhimjay/commons
    cube.set_lights(cozmo.lights.green_light.flash())

    anim = robot.play_anim_trigger(cozmo.anim.Triggers.BlockReact)
    anim.wait_for_completed()


    action = robot.pickup_object(cube)
    print("got action", action)
    result = action.wait_for_completed(timeout=30)
    print("got action result", result)

    robot.turn_in_place(degrees(90)).wait_for_completed()

    action = robot.place_object_on_ground_here(cube)
    print("got action", action)
    result = action.wait_for_completed(timeout=30)
    print("got action result", result)

    anim = robot.play_anim_trigger(cozmo.anim.Triggers.MajorWin)
    cube.set_light_corners(None, None, None, None)
    anim.wait_for_completed()


if __name__ == '__main__':
    cozmo.setup_basic_logging()
    try:
        cozmo.connect(run)
    except cozmo.ConnectionError as e:
        sys.exit("A connection error occurred: %s" % e)