Exemplo n.º 1
0
    def handleConnectButton(self):
        print('In ConnectButton ')
        self.swift = SwiftAPI(dev_port='COM4')
        sleep(2)
        print(self.swift.get_device_info())
        print('set x=150, y=0, z=150')
        self.uarmZ = 150
        self.uarmX = 150
        self.uarmY = 0
        self.swift.set_position(x=self.uarmX,
                                y=self.uarmY,
                                z=self.uarmZ,
                                wait=True,
                                speed=2000)
        self.swift.set_gripper(self.gripper)

        self.sld1.setValue(self.uarmZ)
        self.sldX.setValue(self.uarmX)
        self.sldY.setValue(self.uarmY)
        self.sld1.setEnabled(True)
        self.sldX.setEnabled(True)
        self.sldY.setEnabled(True)
        self.gripperButton.setEnabled(True)

        self.connectButton.setEnabled(False)
Exemplo n.º 2
0
def ustart():
    global swift
    sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
    swift = SwiftAPI()  # {'hwid': 'USB VID:PID=2341:0042'}
    sleep(2)
    swift.set_position(150, 0, 80, speed=20000, wait=True)
    sleep(2)
Exemplo n.º 3
0
    def __init__(self, dev_port, z_height=180):
        self.draw_height = z_height
        self.current_map = None
        self.running = False

        # Set up robot
        print("Connecting to robot")
        self.swift = SwiftAPI(dev_port=dev_port)
        sleep(2)
        print("Done Connecting")
        self.reset()
Exemplo n.º 4
0
def load_material(swift: SwiftAPI, position: dict, amount: int):
    amount *= -1
    dict_args = position
    dict_args['change_z_by'] = 70
    dict_args['wait'] = True
    swift.set_position(**dict_args)

    # back to normal location (relevant in case of using variables)
    dict_args['change_z_by'] = 0
    swift.set_position(**dict_args)

    # loading material
    dict_args = ({'e': amount})
    dict_args['wait'] = True
    dict_args['relative'] = True
    swift.set_position(**dict_args)
    dict_args['relative'] = False  # default is not relative

    # Hovering above
    dict_args = position
    dict_args['change_z_by'] = 70
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    dict_args[
        'change_z_by'] = 0  # back to normal location(relevant in case of using variables)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def creat_swift():
    print('setup swift ...')
    global swift
    #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)
    return swift
Exemplo n.º 7
0
def init_uarm():
    print('setup swift ...')
    # port = '/dev/' + [x for x in os.listdir('/dev/') if x.startswith('cu.usbmodem')][0]
    # port = '/dev/' + [x for x in os.listdir('/dev/') if x.startswith('ttyA')][0]
    # swift = SwiftAPI(dev_port='/dev/cu.usbmodem1421')
    # print(port)
    # swift = SwiftAPI(dev_port=port)
    swift = SwiftAPI()

    sleep(2)

    # 复位
    # swift.set_position(x=60, y=0, z=50, speed=1800, wait=True)
    # swift.set_position(x=60, y=0, z=50, speed=1800, wait=False)
    # while swift.get_is_moving():
    #     sleep(0.1)
    swift.set_buzzer()
    return swift
Exemplo n.º 8
0
class MyArm():
    def __init__(self, speed=1, logging=False):
        self.speed = speed * 10000
        self.timout = 20
        if logging: logger_init(logging.INFO)
        self.robot = SwiftAPI()
        time.sleep(2)

    def goto(self, x, y, z, wait=False):
        print('goto', x, y, z)
        self.robot.set_position(x,
                                y,
                                z,
                                speed=self.speed,
                                timeout=self.timout,
                                wait=wait,
                                relative=False)

    def step(self, x=None, y=None, z=None, wait=False):
        if x is None: x = 0
        if y is None: y = 0
        if z is None: z = 0
        print('goto', x, y, z)
        self.robot.set_position(x,
                                y,
                                z,
                                speed=self.speed,
                                timeout=self.timout,
                                wait=wait,
                                relative=True)

    def grab(self, value=True):
        self.robot.set_pump(value, self.timout)
