Challenge

Week 2- 2R Robotic Arm Challenge

clear all 
close all
clc
%Inputs
l1=4;                       %Length of link 1 in metres
l2=3;                       %Length of Link 2 in metres
theta1=linspace(0,90,10);   %The values of angles theta1n2 lie from 0 to 90 degrees
theta2=linspace(0,90,10);
c=1                         %c is the counter variable here
for i=1:length(theta1);     %Initialising for loop
    THE1=theta1(i);
    for j=1:length(theta2); %Using a nested for loop to change values of arm2
        THE2=theta2(j);
        %Calculating x and y coordinates of the link arms
        x0=0;
        y0=0;
        x1=l1*cosd(THE1);   %Calculation of x n y coordinates
        y1=l1*sind(THE1);   %of the link 1

       x2=x1+l2*cosd(THE2); %Calculating x and y coordinates
   
       y2=y1+l2*sind(THE2); %of the link 2

       %Plotting
       plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',2);  %Ploting both the link graph at a time
       grid on
       axis([-0.1 8 -0.1 8]); %Sets max and min values for axes
       pause (0.1)            %Pausing the computation for a time 0.1sec
       m(c)=getframe(gcf)     %Frame capturing done for the plotted figures
       c=c+1;                 %counter variable incremented
    end
end
%Creating the animation for the movement of the 2R robotic arm in X-Y plane
movie(m)
videofile=VideoWriter('Forward Kinematics of a 2r robotic arm.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,m);
close(videofile);

Explanation:- In this challenge we had to write a program in matlab in order to simulate the kinematics of a 2R Robotic Arm.As mentioned a 2R robotic arm consists of a combination of 2 links (the arms ) and 2 rotary joints. And the two arms making an angle of theta 1 and theta 2 with the x axis.

So in order to determine the position of the links in an X-Y plane we formulated an equation that gave the values of the x-y co-ordinates for both the links 1 2 using x1=L1cos(theta1) and y1=L1sin(theta1) where L1 and L2 are the lengths of link 1 and 2

Similarly for x2=x1+L2cos(theta2) and y2=y1+L2sin(theta2) for which we needed values of theta 1 and theta 2 which we odtained using the linscape function that gave us different values of theta from 0-90 degrees.

Now after computing all the x-y coordinates we neede to obtained the plot that depicted the movement of the arms in the x-y plane for which we used the plot funtion in which we gave all the values of X-Y coordinates in a set of arrays containing the values of x-y.

Here we also used a nested for loop in order to iterate the process of computing the vaues of the coordinates and to plot the that depicted a range of values of theta2(the range of motion of the second arm) for a single value of theta1(the range of motion of arm 1)

As the graphical representation involved a no.of graph at different values of theta we combined all the plots into an animation video in order for a better understanding of the motion of the robotic arm.For which we used the getframe(gcf) function that caputerd the current frame or plot and combined all the plots into a avi(video) file using the videowriter() funtion for which the counter variable was very useful. The video link for the animation is attached herewith.Video file

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.