Exemplo n.º 1
0
 def connect_robot(self):
     if self.__robotIsConnectedFlag == False:
         try:
             self.setRobotIsConnectedFlag(True)
             LeftHand = abb.Robot(ip='192.168.125.1', port_motion=5000)
             RightHand = abb.Robot(ip='192.168.125.1', port_motion=5001)
         except Exception as exc:
             print(exc.args)
             #TODO: messagebox about exceptions
     elif self.__robotIsConnectedFlag == True:
         try:
             self.setRobotIsConnectedFlag(False)
             LeftHand = None
             RightHand = None
             #LeftHand = abb.Robot(ip='192.168.125.1', port_motion=5000)
             #RightHand = abb.Robot(ip='192.168.125.1', port_motion=5001)
         except Exception as exc:
             print(exc.args)
Exemplo n.º 2
0
def robot_move(thing,
               st_list,
               width,
               obj_point,
               worldx0=400,
               worldy0=400,
               ip1='192.168.125.1'):
    R = abb.Robot(ip=ip1)
    R.set_joints([0, 0, 0, 0, 0, 0])
    #设置tool down
    q = Quaternion([0, 0, 1, 0])
    j1 = 0
    sum_j = 0  #用来表示现在是第几个
    height = 15  #代表积木高度
    for j in st_list:
        j1 = j1 + 1  #代表层数
        k = 0  #k代表本层第几
        for i in range(j):
            index = sum_j + i
            # 将角度换为弧度
            angle1 = radians(thing[index][3])
            # 换算四元数
            my_quaternion = Quaternion(axis=[0, 0, 1], angle=angle1)
            quat = (q * my_quaternion).elements
            #手臂到达其上空
            R.set_cartesian(
                [[thing[index][1] + worldx0, thing[index][2] + worldy0, 200],
                 quat])
            #抓取
            R.set_cartesian([[
                thing[index][1] + worldx0, thing[index][2] + worldy0, height
            ], quat])
            #抬起
            R.set_cartesian(
                [[thing[index][1] + worldx0, thing[index][2] + worldy0, 200],
                 [quat[0], quat[1], quat[2], quat[3]]])

            quat = Quaternion(axis=[0, 0, 1], angle=-angle1)
            quat = (q * quat).elements
            #平移
            R.set_cartesian([[obj_point[0] + width * k, obj_point[1], 200],
                             [quat[0], quat[1], quat[2], quat[3]]])
            #放置
            R.set_cartesian(
                [[obj_point[0] + width * k, obj_point[1], (j1) * height],
                 [quat[0], quat[1], quat[2], quat[3]]])
            print(R.get_cartesian())
            #提起来
            R.set_cartesian([[obj_point[0] + width * k, obj_point[1], 200],
                             [quat[0], quat[1], quat[2], quat[3]]])
            k = k + 1
        sum_j = sum_j + j
Exemplo n.º 3
0
def get_robot_controller():
    """ returns a tuple: (robot controller reference, 
    boolean success indicator) """

    # abb = imp.load_source("abb", "./abb/packages/abb_communications/abb.py")
    try:
        robot = abb.Robot(ip='192.168.125.1')
        return (robot, True)
    except socket.error as err:
        print(err)
        if isinstance(err, socket.timeout):
            print(
                "Last time it was caught, this error meant the arm's USB cable"
                " was not plugged in to this computer.")
        elif err.errno == errno.ECONNREFUSED:
            print(
                "Last time it was caught, this error meant the USB cable is plugged "
                "in, but the remote control program was not yet running on the robot's "
                "computer. Use the flex pendant to run the program.")
        else:
            print("We caught a new sort of socket error - raising it again")
            raise err
        return (None, False)
Exemplo n.º 4
0
# coding=UTF-8
import abb
import rospy
import math


doGripperOpen = 1
doGripperClose = 2
R = abb.Robot('192.168.125.1') # connecting to robot
R.set_cartesian([[350, 0, 212], [0.707,0,0.707,0]])
R.set_dio(doGripperClose, 0)
R.set_dio(doGripperOpen, 1)
rospy.sleep(0.1)
R.set_cartesian_v([[350, 0, 250], [0.707,0,0.707,0]],100)
R.set_cartesian_v([[350, 0, 300], [0.707,0,0.707,0]],300)
R.set_cartesian_v([[350, 0, 350], [0.707,0,0.707,0]],50)