Exemplo n.º 9
0
def mix_material(swift: SwiftAPI, position: dict, amount: int, iterations: int,
                 ejecting_delta: int, position_for_delta_injection: dict):
    # Hovering above
    dict_args = position
    dict_args['change_z_by'] = 70
    dict_args['wait'] = True
    swift.set_position(**dict_args)

    # back to normal location (relevant in case of using variables)
    dict_args['change_z_by'] = 0
    swift.set_position(**dict_args)

    for i in range(iterations):
        sleep(1)
        # loading material
        dict_args = {'e': amount * (-1)}
        dict_args['wait'] = True
        dict_args['relative'] = True
        swift.set_position(**dict_args)

        # ejecting material
        dict_args = {'e': amount + ejecting_delta}
        dict_args['wait'] = True
        dict_args['relative'] = True
        swift.set_position(**dict_args)
        dict_args['relative'] = False  # default is not relative

    # Hovering above
    dict_args = position
    dict_args['change_z_by'] = 70
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    dict_args[
        'change_z_by'] = 0  # back to normal location(relevant in case of using variables)

    # delta injection
    load_material(swift=swift,
                  amount=iterations * ejecting_delta,
                  position=position_for_delta_injection)
Exemplo n.º 10
0
def main():
    print('setup swift ...')

    swift = SwiftAPI()

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

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

    movements = [
        {
            'x': 180,
            'y': 180,
            'z': 30
        },
        {
            'x': 180,
            'y': -180,
            'z': 30
        },
        {
            'x': 250,
            'y': 0,
            'z': 150
        },
        {
            'x': 150,
            'y': 0,
            'z': 30
        },
    ]

    for movement in movements:
        print('\nset ' + ' '.join(
            ["%s%d" % (key.upper(), value)
             for key, value in movement.items()]))
        swift.set_position(wait=True, **movement)
        sleep(0.1)
        while swift.get_is_moving():
            sleep(0.1)
        swift.set_buzzer()

    print('done ...')
    while True:
        sleep(1)
Exemplo n.º 11
0
def pick_pipette(swift: SwiftAPI, position: dict):
    # Hovering above pipette
    dict_args = position
    dict_args['wait'] = True
    dict_args['change_z_by'] = 50
    swift.set_position(**dict_args)

    # Acquiring pipette
    dict_args['wait'] = True
    dict_args['change_z_by'] = 0
    swift.set_position(**dict_args)
    sleep(1)

    # Hovering above pipette
    dict_args['wait'] = True
    dict_args['change_z_by'] = 90
    swift.set_position(**dict_args)
    dict_args['change_z_by'] = 0
Exemplo n.º 12
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)
Exemplo n.º 13
0
import numpy as np
import time
from time import sleep
import cv2
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

logger_init(logging.INFO)

SERVO_BOTTOM = 0
SERVO_LEFT = 1
SERVO_RIGHT = 2
SERVO_HAND = 3

arm = SwiftAPI()
sleep(2.0)
position_arr = []

angles_arr = []
'''
       Set servo angle, 0 - 180 degrees, this Function will include the manual servo offset.

       Args:
           servo_id: SERVO_BOTTOM, SERVO_LEFT, SERVO_RIGHT, SERVO_HAND
           angle: 0 - 180 degrees
           wait: if True, will block the thread, until get response or timeout

       Returns:
 
          succeed True or failed False
       '''
Exemplo n.º 14
0
def main():
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
    swift = SwiftAPI()
    app = tornado.web.Application([('/', MainHandler, dict(swift=swift))])
    app.listen(8000)
    tornado.ioloop.IOLoop.current().start()
Exemplo n.º 15
0
import sys
import numpy as np
from time import sleep

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
logger_init(logging.INFO)

arm = SwiftAPI()
sleep(2.0)

arm.set_position(200, -200, 190, speed=1500, timeout=20)
arm.flush_cmd()

while True:
    sleep(1)
Exemplo n.º 16
0
from time import sleep

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

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

#logger_init(logging.VERBOSE)
#logger_init(logging.DEBUG)
logger_init(logging.INFO)

print('setup swift ...')

#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)
"""
test_api2.py:
"""

from time import sleep

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

logger_init(logging.VERBOSE)
# logger_init(logging.INFO)

print('setup swift ...')

# swift = SwiftAPI(dev_port='/dev/cu.usbmodem1421')
swift = SwiftAPI()

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

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

# swift.set_position(x=120,z=80,y=30)


# print('\nset X350 Y0 Z50 F500 ...')
# swift.set_position(350, 0, 50, speed=1500)

swift.set_position(x=300, wait=True)
sleep(3)
Exemplo n.º 18
0
import sys, os
from time import sleep

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
logger_init(logging.DEBUG)

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("Allowing extrusion")
swift.send_cmd_sync("G2203")
Exemplo n.º 19
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import tkinter
import os
import sys
from time import sleep
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

swift = SwiftAPI()  # {'hwid': 'USB VID:PID=2341:0042'}
sleep(2)
swift.set_position(150, 0, 150, speed=20000, timeout=20)
swift.flush_cmd()
sleep(1)


def destructor():
    print("[INFO] Beendet...")
    swift.flush_cmd()
    mainWin.destroy()


def parken():
    swift.set_position(120, 0, 40, speed=20000)
    uxx.set(120)
    uyy.set(0)
    uzz.set(40)
    uww.set(90)

    vlx.set('X=120')

def spectrum_to_string(color):
    return "R" + str(int(color[0])) + " G" + str(int(color[1])) + " B" + str(
        int(color[2]))


def hex_to_rgb(value):
    #value = value.lstrip('#')
    lv = len(value)
    return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))


print('setup swift ...')

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())

swift.set_position(190, 0, 50, speed=5000, timeout=20)
swift.flush_cmd()  # avoid follow 5 command timeout

sleep(3)

# init the RGB led for pin 4
swift.send_cmd_async("M2305 P4 N1 V1")
randian = 1
Exemplo n.º 21
0
sys.path.append('C:\python64\Lib\site-packages')
import tensorflow as tf
import numpy as np
import struct
from fuzzywuzzy import fuzz

import time
from time import sleep
import cv2
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
logger_init(logging.INFO)
import imutils

cap = cv2.VideoCapture(1)
arm = SwiftAPI()

#array intialization
train_x = []
test_x = []
newang = []
posarray = []
angarray = []
posarray_test = []
angarray_test = []
newbitang = []
removebit = []
bit = []

newbitang_test = []
removebit_test = []
Exemplo n.º 22
0
import sys

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
from time import sleep

logger_init(logging.DEBUG)
global swift
try:
    swift = SwiftAPI()  # default by filters: {'hwid': 'USB VID:PID=2341:0042'}
except:  # problem connecting to the arm
    print("123")
    print("Unexpected error:", sys.exc_info())
    exit()
sleep(2)
print("Allowing extrusion")
swift.send_cmd_sync("M302 S0")
for count in range(100):
    dict_args = ({'x': 140.32, 'y': (-109), 'z': 0, 'e': 0})
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    dict_args = ({'x': 140.32, 'y': (-109), 'z': (-50), 'e': 0})
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    dict_args = ({'x': 140.32, 'y': (-109), 'z': (-60), 'e': 0})
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    dict_args = ({'x': 140.32, 'y': (-109), 'z': (-66), 'e': 0})
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    dict_args = ({'x': 140.32, 'y': (-109), 'z': (-66.5), 'e': 0})
Exemplo n.º 23
0
"""
解锁电机.py:
"""
from time import sleep
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

# logger_init(logging.VERBOSE)
# logger_init(logging.DEBUG)
logger_init(logging.INFO)

print('setup swift ...')

# 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('开始测试')
swift.set_buzzer()
swift.set_buzzer()

print('解锁电机')
swift.set_servo_detach()
sleep(10)
Exemplo n.º 24
0
# (async function () {
# // Reset uArm to its home position.
# await UArm.reset();
# await UArm.set_position({"x": 200, "y": 100, "z": 50});
# }());

#logger_init(logging.DEBUG)
#logger_init(logging.INFO)

import time
import numpy
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

logger_init(logging.VERBOSE)
swift = SwiftAPI()
time.sleep(2)

positions = numpy.linspace(-200, 200, 5)
swift.set_gripper(True)

time.sleep(5)

