Beispiel #1
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)
Beispiel #2
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")
Beispiel #3
0
V_max = 255

# 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_r = swift.set_gripper(True)
swift.set_position(x=200, y=0, z=5, relative=False, speed=20000, wait=True)
swift_r = swift.send_cmd_sync("M204 P700 R700 T700\n")
swift.set_position(x=200, y=0, z=3, relative=False, speed=20000, wait=True)

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

#r = cv2.selectROI(frame)
#print(r)
#time.sleep(555)

if RESCALE_FACTOR == 0.5:
    r = (66, 21, 560, 270)
elif RESCALE_FACTOR == 1.0:
    r = (104, 36, 1136, 557)

# so it doesnt keep swinging to hit puck:
Beispiel #4
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())

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,
Beispiel #5
0
from time import sleep

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


def report_position(position):
    print("x:{x} y:{y} z:{z} ".format(x=position[0],
                                      y=position[1],
                                      z=position[2]))


swift = SwiftAPI()  # default by filters: {'hwid': 'USB VID:PID=2341:0042'}
sleep(2)
swift.send_cmd_sync("M2019")
"""Normally, all joint could be attach by command:

M17        # for all, or
M2201 N0~3 # for specified joint
detach by:

M2019      # for all, or
M2202 N0~3 # for specified joint
"""
swift.register_report_position_callback(report_position)
swift.set_report_position(1)

while (True):
    pass