def hault(): while (cloud.getMutex() == 0): if (ultra.distance() > 50): reset() time.sleep(1)
contours, hierarchy = cv2.findContours(th1, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) c = max(contours, key=cv2.contourArea) #choose the largest contour M = cv2.moments(c) cx = int(M["m10"] / M["m00"]) cy = int(M["m01"] / M["m00"]) #perform correction #can add more elifs to turn right/left slowly,fast centerx = 160 #print('Area=',area) #print('Perimeter=',perim) xdiff = centerx - cx dist = ultra.distance() #if(cx<) while (dist < 7): print('Obstruction detected,stop') pwm1.ChangeDutyCycle(0) pwm2.ChangeDutyCycle(0) time.sleep(0.5) dist = ultra.distance() if (abs(xdiff) < 40): turn = True if (not turn): print('Center x - centroid x', xdiff)