def _state_func_control(self): # EFFECTS : 指示に従う状態 while True: try: # 一旦キューを空にする while not self.senders['Julius'].msg_queue.empty(): self.senders['Julius'].msg_queue.get() # 空にしてから待つ msg = self.senders['Julius'].msg_queue.get(timeout = 0.1) if '右' in msg: self.controllers['Motor'].cmd_queue.put((-5000, 5000)) self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') elif '左' in msg: self.controllers['Motor'].cmd_queue.put((5000, -5000)) self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') elif '前' in msg: self.controllers['Motor'].cmd_queue.put((10000, 10000)) self.controllers['JTalk'].cmd_queue.put('./voice-sample/yes.wav') except Empty: pass # ウェブカメラは常にあたらしい画像を送り続けているのでキューを空にする必要はない frame1, frame2 = self.senders['Webcamera'].msg_queue.get() # Gの検出 coc_pos_list = detect_coc(frame1) print(coc_pos_list) if len(coc_pos_list) > 0: self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') return 'chase_coc'
def _state_func_smash_coc(self): # EFFECTS : 虫を叩く # 一旦止まる self.controllers['Motor'].cmd_queue.put((0,0)) # 叩く self.controllers['Arm'].cmd_queue.put(-30) time.sleep(1) # 上げる self.controllers['Arm'].cmd_queue.put(60) # 一定時間待つ time.sleep(2) frame1, frame2 = self.senders['Webcamera'].msg_queue.get() # 虫が動いたかどうかの判定 coc_pos_list = detect_coc(frame1) # 虫が画面にいない if len(coc_pos_list) == 0: # やれなかったと言う self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') return 'chase_coc' # 射程圏外にいる if not self.smash_point[0][0] < coc_pos_list[0][0] < self.smash_point[1][0] or \ not self.smash_point[0][1] < coc_pos_list[0][1] < self.smash_point[1][1]: # やれなかったと言う self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') return 'chase_coc' # 射程圏内から動いていない self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') return 'extermed_coc'
def run(self): while True: # 画像を取得 frame1, frame2 = self.senders['Webcamera'].msg_queue.get() # 画像の中から虫の座標を取得 bug_point_list = detect_coc(frame1) if len(bug_point_list) > 0: # 虫がいないなら何もしない pass
def run(self): frame1, frame2 = self.senders['Webcamera'].msg_queue.get() while True: frame1, frame2 = self.senders['Webcamera'].msg_queue.get() if frame1 is None: continue coc_pos_list = detect_coc(frame2) print(coc_pos_list) if len(coc_pos_list) == 0: continue coc_pos = (coc_pos_list[0][0] - frame2.shape[1] / 2, coc_pos_list[0][1] - frame2.shape[0] / 2) print(coc_pos)
def _state_func_chase_coc(self): # EFFECTS : 虫を追跡する miss_count = 0 # 連続で見失った回数 while True: frame1, frame2 = self.senders['Webcamera'].msg_queue.get() coc_pos_list = detect_coc(frame1) # 見失ったかどうかの処理 if len(coc_pos_list) == 0: miss_count += 1 # インクリメント if miss_count >= self.miss_coc_count_limit: self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') return 'where' else: miss_count = 0 # 虫が射程内にいるかどうか print(coc_pos_list) if self.smash_point[0][0] < coc_pos_list[0][0] < self.smash_point[1][0] and \ self.smash_point[0][1] < coc_pos_list[0][1] < self.smash_point[1][1]: return 'smash_coc'
def _state_func_start(self): # EFFECTS : 初期状態 while True: try: # 一旦キューを空にする while not self.senders['Julius'].msg_queue.empty(): self.senders['Julius'].msg_queue.get() # 空にしてから待つ msg = self.senders['Julius'].msg_queue.get(timeout = 0.1) if '虫でた' in msg: # どこ?と言う状態に遷移 return 'where' except Empty: pass # Gがいるかどうか frame1, frame2 = self.senders['Webcamera'].msg_queue.get() coc_pos_list = detect_coc(frame1) if len(coc_pos_list) > 0: self.controllers['JTalk'].cmd_queue.put('../voice-sample/yes.wav') return 'chase_coc'