Week 3.2 - 2R Robotic Arm Challenge
Aim: To write a program in MATLAB for calculating and plotting the motion of a 2R robotic arm. Also, create an animation for the series of plots generated from the program.
Introduction:
The construct of a 2R robotic arm is very similar to human arms. It consists of two links and two revolute joints with each link having a single degree of freedom limiting its work envelope in 2-Dimension.
While designing a robotic arm it is necessary to determine the kinematics of the robotic arm. Forward kinematics is one such approach which involves finding the coordinates of the end effector with the help of given joint parameters.
In the case of the 2R robotic arm, the lengths of two links (l1 and l2) and the angle of the revolute joint (theta1 and theta2) will be joint parameters.
In this project, link lengths will remain constant, whereas the angle of the revolute joints is restricted to 0 degrees to 90 degrees. The MATLAB program will involve the determination of the positions of the end effector for the variation of revolute joint angles. Using those data, we will create an animation of the motion of the 2R robotic arm.
Main Program:
% Creating animation for Forward Kinematic of 2R Robotic Arm
% Here in the following program, we will write a code to animate the motion
% of the robotic arm changing with respect ot the chnage the link angle
clear all
close all
clc
%% Inputs
% Length of the first link in m
l1= 1;
%Length of the second link in m
l2=0.75;
% Angle between first link and horizontal changing from 1 to 90 degree with
% 5 degree interval
theta1 = 1:5:90;
% Angle between second link and horizontal changing from 1 to 90 degree
% with 2 degree interval
theta2= 1:2:90;
%% Calculating coordinate for End Manipulator and Plotting
% Nested for loop to calculate and creating plot of 2R robotic arm
for i = 1: length(theta1)
THETA1 = theta1(i);
for j = 1: length(theta2)
THETA2 = theta2(j);
%Starting coordinate of first link
x0 = 0; y0 = 0;
%End coordinate of first link
x1 = l1*cosd(THETA1); y1 = l1*sind(THETA1);
% End coordinate for first link acts as starting coordinate for second link
%End coordinate for second link
x2 = x1 + l2*cosd(THETA2); y2 = y1 + l2*sind(THETA2);
%% Plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],LineWidth=5)
axis([0 2 -0 2])
grid on
pause(0.05);
M(j)=getframe(gcf);
end
end
% Creating animation movie from the plot images
movie(M)
videofile = VideoWriter('Forward_Kinematic.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close
Output:
No output in the command terminal
Animation for the motion of 2R Robotic Arm
Conclusion:
The above program used for the simulation of the 2R robotic arm helps in visualizing the work envelope of the 2R robotic arm.