Week 2- 2R Robotic Arm Challenge
% 2R Robotic Arm
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.03)
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)
FORWARD KINEMATICS OF ROBOTIC ARM EXPLANATION
There are two arms named link 1 and link 2.The link 1 substends theta 1 as its angle and link 2 substends theta 2 as its angle
we shall start the program with
clear all
close all
clc
the length of the link 1 and link 2 will be given as the input as 1 and 0.5
then we shall designate theta 1 and theta2 with a command using linspace such that it will divide the angles into 90 equal parts of 0 to 10 and also will represent the position of the links with respect to the change of theta1 and theta2.
we shall start a for loop giving i and j as the size o f 10 for theta1 and 2 and noe introduce THETA1 AND THETA2 for looping the theta1 and 2 with respect the coordinates of x0,x1,x2,y0,y1,y2
starting from the x0,y0 with (0,0)
formulating
x1=l1*cosd(THETA1)
y1=l1*sind(THETA1)
x2=x1+l2*cosd(THETA2)
y2=y1+l2*sind(THETA2)
Now we are ready to plot a robotic arm
with command plot starting from x0 to y2 with matrix multiplication and giving the linewidth as 3 and starting the axis with -0.1 to 1.5
pause w
the video with a speed of 0.03
for movie introduce the coutour at the beggining of the for loop and giving the command as
M(ct)=getframe(gcf)
ct=ct+1
end the loop
end
for movie
use movie(M) connecting the given command before for movie in the for loop
give the videofile a name such as forward kinematics.avi
open the videofile
using writevideo
then close the video
save the video and play it in any movie player
link for youtube video:https://youtu.be/cjPQR2E5Ywk