Simulation of forward kinematics of 2R Robotic arm using Matlab
AIM:
To simulate the forward kinematics of a 2R Robotic Arm using matlab.
OBJECTIVE:
To write a program to simulate the forward kinematics of 2R robotic arm and to create a video file using the program.
THEORY:
Forward kinematics is 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 robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot.In this project, the robotic arm consists of two links. The two links may be translational or rotational. These type of robotic arms are widely used in industries such as automobile etc.
(image from google)
`INPUT DATA:
l1=length of link 1
l2=length of link 2
theta1=angle made by link 1 w.r.t x-axis
theta2=angle made by link 2 w.r.t x-axis
(x0, y0) = starting point of link 1
(x1, y1) = ending point of link 1 or starting point of link 2
(x2, y2) = ending point of link 2
PROGRAM EXPLANATION:
1)Initially length of l1 and l2 are given as 1m and 0.5m respectively.
2)theta1 and theta2 are assigned in an array with linspace command from 0 to 90 which are seperated by 10 parts.
3)Counter is set to 1 which increases by 1 for every iteration.
4)Two for loops are used for iteration of robotic arm position. The first for loop is for link 1 and the second for loop is for link 2.
5)Now the position of link 1 and 2 are plotted in the graph.
6)All figures are assigned to a variable M, one at a time using ct(counter) followed by termination of for loop.
7)Lastly, movie command is used to combine all the figures saved in the M file to make an animation/movie and thereafter saving it in .avi format.
PROGRAM:
%Forward kinematics of 2R Robotic arm
clear all
close all
clc
%length-m
l1=1;
l2=0.5;
%angle-deg
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
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,'color','r')
axis([0 1.5 0 1.5])
pause(0.03)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile=Videowriter('robotic_arm.avi','uncompressed AVI');
open(videofile)
wiriteVideo(videofile,M)
close(videofile)
I have attached the link of the animation of robotic arm. Since i am using matlab online i have screen recorded and uploaded on youtube.
https://www.youtube.com/watch?v=9rw-tDr1IRI&feature=youtu.be
RESULT:
Thus simulation of 2R robotic arm using matlab has been executed successfully.