Challenge

Week 2- 2R Robotic Arm Challenge

Aim:Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video

Objective:

  • writing the code for farward kinamatics of 2R arm
  • Upload an animation on You tube and provide the You tube link for an animation in your report

Inputs: (xo,yo) = this is the initial coordinates

(x1,y1) =middle coordinate

(x2,x2) =last coordinate

L1 = length of the 1st arm

L2 = lenght of the 2nd arm

theta1 = angle at 1st link

theta2 = angle at 2nd link

Code for robertic arm kinamatic:

% program to stimutlate the 2r robertic arm in matlab
 close all
 clear all
 clc
  
 % difining inputs 
  l1 = 1;       % this is lenght of 1st arm
  l2 = 0.5;       % this the lengt 2nd arm
  theta1 = linspace(0,90,10);     % here i am defining the range for theta1
  theta2 = linspace(0,90,10);      % here i am defining the thetha2

  % now we are defining for loop for creating the animation of robertic arm

  ct = 1; % hera i am taking comand called ct which is used to plot our figure  
  for i =1:length(theta1)
       THETA1 = theta1(i);
       for j = 1:length(theta2)
           THETA2 = theta2(j);
       

       % defining the inital  axis

        x0 = 0;   
        y0 = 0; 
% hera we have taken intial axis (0,0) becouse at intial our axis are zero

 % defining 2nd axis 

 x1 = l1*cosd(THETA1);  
 y1 = l2*sind(THETA1);
   % here we are taking wnd axis at link 2 of the robertic arm 
    
   % defining 3rd axis(manuplater)
    
   x2 = x1+l1*cosd(THETA2);
   y2 = x2+l2*sind(THETA2);

   % ploting the figure using above data

   plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',4); % i am taking linwidth comnd to define my line width 
   axis([-1 2 0 1]); % i am taking my axis range 
   pause(0.03); % pause comand is used foe controling the time of the figure 
   M(ct) = getframe(gcf);% hera i am storeing my all the frame which i have got in figure in array called 'm'
   ct = ct+1;
       end
  end
movie(M) % here we are creating the movie of obtained robertic arm
videofile = VideoWriter('animation of robertic arm.Avi ','Uncompressed AVI'); %here we are creating the vedio file for our robertic arm animation  
open(videofile)  % here we are opening our vediom file 
writeVideo(videofile,M)
close(videofile) % after opening the vedio file we have to close it by using fallowing lines 

Explanetion:

  • first we have to start the program by writting the clear all close all,clc
  • after that we have to defione the lenght of the both arms
  • then we have to define the equations for both the arm
  • then after that we have to create a for loop to evaluate every value which we have defined
  • after that we have to store all the value of our output in the 'M'
  • then we have to create the animation vedio of 'M' by using movie command

Animation vedio link: https://youtu.be/Bqs9ljP9DNE

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.