Ejemplo n.º 1
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)
Ejemplo 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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def drop_pipette(swift: SwiftAPI, position: dict):
    # Hovering above trash
    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)
    current_position = swift.get_position()
    robot_move(swift=swift,
               position={
                   'x': current_position[0],
                   'y': current_position[1],
                   'z': position['z'],
                   'e': None,
                   'speed': None
               })
    dict_args = position
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    swift.set_wrist(270)
    sleep(1)
    swift.set_wrist(90)

    # Hovering above trash
    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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
0
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})
    dict_args['wait'] = True
    swift.set_position(**dict_args)
    dict_args = ({'x': 140.32, 'y': (-109), 'z': (-67), 'e': 0})
    dict_args['wait'] = True
    swift.set_position(**dict_args)
Ejemplo n.º 9
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)
    #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

# Get CSV path file
print(os.path.dirname(os.path.abspath(__file__)))

os.chdir(os.path.dirname(os.path.abspath(__file__)))
with open(os.getcwd() + '/' + DATA_FILE, newline='') as csvfile:
    reader = csv.reader(csvfile, delimiter=',')
    for row in reader:
Ejemplo n.º 11
0
import numpy
import time
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)

speed = 25000
x_values = [200, 200] * 20
y_values = [-100, 100] * 20
z_values = [150, 190] * 20

# arm.set_gripper(True)
# arm.set_gripper(False)

for x, y, z in zip(x_values, y_values, z_values):
    print(x, y)
    arm.set_position(x, y, z, speed=speed, timeout=20, wait=True)
    time.sleep(1)
Ejemplo n.º 12
0
class XYZSlider(QWidget):
    def __init__(self):
        print('here')
        self.a = QApplication(sys.argv)
        super().__init__()
        self.initUI()

    def show_ux(self):
        sys.exit(self.a.exec_())

    def initUI(self):

        self.setGeometry(10, 10, 1500, 500)

        self.addSliderZ()
        self.addSliderX()
        self.addSliderY()

        self.addGripperButton()

        self.connectButton = QPushButton('Connect', self)
        self.connectButton.clicked.connect(self.handleConnectButton)

        self.exitButton = QPushButton('Exit', self)
        self.exitButton.clicked.connect(self.handleExitButton)

        self.setGeometry(300, 300, 1500, 500)
        self.setWindowTitle('Control Sliders')

        self.sld1.setEnabled(False)
        self.sldX.setEnabled(False)
        self.sldY.setEnabled(False)
        self.gripperButton.setEnabled(False)
        self.mylayout()

        self.show()

    def mylayout(self):

        self.qwsld = QWidget()
        self.qwsld.setStyleSheet("Background-color: red")

        self.grid = QGridLayout(self.qwsld)
        self.setLayout(self.grid)

        self.subW = QWidget()
        self.grid.addWidget(self.subW, 1, 1)
        self.subGridW = QGridLayout(self.subW)
        self.setLayout(self.subGridW)

        self.dummyW = QWidget()

        connectButtonPos = {"r": 1, "c": 1}
        exitButtonPos = {"r": 1, "c": 2}
        gripperButtonPos = {"r": 2, "c": 1}
        self.grid.addWidget(self.dummyW, 2, 2)

        zSliderPos = {"r": 2, "c": 1}
        zLabelPos = {"r": zSliderPos['r'], "c": 2}

        xSliderPos = {"r": zSliderPos['r'] + 1, "c": zSliderPos['c']}
        xLabelPos = {"r": zLabelPos['r'] + 1, "c": zLabelPos['c']}

        ySliderPos = {"r": zSliderPos['r'] + 2, "c": zSliderPos['c']}
        yLabelPos = {"r": zLabelPos['r'] + 2, "c": zLabelPos['c']}

        print(connectButtonPos["r"], "  ", connectButtonPos["c"])

        self.subGridW.addWidget(self.connectButton, connectButtonPos["r"],
                                connectButtonPos["c"])

        self.subGridW.addWidget(self.exitButton, exitButtonPos["r"],
                                exitButtonPos["c"])

        self.subGridW.addWidget(self.gripperButton, gripperButtonPos["r"],
                                gripperButtonPos["c"])

        self.grid.addWidget(self.l1, zLabelPos["r"], zLabelPos["c"])

        self.grid.addWidget(self.sld1, zSliderPos["r"], zSliderPos["c"])

        self.grid.addWidget(self.lX, xLabelPos["r"], xLabelPos["c"])

        self.grid.addWidget(self.sldX, xSliderPos["r"], xSliderPos["c"])

        self.grid.addWidget(self.lY, yLabelPos["r"], yLabelPos["c"])

        self.grid.addWidget(self.sldY, ySliderPos["r"], ySliderPos["c"])

    def addGripperButton(self):
        self.gripper = True
        self.gripperButton = QPushButton('Gripper', self)
        self.gripperButton.clicked.connect(self.handleGripperButton)

    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)

    def handleGripperButton(self):
        self.gripper = False if self.gripper else True  #toggle
        self.swift.set_gripper(self.gripper)
        sleep(4)

    def handleExitButton(self):
        sys.exit()

#----------------------Z----------------

    def changeValueSld1(self):
        txt = "Z: " + str(self.sld1.value())
        self.l1.setText(txt)
        #print('changeValue slider is: ', self.sld1.value())

    def sliderReleaseSld1(self):
        print('sliderreleased slider is: ', self.sld1.value())
        self.uarmZ = self.sld1.value()
        self.swift.set_position(z=self.uarmZ, wait=True, speed=2000)

    def addSliderZ(self):
        self.sld1 = QSlider(Qt.Horizontal, self)
        p = self.sld1.palette()
        p.setColor(self.sld1.backgroundRole(), Qt.red)
        self.sld1.setPalette(p)
        self.sld1.setFocusPolicy(Qt.NoFocus)
        self.sld1.setGeometry(30, 40, 1000, 30)
        self.sld1.setMaximum(150)
        self.sld1.setMinimum(0)
        self.sld1.setTickPosition(QSlider.TicksBelow)
        self.sld1.setTickInterval(5)
        self.sld1.sliderReleased.connect(self.sliderReleaseSld1)
        self.sld1.valueChanged.connect(self.changeValueSld1)
        self.l1 = QLabel(self)
        self.l1.setForegroundRole(QPalette.Dark)
        self.l1.setText('Z:')

#-----------x-----------------------------------------------

    def addSliderX(self):
        self.sldX = QSlider(Qt.Horizontal, self)
        p = self.sldX.palette()
        p.setColor(self.sldX.backgroundRole(), Qt.red)
        self.sldX.setPalette(p)
        self.sldX.setFocusPolicy(Qt.NoFocus)
        self.sldX.setGeometry(30, 40, 1000, 30)
        self.sldX.setMaximum(350)
        self.sldX.setMinimum(100)
        self.sldX.setTickPosition(QSlider.TicksBelow)
        self.sldX.setTickInterval(5)
        self.sldX.sliderReleased.connect(self.sliderReleaseSldX)
        self.sldX.valueChanged.connect(self.changeValueSldX)

        self.lX = QLabel(self)
        self.lX.setForegroundRole(QPalette.Dark)
        self.lX.setText('X:')

    def changeValueSldX(self):
        txt = "X: " + str(self.sldX.value())
        self.lX.setText(txt)
        #print('changeValue slider is: ', self.sld1.value())

    def sliderReleaseSldX(self):
        print('sliderreleased X slider : ', self.sldY.value())
        self.uarmX = self.sldX.value()
        self.swift.set_position(x=self.uarmX, wait=True, speed=2000)

#-----------Y-----------------------------------------------

    def addSliderY(self):
        self.sldY = QSlider(Qt.Horizontal, self)
        p = self.sldY.palette()
        p.setColor(self.sldY.backgroundRole(), Qt.red)
        self.sldY.setPalette(p)
        self.sldY.setFocusPolicy(Qt.NoFocus)
        self.sldY.setGeometry(30, 40, 1000, 30)
        self.sldY.setMaximum(100)
        self.sldY.setMinimum(-100)
        self.sldY.setTickPosition(QSlider.TicksBelow)
        self.sldY.setTickInterval(5)
        self.sldY.sliderReleased.connect(self.sliderReleaseSldY)
        self.sldY.valueChanged.connect(self.changeValueSldY)

        self.lY = QLabel(self)
        self.lY.setForegroundRole(QPalette.Dark)
        self.lY.setText('Y:')

    def changeValueSldY(self):
        txt = "Y: " + str(self.sldY.value())
        self.lY.setText(txt)
        #print('changeValue slider is: ', self.sld1.value())

    def sliderReleaseSldY(self):
        print('sliderreleased Y slider : ', self.sldY.value())
        self.uarmY = self.sldY.value()
        self.swift.set_position(y=self.uarmY, wait=True, speed=2000)
Ejemplo n.º 13
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)
Ejemplo n.º 14
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')
Ejemplo n.º 15
0
#logger_init(logging.VERBOSE)
#logger_init(logging.DEBUG)
logger_init(logging.INFO)

print('setup swift ...')

swift = SwiftAPI(dev_port='/dev/ttyACM0')

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

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

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

print('set X340 ...')
swift.set_position(x=340)
print('set X320 ...')
swift.set_position(x=320)
print('set X300 ...')
swift.set_position(x=300)
print('set X200 ...')
swift.set_position(x=200)
print('set X190 ...')
swift.set_position(x=190)

