Advertisement
Guest User

Untitled

a guest
May 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. clc,format compact
  2. clear
  3. close all
  4. %% The length of the links of the mechanism
  5. L(1) = 20;
  6. L(2) = 17;
  7. L(3) = 40;
  8. L(4) = 36;
  9. L(5) = 36;
  10.  
  11. %% Initialization of the figure
  12. figure, hold on
  13.  
  14. %% give initial guess for the solution (value of X at which fvec~=0)
  15. X(1) = deg2rad(120);
  16. X(2) = deg2rad(90);
  17. X(3) = deg2rad(100);
  18. X(4) = 15;
  19. ThetaRange = deg2rad(0:4:360);
  20. [THETA2,THETA3,THETA4,THETA5,D] = deal(zeros(size(ThetaRange)));
  21. Theta1 = deg2rad(15);
  22. i = 1;
  23. for ThetaCurrent = ThetaRange
  24. clf
  25. THETA2(i) = ThetaCurrent;
  26. X0 = X;
  27. options = optimset('Display','off');
  28. [X,fval,condition] = fsolve(@(X)FCN(L,THETA2(i),X,Theta1),X0,options);
  29. if condition ~=1
  30. warning(['Convergence Problem at Theta2 = ' num2str(rad2deg(ThetaCurrent)) ])
  31. end
  32.  
  33. THETA3(i) = X(1);
  34. THETA4(i) = X(2);
  35. THETA5(i) = X(3);
  36. D(i) = X(4);
  37. % disp([rad2deg(X(1:3)) d])
  38.  
  39. P1 = [0 , 0];
  40. P2(1) = L(2)*cos(THETA2(i));
  41. P2(2) = L(2)*sin(THETA2(i));
  42.  
  43.  
  44. P5(1) = -L(1)*cosd(180);
  45. P5(2) = -L(1)*sind(180);
  46.  
  47. P3(1) = P2(1)-L(3)*cos(THETA3(i));
  48. P3(2) = P2(2)-L(3)*sin(THETA3(i));
  49.  
  50. P6(1) = P5(1)+D(i)*cosd(90);
  51. P6(2) = P5(2)+D(i)*sind(90);
  52.  
  53. P4(1) = P3(1)-(L(4)/2)*cos(THETA4(i));
  54. P4(2) = P3(2)-(L(4)/2)*sin(THETA4(i));
  55.  
  56. plot(P1(1),P1(2),'Or','MarkerSize',10,'LineWidth',3)
  57. hold on
  58. plot( [P1(1),P2(1),P3(1),P4(1),P5(1)] , [P1(2),P2(2),P3(2),P4(2),P5(2)] ,'-*','LineWidth',2)
  59. plot( [P3(1),P6(1)] , [P3(2),P6(2)] ,'-r*','LineWidth',2)
  60. plot( [P1(1),P5(1)] , [P1(2),P5(2)] ,'-g*','LineWidth',4)
  61. plot( [P5(1),P5(1)] , [P1(2),100] ,'-g*','LineWidth',4)
  62. text(P1(1),P1(2),'P1')
  63. text(P2(1),P2(2),'P2')
  64. text(P3(1),P3(2),'P3')
  65. text(P4(1),P4(2),'P4')
  66.  
  67. axis equal
  68. axis([-50 120 -50 120])
  69. grid on
  70. pause(0.001)
  71. i = i+1;
  72. end
  73. %% Velocity and Acceleration Analysis
  74. %------------------------------------
  75. % Initialization
  76. %---------------
  77. [dTHETA3,dTHETA4,dTHETA5,dD,ddTHETA3,ddTHETA4,ddTHETA5,ddD] = deal(zeros(size(ThetaRange)));
  78.  
  79. dTHETA2 = 2*ones(size(ThetaRange)); % rad/s (Input angular velocity)
  80. ddTHETA2 = 0*ones(size(ThetaRange)); % rad/s^2 (Input angular acceleration)
  81.  
  82. for i = 1:length(THETA2)
  83. % Velocity analysis
  84. % -----------------
  85. A = [L(3)*cos(THETA3(i)) (L(4)/2)*cos(THETA4(i)) L(5)*cos(THETA5(i)) 0;
  86. L(3)*sin(THETA3(i)) (L(4)/2)*sin(THETA4(i)) L(5)*sin(THETA5(i)) 0;
  87. 0 L(4)*cos(THETA4(i)) L(5)*cos(THETA5(i)) -1;
  88. 0 L(4)*sin(THETA4(i)) L(5)*sin(THETA5(i)) 0 ];
  89. b = [L(2)*cos(THETA2(i))*dTHETA2(i);
  90. L(2)*sin(THETA2(i))*dTHETA2(i);
  91. 0;
  92. 0];
  93. dTHETA = A\b;
  94. dTHETA3(i) = dTHETA(1);
  95. dTHETA4(i) = dTHETA(2);
  96. dTHETA5(i) = dTHETA(3);
  97. dD(i) = dTHETA(4);
  98. % Acceleration analysis
  99. % ---------------------
  100. C = [-L(3)*cos(THETA3(i)) -(L(4)/2)*cos(THETA4(i)) -L(5)*cos(THETA5(i)) 0;
  101. -L(3)*sin(THETA3(i)) -(L(4)/2)*sin(THETA4(i)) -L(5)*sin(THETA5(i)) 0;
  102. 0 L(4)*cos(THETA4(i)) L(5)*cos(THETA5(i)) -1;
  103. 0 L(4)*sin(THETA4(i)) L(5)*cos(THETA5(i)) 0 ];
  104.  
  105. D = [-L(2)*cos(THETA2(i))*ddTHETA2(i)+L(2)*sin(THETA2(i))*dTHETA2(i)^2-L(3)*sin(THETA3(i))*dTHETA3(i)^2-(L(4)/2)*sin(THETA4(i))*dTHETA4(i)^2-L(5)*sin(THETA5(i))*dTHETA5(i)^2;
  106. -L(2)*sin(THETA2(i))*ddTHETA2(i)-L(2)*cos(THETA2(i))*dTHETA2(i)^2+L(3)*cos(THETA3(i))*dTHETA3(i)^2+(L(4)/2)*cos(THETA4(i))*dTHETA4(i)^2+L(5)*cos(THETA5(i))*dTHETA5(i)^2;
  107. L(5)*sin(THETA5(i))*dTHETA5(i)^2+L(4)*sin(THETA4(i))*dTHETA4(i)^2;
  108. -L(5)*cos(THETA5(i))*dTHETA5(i)^2-L(4)*cos(THETA4(i))*dTHETA4(i)^2
  109. ];
  110. ddTHETA = C\D;
  111. ddTHETA3(i) = ddTHETA(1);
  112. ddTHETA4(i) = ddTHETA(2);
  113. ddTHETA5(i) = ddTHETA(3);
  114. ddD(i) = ddTHETA(4);
  115.  
  116. end
  117.  
  118. % Velocity analysis plots
  119. % -----------------------
  120. figure('Name','Joint velocities')
  121. subplot(2,3,1)
  122. plot(ThetaRange,dTHETA2),grid on,axis tight
  123. xlabel('\theta_2'),title('\omega_2')
  124. subplot(2,3,2)
  125. plot(ThetaRange,dTHETA3),grid on,axis tight
  126. xlabel('\theta_2'),title('\omega_3')
  127. subplot(2,3,3)
  128. plot(ThetaRange,dTHETA4),grid on,axis tight
  129. xlabel('\theta_2'),title('\omega_4')
  130. subplot(2,3,4)
  131. plot(ThetaRange,dTHETA5),grid on,axis tight
  132. xlabel('\theta_2'),title('\omega_5')
  133. subplot(2,3,5)
  134. plot(ThetaRange,dD),grid on,axis tight
  135. xlabel('\theta_2'),title('dD')
  136. % Acceleration analysis plots
  137. % ---------------------------
  138. figure('Name','Joint accelerations')
  139. subplot(2,3,1)
  140. plot(ThetaRange,ddTHETA2),grid on,axis tight
  141. xlabel('\theta_2'),title('\alpha_2')
  142. subplot(2,3,2)
  143. plot(ThetaRange,ddTHETA3),grid on,axis tight
  144. xlabel('\theta_2'),title('\alpha_3')
  145. subplot(2,3,3)
  146. plot(ThetaRange,ddTHETA4),grid on,axis tight
  147. xlabel('\theta_2'),title('\alpha_4')
  148. subplot(2,3,4)
  149. plot(ThetaRange,ddTHETA5),grid on,axis tight
  150. xlabel('\theta_2'),title('\alpha_5')
  151. subplot(2,3,5)
  152. plot(ThetaRange,ddD),grid on,axis tight
  153. xlabel('\theta_2'),title('ddD')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement