def moveRandom(): SERVO_BOTTOM = 0 SERVO_LEFT = 1 SERVO_RIGHT = 2 SERVO_HAND = 3 position_arr = [] pixel_position = [] angles_arr = [] arm = SwiftAPI() sleep(2.0) rand = np.random.rand(3) angles = rand * 180 print("angles are", angles) arm.flush_cmd() arm.reset() arm.set_servo_angle_speed(SERVO_RIGHT, angles[0], wait=True, timeout=100, speed=5000) arm.set_servo_angle_speed(SERVO_BOTTOM, angles[1], wait=True, timeout=100, speed=5000) arm.set_servo_angle_speed(SERVO_LEFT, angles[2], wait=True, timeout=100, speed=5000) a = arm.get_is_moving() print("the status is", a, "\n") pos = arm.get_position( ) # float array of the format [x, y, z] of the robots current location cap = cv2.VideoCapture(0) cap1 = cv2.VideoCapture(0) red = detect_w_avg(cap, 600, 166, 84, 80, 286, 255, 255, "red") print("red", red) blue = detect_w_avg(cap1, 600, 97, 100, 117, 117, 255, 255, "blue") print("blue", blue) pixel_position.append(red) pixel_position.append(blue) cv2.destroyAllWindows() cap.release() cap1.release() # pixelpostion= get the pixel position here print("the position is ", pos, "\n") position_arr.append(pos) angles = angles.tolist() angles_arr.append(angles) # [right bottom left] sleep(2.0) return angles, pixel_position
def moveRandom(): SERVO_BOTTOM = 0 SERVO_LEFT = 1 SERVO_RIGHT = 2 SERVO_HAND = 3 position_arr=[] angles_arr=[] arm = SwiftAPI() sleep(2.0) rand = np.random.rand(3) angles = rand * 180 print("angles are", angles) arm.flush_cmd() arm.reset() arm.set_servo_angle_speed(SERVO_RIGHT, angles[0], wait=True, timeout=100, speed=5000) arm.set_servo_angle_speed(SERVO_BOTTOM, angles[1], wait=True, timeout=100, speed=5000) arm.set_servo_angle_speed(SERVO_LEFT, angles[2], wait=True, timeout=100, speed=5000) a = arm.get_is_moving() print("the status is", a, "\n") pos = arm.get_position() # float array of the format [x, y, z] of the robots current location # pixelpostion= get the pixel position here print("the position is ", pos, "\n") position_arr.append(pos) angles = angles.tolist() angles_arr.append(angles) # [right bottom left] sleep(2.0)
succeed True or failed False ''' for _ in range(100): rand = np.random.rand(3) angles = rand * 180 print("angles are", angles) arm.flush_cmd() arm.reset() arm.set_servo_angle_speed(SERVO_RIGHT, angles[0], wait=True, timeout=100, speed=5000) arm.set_servo_angle_speed(SERVO_BOTTOM, angles[1], wait=True, timeout=100, speed=5000) arm.set_servo_angle_speed(SERVO_LEFT, angles[2], wait=True, timeout=100, speed=5000) a = arm.get_is_moving()