Project

Simulation of forward kinematics of a 2R Robotic Arm

AIM: Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm

SOLUTION:

Coding:

%Initial Values
length1=1;
length2=0.5;

%Assigning theta values
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);

%Calculating
count=1;
for i=1:length(theta1)
    o1=theta1(i);
    for j=1:length(theta2)
        o2=theta2(j);

        %First coordinate
        x0=0;
        y0=0;

        %Second coordinate
        x1=length1*cosd(o1);
        y1=length1*sind(o1);

        %Third coordinate
        x2=x1+length2*cosd(o2);
        y2=y1+length2*sind(o2);

        %Plotting the above three coordinates
        plot([x0 x1],[y0 y1],[x1,x2],[y1,y2],'linewidth',3);
        axis([-1 1.5 0 1.5])
        pause(0.03)
        M(count)=getframe(gcf);
        count=count+1;
    end
    
end

%Creating Animation
movie(M)
videofile=VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

While running the above code I did not get any errors, it runs successfully.

Output:

Animation file:

Report:

* First we find out the length of two arms.

* Then find out the angles for both the arms(i.e Theta1 and Theta2).

* Initially x0=0 and y0=0, then calculate the x1,y1 and x2,y2.

* Finally plot the three coordinates.

* Repeat the above procedure for differnet values of Theta1 and Theta2 by using linspace command and for loop.

* Get every frame of plot and finally create a animation file as shown in the coding.

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.