swift.set_gripper(False)
Exemplo n.º 25
0
class RobotMapper:
    BOUNDS = (150, -80, 225, 80)
    MOVE_SPEED = 1500
    LASER_SPEED = 150

    # 180 > 150

    def __init__(self, dev_port, z_height=180):
        self.draw_height = z_height
        self.current_map = None
        self.running = False

        # Set up robot
        print("Connecting to robot")
        self.swift = SwiftAPI(dev_port=dev_port)
        sleep(2)
        print("Done Connecting")
        self.reset()

    def draw_map(self, map):
        """ Resize map and prep for use, then start running"""

        map = map.fit_to(self.BOUNDS)

        self.current_map = map
        self.swift.set_position(150,
                                0,
                                self.draw_height,
                                speed=self.MOVE_SPEED,
                                wait=True)

        for cur_pt, next_pt, pen_down in self.current_map:
            if not pen_down: continue
            self.draw_line(cur_pt, next_pt)

        self.reset()

    def draw_line(self, from_pt, to_pt):
        # Make sure it's a valid request
        if from_pt == to_pt: return

        LASER_CMD = "G1 X{} Y{} Z{} F{}"

        # Get into the correct position before drawing the linn
        cur_pos = self.swift.get_position()[:2]
        if cur_pos != from_pt:
            print("Moving to", from_pt, "from", cur_pos)
            self.swift.set_position(x=from_pt[0],
                                    y=from_pt[1],
                                    z=self.draw_height,
                                    speed=self.MOVE_SPEED,
                                    wait=True)

        # Actually draw the line
        print("Drawing Line: ", from_pt, to_pt)
        to_pt = [int(round(to_pt[0])), int(round(to_pt[1]))]
        cmd = LASER_CMD.format(to_pt[0], to_pt[1], self.draw_height,
                               self.LASER_SPEED)
        assert self.swift.send_cmd_sync(
            cmd) == "ok", "Unable to send robot to using laser command!"

        # Set the position normally, to turn off the laser
        self.swift.set_position(x=to_pt[0],
                                y=to_pt[1],
                                z=self.draw_height,
                                speed=self.MOVE_SPEED,
                                wait=True)

    def stop(self):
        self.running = False
        self.reset()

    def reset(self):
        """ Put the swift in a resting position """
        self.swift.set_polar(s=112,
                             r=90,
                             h=67,
                             speed=self.MOVE_SPEED,
                             wait=True)
Exemplo n.º 26
0
#!/usr/bin/python3
from time import sleep
import datetime, os
from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
import json
import cgi, cgitb

print("Content-type: application/json")
print()
form = cgi.FieldStorage()

swift = SwiftAPI()
sleep(2)
swift.set_buzzer()

try:
    os.remove("Armstatus.txt")
except OSError:
    pass

file = open('Armstatus.txt', 'w')
file.write('True')
file.close()


## Arm move controller
def armmove(x, y, toX, toY):

    # global arm_speed
    global arm_speed
Exemplo n.º 27
0
Note that the coordinate frame turns as the robot turns. Forward and backback should really
be defined in terms of the robots current position and not world x,y and z. But hey, this
works as a demo.
'''

import sys, os
from time import sleep

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

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

#logger_init(logging.VERBOSE)
#logger_init(logging.DEBUG)
logger_init(logging.INFO)
print('setup swift ...')
#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())

# for the non-pro swift by current firmware,
# you have to specify all arguments for x, y, z and the speed
swift.set_position(220, 320, 100, speed=1500, timeout=20)
]

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

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *

logger_init(logging.VERBOSE)
# logger_init(logging.DEBUG)
# logger_init(logging.INFO)

print('setup swift ...')

# 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())
sleep(2)
print('\nset X350 Y0 Z50 F500 ...')
swift.set_position(150, -100, 150, wait=True)
sleep(2)
print('\nset X350 Y0 Z50 F500 ...')
swift.set_position(x=280, y=0, z=140, wait=True)

swift.set_buzzer()
sleep(2)
Exemplo n.º 29
0
# Arm_Flag = True
armOn = True

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
Exemplo n.º 30
0
from time import sleep

from uf.wrapper.swift_api import SwiftAPI
from uf.utils.log import *
logger_init(logging.DEBUG)

print("retrieveing coords from file")
coords = []

with open("40by40flip.png.coords", 'r') as f:
    for line in f:
        x, y = line.strip().split(",")
        coords.append((float(x), float(y)))

sleep(2)
swift = SwiftAPI()  # default by filters: {'hwid': 'USB VID:PID=2341:0042'}

current_liquid = 0
release_step = 0.025
total_liquid = release_step * (len(coords) + 500)
step_proportional = 2
protection_sip = 1.5
starting_x = 164.36
starting_y = -19
printing_z = 28.5

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

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