R.set_joints([12.8, -15, 60.3, 16.3, -31.5, -17.45])
rospy.sleep(0.1)
R.set_joints_v([12.8, -15, 60.3, 16.3, -31.5, -17.45],200)
R.set_joints_v([32.8, -15, 60.3, 16.3, -31.5, -17.45],400)
R.set_joints_v([62.8, -15, 60.3, 16.3, -31.5, -17.45],100)

grip_down_time = 0.85
dx = 0.406  # image space to robot space   60.5/149
dy = 0.406 # image space to robot space 60.5/149
s = 255 #等待的距离
track_time = 1.0025 #追物体的时间

def grip(pos_y,pos_x,speed):
    global track_time
Exemplo n.º 5
0
        while True:
            data = connection.recv(3)
            if data:
                # output received data
                pos.append(data)
            else:
                # no more data -- quit the loop
                print("no more data.")
                break
    finally:
        # Clean up the connection
        connection.close()

try:
    print("connecting to 192.168.125.1")
    r = abb.Robot(ip='192.168.125.1')
except:
    a = 1
    print("trying another ip address")

r.set_speed([500, 150, 150, 150])

if (a == 1):
    print("connecting to 127.0.0.1")

while (True):
    r.set_speed([500, 150, 150, 150])

    r.set_cartesian([[pos[0], 0, 1000], [0, 0, 1, 0]])

    r.set_cartesian([[pos[0], pos[1], 1000], [0, 0, 1, 0]])
Exemplo n.º 6
0
def main(mode_selection):
    '''
    Main function to generate toolpath
    '''
    prev_path_x = []
    prev_path_y = []
    prev_path_z = []
    tip_xyz = []
    base_theta = []
    curr_layer = []

    x_path = []
    y_path = []
    z_path = []
    theta_path = []

    # Generate tool path
    initial_x, initial_y, _ = xyzGenerator.retrieve_xyz(
        XYZ_SELECTION, CYLINDER_R, CYLINDER_H)
    initial_x = np.array(initial_x)
    initial_y = np.array(initial_y)

    for init_x_val, init_y_val in zip(initial_x, initial_y):
        x = np.array(init_x_val)
        theta_path.append(x / CYLINDER_R)
        z_path.append(init_y_val)
        temp_x, temp_y = rotate_vector(CYLINDER_XY[0], CYLINDER_XY[1],
                                       theta_path[-1])
        x_path.append(temp_x)
        y_path.append(temp_y)

    x_path = np.array(x_path)
    y_path = np.array(y_path)
    z_path = np.array(z_path)

    for layer_offset in LAYER_OFFSETS:
        base_radius = CYLINDER_R + layer_offset
        for i, _ in enumerate(x_path):
            tip_xyz.append([[x-base_radius, y, z] \
                for x, y, z in zip(x_path[i], y_path[i], z_path[i])])

            # Generate trace path
            # - Untransformed path around cylinder at zero rotation
            prev_x, prev_y = rotate_vector(-1 * base_radius, 0,
                                           -1 * theta_path[i])
            prev_x += CYLINDER_XY[0]
            prev_y += CYLINDER_XY[1]

            prev_path_x.append(prev_x)
            prev_path_y.append(prev_y)
            prev_path_z.append(z_path[i])

            base_theta.append(theta_path[i])
            curr_layer.append(layer_offset)

    # Display
    if mode_selection == 0 and ANIMATE_PRINT:
        for i in range(len(prev_path_x)):
            for j, r in enumerate(base_theta[i]):
                if j % 3:
                    continue

                xyz = tip_xyz[i][j]

                cylinder_xyz = get_cylinder_coordinates(r)
                update_plot(cylinder_xyz, xyz)

                # Add previous path traces...
                for k in range(0, i + 1):
                    x, y = rotate_vector(prev_path_x[k], prev_path_y[k], r)
                    if k == i:
                        update_plot_add_trace(x[0:j], y[0:j],
                                              prev_path_z[k][0:j])
                    else:
                        update_plot_add_trace(x, y, prev_path_z[k])

                update_plot_show()
            # end section loop
        # End display loop

    elif mode_selection == 0 and not ANIMATE_PRINT:
        # Uses final values of above to show print
        r = base_theta[-1][-1]
        xyz = tip_xyz[-1][-1]

        cylinder_xyz = get_cylinder_coordinates(r)
        update_plot(cylinder_xyz, xyz)
        for k, _ in enumerate(prev_path_x):
            x, y = rotate_vector(prev_path_x[k], prev_path_y[k], r)
            update_plot_add_trace(x, y, prev_path_z[k])
        update_plot_show()
        raw_input()

    elif mode_selection == 1 or mode_selection == 2:
        print "----------- Warning: Use RESET_POSITION 2 to reset -------------------"
        if mode_selection == 1:
            R = abb.Robot("127.0.0.1")
        else:
            R = abb.Robot("192.168.125.1")

        R.reset_position(2)
        wobj_coord = robot_config.get_wobj(1)
        tool_coord = robot_config.get_tool(False)
        initial_joint_coord = robot_config.get_initJoint(5)

        R.set_joints(initial_joint_coord)
        R.set_speed([25, 250, 250, 250])
        R.set_workobject(wobj_coord)
        R.set_tool(tool_coord)
        R.set_zone('z1')
        R.set_external_axis([0, 0])

        print_speed = [30, 2000, 2000, 2000]
        fast_print_speed = [50, 2000, 2000, 2000]
        travel_speed = [200, 2000, 2000, 2000]

        q_val = [0.5, 0.5, 0.5, 0.5]  # XYZ rotation (0, 90, 90)

        curr_theta = 0
        b_updated_speed = False

        R.set_speed(print_speed)

        for i, _ in enumerate(tip_xyz):
            print "Path %d of %d" % (i, len(tip_xyz))
            if abs(base_theta[i][0] - curr_theta) > 0.5:
                R.set_speed(travel_speed)
                R.set_zone('fine')
                R.set_joints(initial_joint_coord)
                time.sleep(0.5)
                R.set_external_axis([0, np.degrees(base_theta[i][0])])
                R.set_zone('z1')
                R.set_speed(print_speed)

            pose_list = [[XYZ, q_val, np.degrees(theta)] \
                            for XYZ, theta in zip(tip_xyz[i], base_theta[i])]

            R.buffer_set(pose_list, True)
            R.buffer_execute(1)

            curr_theta = base_theta[i][-1]

            if curr_layer[i] >= LAYER_OFFSETS[1] and not b_updated_speed:
                R.set_speed(fast_print_speed)
                b_updated_speed = True
Exemplo n.º 7
0
# coding=UTF-8
import abb
import time

# connecting to robot
R = abb.Robot('192.168.125.1')
R.set_speed([200, 200, 200, 200])
# start point
# R.set_cartesian([[350, 0, 212], [0.707,0,0.707,0]])
#time.sleep(1) #加入延时会让后面的PT控制的计时有些干扰,实际机器人运动时间没有什么干扰,但是time计时器会有干扰
R.set_joints_t([-60, -15, 60.3, 16.3, -31.5, -17.45], 1.5)

# firstly,start robot. the first step is less than you setting
time_start = time.time()  #start timing
R.set_joints_t([-50, -15, 60.3, 16.3, -31.5, -17.45], 0.6)
time_end = time.time()  #stop timing
time_c = time_end - time_start  #running time
# print('time cost', time_c, 's')

# # firstly,start robot. the first step is less than you setting
# time_start = time.time() #start timing
# R.set_cartesian_v([[350, 0, 250], [0.707,0,0.707,0]],100)
# time_end = time.time()    #stop timing
# time_c= time_end - time_start   #running time
# # print('time cost', time_c, 's')

# #v
# time_start = time.time() #start timing
# R.set_cartesian_v([[350, 0, 300], [0.707,0,0.707,0]],50) # move
# time_end = time.time()    #stop timing
# time_c= time_end - time_start   #running time
Exemplo n.º 8
0
def auto_canny(img, sigma=0.1):
	global apertureSize
	# compute the median of the single channel pixel intensities
	v = np.median(img)
	# apply automatic Canny edge detection using the computed median
	lower = int(max(0, (1.0 - sigma) * v))
	upper = int(min(255, (1.0 + sigma) * v))
	edged = cv2.Canny(img, lower, upper, apertureSize)
	return edged

if ROBOT_MODE:
	a = 0
	try:
	    print ("Connecting to %s ..." % (robot_ip))
	    R = abb.Robot(ip=robot_ip)
	    print ("\t+ Successfully connected to %s" % (robot_ip))
	    print ("\t+ %s" % (R.get_robotinfo()))
	    # R.set_joints([0,0,0,0,0,0])
	except:
	    a = 1;
	    print ("\t- Error: Failed to connect to %s. Trying 127.0.0.1 now ..." % (robot_ip))
	if(a == 1):
		try:
		    print ("Connecting to 127.0.0.1 ...")
		    R = abb.Robot(ip='127.0.0.1')
		except:
			print ("\t- Error: Failed to connect to 127.0.0.1. Exiting now.")
			exit(-1)

	robot_get_cartesian = R.get_cartesian()
Exemplo n.º 9
0
 - - 0      Immediate robot reset
 - - 1      Reset simulation on 127.0.0.1
 [other]    Reset robot in 5 seconds
'''
import abb
import time
import sys
from Robot_Config import robot_config

modeSelection = 2
cmdArgs = sys.argv
if len(cmdArgs) == 2:
    modeSelection = int(cmdArgs[1])

if modeSelection == 1:
    R = abb.Robot("127.0.0.1")
    print("Robot resetting")
elif modeSelection == 0:
    R = abb.Robot("192.168.125.1")
    print("Robot resetting now")
elif modeSelection == 2:
    R = abb.Robot("192.168.125.1")
    print("Robot moving backwards and then resetting")
    currPos = R.get_cartesian()
    currPos[0][0] -= 100
    R.set_cartesian(currPos)
else:
    R = abb.Robot("192.168.125.1")
    print("---- WARNING ----")
    print(" Robot will move suddenly in 5 seconds")
    print(" Press CTRL+C to cancel move")
#!/usr/bin/env python
import sys
from socket import socket,AF_INET,SOCK_STREAM, gethostbyname
import abb
TCP_IP = '192.168.1.73' #type your server ip
TCP_PORT = 10049 #if error occur, you can simply fix by changing this port number
SIZE = 1024  #predefined size for recv function
message = "1"
clientSocket =socket(AF_INET, SOCK_STREAM)#initial for a client socket
clientSocket.connect((TCP_IP, TCP_PORT))#wait for accept
movementA = 1;
a = 0;
try:
    print ("connecting to 192.168.125.1")
    r = abb.Robot(ip = '192.168.125.1')
except:
    a=1;
    print ("trying another ip address")
if(a==1):
    print ("connecting to 127.0.0.1")
    r=abb.Robot(ip='127.0.0.1')
r.set_speed([50,150,150,150])
while(True):
    clientSocket.send(message)#send the message
    receivedMessage = clientSocket.recv(SIZE)#receive message from server
    num = int(receivedMessage)
    print ("Received a message from client: "+receivedMessage)
    if num == '1':
        r.set_speed([50,150,150,150])
    elif num == '2':
        r.set_speed([100,150,150,150])
    DIRECTION_STATE = bconf.DIRECTION.DOWN
    ROBOT_POS_X = int((bconf.AXIS_RANGE_X[0] + bconf.AXIS_RANGE_X[1]) / 2)
    ROBOT_POS_Y = int((bconf.AXIS_RANGE_Y[0] + bconf.AXIS_RANGE_Y[1]) / 2)
    ROBOT_POS_Z = int((bconf.AXIS_RANGE_Z[0] + bconf.AXIS_RANGE_Z[1]) / 2)

vs = None
frame = None
fps = None
(H, W) = (None, None)
centerPos = (None, None)

if ROBOT_MODE:
    a = 0
    try:
        print("Connecting to %s ..." % (bconf.ROBOT_IP))
        R = abb.Robot(ip=bconf.ROBOT_IP)
        print("\t+ Successfully connected to %s" % (bconf.ROBOT_IP))
        print("\t+ %s" % (R.get_robotinfo()))
        R.set_speed([500, 50, 50, 50])
        # R.set_joints([0,0,0,0,0,0])
    except:
        a = 1
        print("\t- Error: Failed to connect to %s. Trying 127.0.0.1 now ..." %
              (bconf.ROBOT_IP))
    if (a == 1):
        try:
            print("Connecting to 127.0.0.1 ...")
            R = abb.Robot(ip='127.0.0.1')
        except:
            print("\t- Error: Failed to connect to 127.0.0.1. Exiting now.")
            exit(-1)