Week 2- 2R Robotic Arm Challenge
In this challenge we have to create a video for forward kinematics of 2R robotic arm
first of all i have given the inputs such as length of both the arm as l1 and l2.
Then i have given the angle of both the arm ranging from 0 to 180 and divided them into 20 parts so i will get 20 diffrent angle of arm 2 on one single angle of arm 1 and from that we will get 400 result from that.
To creat this we have to make a loop so that the process go on repeating for each angle of arm 1 to the angle of arm 2 and to do so here we are using For loop for that
Loop one for arm and and loop 2 for arm 2. We will plot our coordinates in loop 2 and then close our loop by End command
In this we are creating a frame of each angle of arm 2 to each angle of arm 1 and at the end we are combining all the frame to get a single figure and in that we can get motion of both the arm at diffrent angle.
And at the last we have used the code to create a video of this so that we can easily understand the motion of the robotic arm.
link for the video... https://drive.google.com/file/d/1rozT2oSBrYoNfpVTEgJgXYaEWIWTtCbA/view?usp=sharing
%forward kinematics of 2R robotic arm
clear all
close all
clc
%inputs
% length of arm 1
l1 = 1.5;
% length of arm 2
l2 = 1;
%angle made by arm 1
theta1 = linspace(0,180,20);
%angle made by arm 2
theta2 = linspace(0,180,20);
ct = 1;
%first for loop for arm 1
for i= 1: length(theta1)
THETA1 = theta1(i);
%Now we have to apply another loop for arm 2
for j = 1 : length(theta2)
THETA2 = theta2(j);
%now here we will plot the graph
%given coordinates
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([-2.5 2.5 0 2.5])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
%creating a video
movie(M)
videofile = VideoWriter('Two_R_robotic_arm.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M)
close(videofile);