def join(self, timeout=None): """ Stop the thread. """ self._stopevent.set() pixy.set_lamp(0, 0) drive = clsDrive.Drive() drive.stop() threading.Thread.join(self, timeout)
def reboot(self): for x in range(6): backlight.set_pixel(x, 0, 0, 0) touch.set_led(x, 0) backlight.show() lcd.clear() drive = clsDrive.Drive() drive.stop() lcd.show() call("sudo reboot", shell=True)
def run(self): drive = clsDrive.Drive() control = clsDrive.Control() point = 0 pixy.init() pixy.change_prog("color_connected_components") pixy.set_lamp(0, 0) pixy.set_servos(500, 650) blocks = BlockArray(100) while not self._stopevent.isSet(): count = pixy.ccc_get_blocks(100, blocks) if count > 0: x = 0 y = 0 width = 0 for index in range(0, count): curBlock = blocks[index] if curBlock.m_signature == 1 and curBlock.m_width > width: width = curBlock.m_width x = curBlock.m_x y = curBlock.m_y if width > 0: control.maze(x, y, width) if control.stop == True: if control.progress == 0 or control.progress == 1 or control.progress == 4 or control.progress == 5 or control.progress == 6: drive.turnLeft() elif control.progress == 2 or control.progress == 3 or control.progress == 7: drive.turnRight() control.progress += 1 elif control.frame == 2: drive.joltRight() elif control.frame == 0: drive.joltLeft() else: control.angle = 0 control.speed = 0.7 control.stop = False drive.HarDrive(control) else: control.angle = 0 control.speed = 0.3 control.stop = False drive.HarDrive(control) else: control.angle = 0 control.speed = 0.3 control.stop = False drive.HarDrive(control)
def run(self): drive = clsDrive.Drive() control = clsDrive.Control() while not self._stopevent.isSet(): with ControllerResource() as joystick: print('Found a joystick and connected') while not self._stopevent.isSet(): l1, r1 = joystick['l1', 'r1'] if l1 is not None: drive.spinLeft() if r1 is not None: drive.spinRight() else: control.calcControl(round(joystick.rx, 2), round(joystick.ry, 2)) drive.HarDrive(control)
def run(self): drive = clsDrive.Drive() control = clsDrive.Control() pixy.init() pixy.change_prog("line") pixy.set_servos(500, 800) pixy.set_lamp(1, 0) vectors = VectorArray(100) intersections = IntersectionLineArray(100) while not self._stopevent.isSet(): line_get_all_features() i_count = line_get_intersections(100, intersections) v_count = line_get_vectors(100, vectors) print("Scanning") if i_count > 0 or v_count > 0: # print('frame %3d:' % (frame)) for index in range(0, v_count): control.lineFollow(vectors[index].m_x0, vectors[index].m_y0, vectors[index].m_x1, vectors[index].m_y1) print(str(control.frame)) if control.frame == 2: drive.joltRight() elif control.frame == 0: drive.joltLeft() else: control.angle = 0 control.speed = 1 control.stop = False drive.HarDrive(control) else: control.angle = 0 control.speed = 0.3 control.stop = False drive.HarDrive(control) drive.stop()
def run(self): '''pixy.init() pixy.change_prog("color_connected_components"); pixy.set_lamp(1, 0) drive = clsDrive.Drive() control = clsDrive.Control() blocks = BlockArray(100) while not self._stopevent.isSet( ): count = pixy.ccc_get_blocks(100, blocks) if count > 0: for index in range(0, count): curBlock = blocks[index] print("x " + str(curBlock.m_x) + "- y " + str(curBlock.m_y)) #control.neb(curBlock.m_x, curBlock.m_y) #control.speed = 0.5 #drive.HarDrive(control) else: #drive.joltLeft() print("Jolt") ''' tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29) tof.open() # Initialise the i2c bus and configure the sensor tof.start_ranging( 1 ) # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range drive = clsDrive.Drive() control = clsDrive.Control() control.progress = 2 pixy.init() pixy.change_prog("color_connected_components") pixy.set_lamp(0, 0) pixy.set_servos(500, 650) blocks = BlockArray(100) while not self._stopevent.isSet(): count = pixy.ccc_get_blocks(100, blocks) if count > 0 and control.progress < 6: x = 0 y = 0 width = 0 for index in range(0, count): curBlock = blocks[index] if curBlock.m_signature == control.progress and curBlock.m_width > width: width = curBlock.m_width x = curBlock.m_x y = curBlock.m_y if width > 0: control.distance = tof.get_distance() #print(str(control.distance)) if control.distance < 100: if control.progress == 5: drive.stop() else: control.angle = 180 control.speed = 0.5 control.stop = False drive.HarDrive(control) sleep(1) drive.stop() control.progress += 1 else: #print("control.neb") print(str(width)) control.neb(x, y, width) #print(str(control.frame)) if control.frame == 2: drive.joltRight() elif control.frame == 0: drive.joltLeft() else: control.angle = 0 control.speed = 0.5 control.stop = False drive.HarDrive(control) else: drive.joltLeft() elif control.progress == 6: drive.stop() break else: drive.joltLeft() tof.close()
def testTurn(self): drive = clsDrive.Drive() drive.turnRight() sleep(2) drive.turnLeft()
else: print("Turning On") menu.ledThread = menu.options[menu.curPos][1]() menu.ledThread.start() menu.toggleLed = True elif menu.options[menu.curPos][2] == True: menu.inThread = True menu.curThread = menu.options[menu.curPos][1]() menu.curThread.start() else: menu.options[menu.curPos][1]() elif ch == 0 and menu.inThread == True: menu.curThread.join() menu.inThread = False touch.set_led(ch, 0) print(str(menu.curPos)) for x in range(6): touch.on(x, handler) try: signal.pause() except KeyboardInterrupt: for x in range(6): backlight.set_pixel(x, 0, 0, 0) touch.set_led(x, 0) backlight.show() lcd.clear() drive = clsDrive.Drive() drive.stop() lcd.show()