Week 2- 2R Robotic Arm Challenge
AIM
Program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
OBJECTIVE
- To simulate the forward kinematics of a 2R Robotic Arm.
- Animating and creating a movie from the plots obtained.
THEORY
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 such a manipulator are connected by joints allowing either rotational motion or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain.
GOVERNING EQUATIONS
x2 = x0 + x1 + l2*cosϴ
y2 = y0 + y1 + l2*sinϴ
x1 = x0 + l1* cosϴ
y1 = y0 + l1* sinϴ
Where,
x0, y0 = starting point of link 1
x1, y1 = ending point of link 1 / starting point of link 2
x2, y2 = ending point of link 2
l1 = length of link 1
l2 = lenth of link 2
PROGRAM
% Program for a 2R robotic arm
clear all
close all
clc
% Inputs
% Length of link 1
l1 = 1.5;
% Length of link 2
l2 = 0.75;
ct = 1;
% Set of angles for the movement of robotic arm
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
for i = 1 : length(theta1) % iterating i from 1 to 20 as theta1 is having 20 values
THETA1 = theta1(i);
for j = 1 : length(theta2) % iterating j from 1 to 20 as theta2 is having 20 values
THETA2 = theta2(j);
% Coordinates of starting point of first arm
x0 = 0;
y0 = 0;
% Coordinates of starting point of second arm
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
% Coordinates of ending point of second arm
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
% Plotting
% coordinates of arms
plot( [x0 x1], [y0 y1],[x1 x2],[y1 y2],'linewidth',5,'marker','*')
% Limits for x and y axis in the graph
axis ([-0.5 3 0 3])
title('Forward Kinematics of a 2R Robotic Arm')
% Collecting frames for making animation
M(ct) = getframe(gcf);
ct = ct + 1;
end
end
% To make a movie of collected frames
movie(M)
% saving the file in avi format
videofile = VideoWriter('robotic_arm.avi','Uncompressed AVI');
% Writing the movie in videofile created
open(videofile)
writeVideo(videofile,M)
close(videofile)EXPLANATION
- Initially we assign the length of two links, namely l1 and l2.
- Set of values for theta1 and theta2 are assigned as an array with the command linspace.
- for command is used for the iteration of values for the desired variable. Again, for command is used for the movement of second robotic arm. Thus, for a particular position of link 1, we can obtain different positions of link 2.
- Coordinates of both the arms are defined.
- Coordinate values are plotted and commands are provided as changing the appearance of the contours.
- All figures are assigned to a variable M, one at a time using ct followed by termination of for loop.
- movie command is used to combine all figures saved in the M file to make an animation and there after saving it in avi format.
ANIMATION
The link for the animation has been mentioned.
CONCLUSION
A practical scenario regarding the functioning of robotic arm and its workspace has been experienced with a program in MATLAB.