Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. #%%%%%%%% NEUROMECHANICS %%%%%%%%%%%%%
  3. # (c) Daniel A Hagen
  4. # August 2016, version 1.0
  5. # Filename: J2D2DOF.py
  6. # Jacobian of 2D, 2DOF linkage system
  7.  
  8. import numpy as np
  9. import sympy as sp
  10.  
  11. # Define the symbolic variables
  12. G, J = sp.symbols('G J', real = True) # Vector Functions
  13. angle1, angle2, x, y = sp.symbols('angle1 angle2 x y', real = True) # Degrees of Freedom
  14. link1, link2 = sp.symbols('link1 link2', real = True) # System Parameters
  15.  
  16. # Define x and y coordinates of the endpoint
  17. # Create Matrix for Geometric Model
  18. x = link1*sp.cos(angle1) + link2*sp.cos(angle1+angle2)
  19. y = link1*sp.sin(angle1) + link2*sp.sin(angle1+angle2)
  20. G = sp.Matrix([x,y])
  21.  
  22. #Create Jacobian and its permutations
  23. J = G.jacobian([angle1,angle2])
  24. J_inv = J**-1
  25. J_trans = J.T
  26. J_inv_transpose = (J**-1).T
  27.  
  28. print("G\n",G,"\n")
  29. print("J\n",J,"\n")
  30. print("J Inverse\n",J_inv,"\n")
  31. print("J Transpose\n",J_trans,"\n")
  32. print("J Inverse Transpose\n",J_inv_transpose,"\n")
  33.  
  34. # Numerical Example 1
  35. # Define Link Lengths (m)
  36. Link1 = 1
  37. Link2 = 1
  38. #Define Joint Angles (radians)
  39. Angle1 = 0 # 0 degrees
  40. Angle2 = np.pi/2 # 90 degrees
  41.  
  42. print("Evaluate the functions for these parameters:\n")
  43. print("G:\n",G.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)]),"\n")
  44. print("J:\n",J.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)]),"\n")
  45. print("J Inverse:\n",J_inv.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)]),"\n")
  46. print("J Transpose:\n",J_trans.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)]),"\n")
  47. print("J Inverse Transpose:\n",J_inv_transpose.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)]),"\n")
  48.  
  49. # Numerical Example 2
  50. print("Example of applying a positive angular velocity at Angle1 to find the resulting instantaneous endpoint velocity\n")
  51. AngularVelocity1 = 1
  52. AngularVelocity2 = 0
  53. Velocity = J.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)])*np.matrix([[AngularVelocity1],[AngularVelocity2]])
  54. print("Velocity:\n",Velocity,"\n")
  55.  
  56. print("Example of applying that same endpoint velocity to find the resulting instantaenous angular velocities\n")
  57. AngularVelocities = J_inv.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)])*Velocity
  58. print("Angular Velocities:\n",AngularVelocities,"\n")
  59.  
  60. print("Example of finding which torques produce a horizontal endpoint force vector in equilibrium\n")
  61. Tau = J_trans.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)])*np.matrix([[1],[0]])
  62. print("Torques:\n",Tau,"\n")
  63.  
  64. print("Example of applying those joint torques to find the resulting endpoint force vector in equilibrium\n")
  65. Force = J_inv_transpose.subs([(angle1, Angle1), (angle2, Angle2), (link1, Link1), (link2, Link2)])*Tau
  66. print("Force:\n",Force,"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement