Week 2- 2R Robotic Arm Challenge
AIM :- To write a program of Forward kinematics of a 2R Robotic Arm by using matlab.
OBJECTIVE:-
i. write a program of forward kinematics of a 2R robotic arm.
ii. Animating and creating the moviefrom the plots obtained from the program.
INPUTS :-
(x0, y0) = Starting point of link1
(x1, y1) = End point of link1 / Starting point of link2
(x2, y2) = End point of link2
l1 = length of link attached to the base
l2 = length of link between end point of l1 and end point of end effector
theta1 = angle made by link1 with x-axis
theta2 = angle made by link2 with y-axis
CODE :-
% Forward kinematic of a 2R robotic arm manipulator
clear all
close all
clc
% Inputs
% Length of robotic arms
l1 = 1;
l2 = 0.5;
% angles for the movement of robotic arm
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);
% Coordinates of start point first of arm
x0 = 0;
y0 = 0;
% Coordinates of end point of first arm/Start point of second arm
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
% Coordinates of end point of second arm
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
% Plotting
% Coordinates of arms assigned over a set of theta1 and theta2
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
% The limits of x-axis and y-axis
axis([-0.1 1.5 0 1.5]);
% To create an animation
pause(0.03)
% Collecting frames of figure to create a movie/animation
M(ct) = getframe(gcf);
ct=ct+1;
end
end
% To make a movie collected frames
movie(M)
% Saving the movies in '.avi' format
videofile = VideoWriter('robotic_arm.avi','Uncompressed AVI');
open(videofile)
% Write the movie in the videofile created
writeVideo(videofile,M)
close(videofile)
PROGRAM EXPLANATION :-
i. To start the program clear and close all the previous programs use commands.
ii. So define the lengths of robotic arms i.e l1 and l2.
iii. Set the values for theta1 and theta2 in an array to create an animation use linspace command.
iv. Then use of for command for iterating the values of the desired values.
v. Again use for command to provide the movementum for second arm.
vi. After that define the coordinates of both the robotic arms.
v. Plotting all the coordinate values and writting commands for changing the appearances of the contours.
vi. To assign all the figures to a variable M,one at a time using ct followed by termination of for loop.
vii. Use movie command , to combine all the figures saved in the M file to make an animation/movie and saving in format of .avi format.
ANIMATION LINK :-
https://youtu.be/pVqdUimK3O0
CONCLUSION :-
A practical scenario has done regarding the functioning of the robotic arm and its workspace has been expeirienced by simulating the forward kinematics with a program in MATLAB.