Advertisement
rikisu_

SMR LAB Matlab Code without unnecessary comments

Apr 11th, 2024 (edited)
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.66 KB | Source Code | 0 0
  1. clear; clc; close all;
  2.  
  3. dt = 0.1; ts = 10;  t = 0:dt:ts;
  4.  
  5. x = 0; y = 0; psi = 0;
  6. eta = [x; y; psi];
  7.  
  8. a = 0.1; d = 0.2; l = 0.5;
  9.  
  10. mr_co = [-l/2, l/2, l/2, -l/2;
  11.          -d,    -d,   d,   d];
  12.          
  13. % MR_CO FOR OMNI WHEEL NOT NEEDED AS PER SIR
  14. %mr_co = [l, (-sqrt((l^2)-((w/2)^2))),(-sqrt((l^2)-((w/2)^2)));
  15. %        0,                      w/2,                   -w/2];
  16.  
  17. %For Kinematics use u v r
  18. %u = 0.4; v = 0; r = 0.2;
  19. %zeta=[u;v;r];
  20.  
  21. % For Kinematics of DIFFERENTIAL bot use this W and omega
  22. %omega = [0.4;0.4];
  23. %W = [a/2,a/2;            0,0;       -a/(2*d), a/(2*d)];
  24. %zeta=(W * omega);
  25.  
  26. % For Kinematics of OMNI bot use this W and omega
  27. %omega = [0; 0.2; -0.2;]; % angular velocities of three wheels
  28. %W = a/3*[0,-sqrt(3),sqrt(3);     2,-1,-1;      1/l,1/l,1/l]
  29. %zeta=(W * omega);
  30.  
  31. % For Kinematics of MECHANUM bot use this W and omega
  32. %omega = [0.5;0.5;0.5;0.5]; % angular velocities of four wheels
  33. %W = a/4*[1,1,1,1;       1,-1,1,-1;       -1/(d-l),-1/(d-l),1/(d-l),1/(d-l)];
  34. %zeta=(W * omega);
  35.  
  36. for i = 1:length(t)
  37.     Jacobian = [cos(eta(3,i)), -sin(eta(3,i)), 0;
  38.              sin(eta(3,i)), cos(eta(3,i)),  0;
  39.              0,              0,             1];
  40.     eta_dot = Jacobian * zeta;
  41.     eta(:,i+1) = eta(:,i) + dt * eta_dot;
  42. end
  43.  
  44. figure
  45. for i = 1:length(t)
  46.     pos = [cos(eta(3,i)), -sin(eta(3,i));
  47.            sin(eta(3,i)),  cos(eta(3,i))] * mr_co;
  48.     fill(pos(1,:)+eta(1,i), pos(2,:)+eta(2,i), 'o')
  49.     hold on, grid on, axis equal;
  50.     plot(eta(1,1:i), eta(2,1:i), 'b-');
  51.     axis([-1 5 -1 5]);
  52.     xlabel('x[m]'); ylabel('y[m]');
  53.     legend('MR','Path'), set(gca,'fontsize',24)
  54.     pause(0.001);
  55.     hold off;
  56. end
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement