dorbird

MatLab_Helix

May 21st, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.30 KB | None | 0 0
  1. clear all
  2. close all
  3.  
  4. theta = [ pi/2; pi/2; pi/2 ] ;
  5. Xhistory = zeros(1, 0);
  6. Yhistory = zeros(1, 0);
  7. Zhistory = zeros(1, 0);
  8. thetahistory = zeros( 3, 0);
  9. q = [0,0,0]' ;
  10.  
  11. a = [120,80];
  12. R=100;
  13. H=20;
  14. dt=50;
  15. umrundungen=5;
  16.  
  17. niter=10;
  18.  
  19. fig1 = figure( 'Position', [100, 100, 600, 600]);
  20. for t = -umrundungen*pi:pi/dt:umrundungen*pi;
  21.     figure( fig1);
  22.     p=[R*cos(t);R*sin(t);H*t/pi];
  23.     %inverse kinematic
  24.     for i = 1:niter
  25.        
  26.         r = a(1) * [cos(theta(1)) * cos(theta(3)) ;
  27.             cos(theta(1)) * sin(theta(3)) ;
  28.             sin(theta(1))] ;
  29.        
  30.         s = a(2) * [cos(theta(1) + theta(2)) * cos(theta(3)) ;
  31.             cos(theta(1) + theta(2)) * sin(theta(3)) ;
  32.             sin(theta(1) + theta(2))] ;
  33.        
  34.         f =  q + r + s;
  35.        
  36.         F_theta1 = [-a(1) * sin(theta(1)) * cos(theta(3)) - a(2) * sin(theta(1) + theta(2)) * cos(theta(3)) ;
  37.             -a(1) * sin(theta(1)) * sin(theta(3)) - a(2) * sin(theta(1) + theta(2)) * sin(theta(3)) ;
  38.             a(1) * cos(theta(1)) + a(2) * cos(theta(1) + theta(2))] ;
  39.        
  40.         F_theta2 = [-a(2) * sin(theta(1) + theta(2)) * cos(theta(3)) ;
  41.             -a(2) * sin(theta(1) + theta(2)) * sin(theta(3));
  42.             a(2) * cos(theta(1) + theta(2))] ;
  43.        
  44.        
  45.         F_theta3 = [-a(1)*cos(theta(1)) *sin(theta(3)) - a(2)*cos(theta(1) + theta(2) ) * sin(theta(3)) ;
  46.             a(1)*cos(theta(1)) *cos(theta(3)) + a(2)*cos(theta(1) + theta(2) ) * cos(theta(3)) ;
  47.             0 ] ;
  48.        
  49.         J = [F_theta1  F_theta2  F_theta3] ;
  50.        
  51.         dtheta = (J'*J) \ J' * (p-f);
  52.         theta = theta + dtheta;
  53.     end
  54.    
  55.     % save points that have been reached by end effector
  56.     Xhistory( end+1) = f(1);
  57.     Yhistory( end+1) = f(2);
  58.     Zhistory( end+1) = f(3);
  59.     thetahistory( :, end+1) = theta;
  60.    
  61.     % plot manipulator and point history
  62.     plot3([20 0 r(1) f(1)], [0 0 r(2), f(2)],[0 0 r(3) f(3)], 'r', 'Linewidth', 3);
  63.     %plot3([20 0 s(1) f(1)], [0 0 s(2), f(2)],[0 0 s(3) f(3)], 'r', 'Linewidth', 3);
  64.     hold on
  65.     grid on
  66.     plot3( Xhistory', Yhistory', Zhistory', '.');
  67.     hold off
  68.    
  69.     axis([-100, 100, -100, 100, -100, 100]);
  70. end
  71. % figure(2)
  72. % plot( thetahistory(1,:));
  73. % hold on
  74. % plot( thetahistory(2,:), 'r');
  75. % plot( thetahistory(3,:), 'g');
  76. % hold off
Advertisement
Add Comment
Please, Sign In to add comment