Project

Program to simulate the forward kinematics of a 2R Robotic Arm using MATLAB

close all
clear all
clc

%inputs
l1=2;
l2=1.5;

theta1=linspace(0,90,10);
theta2=linspace(0,90,10);

%generation of multiple values of theta2 for each value of theta1 automatically 
ct=1;
for i=1:length(theta1)
    THETA1=theta1(i)
    for j=1:length(theta2)
        THETA2=theta2(j)
        
        x0=0;
        y0=0;
        
        x1=l1*cosd(THETA1);
        y1=l1*sind(THETA1);
        
        x2=x1+l2*cosd(THETA2);
        y2=y1+l2*sind(THETA2);
        
        %plotting
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-0.1 4 0 4])
        pause(0.05)
        M(ct)=getframe(gcf);
        ct=ct+1;
       
        
        
    end
        
        
        
end
movie(M)
videofile=VideoWriter('forward_kinematics_of_robotic_arm.avi','uncompressed avi')
open(videofile)
writeVideo(videofile,M)
close(videofile)

AIM:

The aim of the project is to write a program to simulate the forward kinematics of a 2R robotic arm manipulator automatically in space to finish the desired job.

INPUTS:

STEP 1:

The inputs mandatory for the 2R robotis arm manipulator in the editor window are the length of each links

Here, we are considering the length of link1 as 2m and the length of link2 as 1.5m and providing the theta value for link1 and link2 as 'theta1' and 'theta2' using linspace command.

STEP 2:

After completion of step 1 our next step is to provide the value for coordinates

To provide the value for coordinates we are using the 'for' loop command so that the value of THETA1 and THETA2 for each value of theta1(i) and theta2(j)gets generated through which the value for (x0,y0),(x1,y1),(x2,y2) coordinates get assigned as per our formula for each coordinates

STEP 3:

After completion of step 2 our next step is to plot these coordinates

For plotting the coordinates we are using the 'plot' command then we are using the 'axis' command so that the entire animation of the plot gets clearly visible and then we are using the 'pause' command for smoother transition of links

Then we are using a command

M(ct)=getframe(gcf);

Here, M,represents movie

ct,represents frame

The whole meaning of the above command is to 'capture each and every frame as a movie'

Then we are using a command 'ct=ct+1',which means that each and every frame gets incremented by +1

STEP 4:

After completion of step 3 our next step is to create and save an animation or a movie file of the above mechanism

ERRORS FACED WHILE PROGRAMMING:

1.forgotten to use end command while using for loop

2.Use of semicolon made my command not being executed in command window

3.Forget to use uppercase letter while using command VideoWriter and writeVideo

STEPS TAKEN TO OVERCOME THESE ERRORS:

1.The errors are cleared by looking at the red coloured hints popped in the command window

and by recaping the instructions provided by the instructor during the course

OUTPUT:

The animated video link

https://youtu.be/_p4bJS7vtBw

CONCLUSION:

Thus, the program to simulate the forward kinematics of a 2R Robotic Arm manipulator automatically in space to finish the desired job is coded in MATLAB and the corresponding results are displayed as images and a video link above.

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.