Week 2- 2R Robotic Arm Challenge
AIM:To simulate the forward kinematics of a 2R Robotic Arm using MATLAB.
OBJECTIVE:
1.To write a program for a 2R robotic arm.
2.To plot the animation of the end-effector position according to forward kinematics.
Theory:
Robotic Arm:
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.The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand. However, the term "robotic hand" as a synonym of the robotic arm is often proscribed.
Forward Kinematics: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 parameteres.
Applications:
The robotic arm are used in various applications such as
1-Welding
2-Painting
3-Automotive Robot Solution
4-Food,Beverge,Sanitation
5-Package Industry
6-MateriaL Handling
7-Thermal Spraying
Schematic Diagram:

Solution:
PROCEDURE/STEPS:
1.Assign suitable variables to store the length & angle for the links.
2.Create a loop for generation of frames & declare a variable named counter(ct) to start with.
3.The first loop (i) will be ranging from 1 to the maximum value of theta1 whereas the second one (j) will be ranging from 1 to the maximum value of theta2.
4.For one count of loop i, loop j would finish complete rotation & compute the values as shown in the code.
5.The images are plotted with the help of plot function.
6.Finally,the counter will increment by 1(ct+1) until loop i is finished and step #4 & #5 are repeated.
7.Get frame () captures the indivisual frame & stores it in an array M.
8.To create an animation of all the frames generated,
a.assign the frame movie in array M.
b.assign appropriate file name & extension in videofile().
C.Open () begins to extract the files.
d.writeVideo writes data from an array to the video file.
e.Close() terminates the operatin.
MATLAB CODE:
clear all
close all
clc
% inputs
l1=1;
l2=0.5;
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)
axis([-0.1 1.5 0 1.5])
pause(0.3)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
movie(M)
videofile = VideoWriter('forward_kinematics.AVI','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation:
theta1 & theta2 array are initialized. A variable for frame counting 'ct'is initialized the value 1.Two for loops are defined for conrolling values of theta1 & theta2 arrays are stored in variables THETA1 & THETA2 for each itteration for the loops.
The position of the end points for each of te links are calculated using the equations given below:-
Link 1 :
Start point x0=0,y0=0
End points x1=x0+l1costheta1
y1=y0+l1sintheta1
Link 2 :
End point x2=x1+l2costheta2
y2=y1+l2sintheta2
The graph is plotted using command. The 'getframe(gcf)' command is used inside the second loop(contolling second link position) to get the current frame and store it as an image into the array 'M'.
The videowriter command creates an empty video file by the name 'forward kinematics' in .AVI format and it is stored in the variable videofile.
The writevideo commands insert the frames stored in the array 'M' into the video file.
RESULTS:
The video file was made and published. The link to the video is given below.
https://drive.google.com/file/d/1SwmCWi1m4RfnxOR98VoR7MPdff6FT_2p/view?usp=sharing