# make sure at least one position was sent to device before start checking
sleep(0.1)
# make sure corresponding topics was empty before start service call
Ejemplo n.º 16
0
# swift = SwiftAPI(filters = {'hwid': 'USB VID:PID=2341:0042'})
swift = SwiftAPI()  # default by filters: {'hwid': 'USB VID:PID=2341:0042'}

# def report_position(data):
#     print('data:', data)  # [x, y, z, r], r is wrist angle, ignore if not used
# swift.register_report_position_callback(report_position)
# swift.set_report_position(interval=0.5)  # 0.5 second (set 0 disable report)

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

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

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

swift.set_buzzer()
from evdev import categorize, ecodes

print('start control ...')
try:

    for event in device.read_loop():
        cate = categorize(event)
        if event.type == ecodes.EV_KEY:
            print('EV_KEY', event)

        if event.type == ecodes.EV_ABS:
            print('EV_ABS', event)
        if event.value == 0:
Ejemplo n.º 17
0
liquids = [20, 10, 5, 4, 3, 2, 1, 0.5, 0.25]
printing_x = 180
printing_y = -50  # hasta 1
printing_z = -73.5
fufu_amount = -9

for y in y_inc:
    printing_y += y
    printing_x = 180
    for l in liquids:
        total_liquid = l
        release_step = l

        swift.set_position(189.8,
                           -129.8,
                           80,
                           speed=30000,
                           timeout=30,
                           wait=True)
        swift.set_position(z=0, speed=3000, timeout=30, wait=True)
        swift.set_position(z=-63, speed=300, timeout=30, wait=True)

        swift.set_position(e=total_liquid, speed=50, timeout=30, wait=True)
        current_liquid = total_liquid
        sleep(0.2)
        swift.set_position(z=80, speed=30000, timeout=30, wait=True)

        swift.set_position(printing_x,
                           printing_y,
                           80,
                           speed=30000,
                           timeout=30,
Ejemplo n.º 18
0
from uf.utils.log import *
from time import sleep

logger_init(logging.DEBUG)
global swift

swift = SwiftAPI()  # default by filters: {'hwid': 'USB VID:PID=2341:0042'}
sleep(2)
print("Allowing extrusion")
swift.send_cmd_sync("M302 S0")

# d = swift.send_cmd_sync("M503")
# print(d)
dict_args = ({'x': 221, 'y': (-114.5), 'z': 80, 'e': 0, 'speed': 5000})
dict_args['wait'] = True
swift.set_position(**dict_args)
#
# dict_args = ({'x':221, 'y':(-114.5), 'z':59, 'e':0, 'speed':5000})
# dict_args['wait'] = True
# swift.set_position(**dict_args)
#
# dict_args = ({'x':221, 'y':(-114.5), 'z':59, 'e':-20, 'speed':5000})
# dict_args['wait'] = True
# swift.set_position(**dict_args)
# sleep(4)
#
# dict_args = ({'x':221, 'y':(-114.5), 'z':80 , 'e':-20, 'speed':5000})
# dict_args['wait'] = True
# swift.set_position(**dict_args)
#
# swift.set_position(e=0, speed=1500, timeout=30, wait=True)
Ejemplo n.º 19
0
def print_pattern_mini(swift: SwiftAPI, pattern_format, starting_position):
    # Reading the coords file into a list
    print(f'retrieveing coords from {pattern_format}')
    coords = []
    with open(os.path.join('uploads\coords', pattern_format), 'r') as f:
        for line in f:
            x, y = line.strip().split("\,")
            coords.append((float(x), float(y)))

    # Initializing required variables
    release_step = -0.070
    step_proportional = 2

    # Initializing required positions
    start_args = starting_position  # Starting Point
    start_args['wait'] = True
    starting_x = start_args['x']
    starting_y = start_args['y']
    printing_z = start_args['z']

    # Moves to printing starting point
    swift.set_position(x=(step_proportional * coords[0][0]) + starting_x,
                       y=(step_proportional * coords[0][1]) + starting_y,
                       z=60,
                       speed=1500,
                       timeout=30,
                       wait=True)

    # Printing image's coords
    picture = coords
    total_len = len(picture)
    current_step = 0
    for x, y in picture:
        current_step += 1
        print("{c_step}/{total}".format(c_step=current_step, total=total_len))
        print(x, y)
        swift.set_position(x=starting_x + (step_proportional * x),
                           y=starting_y + (step_proportional * y),
                           wait=True,
                           speed=1500)
        sleep(0.3)
        swift.set_position(z=printing_z, wait=True)
        swift.set_position(e=-release_step,
                           wait=True,
                           speed=500,
                           relative=True)
        swift.set_position(z=printing_z + 5, wait=True)

    # Printing last step
    swift.set_position(z=printing_z, wait=True)
    swift.set_position(e=release_step, wait=True, speed=300, relative=True)
    swift.set_position(z=printing_z + 3, wait=True)
# 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)

# for i in range(1):#3
for words in say_list:  #3
    swift.set_position(x=280, y=0, z=109, wait=True)
    swift.set_buzzer()

    # subprocess.call(['say', 'good morning,how are you'])
    # subprocess.call(['say', 'sing happy birthday'])
    subprocess.call(['say', words])
Ejemplo n.º 21
0
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())

