Advertisement
Guest User

Untitled

a guest
May 7th, 2017
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. clear all; clc; close all;
  2.  
  3. %constants
  4. l2 = .325; %long arm length
  5. l1 = .22; %short arm length
  6. l4 = .5; %length to mass 1
  7. m1 = 10; %counterweight
  8. m2 = .1; %projectile
  9. I1 = .00605; %moment of inertia of arm
  10. I2 = 2/5*m2*(.0254/2)^2;%moment of inertia of projectile
  11. rad = pi/180;
  12. ho = l1*(1 + sin(0));
  13.  
  14. %experimental varaiables
  15. l3 = .2;
  16.  
  17. %loop stuff
  18. tfinal = 100;
  19. step = .1;
  20. n = tfinal/step;
  21.  
  22. %initial vals
  23.  
  24. beta(1) = 180*rad;
  25.  
  26. theta(1) = 0;
  27. phi(1) = 0;
  28. psi(1) = -45*rad;
  29. thetaDot(1) = 0;
  30. phiDot(1) = 0;
  31. psiDot(1) = 0;
  32. thetaDdot(1) = 0;
  33. phiDdot(1) = 0;
  34. psiDdot(1) = 0;
  35.  
  36. for ii=1:n
  37.  
  38. p = [theta(ii); psi(ii); phi(ii); thetaDot(ii); psiDot(ii); phiDot(ii)];
  39. Mmat = [1, 0, 0, 0, 0, 0, 0;
  40. 0, 1, 0, 0, 0, 0, 0;
  41. 0, 0, 1, 0, 0, 0, 0;
  42. 0, 0, 0, m1*l1^2 + m2*l2^2 + I1, -m2*l2*l3*cos(p(1) - p(2)), m1*l1*l4*cos(p(1) - p(3)), -l2*cos(p(1));
  43. 0, 0, 0, -m2*l2*l3*cos(p(1) - p(2)), m2*l3^2 + I2, 0, l3*cos(p(2));
  44. 0, 0, 0, m1*l1*l4*cos(p(1) - p(3)), 0, m1*(l4^2 + 1), 0;
  45. 0, 0, 0, -l2*cos(p(1)), l3*cos(p(2)), 0, 0];
  46.  
  47. Qmat = [p(4);
  48. p(5);
  49. p(6);
  50. m1*l1*l4*p(6)^2*sin(p(1) - p(3)) + m2*l2*l3*p(5)^2*sin(p(1) - p(2)) - (m1*l1 - m2*l2)*9.8*cos(p(1));
  51. -m2*l2*l3*p(4)^2*sin(p(1) - p(2)) - m2*l3*9.8*cos(p(2));
  52. m1*l1*l4*p(4)^2*sin(p(1) - p(3)) - m2*l3*9.8*cos(p(3));
  53. -p(4)^2*l2*sin(p(1)) + l3*p(5)^2*sin(p(2))];
  54.  
  55. temp = step*(Mmat\Qmat);
  56. newP = p(1:6) + .5*temp(1:6);
  57.  
  58. Mmat = [1, 0, 0, 0, 0, 0, 0;
  59. 0, 1, 0, 0, 0, 0, 0;
  60. 0, 0, 1, 0, 0, 0, 0;
  61. 0, 0, 0, m1*l1^2 + m2*l2^2 + I1, -m2*l2*l3*cos(newP(1) - newP(2)), m1*l1*l4*cos(newP(1) - newP(3)), -l2*cos(newP(1));
  62. 0, 0, 0, -m2*l2*l3*cos(newP(1) - newP(2)), m2*l3^2 + I2, 0, l3*cos(newP(2));
  63. 0, 0, 0, m1*l1*l4*cos(newP(1) - newP(3)), 0, m1*(l4^2 + 1), 0;
  64. 0, 0, 0, -l2*cos(newP(1)), l3*cos(newP(2)), 0, 0];
  65.  
  66. Qmat = [newP(4);
  67. newP(5);
  68. newP(6);
  69. m1*l1*l4*newP(6)^2*sin(newP(1) - newP(3)) + m2*l2*l3*newP(5)^2*sin(newP(1) - newP(2)) - (m1*l1 - m2*l2)*9.8*cos(newP(1));
  70. -m2*l2*l3*newP(4)^2*sin(newP(1) - newP(2)) - m2*l3*9.8*cos(newP(2));
  71. m1*l1*l4*newP(4)^2*sin(newP(1) - newP(3)) - m2*l3*9.8*cos(newP(3));
  72. -newP(4)^2*l2*sin(newP(1)) + l3*newP(5)^2*sin(newP(2))];
  73.  
  74. qDotMat = step*(Mmat\Qmat);
  75. pDot = qDotMat(1:6);
  76. lamda = qDotMat(7);
  77.  
  78. theta(ii+1) = p(1) + pDot(1);
  79. psi(ii+1) = p(2) + pDot(2);
  80. phi(ii+1) = p(3) + pDot(3);
  81. thetaDot(ii+1) = p(4) + pDot(4);
  82. psiDot(ii+1) = p(5) + pDot(5);
  83. phiDot(ii+1) = p(6) + pDot(5);
  84.  
  85. beta(ii+1) = beta(ii) - p(1);
  86. x(ii) = cos(p(2))*l3;
  87. y(ii) = sin(p(2))*l3;
  88.  
  89. end
  90.  
  91. figure;
  92. plot(x, y)
  93. xlabel('X'); ylabel('Y'); title('X and Y position of projectile');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement