def __init__internal(self, next_wave=True): self.enemies = [] for i in range(self.enemy_in_waves[self.wave]): x = random.randint(20, 780) y = random.randint(320, 580) enemy = Enemy(x, y) self.enemies.append(enemy) self.character = Character(400, 50) self.pressed = [] self.mouse_position = (0, 0) if next_wave: for bullet in self.bullets: bullet.visible = False for ebullet in self.enemy_bullets: ebullet.visible = False self.bullets = [] self.recent_fire = 0 self.enemy_bullets = [] self.recent_enemy_fire = 0 self.finished = False if not next_wave: self.shield_gauge = Gauge(100, 40, 150, 25) self.power_gauge = Gauge(100, 80, 150, 25) self.timer = Timer(10, SCREEN_HEIGHT - 30) self.time = 0 self.score = ScoreCalculator() self.total_score = 0 self.is_using_shield = False self.is_using_power = False
def __init__(self, session): Screen.__init__(self, session) self["hddtempg"] = Gauge() self["ramg"] = Gauge() self["swapg"] = Gauge() self["memtg"] = Gauge() self["spacetg"] = Gauge() self["cffg"] = Gauge() self["usbg"] = Gauge() self["hddg"] = Gauge() self["flashg"] = Gauge() self["spy1"] = Pixmap() self["spy2"] = Pixmap() self["spy3"] = Pixmap() self["spy4"] = Pixmap() self["spy5"] = Pixmap() self["spy6"] = Pixmap() self["spy7"] = Pixmap() self["spy8"] = Pixmap() self["spy9"] = Pixmap() self["spy10"] = Pixmap() self["spy11"] = Pixmap() self["smallmon"] = Label("") self["moni"] = Label("") self["moni2"] = Label("") self["monipix"] = Pixmap() self["smallmon"].hide() self["monipix"].hide() self["moni2"].hide() self["actions"] = ActionMap( ["WizardActions", "ColorActions", "NumberActions"], { "ok": self.KeyOk, "back": self.KeyOk, "red": self.KeyRed, "green": self.KeyGreen, "yellow": self.KeyYellow, "blue": self.KeyBlue, "1": self.KeyOne, "2": self.KeyTwo, "3": self.KeyThree }) self.extendedFlash = False self.activityTimer = eTimer() self.activityTimer.timeout.get().append(self.updateList) self.moni_state = 0 self.moniTimer = eTimer() self.moniTimer.timeout.get().append(self.moveON) self.onShow.append(self.startShow) self.onClose.append(self.delTimer)
def __init__(self, session): Screen.__init__(self, session) self['hddtempg'] = Gauge() self['ramg'] = Gauge() self['swapg'] = Gauge() self['memtg'] = Gauge() self['spacetg'] = Gauge() self['cffg'] = Gauge() self['usbg'] = Gauge() self['hddg'] = Gauge() self['flashg'] = Gauge() self['spy1'] = Pixmap() self['spy2'] = Pixmap() self['spy3'] = Pixmap() self['spy4'] = Pixmap() self['spy5'] = Pixmap() self['spy6'] = Pixmap() self['spy7'] = Pixmap() self['spy8'] = Pixmap() self['spy9'] = Pixmap() self['spy10'] = Pixmap() self['spy11'] = Pixmap() self['smallmon'] = Label('') self['moni'] = Label('') self['moni2'] = Label('') self['monipix'] = Pixmap() self['smallmon'].hide() self['monipix'].hide() self['moni2'].hide() self['actions'] = ActionMap( ['WizardActions', 'ColorActions', 'NumberActions'], { 'ok': self.KeyOk, 'back': self.KeyOk, 'red': self.KeyRed, 'green': self.KeyGreen, 'yellow': self.KeyYellow, 'blue': self.KeyBlue, '1': self.KeyOne, '2': self.KeyTwo, '3': self.KeyThree }) self.extendedFlash = False self.activityTimer = eTimer() self.activityTimer.timeout.get().append(self.updateList) self.moni_state = 0 self.moniTimer = eTimer() self.moniTimer.timeout.get().append(self.moveON) self.onShow.append(self.startShow) self.onClose.append(self.delTimer)
def renderGroupINSM(self): #Render Group Frame self.grpINSM = tk.LabelFrame( self, text="Intelligent Navigation System Monitor", width=530, height=260, bg="light gray") self.grpINSM.grid(row=0, column=0, padx=5, pady=5, sticky=tk.N + tk.W, columnspan=2) self.grpINSM.grid_propagate(0) #Render Group Widgets self.INSM_Acceleration = Gauge(self.grpINSM, "Acceleration", "Components/GaugeTransparent.jpg", width=150, height=150, radius=68) self.INSM_Acceleration.grid(row=0, column=0, padx=5, pady=0) self.INSM_Speed = Gauge(self.grpINSM, "Speed", "Components/GaugeTransparent.jpg", width=200, height=200, radius=93) self.INSM_Speed.grid(row=0, column=1, padx=5, pady=0) self.INSM_Temperature = Gauge(self.grpINSM, "Temperature", "Components/GaugeWarning.jpg", width=150, height=150, radius=68) self.INSM_Temperature.grid(row=0, column=2, padx=5, pady=0) self.INSM_lblAcceleration = tk.Label(self.grpINSM, text=" 4.6 ", font="Digital-7 24", bg="light gray", fg="black", relief="sunken") self.INSM_lblAcceleration.grid(row=1, column=0, padx=5, pady=0) self.INSM_lblSpeed = tk.Label(self.grpINSM, text="0", font="Digital-7 24", bg="light gray", fg="black", relief="sunken") self.INSM_lblSpeed.grid(row=1, column=1, padx=5, pady=0) self.INSM_lblTemperature = tk.Label(self.grpINSM, text=" 35 ", font="Digital-7 24", bg="light gray", fg="black", relief="sunken") self.INSM_lblTemperature.grid(row=1, column=2, padx=5, pady=0)
class MainScene(BaseScene): def __init__(self, level=1): super().__init__() self.level = level self.wave = 0 self.enemy_in_waves = [] with open("StageData/level.txt") as f: while True: l = f.readline() if len(l) == 0: break if l[0] == "#": continue #level 글자를 찾아야하고, level level 에 해당되는 줄 탐색 #enemies in waves 에 읽은 값을 추가 if l.find("LEVEL") == 0: if int(l.split()[1]) == self.level: l = f.readline() self.enemy_in_waves.extend(map(int, l.split())) self.__init__internal(False) def __init__internal(self, next_wave=True): self.enemies = [] for i in range(self.enemy_in_waves[self.wave]): x = random.randint(20, 780) y = random.randint(320, 580) enemy = Enemy(x, y) self.enemies.append(enemy) self.character = Character(400, 50) self.pressed = [] self.mouse_position = (0, 0) if next_wave: for bullet in self.bullets: bullet.visible = False for ebullet in self.enemy_bullets: ebullet.visible = False self.bullets = [] self.recent_fire = 0 self.enemy_bullets = [] self.recent_enemy_fire = 0 self.finished = False if not next_wave: self.shield_gauge = Gauge(100, 40, 150, 25) self.power_gauge = Gauge(100, 80, 150, 25) self.timer = Timer(10, SCREEN_HEIGHT - 30) self.time = 0 self.score = ScoreCalculator() self.total_score = 0 self.is_using_shield = False self.is_using_power = False def draw(self): for bullet in self.enemy_bullets: bullet.draw() for enemy in self.enemies: enemy.draw() self.character.draw() for bullet in self.bullets: bullet.draw() self.timer.draw() self.shield_gauge.draw1() self.power_gauge.draw2() arcade.draw_text("Score: %6d" % (self.score.calculate(self.timer.time, False)), SCREEN_WIDTH - 10, SCREEN_HEIGHT - 30, arcade.color.BLACK, font_size=20, align="right", anchor_x="right") if self.finished: arcade.draw_text(str("Play Again?"), SCREEN_WIDTH / 2, SCREEN_HEIGHT - 400, arcade.color.BLACK, font_size=40, align="center", anchor_x="center") arcade.draw_text(str(self.total_score), SCREEN_WIDTH / 2, SCREEN_HEIGHT - 200, arcade.color.BLACK, font_size=40, align="center", anchor_x="center") def update(self, delta_time): delta_x = 0 delta_y = 0 if check_pressed("q", self.pressed): if self.finished: SceneController.to_leaderboard_scene(self.create_name(), self.total_score) else: SceneController.to_start_scene() if not self.finished: if check_pressed("left", self.pressed): delta_x -= 5 if check_pressed("right", self.pressed): delta_x += 5 if check_pressed("up", self.pressed): delta_y += 5 if check_pressed("down", self.pressed): delta_y -= 5 self.character.update(delta_x, delta_y) if check_pressed("shield", self.pressed): delta_shield = -delta_time * SHIELD_DECREASE self.shield_gauge.update(delta_shield) self.is_using_shield = self.shield_gauge.fill > 0 else: delta_shield = delta_time * SHIELD_INCREASE self.shield_gauge.update(delta_shield) self.is_using_shield = False self.character.is_shield_on = self.is_using_shield if check_pressed("power", self.pressed): if not self.is_using_power: if self.power_gauge.fill == 1: self.is_using_power = True if self.is_using_power: delta_power = -delta_time * POWER_DECREASE self.power_gauge.update(delta_power) self.is_using_power = self.power_gauge.fill > 0 else: delta_power = delta_time * POWER_INCREASE self.power_gauge.update(delta_power) self.character.is_power_on = self.is_using_power else: if check_pressed("r", self.pressed): LeaderBoard(self.create_name(), self.total_score) self.reset() for bullet in self.bullets: bullet.update(delta_time) for bullet in self.enemy_bullets: bullet.update(delta_time) if not self.finished: for enemy in self.enemies: enemy.update(delta_time) if not self.finished: self.timer.update(delta_time) self.time += delta_time if self.is_using_power: if check_pressed("shoot", self.pressed) and not self.finished: if self.recent_fire == 0 or self.recent_fire + self.character.power_attack_speed < self.time: x = self.character.x y = self.character.y + 15 bullet = Bullet.create_normal_bullet( x, y, (self.mouse_position[0] - x, self.mouse_position[1] - y)) self.bullets.append(bullet) self.recent_fire = self.time else: if check_pressed("shoot", self.pressed) and not self.finished: if self.recent_fire == 0 or self.recent_fire + self.character.attack_speed < self.time: x = self.character.x y = self.character.y + 15 bullet = Bullet.create_normal_bullet( x, y, (self.mouse_position[0] - x, self.mouse_position[1] - y)) self.bullets.append(bullet) self.recent_fire = self.time # 지금은 적 fire가 임시구현이라 하드코딩 if not self.finished: if self.recent_enemy_fire + 1 < self.time: self.recent_enemy_fire = self.time for enemy in self.enemies: if enemy.visible: self.enemy_bullets.extend(enemy.fire()) self.on_collide() self.check_finish() delete_list = [] for i, bullet in enumerate(self.bullets): if bullet.y > 600: delete_list.insert(0, i) for i in delete_list: bullet = self.bullets[i] self.bullets.pop(i) delete_list = [] for i, bullet in enumerate(self.enemy_bullets): if bullet.x > 800 or bullet.x < 0 or \ bullet.y > 600 or bullet.y < 0: delete_list.insert(0, i) for i in delete_list: self.enemy_bullets.pop(i) def on_collide(self): for enemy in self.enemies: for bullet in self.bullets: if abs(bullet.x - enemy.x) < bullet.size + enemy.size / 2 \ and abs(bullet.y - enemy.y) < bullet.size + enemy.size / 2 \ and enemy.visible \ and bullet.visible: enemy.hp -= 1 if not self.finished: self.score.hit += 1 if enemy.hp == 0: enemy.visible = False if not self.finished: self.score.kill += 1 bullet.visible = False for ebullet in self.enemy_bullets: if abs(ebullet.x - self.character.x) < ebullet.size + self.character.size / 2 \ and abs(ebullet.y - self.character.y) < ebullet.size + self.character.size / 2: ebullet.visible = False if not self.is_using_shield: self.character.visible = False def check_finish(self): if self.finished: return is_win = True for enemy in self.enemies: is_win = is_win and not enemy.visible if is_win: if self.wave == len(self.enemy_in_waves) + 1: self.finished = True self.total_score += self.score.calculate( self.timer.time, is_win) else: self.wave += 1 self.__init__internal() if not self.character.visible: self.finished = True self.total_score += self.score.calculate(self.timer.time, False) def reset(self): if self.finished: for enemy in self.enemies: if enemy.visible: enemy.visible = False for bullet in self.bullets: if bullet.visible: bullet.visible = False for ebullet in self.enemy_bullets: if ebullet.visible: ebullet.visible = False if self.character.visible: self.character.visible = False self.__init__() def create_name(self): t = datetime.datetime.today() name = str(t.date())[2:] + "-" + str(t.time()).split(".")[0] return name
class SkyeCortex(tk.Frame): def __init__(self, master=None): #Start SKYE Talk self.voice = pyvona.create_voice( 'GDNAJLXBSXZ5SF2J65LA', 'ZEPIRgVi/bppB7gq4VGlKDesbvJYir24LAdAhRAO') self.voice.voice_name = "Salli" #Initialize Window Setting tk.Frame.__init__(self, master, padx=5, pady=5, bg="light gray") master.minsize(width=500, height=700) master.maxsize(width=1000, height=900) master.title("Skye Cortex") master.wm_title("Skye Cortex") master.wm_protocol("WM_DELETE_WINDOW", self.onClose) self.grid() #Start Camera print("Initializing Camera...") self.vs = VideoStream(usePiCamera=True).start() time.sleep(2.0) self.frame = None self.captureThread = None self.stopEvent = None self.faceCascade = cv2.CascadeClassifier( "Components/HaarClassifier.xml") self.stopEvent = threading.Event() self.captureThread = threading.Thread(target=self.renderFeed, args=()) self.captureThread.start() #Setup Raspberry Pi GPIO self.heartDutyCycle = 100 self.initializeGPIO() self.speed = tk.IntVar() # Identify Power Management Registers self.power_mgmt_1 = 0x6b self.power_mgmt_2 = 0x6c #Setup I2C self.bus = smbus.SMBus(1) self.address = 0x68 #I2C Address self.bus.write_byte_data(self.address, self.power_mgmt_1, 0) # Start the sensor in sleep mode #Draw Graphics self.renderGUI() self.temp = ImageTk.PhotoImage(Image.open("Components/Hymn.jpg")) self.captureDisplay = tk.Label(self.grpVision, image=self.temp, borderwidth=0, highlightthickness=0, width=320, height=240) self.captureDisplay.grid(row=0, column=0, padx=5, pady=5, columnspan=3, sticky=tk.N) self.captureDisplay.grid_propagate(0) #Start Metrics Thread self.metricsThread = None self.metricsThread = threading.Thread(target=self.updateMetrics, args=()) self.metricsThread.start() #Start Heart PWM Thread self.heartPWMThread = None self.heartPWMThread = threading.Thread(target=self.heartPulse, args=()) self.heartPWMThread.start() def renderGroupINSM(self): #Render Group Frame self.grpINSM = tk.LabelFrame( self, text="Intelligent Navigation System Monitor", width=530, height=260, bg="light gray") self.grpINSM.grid(row=0, column=0, padx=5, pady=5, sticky=tk.N + tk.W, columnspan=2) self.grpINSM.grid_propagate(0) #Render Group Widgets self.INSM_Acceleration = Gauge(self.grpINSM, "Acceleration", "Components/GaugeTransparent.jpg", width=150, height=150, radius=68) self.INSM_Acceleration.grid(row=0, column=0, padx=5, pady=0) self.INSM_Speed = Gauge(self.grpINSM, "Speed", "Components/GaugeTransparent.jpg", width=200, height=200, radius=93) self.INSM_Speed.grid(row=0, column=1, padx=5, pady=0) self.INSM_Temperature = Gauge(self.grpINSM, "Temperature", "Components/GaugeWarning.jpg", width=150, height=150, radius=68) self.INSM_Temperature.grid(row=0, column=2, padx=5, pady=0) self.INSM_lblAcceleration = tk.Label(self.grpINSM, text=" 4.6 ", font="Digital-7 24", bg="light gray", fg="black", relief="sunken") self.INSM_lblAcceleration.grid(row=1, column=0, padx=5, pady=0) self.INSM_lblSpeed = tk.Label(self.grpINSM, text="0", font="Digital-7 24", bg="light gray", fg="black", relief="sunken") self.INSM_lblSpeed.grid(row=1, column=1, padx=5, pady=0) self.INSM_lblTemperature = tk.Label(self.grpINSM, text=" 35 ", font="Digital-7 24", bg="light gray", fg="black", relief="sunken") self.INSM_lblTemperature.grid(row=1, column=2, padx=5, pady=0) def renderGroupCASM(self): #Render Group Frame self.grpCASM = tk.LabelFrame(self, text="Collision Avoidance System Monitor", width=300, height=100, bg="light gray") self.grpCASM.grid(row=1, column=0, padx=5, pady=5, sticky=tk.N + tk.W, columnspan=2) self.grpCASM.grid_propagate(0) #Render Group Widgets self.CASM_lblACDA = tk.Label(self.grpCASM, text="Assured Clear Distance Ahead: ", bg="light gray") self.CASM_lblACDA.grid(row=0, column=0, padx=5, pady=10, sticky=tk.E) self.CASM_lblRCPW = tk.Label(self.grpCASM, text="Rear Collision Proximity Warning: ", bg="light gray") self.CASM_lblRCPW.grid(row=1, column=0, padx=5, pady=0, sticky=tk.W) self.CASM_lblRCPWMetric = tk.Label(self.grpCASM, text="Clear", bg="light gray") self.CASM_lblRCPWMetric.grid(row=1, column=1, padx=5, pady=0, sticky=tk.W) self.CASM_lblACDAMetric = tk.Label(self.grpCASM, text="37.5cm", bg="light gray") self.CASM_lblACDAMetric.grid(row=0, column=1, padx=5, pady=0, sticky=tk.E) # self.CASM_lblACDAWarning = tk.Label(self.grpCASM, text="WARNING", bg="light gray",fg="red") # self.CASM_lblACDAWarning.grid(row=0, column=2, padx=5, pady=0, sticky=tk.E) # self.CASM_btnEmergency = tk.Button(self.grpCASM, text="Emergency System Shutoff", bg="light gray", borderwidth=0, highlightthickness=0, highlightbackground="light gray") # self.CASM_btnEmergency.grid(row=1, column=2, padx=5, pady=0, sticky=tk.W) def renderGroupSPEED(self): #Render Group Frame self.grpSPEED = tk.LabelFrame(self, text="Speed Setting", width=200, height=100, bg="light gray") self.grpSPEED.grid(row=1, column=1, padx=5, pady=5, sticky=tk.N + tk.W, columnspan=1) self.grpSPEED.grid_propagate(0) #Render Group Widgets self.radioFast = tk.Radiobutton(self.grpSPEED, text='Fast', value=2, bg='light gray', variable=self.speed) self.radioFast.grid(row=0, column=0, padx=10, pady=0, sticky=tk.W) self.radioSlow = tk.Radiobutton(self.grpSPEED, text='Slow', value=1, bg='light gray', variable=self.speed) self.radioSlow.grid(row=2, column=0, padx=10, pady=0, sticky=tk.W) self.radioFast.select() def renderGroupTALK(self): #Render Group Frame self.grpTalk = tk.LabelFrame(self, text="SKYE Talk", width=530, height=100, bg="light gray") self.grpTalk.grid(row=3, column=0, padx=5, pady=5, sticky=tk.N + tk.W, columnspan=2) self.grpTalk.grid_columnconfigure( 0, weight=1) # allows textbox size to expand to fill frame self.grpTalk.grid_propagate(0) #Render Group Widgets self.TALK_txtSynthesis = tk.Entry(self.grpTalk, text="Enter Text:") self.TALK_txtSynthesis.grid(row=0, column=0, padx=5, pady=10, sticky=tk.W + tk.E) self.TALK_btnSynthesis = tk.Button(self.grpTalk, text="Speak Text", bg="light gray", borderwidth=0, highlightthickness=0, highlightbackground="light gray") self.TALK_btnSynthesis.grid(row=1, column=0, padx=5, pady=0, sticky=tk.E) #Create Event Handler self.TALK_btnSynthesis["command"] = self.speak def renderGroupATTITUDE(self): #Render Group Frame self.grpAttitude = tk.LabelFrame(self, text="Attitude Indicator", width=320, height=300, bg="light gray") self.grpAttitude.grid(row=4, column=0, padx=5, pady=5, sticky=tk.S + tk.W) self.grpAttitude.grid_propagate(0) #Render Group Widgets self.ATTITUDE_inicator = AttitudeIndicator(self.grpAttitude) self.ATTITUDE_inicator.grid(row=0, column=0, padx=15, pady=5) def renderGroupVISION(self): #Render Group Frame self.grpVision = tk.LabelFrame(self, text="SKYE Vision", width=350, height=370, padx=5, pady=5, bg="light gray") self.grpVision.grid(row=0, column=2, padx=5, pady=5, rowspan=4, sticky=tk.N + tk.W) #self.grpVision.grid_propagate(0) #Render Group Widgets self.VISION_Canvas = tk.Canvas( self.grpVision, bg="light gray", borderwidth=0, highlightthickness=0, height=80) ### Height was originally 30 when working on the Pi self.VISION_Canvas.grid(row=1, column=0, padx=5, pady=5, columnspan=3, sticky=tk.N) #Draw Group Canvas Objects self.head_fine_left = ImageTk.PhotoImage( self.triangle_left_image.resize((30, 30)), Image.ANTIALIAS) self.head_fine_right = ImageTk.PhotoImage( self.triangle_right_image.resize((30, 30)), Image.ANTIALIAS) self.VISION_Canvas.create_image(110, 15, image=self.head_fine_left, tag="fine_left") self.VISION_Canvas.create_image(170, 15, image=self.head_fine_right, tag="fine_right") self.VISION_Canvas.create_oval(0, 50, 80, 78, fill="gray", tag="full_left") self.VISION_Canvas.create_oval(100, 50, 180, 78, fill="gray", tag="center") self.VISION_Canvas.create_oval(200, 50, 280, 78, fill="gray", tag="full_right") self.VISION_Canvas.create_text(140, 64, text="Center", fill="black", font="Arial 12", tag="center_text") self.VISION_Canvas.create_text(40, 64, text="Full Left", fill="black", font="Arial 12", tag="full_left_text") self.VISION_Canvas.create_text(240, 64, text="Full Right", fill="black", font="Arial 12", tag="full_right_text") #Create Event Handlers self.VISION_Canvas.tag_bind("fine_left", '<ButtonPress-1>', self.btnPressed_VISION_FineLeft) self.VISION_Canvas.tag_bind("fine_right", '<ButtonPress-1>', self.btnPressed_VISION_FineRight) self.VISION_Canvas.tag_bind("fine_left", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.VISION_Canvas.tag_bind("fine_right", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.VISION_Canvas.tag_bind("full_right", '<ButtonPress-1>', self.btnPressed_VISION_FullRight) self.VISION_Canvas.tag_bind("center", '<ButtonPress-1>', self.btnPressed_VISION_Center) self.VISION_Canvas.tag_bind("full_left", '<ButtonPress-1>', self.btnPressed_VISION_FullLeft) self.VISION_Canvas.tag_bind("full_right_text", '<ButtonPress-1>', self.btnPressed_VISION_FullRight) self.VISION_Canvas.tag_bind("center_text", '<ButtonPress-1>', self.btnPressed_VISION_Center) self.VISION_Canvas.tag_bind("full_left_text", '<ButtonPress-1>', self.btnPressed_VISION_FullLeft) def renderGroupLISTEN(self): #Render Group Frame self.grpListen = tk.LabelFrame(self, text="SKYE Listen", width=350, height=100, bg="light gray") self.grpListen.grid(row=3, column=2, padx=5, pady=5, sticky=tk.N + tk.W, columnspan=2) self.grpListen.grid_propagate(0) #Render Group Widgets self.LISTEN_lblCurrentQuery = tk.Label( self.grpListen, text= "In the beginning God created the heavens and the earth. The spirit of God was hovering over the waters.", bg="light gray", wraplength=330, justify=tk.LEFT) self.LISTEN_lblCurrentQuery.grid(row=0, column=0, padx=5, pady=5, sticky=tk.E) def renderGroupMOTION(self): #Render Group Frame self.grpMotion = tk.LabelFrame(self, text="SKYE Motion", width=560, height=300, bg="light gray") self.grpMotion.grid(row=4, column=1, padx=5, pady=5, sticky=tk.S, columnspan=2) self.grpMotion.grid_propagate(0) #Render Group Widgets self.MOTION_Canvas = tk.Canvas(self.grpMotion, bg="light gray", borderwidth=0, highlightthickness=0, width=480, height=280) self.MOTION_Canvas.grid(row=0, column=0) self.MOTION_Canvas.grid_propagate(0) #Draw Canvas Objects self.MOTION_Canvas.create_oval(20, 10, 280, 270) self.MOTION_Canvas.create_rectangle(320, 20, 470, 260) self.MOTION_Forward = ImageTk.PhotoImage( self.triangle_up_image.resize((70, 70)), Image.ANTIALIAS) self.MOTION_Canvas.create_image(150, 55, image=self.MOTION_Forward, tag="forward") self.MOTION_Reverse = ImageTk.PhotoImage( self.triangle_down_image.resize((70, 70)), Image.ANTIALIAS) self.MOTION_Canvas.create_image(150, 215, image=self.MOTION_Reverse, tag="reverse") self.MOTION_Left = ImageTk.PhotoImage( self.triangle_left_image.resize((70, 70)), Image.ANTIALIAS) self.MOTION_Canvas.create_image(70, 135, image=self.MOTION_Left, tag="left") self.MOTION_Right = ImageTk.PhotoImage( self.triangle_right_image.resize((70, 70)), Image.ANTIALIAS) self.MOTION_Canvas.create_image(230, 135, image=self.MOTION_Right, tag="right") self.MOTION_Canvas.create_arc(170, 45, 240, 115, fill="gray", tag="driftleft") self.MOTION_Canvas.create_arc(60, 45, 130, 115, start=90.0, fill="gray", tag="driftright") self.MOTION_WingUp = ImageTk.PhotoImage( self.triangle_up_image.resize((50, 50)), Image.ANTIALIAS) self.MOTION_Canvas.create_image(395, 60, image=self.MOTION_WingUp, tag="wing_up") self.MOTION_WingDown = ImageTk.PhotoImage( self.triangle_down_image.resize((50, 50)), Image.ANTIALIAS) self.MOTION_Canvas.create_image(395, 170, image=self.MOTION_WingDown, tag="wing_down") self.MOTION_Canvas.create_oval(385, 105, 405, 125, fill="dark gray", tag="wing_home") self.MOTION_Canvas.create_text(395, 230, text="Wing Control", fill="black", font="Arial 16") #Create Event Handlers self.MOTION_Canvas.tag_bind("forward", '<ButtonPress-1>', self.btnPressed_MOTION_Forward) self.MOTION_Canvas.tag_bind("reverse", '<ButtonPress-1>', self.btnPressed_MOTION_Reverse) self.MOTION_Canvas.tag_bind("left", '<ButtonPress-1>', self.btnPressed_MOTION_Left) self.MOTION_Canvas.tag_bind("right", '<ButtonPress-1>', self.btnPressed_MOTION_Right) self.MOTION_Canvas.tag_bind("driftleft", '<ButtonPress-1>', self.btnPressed_MOTION_DriftLeft) self.MOTION_Canvas.tag_bind("driftright", '<ButtonPress-1>', self.btnPressed_MOTION_DriftRight) self.MOTION_Canvas.tag_bind("forward", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.MOTION_Canvas.tag_bind("reverse", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.MOTION_Canvas.tag_bind("left", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.MOTION_Canvas.tag_bind("right", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.MOTION_Canvas.tag_bind("driftleft", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.MOTION_Canvas.tag_bind("driftright", '<ButtonRelease-1>', self.btnReleased_MOTION_Stop) self.MOTION_Canvas.tag_bind("wing_up", '<ButtonPress-1>', self.btnPressed_MOTION_WingUp) self.MOTION_Canvas.tag_bind("wing_home", '<ButtonPress-1>', self.btnPressed_MOTION_WingHome) self.MOTION_Canvas.tag_bind("wing_down", '<ButtonPress-1>', self.btnPressed_MOTION_WingDown) def heartPulse(self): while not self.stopEvent.is_set(): time.sleep(0.01) if self.heartDutyCycle > 0: self.heartDutyCycle -= 1 else: self.heartDutyCycle = 100 self.heartPWM.ChangeDutyCycle(self.heartDutyCycle) def updateMetrics(self): while not self.stopEvent.is_set(): #Delay 1-Second time.sleep(1) #Update Temperature temp = int( float( os.popen("vcgencmd measure_temp").read().lstrip( "temp=").rstrip("'C\n"))) self.INSM_Temperature.renderNeedle(temp) self.INSM_lblTemperature.configure(text=str(temp)) #Update Attitude accel_xout = self.read_word_2c(0x3b) accel_yout = self.read_word_2c(0x3d) accel_zout = self.read_word_2c(0x3f) te = self.read_word_2c(0x41) accel_xout_scaled = accel_xout / 16384.0 accel_yout_scaled = accel_yout / 16384.0 accel_zout_scaled = accel_zout / 16384.0 pitch = int( self.get_y_rotation(accel_xout_scaled, accel_yout_scaled, accel_zout_scaled)) roll = int( self.get_x_rotation(accel_xout_scaled, accel_yout_scaled, accel_zout_scaled)) self.ATTITUDE_inicator.renderBubble(-roll, -pitch) #Update Acceleration # self.INSM_lblAcceleration.configure(text = str(te)) # self.INSM_lblAcceleration.configure(text = str( int(max(accel_yout_scaled * 100, 0)) )) # self.INSM_Acceleration.renderNeedle(int(max(accel_yout_scaled, 0) * 1000)) #Update Speed # self.INSM_Speed.renderNeedle(int(int(self.INSM_lblSpeed.cget("text")) + (accel_yout_scaled * 1000))) # self.INSM_lblSpeed.configure(text = str(int(int(self.INSM_lblSpeed.cget("text")) + (accel_yout_scaled * 1000)))) def loadShapes(self): self.triangle_left_image = Image.open("Components/triangle_left.jpg") self.triangle_right_image = Image.open("Components/triangle_right.jpg") self.triangle_up_image = Image.open("Components/triangle_up.jpg") self.triangle_down_image = Image.open("Components/triangle_down.jpg") def renderGUI(self): self.loadShapes() self.renderGroupINSM() self.renderGroupCASM() self.renderGroupSPEED() self.renderGroupTALK() self.renderGroupATTITUDE() self.renderGroupVISION() self.renderGroupLISTEN() self.renderGroupMOTION() def renderFeed(self): try: while not self.stopEvent.is_set(): self.frame = self.vs.read() self.frame = imutils.resize(self.frame, width=320) image = cv2.cvtColor(self.frame, cv2.COLOR_BGR2RGB) gray = cv2.cvtColor(self.frame, cv2.COLOR_BGR2GRAY) faces = self.faceCascade.detectMultiScale( gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags=cv2.CASCADE_SCALE_IMAGE) for (x, y, w, h) in faces: cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2) image = Image.fromarray(image) image = ImageTk.PhotoImage(image) self.captureDisplay.configure(image=image) self.captureDisplay.image = image except RuntimeError: print("RuntimeError") def onClose(self): print("Closing...") self.stopEvent.set() self.vs.stop() self.heartPWM.stop() GPIO.cleanup() self.quit() sys.exit(0) def btnPressed_VISION_FineLeft(self, event): self.executeCommand('10000') def btnPressed_VISION_FineRight(self, event): self.executeCommand('10001') def btnPressed_VISION_FullLeft(self, event): self.executeCommand('01101') def btnPressed_VISION_Center(self, event): self.executeCommand('01110') def btnPressed_VISION_FullRight(self, event): self.executeCommand('01111') def btnPressed_MOTION_Forward(self, event): if self.speed.get() == 1: motionThread = threading.Thread(target=self.executeCommand, args=('00111', )) motionThread.start() elif self.speed.get() == 2: motionThread = threading.Thread(target=self.executeCommand, args=('00001', )) motionThread.start() def btnPressed_MOTION_Reverse(self, event): if self.speed.get() == 1: motionThread = threading.Thread(target=self.executeCommand, args=('01000', )) motionThread.start() elif self.speed.get() == 2: motionThread = threading.Thread(target=self.executeCommand, args=('00010', )) motionThread.start() def btnPressed_MOTION_Left(self, event): if self.speed.get() == 1: motionThread = threading.Thread(target=self.executeCommand, args=('01001', )) motionThread.start() elif self.speed.get() == 2: motionThread = threading.Thread(target=self.executeCommand, args=('00011', )) motionThread.start() def btnPressed_MOTION_Right(self, event): if self.speed.get() == 1: motionThread = threading.Thread(target=self.executeCommand, args=('01010', )) motionThread.start() elif self.speed.get() == 2: motionThread = threading.Thread(target=self.executeCommand, args=('00100', )) motionThread.start() def btnPressed_MOTION_DriftLeft(self, event): if self.speed.get() == 1: motionThread = threading.Thread(target=self.executeCommand, args=('01010', )) motionThread.start() elif self.speed.get() == 2: motionThread = threading.Thread(target=self.executeCommand, args=('01011', )) motionThread.start() def btnPressed_MOTION_DriftRight(self, event): if self.speed.get() == 1: motionThread = threading.Thread(target=self.executeCommand, args=('01100', )) motionThread.start() elif self.speed.get() == 2: motionThread = threading.Thread(target=self.executeCommand, args=('00110', )) motionThread.start() def btnReleased_MOTION_Stop(self, event): self.executeCommand('00000') def btnPressed_MOTION_WingUp(self, event): self.executeCommand('10010') def btnPressed_MOTION_WingHome(self, event): self.executeCommand('10011') def btnPressed_MOTION_WingDown(self, event): self.executeCommand('10100') def speak(self): self.voice.speak(self.TALK_txtSynthesis.get()) def executeCommand(self, bitString): GPIO.output(self.C1, int(bitString[0])) GPIO.output(self.C2, int(bitString[1])) GPIO.output(self.C3, int(bitString[2])) GPIO.output(self.C4, int(bitString[3])) GPIO.output(self.C5, int(bitString[4])) time.sleep(0.1) def initializeGPIO(self): #Set Pin Mode to Board GPIO.setmode(GPIO.BOARD) #Initialize Control Pin Variables self.C1 = 29 self.C2 = 31 self.C3 = 33 self.C4 = 35 self.C5 = 37 self.HeartLED = 12 #Set Control Pins as Outputs GPIO.setup(self.C1, GPIO.OUT) GPIO.setup(self.C2, GPIO.OUT) GPIO.setup(self.C3, GPIO.OUT) GPIO.setup(self.C4, GPIO.OUT) GPIO.setup(self.C5, GPIO.OUT) GPIO.setup(self.HeartLED, GPIO.OUT) #Set Initial Pin State Low GPIO.output(self.C1, GPIO.LOW) GPIO.output(self.C2, GPIO.LOW) GPIO.output(self.C3, GPIO.LOW) GPIO.output(self.C4, GPIO.LOW) GPIO.output(self.C5, GPIO.LOW) GPIO.output(self.HeartLED, GPIO.LOW) #Initialize PWM self.heartPWM = GPIO.PWM(self.HeartLED, 2000) self.heartPWM.start(self.heartDutyCycle) #I2C I/O Functions def read_byte(self, adr): return self.bus.read_byte_data(self.address, adr) def read_word(self, adr): high = self.bus.read_byte_data(self.address, adr) low = self.bus.read_byte_data(self.address, adr + 1) val = (high << 8) + low return val def read_word_2c(self, adr): val = self.read_word(adr) if (val >= 0x8000): return -((65535 - val) + 1) else: return val def dist(self, a, b): return math.sqrt((a * a) + (b * b)) def get_y_rotation(self, x, y, z): radians = math.atan2(x, self.dist(y, z)) return -math.degrees(radians) def get_x_rotation(self, x, y, z): radians = math.atan2(y, self.dist(x, z)) return math.degrees(radians)
arcade.start_render() self.obj.draw() arcade.draw_text("(%d, %d)" % (self.x, self.y), 10, 10, arcade.color.BLACK) def on_key_press(self, symbol: int, modifiers: int): self.pressed.append(symbol) def on_key_release(self, symbol: int, modifiers: int): if symbol in self.pressed: self.pressed.remove(symbol) def on_update(self, delta_time: float): if UP in self.pressed: self.y += 1 if DOWN in self.pressed: self.y -= 1 if LEFT in self.pressed: self.x -= 1 if RIGHT in self.pressed: self.x += 1 self.obj.x = self.x self.obj.y = self.y if __name__ == "__main__": from Components.Gauge import Gauge ComponentTest(Gauge(0, 0, SCREEN_WIDTH / 8, SCREEN_HEIGHT / 48)) arcade.set_background_color(arcade.color.WHITE) arcade.run()