Project

A program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.

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

GOVERNING EQUATION:

For link 1(arm1)

Start Point

`x=0`

`y=0`

End point:

`x1=l1xxcos(theta1)`

`y1=l1xxsin(theta1)`

For link 2 (arm2)

Start Point

`x1=l1xxcos(theta1)`

`y1=l1xxsin(theta1)`

End point

`x2=x1+(l2xxcos(theta2))`

`y2=y1+(l2xxsin(theta2))`

INTRODUCTION:

Kinematics the branch of mechanics concerned with the motion of objects without reference to the forces which cause the motion.

Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the end-effector from specified values for the joint parameters.

A robotics arm is mechanical arm usually programmable , with similar functions to human arm.The link such as manipulator are connected by joints allowing either by rotational motion or translational displacement. This link consider to form a kinematic chain. The terminus of kinematic chain of manipulator is called end effector.

OBJECTIVE:

1) Write the matlab program to simulate forward kinematics of a 2R Robotic Arm.

2) Write program with loop and Create the Animation File of Plot.

MATLAB CODE EXPLANATION:

Firstly before start your program, it is always good practice add comment '%' to mention title of program.its allow others to understand code and what is all about.

followed by clear all , close all , clc for clear all the variable in workspaces , closed all the background graphs, plots and clear all present in command window respectively.

then we should start with input to program (you can use "%input" for input condition) by giving initial condition and put ";" (semicolon) to terminate output shown in command window. (as shown in fig 2). then think about what process apply to get output in our case we provide the necessary boundary condition and formed above equation.

write the program for first arm condition and execute it. if run fails try to find error.

then write the next condition and execute it. its make good habit by step by step execution.This leads to avoid mistake

then plot the graph with necessary title, labels , axis condition.

1) A Program on Forward kinematics of 2R Robotics arm manipulator

In this Program we manually changing value of "theta 1" and "theta2". we get only one graph

% A Program on Forward kinematics of 2R Robotics arm manipulator
clear all
close all
clc

%input condition 

l1 = 1;                  %length of arm link 1
l2 = 0.5;                %length of arm link 2

theta1 = 45;             %angle made by link1 with horizontal 
theta2 = 25;             %angle made by link2 with horizontal

%coordinates of the link

x0 = 0;                  %starting points of link 1
y0 = 0;

x1 = l1*cosd(theta1);     %starting points of link 2
y1 = l1*sind(theta1);

x2 = x1 + l2*cosd(theta2);    %ending points of link 1
y2 = y1 + l2*sind(theta2);

%plotting the link to show position

line([x0 x1],[y0 y1],'linewidth',3,'color','b')
line([x1 x2],[y1 y2],'linewidth',3,'color','r')
axis([0 1.4 0 1])

output of First program

2) Write the Program using For Loop

In this Program we use For loop to create motion of arm.

Basically For loop is control flow statement specifying iteration , which allow code to be executed repeatedly. Now by using this logic we execute "theta" value for 10 iteration

that sound good, for that firstly we use linspace for theta1 and theta 2 to create an array of 10 random degree's values.

(a) "ct" - represent each and everyframe for create plotting animation.

(b) in first for loop we use "i" for create 10 value of theta 1 stored in variable THETA1.

in Second loop we use "j" for repeating theta 2 values with respect to link 1 , i.e 10*10 =100

then Copy or repeat the first program by changing the variable that we assigned in i and j value.

(c) plot(x,y) graph using plot() command or we use "hold on" command to use two plot function combined and execute

(d) pause command is use to pause the program between iteration to be done and execute program.for this it take n seconds and then continues.

(e) getframe (gcf) is use to capture entire in figure window to capture figure.

(f) movie() command use to create and animation.

ERROR: In my Program I faced an error that 'VideoWriter' function is undefined function. i check ones twice , trice but i couldn't find error in code. I go to internet check why is it so , it because of my license issue with MATHLAB r2010a. so it will enable to create video outside.

Overcome:

To overcome this error i found another command in help browser that "movie2avi()".

In this way I overcome error and export the video in avi format. with following code

%A program of making an animation of 2R robotic arm
clear all
close all
clc

%input
l1 = 1;                             %length of arm link 1
l2 = 0.5;                           %length of arm link 2
theta1 = linspace(0,90,10);         %different Angle array of arm link 1
theta2 = linspace(0,90,10);         %different Angle array of arm link 2

ct=1;                               %every frame counter 
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 1.5 0 1.5])
pause(0.03)
M(ct) = getframe(gcf);             %capture the figure from figure window
ct=ct+1;
    end
end
movie(M)                              %movie of all frame 
%videofile = VideoWriter('forward_kinematics.avi');
%open(videofile)
%writeVideo(M,videofile);
%close(videofile)
movie2avi(M,'Forward_kinematics');     % export movie to avi outside matlab

output of Program

You tube link for outcome

https://youtu.be/W_vZ3_bK1Vs

CONCLUSION: At end of Program we successfully learned of for loop , stored the video and Simulate Arm of manipulator using MATLAB.

thankyou!

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.