Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 KB | None | 0 0
  1. from Python.robolink.robolink import *
  2. from Python.robodk import *
  3. import numpy as np
  4. import math
  5. sim = Robolink()
  6. robot = sim.Item('H-Bot')
  7. def jointValue():
  8.     jointMatrix = robot.Joints()
  9.     jointArray = []
  10.     for x in jointMatrix:
  11.         for y in x:
  12.             jointArray.append(y)
  13.     return jointArray
  14. dhtable = [[0, -90, 285, "theta"],
  15.      [700, 0, 0, "theta"],
  16.      [0, -90, 0, "theta"],
  17.      [0, 90, 650, "theta"],
  18.      [0, -90, 0, "theta"],
  19.      [0, 0, 170, "theta"]]
  20. joints = jointValue()
  21. for x in range(0, len(dhtable)):
  22.     dhtable[x][3] = (joints[x]*math.pi)/180
  23. def aMatrices(table):
  24.     A = []
  25.     for y in range (0,len(table)):
  26.         a = table[y][0]
  27.         alpha = math.radians(table[y][1])
  28.         d = table[y][2]
  29.         theta = math.radians(table[y][3])
  30.         test = np.array([[math.cos(theta), -(math.cos(alpha)*math.sin(theta)), math.sin(alpha)*math.sin(theta), a*math.cos(theta)],
  31.                   [math.sin(theta), math.cos(alpha)*math.cos(theta), -(math.sin(alpha)*math.cos(theta)), a*math.sin(theta)],
  32.                   [0, math.sin(alpha), math.cos(alpha), d],
  33.                   [0, 0, 0, 1 ]])
  34.         A.append(test)
  35.  
  36.     return A
  37. def A03(a):
  38.     af = np.matmul(a[0], a[1])
  39.     A03 = np.matmul(af, a[2])
  40.     return A03
  41. def A36(a):
  42.     A36 = np.matmul(np.matmul(a[3], a[4]), a[5])
  43.     return A36
  44. def hMatrix(a):
  45.     H = np.matmul(a[0], a[1])
  46.     for x in range (2,len(a)):
  47.         H = np.matmul(H, a[x])
  48.     return H
  49.  
  50. def inversePos():
  51.     links = robot.JointPoses()
  52.     o6 = links[6]
  53.     d6 = 170
  54.     x = o6[0,3]-d6*o6[0,2]
  55.     y = o6[1,3]-d6*o6[1,2]
  56.     z = o6[2,3]-d6*o6[2,2]
  57.     a2 = 650
  58.     a3 = 700
  59.     d = 0
  60.     print("sadsadasda", o6[0,3], o6[1,3], o6[2,3])
  61.     print("daibfackvxonwe0porjpflkn", x, y, z)
  62.     Dd = (math.pow(x,2)+math.pow(y,2)-math.pow(d,2)+math.pow(z-285,2)-math.pow(a2,2)-math.pow(a3,2))/(2*a2*a3)
  63.     theta1 = math.atan2(y, x)
  64.     theta11 = math.pi+theta1
  65.     theta3 = math.atan2((1-(Dd*Dd)), Dd )
  66.     print("Dd: ", Dd)
  67.     theta33 = math.atan2((-1-(Dd*Dd)), Dd)
  68.     theta2 = math.atan2((z-285),math.sqrt(math.pow(x,2)+math.pow(y,2)-math.pow(d,2)))-math.atan2(a3*math.sin(theta3),a2+(a3*math.cos(theta3)))
  69.     theta22 = math.atan2(z-285,math.sqrt(math.pow(x,2)+math.pow(y,2)-math.pow(d,2)))-math.atan2(a3*math.sin(theta33),a2+a3*math.cos(theta33))
  70.     theta1 = np.degrees(theta1)
  71.     theta2 = np.degrees(theta2)
  72.     theta3 = np.degrees(theta3)
  73.     if theta11 > 180:
  74.         theta11 = -180+theta1
  75.     dhtable[0][3] = theta1
  76.     dhtable[1][3] = theta2
  77.     dhtable[2][3] = theta3
  78.     print("Theta 1: ", theta1, " Theta 2: ", theta2, " Theta 3: ", theta3)
  79.     print("Invers theta A03: \n", A03(aMatrices(dhtable)))
  80. print("H matrix:  \n", hMatrix(aMatrices(dhtable)))
  81. inversePos()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement