Advertisement
Ostu

Untitled

Jun 11th, 2021
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.43 KB | None | 0 0
  1. TIME_STEP = 64;
  2.  
  3.  
  4. silnik1 = wb_robot_get_device('left wheel motor');
  5. silnik2 = wb_robot_get_device('right wheel motor');
  6.  
  7. wb_motor_set_position( silnik1, inf );
  8. wb_motor_set_position( silnik2, inf );
  9.  
  10. lazik = wb_supervisor_node_get_from_def( 'robot1' )
  11.  
  12. translacja = wb_supervisor_node_get_field( lazik, 'translation' )
  13. rotacja = wb_supervisor_node_get_field( lazik, 'rotation' )
  14.  
  15. zegar = tic
  16. t = toc(zegar)
  17. v = 1
  18. while wb_robot_step(TIME_STEP) ~= -1
  19. dt = toc(zegar) - t
  20. t = toc(zegar)
  21. polozenie = wb_supervisor_field_get_sf_vec3f( translacja );
  22. obrot = wb_supervisor_field_get_sf_rotation( rotacja );
  23. wykres1.XData = polozenie(3)
  24. wykres1.YData = polozenie(1)
  25. x = polozenie(3)
  26. y = polozenie(1)
  27. theta = obrot(4)
  28. [a,w] = sterowanie( t, x, y, theta, v )
  29. v = v + a*dt;
  30.  
  31. R = 0.02;
  32. L = 0.05;
  33. v_12 = inv( [ R/2 R/2 ; R/L, -R/L ]) * [v;w];
  34.  
  35. wb_motor_set_velocity( silnik1, -v_12(1) );
  36. wb_motor_set_velocity( silnik2, -v_12(2) );
  37.  
  38. drawnow;
  39.  
  40. end
  41.  
  42. function [a,w] = sterowanie( t, x, y, theta, v )
  43. % trajektoria
  44. xr = sin(0.1*t);
  45. yr = cos(0.1*t);
  46. dxr = 0.1*cos(0.1*t);
  47. dyr = -0.1*sin(0.1*t);
  48. ddxr = -0.01*sin(0.1*t);
  49. ddyr = -0.01*cos(0.1*t);
  50.  
  51.  % robot:
  52. dx = v*cos(theta);
  53. dy = v*sin(theta);
  54. % opis celu sterowania
  55. e = [xr;yr] - [x;y];
  56. de = [dxr;dyr] - [dx;dy];
  57. dde = -10*de-25*e;
  58. % sterowanie
  59. A = [ cos(theta), -v*sin(theta) ; ...
  60. sin(theta), v*cos(theta) ];
  61. aw = inv(A)*(-dde + [ddxr;ddyr] );
  62. a = aw(1);
  63. w = aw(2);
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement