Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. %
  2. % RobotScript
  3. %
  4.  
  5. %%% Your job is to complete the script by replacing the sections
  6. %%% marked with ???
  7.  
  8. %% Create the axes
  9. axis ([-10 10 -10 10]);
  10.  
  11. %% Animation loop
  12. for i = 0:200
  13.  
  14. x = sind(3*i);
  15.  
  16. %% Joint angles
  17. left_elbow_angle = 45*x;
  18. left_shoulder_angle = 45*x;
  19.  
  20. right_elbow_angle = -45*x;
  21. right_shoulder_angle = -45*x;
  22.  
  23. %% Compute Relevant Coordinate Transforms to the base frame of reference
  24.  
  25. % Transform coordinates from frame 2 to frame 1
  26. g12 = Translation2D(0, -1.5);
  27.  
  28. % Transform coordinates from frame 3 to frame 1
  29. g13 = Translation2D(0, -3);
  30.  
  31. % Transform coordinates from frame 4 to frame 1
  32. g14 = Translation2D(-2, 0) * Rotation2D(-left_shoulder_angle) * Translation2D(-1.5, 0);
  33.  
  34. % Transform coordinates from frame 5 to frame 4
  35. g45 = Translation2D(-1.5, 0) * Rotation2D(-left_elbow_angle) * Translation2D(-1.5, 0);
  36.  
  37. % Transform coordinates from frame 5 to frame 1
  38. g15 = Translation2D(-2, 0) * Rotation2D(-left_shoulder_angle) * Translation2D(-1.5, 0) * Translation2D(-1.5, 0) * Rotation2D(-left_elbow_angle) * Translation2D(-1.5, 0);
  39.  
  40. % Transform coordinates from frame 6 to frame 1
  41. g16 = Translation2D(2, 0) * Rotation2D(right_shoulder_angle) * Translation2D(1.5, 0);
  42.  
  43. % Transform coordinates from frame 5 to frame 4
  44. g67 = Translation2D(1.5, 0) * Rotation2D(right_elbow_angle) * Translation2D(1.5, 0);
  45.  
  46.  
  47. % Transform coordinates from frame 5 to frame 1
  48. g17 = Translation2D(2, 0) * Rotation2D(right_shoulder_angle) * Translation2D(1.5, 0) * Translation2D(1.5, 0) * Rotation2D(right_elbow_angle) * Translation2D(1.5, 0);
  49.  
  50. %% Scaling Transforms
  51. % Compute scaling transformations required to map the vertices of the unit
  52. % square returned by Box2D to the appropriate size box.
  53.  
  54. % Scaling for Box 1
  55. g1W = Scale2D (4, 2);
  56.  
  57. % Scaling for Box 2
  58. g2W = Scale2D (1, 1);
  59.  
  60. % Scaling for Box 3
  61. g3W = Scale2D (2, 2);
  62.  
  63. % Scaling for Box 4
  64. g4W = Scale2D (3, 1);
  65.  
  66. % Scaling for Box 5
  67. g5W = Scale2D (3, 1);
  68.  
  69. % Scaling for Box 6
  70. g6W = Scale2D (3, 1);
  71.  
  72. % Scaling for Box 7
  73. g7W = Scale2D (3, 1);
  74.  
  75. %% Draw the transformed boxes including the appropriate scale factors
  76.  
  77. % Clear the drawing
  78. cla;
  79.  
  80. DrawWireframe(ApplyTransform( g1W, Box2D())); % Draw box centered at frame 1
  81. DrawWireframe(ApplyTransform( inv(g12)*g2W, Box2D())); % Draw box centered at frame 2
  82. DrawWireframe(ApplyTransform( inv(g13)*g3W, Box2D())); % Draw box centered at frame 3
  83. DrawWireframe(ApplyTransform( inv(g14)*g4W, Box2D())); % Draw box centered at frame 4
  84. DrawWireframe(ApplyTransform( inv(g15)*g5W, Box2D())); % Draw box centered at frame 5
  85. DrawWireframe(ApplyTransform( inv(g16)*g6W, Box2D())); % Draw box centered at frame 6
  86. DrawWireframe(ApplyTransform( inv(g17)*g7W, Box2D())); % Draw box centered at frame 7
  87.  
  88. % These lines are here to smooth the animation
  89. pause (0.1);
  90. drawnow;
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement