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
Пример #2
0
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)
Пример #3
0
def main():
    logging.info('setup swift ...')
    swift = SwiftAPI()
    sleep(2)

    logging.info('device info: ')
    device_info = swift.get_device_info()
    logging.info(device_info)
    logging.info('firmware version:')
    fw_version = tuple(int(number) for number in device_info[2].split('.'))
    logging.info(fw_version)

    print('set mode to 3D print: %s' % send_cmd_sync_ok(swift, 'M2400 S2'))

    print('enable fan: %s' % send_cmd_sync_ok(swift, 'M106'))

    print('set temperature units: %s' % send_cmd_sync_ok(swift, 'M149 C'))

    # print('temperature hack: %s' % send_cmd_sync_ok(swift, 'M2213 V0'))

    print('set hotend to 205: %s' % send_cmd_sync_ok(swift, 'M104 S205'))

    print('wait for hotend...')
    while True:
        sleep(10)
        swift.flush_cmd()
        temp = send_cmd_sync_ok(swift, 'M105', TEMP_RESPONSE_REGEX)
        logging.info("temp is: %s" % temp)
        try:
            temp = float(temp)
        except ValueError:
            ValueError("Temp response was not a float: %s" % temp)

        if temp > 190:
            break

    print("retracting extruder...")
    response = send_cmd_sync_ok(swift, "G2204 E-60 F200")
    logging.debug("response: %s" % response)
    while True:
        response = send_cmd_sync_ok(swift, "G2204 E-10 F1000")
        logging.debug("response: %s" % response)

    print('done ...')
    while True:
        sleep(1)
Пример #4
0
orginal_widht, orginal_height = 600, 350
image_widht, image_height = 960, 540

ratio_x, ratio_y = orginal_widht / image_widht, orginal_height / image_height
arm_speed = 30  # max 99
reference_circle = 24.26  #Reference circle diameter (mm)
gurl = "http://192.168.2.120:8080"
url_img = "imge.png"

if (armOn):
    # print"Initializing Uarm")
    swift = SwiftAPI()
    sleep(2)
    # swift.set_buzzer()
    swift.flush_cmd()

    ## print"set Uarm position to leftside to start calibration")
    ## set Uarm to left side
    # SwiftAPI().set_buzzer()
    swift.set_position(0, 250, 100, 80, relative=False, wait=True)
    sleep(1)

# swift.set_position(0, 250, 100, 80, relative=False, wait=True)
# sleep(1)


## Arm move controller
def armmove(x, y, toX, toY):
    # swift = SwiftAPI()
    # sleep(2)
Пример #5
0
#swift = SwiftAPI(dev_port = '/dev/ttyACM0')
#swift = SwiftAPI(filters = {'hwid': 'USB VID:PID=2341:0042'})
swift = SwiftAPI()  # default by filters: {'hwid': 'USB VID:PID=2341:0042'}

print('sleep 2 sec ...')
sleep(2)

print('device info: ')
print(swift.get_device_info())

print('\nset X350 Y0 Z100 F1500 ...')
# for the non-pro swift by current firmware,
# you have to specify all arguments for x, y, z and the speed
swift.set_position(330, 0, 100, speed=1500, timeout=20)
swift.flush_cmd()  # avoid follow 5 command timeout

print('\nset X340 ...')
swift.set_position(330, 0, 150, speed=1500)
print('set X320 ...')
swift.set_position(320, 0, 150, speed=1500)
print('set X300 ...')
swift.set_position(300, 0, 150, speed=1500)
print('set X200 ...')
swift.set_position(200, 0, 150, speed=1500)
print('set X190 ...')
swift.set_position(190, 0, 150, speed=1500)

# wait all async cmd return before send sync cmd
swift.flush_cmd()
Пример #6
0
           angle: 0 - 180 degrees
           wait: if True, will block the thread, until get response or timeout

       Returns:
 
          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,
Пример #7
0
import sys, os
from time import sleep

sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))

# from uf.wrapper.uarm_api import UarmAPI
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

print('Start Testing')

swiftPro = SwiftAPI()

sleep(2)
print(swiftPro.get_device_info())

while True:
    print('\nset X340 ...')
    swiftPro.set_position(340, 0, 150)
    print('set X320 ...')
    swiftPro.set_position(320, 0, 150)
    print('set X300 ...')
    swiftPro.set_position(300, 0, 150)
    print('set X200 ...')
    swiftPro.set_position(200, 0, 150)
    print('set X190 ...')
    swiftPro.set_position(190, 0, 150)
    swiftPro.flush_cmd()
    swiftPro.set_buzzer()
    print('doneOnce')
    sleep(10)
Пример #8
0
# #Moves the robot to position
# def setposition(ax,ay,az,ispump):
# 	mov_status = swift.set_position(ax , ay, az, speed, relative=False, wait=True)
# 	sleep(1)

# 	if(mov_status == True):
# 		pos=swift.get_position()
# 		swift.set_pump(ispump)
# 		sleep(1)
# 		reset(not ispump)
# 	else:
# 		print("Robot Arm movement Unavailable.Kindly give valid coordinates")

swift = SwiftAPI()
swift.set_buzzer()
swift.flush_cmd()  #Flushes the UARM buffer and makes it empty


def picQuarter(x, y):
    #sleep(3)

    #pos = swift.get_position() #Gets the current position of UARM
    print("PIC QUARTER$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
    print(x)
    print(y)
    print("Moving to the position")

    swift.set_position(x, y, 70, 60, relative=False, wait=True)
    sleep(1)
    print("Moving head")