print("Allowing extrusion")
swift.send_cmd_sync("M302 S0")

print('get_position:', swift.get_position())
swift.set_wrist(90)
swift.set_position(120, 0, 50, speed=15000, wait=True)  # Home
swift.set_position(131, -5, 90, speed=15000, wait=True)

#swift.set_position(139.88, -112.31, 60.24, speed=30000, timeout=30, wait=True) # Center in first pippet
#swift.set_position(z=-43.25, speed=30000, timeout=30, wait=True)  # Acquire pippet
#swift.set_position(z=-60, speed=300, timeout=30, wait=True)  # Acquire pippet
#swift.set_position(z=-65, speed=300, timeout=30, wait=True)  # Acquire pippet
#swift.set_position(z=-69, speed=300, timeout=30, wait=True)  # Acquire pippet
#sleep(0.1)
#swift.set_position(z=60.24, speed=30000, timeout=30, wait=True)

swift.set_position(x=221, y=-114.5, z=80, speed=30000, timeout=30,
                   wait=True)  # Center to water
swift.set_position(z=62, speed=30000, timeout=30, wait=True)  # Get close
swift.set_position(z=57, speed=700, timeout=30, wait=True)  # Smooth in
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
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)
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()
Ejemplo n.º 24
0
def move_to_starting_position(swift: SwiftAPI):
    swift.set_position(e=0, speed=1500, timeout=30, wait=True)
    swift.set_position(120, 0, 50, speed=1500, timeout=30, wait=True)
# 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)
swift.set_position(x=200,y=100,z=50, wait=True)

print('finished')
try:
    while True:
        sleep(1)
except KeyboardInterrupt as e:
    print('KeyboardInterrupt',e)
finally:
    swift.reset()
Ejemplo n.º 26
0
cap = cv2.VideoCapture(1)
cap.set(3, int(1280 * RESCALE_FACTOR))
cap.set(4, int(720 * RESCALE_FACTOR))

# could not open port 'COM4': PermissionError(13, 'Access is denied.', None, 5)
accessed = False
while not accessed:
    try:
        swift = SwiftAPI()
        accessed = True
    except Exception as e:
        time.sleep(0.2)

print('device info: ')
print(swift.get_device_info())
swift.set_position(x=200, y=0, z=31, relative=False, speed=20000, wait=True)
swift.set_pump(True)

for i in range(15):
    _, frame = cap.read()

# find air hockey table
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_table = np.array([0, 0, 128])
upper_table = np.array([180, 55, 255])
mask_table = cv2.inRange(hsv, lower_table, upper_table)
_, contours, _ = cv2.findContours(mask_table, cv2.RETR_TREE,
                                  cv2.CHAIN_APPROX_SIMPLE)

fieldx = 0
fieldy = 0
Ejemplo 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)
Ejemplo n.º 28
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("Allowing extrusion")
swift.send_cmd_sync("M302 S0")
print('get_position:', swift.get_position())
print('\nset X10 Y193 z50 F1500 ...')
current_z = swift.get_position()[2]
swift.set_position(10, 193, 50, speed=1500, timeout=20)
swift.se
# swift.flush_cmd() # avoid follow 5 command timeout

offset_x = 0
offset_y = 193
total = len(coords)
i = 0
for i in range(50):
    print("e={}".format(i / 2))
    swift.set_position(10,
                       193,
                       50,
                       extrude=i / 2,
                       wait=True,
                       speed=500,
Ejemplo n.º 29
0
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)

    # global Arm_Flag ,arm_speed
    global arm_speed
    file = open("Arm_Flag.txt", "w")
    file.write("False")
Ejemplo n.º 30
0
       Returns:

          succeed True or failed False
       '''

arm.flush_cmd()
arm.reset()

for _ in range(100):
    rand = np.random.rand(2)
    x = rand[0]*300
    y = rand[1]*600
    y=y-300
    z_const = 100
    print("aimed positions are",x,y,z_const)
    arm.set_position(x= x,y= y,z=z_const,speed=4000,wait=True,timeout=100)
    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
    print("x values " , pos[0])
    print("y values" , pos[1])
    print("z values", pos [2])
    if(pos[2]!= z_const):
        print("invalid data height misconception")
        sys.stdout.write('/a')
        sys.stdout.flush()
        sleep(2.0)
        continue
    else:
        print("valid data with desired height")
        servo_angles=arm.get_servo_angle()