def __init__(self, _zumi=None): if _zumi is None: self.zumi = Zumi() else: self.zumi = _zumi self.current_x = 0 self.current_y = 0 self.zumi.reset_gyro()
def __init__(self, _zumi=None): if _zumi is None: self.z = Zumi() else: self.z = _zumi self.z.mpu.calibrate_MPU() self.NORTH = 0 self.WEST = 90 self.EAST = -90 self.SOUTH = 180 self.heading = self.NORTH self.current_x = 0 self.current_y = 0 self.motor_speed = 10 self.ir_threshold = 125
def __init__(self): # OELD 제어를 위한 설정 self.disp = Adafruit_SSD1306.SSD1306_128_64(rst=24) self.disp.begin() self.image = Image.new('1', (self.disp.width, self.disp.height)) self.draw = ImageDraw.Draw(self.image) # 포인터의 크기 self.size = 3 # 자이로 X,Y 각도 값 self.oldCharX = 255 self.oldCharY = 255 # 펜의 좌표 X,Y 값 self.penX = 0 self.penY = 0 # 자이로 센서 self.zumi = Zumi() self.zumi.reset_gyro()
def __init__(self, zumi = None): self.start_node = Point(0, 0) self.bigben = Point(5, 20) self.seattle = Point(25, 0) self.paris = Point(15, 10) self.NY = Point(10, 15) self.china = Point(25, 20) self.node1 = Point(10, 0) self.node2 = Point(20, 0) self.node3 = Point(30, 0) self.node4 = Point(0, 10) self.node5 = Point(10, 10) self.node6 = Point(20, 10) self.node7 = Point(30, 10) self.node8 = Point(0, 20) self.node9 = Point(10, 20) self.node10 = Point(20, 20) self.node11 = Point(30, 20) self.node12 = Point(0, 30) self.node13 = Point(10, 30) self.node14 = Point(30, 30) self.G = nx.Graph() self.generate_map() self.NORTH = 0 self.WEST = 90 self.EAST = -90 self.SOUTH = 180 self.heading = self.NORTH if zumi is None: # pass self.zumi = Zumi() self.motor_speed = 10 self.ir_threshold = 70 self.reverse = False
def run(): try: zumi = Zumi() camera = Camera() screen = Screen() personality = Personality(zumi, screen) faceDetector = FaceDetector() camera.start_camera() while True: image = camera.capture() face = faceDetector.detect_face(image) if face: face_roi = faceDetector.get_face_roi() smile = faceDetector.detect_smile(face_roi) if smile: personality.happy() else: personality.angry() else: screen.close_eyes() finally: screen.draw_text("") camera.close()
def acc_text(string='', line=25, count=100, font_size=16): import Adafruit_SSD1306 import time import os from PIL import Image, ImageFont, ImageDraw length = len(string) zumi = Zumi() zumi.reset_gyro() state = 0 TEXT_FILE_PATH = os.path.dirname( os.path.abspath('__file__')) + "/module/futura.ttf" disp = Adafruit_SSD1306.SSD1306_128_64(rst=24) #print(length) disp.begin() width = disp.width height = disp.height screen_image = None image = Image.new('1', (width, height)) font = ImageFont.truetype(TEXT_FILE_PATH, font_size) draw = ImageDraw.Draw(image) disp.clear() disp.display() size = draw.textsize(string, font=font) if (line >= 0 and line <= 45): if (size[0] > 128): print("The string entered is too long.") else: draw.text((50, line), string, font=font, fill=255) disp.image(image) disp.display() disp.command(0x2E) #SSD1306_DEACTIVATE_SCROLL for i in range(0, count): angles = zumi.update_angles() time.sleep(0.1) if (angles[3] > 5): if (state != 1): state = 1 #loop_text('L', string) disp.command(0x27) #SSD1306_LEFT_HORIZONTAL_SCROLL disp.command(0x00) #dummy disp.command(0x00) #start disp.command(0x00) disp.command(0x0f) #stop disp.command(0x00) disp.command(0xff) disp.command(0x2f) #activate scroll elif (angles[3] < -5): if (state != 2): state = 2 #loop_text('R', string) disp.command(0x26) #SSD1306_RIGHT_HORIZONTAL_SCROLL disp.command(0x00) #dummy disp.command(0x00) #start disp.command(0x00) disp.command(0x0f) #stop disp.command(0x00) disp.command(0xff) disp.command(0x2f) #activate scroll else: if (state != 0): state = 0 disp.command(0x2E) #SSD1306_DEACTIVATE_SCROLL disp.command(0x2E) #SSD1306_DEACTIVATE_SCROLL else: print('Lines can be entered from 0 to 45.')
from zumi.zumi import Zumi import time from zumi.protocol import IR zumi = Zumi() def crossing_line(numLines, motor_speed=10, ir_threshold=125): # 직진을 위한 자이로 센서 보정 #zumi.mpu.calibrate_MPU(100) zumi.reset_gyro() heading = 0 left_on_white = True right_on_white = True right_switch = 0 left_switch = 0 time_switch = False lineCount = 1 # 흰색에서 출발 print("start") while True: bottom_left_ir = zumi.get_IR_data(IR.bottom_left) bottom_right_ir = zumi.get_IR_data(IR.bottom_right) # white check
def predict(model): c = Crop() eye = Screen() zumi = Zumi() camera = Camera(64, 64) personality = Personality(zumi, eye) cnt = 0 prev_label = -1 cnt_none_crop = 0 try: while True: zumi.reset_drive() img = camera.run() crop_img = c.crop(img) if crop_img is None: if cnt_none_crop == 0: personality.look_around_open01() elif cnt_none_crop == 1: personality.look_around_open02() elif cnt_none_crop == 2: personality.look_around_open03() elif cnt_none_crop == 3: personality.look_around_open04() prev_label = -1 print(cnt, prev_label, cnt_none_crop) cnt_none_crop += 1 cnt_none_crop %= 4 continue else: cnt_none_crop = 0 x = Image.fromarray(crop_img) x = np.expand_dims(x, axis=0) preds = model.predict_classes(x) print(landmark[preds[0]]) if prev_label == preds[0]: cnt += 1 if cnt > 2: print(eye.EYE_IMAGE_FOLDER_PATH + "sad1.ppm") print("reaction!!!!") eye.draw_image( eye.path_to_image(LAND_PATH + landmark[preds[0]] + ".jpg")) time.sleep(2) if landmark[preds[0]] == 'eiffel': zumi.turn_right(90) elif landmark[preds[0]] == 'nyc': zumi.turn_right(45) elif landmark[preds[0]] == 'seattle': zumi.turn_left(45) elif landmark[preds[0]] == 'china': zumi.turn_left(90) time.sleep(.5) zumi.forward(10, duration) time.sleep(.5) personality.celebrate() time.sleep(.5) zumi.reverse(10, duration) time.sleep(.5) if landmark[preds[0]] == 'eiffel': zumi.turn_left(90) elif landmark[preds[0]] == 'nyc': zumi.turn_left(45) elif landmark[preds[0]] == 'seattle': zumi.turn_right(45) elif landmark[preds[0]] == 'china': zumi.turn_right(90) cnt = 0 else: personality.reading( eye.path_to_image(READ_PATH + "reading_" + str(cnt) + ".PPM")) else: cnt = 0 prev_label = preds[0] except KeyboardInterrupt: camera.shutdown() eye.draw_text("") zumi.stop() print("\nExiting...") except: camera.shutdown() eye.draw_text("") zumi.stop() print("\nExiting...")
def __init__(self): self.myConnection = '' self.user = '' #init zumi instance self.zumi = Zumi()
def predict(model,Reroute=False): c = Crop() eye = Screen() zumi = Zumi() camera = Camera(64, 64) personality = Personality(zumi, eye) cnt = 0 prev_label = -1 cnt_none_crop = 0 try: while True: img = camera.run() crop_img = c.crop(img) if crop_img is None: if cnt_none_crop == 0: personality.look_around_open01() elif cnt_none_crop == 1: personality.look_around_open02() elif cnt_none_crop == 2: personality.look_around_open03() elif cnt_none_crop == 3: personality.look_around_open04() prev_label = -1 print(cnt, prev_label, cnt_none_crop) cnt_none_crop += 1 cnt_none_crop %= 4 continue else: cnt_none_crop = 0 x = Image.fromarray(crop_img) x = np.expand_dims(x, axis=0) preds = model.predict_classes(x) print(landmark[preds[0]]) if prev_label == preds[0]: cnt += 1 if cnt > 2: print(eye.EYE_IMAGE_FOLDER_PATH + "sad1.ppm") print("reaction!!!!") eye.draw_image(eye.path_to_image(LAND_PATH + landmark[preds[0]] + ".jpg")) time.sleep(2) route = Route_new() if Reroute: print("go with rerouting") if landmark[preds[0]] == 'eiffel': route.driving(route.start_node, route.paris) elif landmark[preds[0]] == 'nyc': route.driving(route.start_node, route.NY) elif landmark[preds[0]] == 'seattle': route.driving(route.start_node, route.seattle) elif landmark[preds[0]] == 'china': route.driving(route.start_node, route.china) else: route.driving(route.start_node, route.bigben) zumi.stop() personality.celebrate() time.sleep(.5) else: print("no reroute") if landmark[preds[0]] == 'eiffel': route.driving_without_reroute(route.start_node, route.paris) route.park_right() elif landmark[preds[0]] == 'nyc': route.driving_without_reroute(route.start_node, route.NY) route.park_right() elif landmark[preds[0]] == 'seattle': route.driving_without_reroute(route.start_node, route.seattle) route.park_left() elif landmark[preds[0]] == 'china': route.driving_without_reroute(route.start_node, route.china) route.park_left() else: route.driving_without_reroute(route.start_node, route.bigben) route.park_right() zumi.stop() personality.celebrate() time.sleep(.5) cnt = 0 else: personality.reading(eye.path_to_image(READ_PATH + "reading_" + str(cnt) + ".PPM")) else: cnt = 0 prev_label = preds[0] except KeyboardInterrupt: camera.shutdown() eye.draw_text("") zumi.stop() print("\nExiting...") except: camera.shutdown() eye.draw_text("") zumi.stop() print("\nExiting...")