dorbird

3D Krane in Matlab

Apr 27th, 2015
4,645
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.23 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]' ;%ursprung atm noch fest
  10. a = [90,80];%armlänge
  11. niter=100;%iterationen
  12. t=0;
  13.  
  14.  
  15. Q =[  0 60 60 50 50 20 20 30 30 40 40 30 30 20 20 50 50 60 60  0  0 10 10  0  0;...
  16.       0  0 20 20 10 10 40 40 30 30 60 60 50 50 80 80 70 70 90 90 80 80 10 10  0;...
  17.      20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20];
  18. %Punkte=getCurve(Q,1);
  19. %Punkte=getBallSurf(50,25,50);
  20. %Punkte=getCubeWire(50,1);
  21. Punkte=getCubeBetterWire(50,1);
  22. %Punkte=getCubeSurf(50,10);
  23. %Punkte=getCubeSolid(10,5);
  24. %Punkte=getDog();
  25. %Punkte=getDogSD();
  26. %Punkte=getDogHD();
  27. %Punkte=getHelix(100,100,100);
  28. %Punkte=getTorus(50,30,50,25);
  29. %Punkte=getBezierGrad3([100;100;100],[100;100;-100],[-100;-100;-100],0.01);
  30. %Punkte=getBezierGrad4([100;100;100],[-100;100;-100],[-100;-100;-100],[-100;-100;100],0.01);
  31. %Punkte=getBezierGrad5([100;100;100],[100;100;-100],[-100;100;-100],[100;-100;100],[-100;-100;-100],0.01);
  32. %Punkte=getBezierGrad6([100;100;100],[100;100;-100],[-100;100;100],[100;-100;100],[-100;100;100],[-100;-100;-100],0.01);
  33.  
  34. anzahlDerPunkte=length(Punkte)
  35. fig1 = figure( 'Position', [100, 100, 600, 600]);
  36. for t =1:1:anzahlDerPunkte;
  37.     figure( fig1);
  38.     p=Punkte(:,t);
  39.     %inverse kinematic
  40.     for i = 1:niter
  41.        
  42.         r = a(1) * [cos(theta(1)) * cos(theta(3)) ;
  43.             cos(theta(1)) * sin(theta(3)) ;
  44.             sin(theta(1))] ;
  45.        
  46.         s = a(2) * [cos(theta(1) + theta(2)) * cos(theta(3)) ;
  47.             cos(theta(1) + theta(2)) * sin(theta(3)) ;
  48.             sin(theta(1) + theta(2))] ;
  49.        
  50.         f =  q + r + s;
  51.        
  52.         F_theta1 = [-a(1) * sin(theta(1)) * cos(theta(3)) - a(2) * sin(theta(1) + theta(2)) * cos(theta(3)) ;
  53.                     -a(1) * sin(theta(1)) * sin(theta(3)) - a(2) * sin(theta(1) + theta(2)) * sin(theta(3)) ;
  54.                     a(1) * cos(theta(1)) + a(2) * cos(theta(1) + theta(2))] ;
  55.        
  56.         F_theta2 = [-a(2) * sin(theta(1) + theta(2)) * cos(theta(3)) ;
  57.                     -a(2) * sin(theta(1) + theta(2)) * sin(theta(3));
  58.                     a(2) * cos(theta(1) + theta(2))] ;
  59.        
  60.        
  61.         F_theta3 = [-a(1)*cos(theta(1)) *sin(theta(3)) - a(2)*cos(theta(1) + theta(2) ) * sin(theta(3)) ;
  62.                     a(1)*cos(theta(1)) *cos(theta(3)) + a(2)*cos(theta(1) + theta(2) ) * cos(theta(3)) ;
  63.                     0 ] ;
  64.        
  65.         J = [F_theta1  F_theta2  F_theta3] ;
  66.        
  67.         dtheta = (J'*J) \ J' * (p-f);
  68.         theta = theta + dtheta;
  69.     end
  70.    
  71.     % save points that have been reached by end effector
  72.     Xhistory( end+1) = f(1);
  73.     Yhistory( end+1) = f(2);
  74.     Zhistory( end+1) = f(3);
  75.     thetahistory( :, end+1) = theta;
  76.    
  77.     % plot manipulator and point history
  78.     plot3([q(1)+20 q(1) r(1) f(1)], [q(2) q(2) r(2), f(2)],[q(3) q(3) r(3) f(3)], 'r', 'Linewidth', 3);
  79.     hold on
  80.     grid on
  81.     plot3( Xhistory', Yhistory', Zhistory', '.');
  82.     hold off
  83.    
  84.     axis([-100, 100, -100, 100, -100, 100]);
  85. end
  86.  %figure(2)
  87.  %plot( thetahistory(1,:));
  88.  %hold on
  89.  %plot( thetahistory(2,:), 'r');
  90.  %plot( thetahistory(3,:), 'g');
  91.  %hold off
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment