def keep_front_cycle(self): self.__timestemp.set_k(0.5) while True: flag, x, y, w_h = Data().get_filter("red").quadrangle( Data().get_img_front()) if flag: while self.__timestemp.add_item(length(x, y)): flag, x, y, w_h = Data().get_filter("red").quadrangle( Data().get_img_front()) self.keep_x_y(x, y, 2, 3) #self.move_to_time(1, 40) sleep(0.05) break else: pass
def search_cycle(self, img): info = ["red", "green", "blue"] for i in info: flag, x, y, area = Data().get_filter(i).cycle(img) if flag: return True, i, area return False, "None", 0
def search_color(self): st = detect() info = ["red", "green", "yellow", "white", "black"] tm = int(round(time() * 1000)) center = [] while tm - int(round(time() * 1000)) > 10 * -1000: frame = Data().get_img_front() if st == "right": frame = Data().get_filter("red").right(frame) else: frame = Data().get_filter("red").left(frame) for i in range(len(info)): flag, x, y, area = Data().get_filter(info[i]).quadrangle(frame) if flag: del info[i] center.append((x, y, area)) break if len(center) == 2: break print(info) return center
def keep_bottom_line(self): while True: flag, x, y, angle = Data().get_filter("yellow").square( Data().get_img_bottom()) if flag: self.__timestemp.set_k(2) while self.__timestemp.add_item(length(x, y)): flag, x, y, angle = Data().get_filter("yellow").square( Data().get_img_bottom()) self.keep_x_y(x, y, 0, 1) self.keep_depth(Data().get_depth()) sleep(0.05) Data().set_yaw(angle) print(Data().get_yaw()) break else: self.keep_depth(Data().get_depth()) self.keep_yaw(Data().get_yaw(), 30) sleep(0.05)
def yaw_to_time(self, time_yaw, yaw=None): tm = int(round(time() * 1000)) yaw = Data().get_yaw() if yaw is None else yaw while tm - int(round(time() * 1000)) > time_yaw * -1000: self.keep_yaw(yaw, 0) sleep(0.05)
def depth_to_time(self, time_depth, h=None): tm = int(round(time() * 1000)) h = Data().get_depth() if h is None else h while tm - int(round(time() * 1000)) > time_depth * -1000: self.keep_depth(h) sleep(0.05)
def move_to_time(self, time_move, speed): tm = int(round(time() * 1000)) while tm - int(round(time() * 1000)) > time_move * -1000: self.keep_yaw(Data().get_yaw(), speed) sleep(0.05)
from Class.Motor import Motor from Class.Math import PD import pymurapi as mur from Class.Data import Data from Class.Classificate import ColorClassif from time import sleep avi = mur.mur_init() motor = Motor({"depth": PD(30, 5), "yaw": PD(0.5, 0.8), "x_y": PD(0.1, 0.6)}) Data().set_filters("red", ColorClassif((0, 139, 0), (16, 255, 255))) Data().set_filters("green", ColorClassif((62, 229, 93), (98, 255, 255))) Data().set_filters("blue", ColorClassif((30, 185, 211), (255, 255, 255))) Data().set_filters("yellow", ColorClassif((19, 193, 95), (33, 255, 255))) Data().set_filters("white", ColorClassif((0, 0, 0), (255, 4, 255))) Data().set_filters("black", ColorClassif((0, 0, 0), (123, 255, 36))) motor.depth_to_time(14, 2.3) motor.keep_front_cycle()