Week 2- 2R Robotic Arm Challenge
Simulate forward kinematics of a 2R robotic arm
GIVEN PROBLEM:
Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video.
- Create an animation file of the plot.
SOLUTION :

2R robotic arm is a component consisting of two links as shown in the figure. for making the simulation we have to find out the mathematical formula.
MATHEMATICAL FORMULA
initial coordinates x0=0,y0=0, x1= l1*cosd(theta1),y1=l1*sind(theta1),
x2=x1+l2*cosd(theta2),y2=y1+l2*sind(theta2) .
CODE:
clear all
close all
clc
%inputs
l1=1;
l2=.5;
theta1=linspace(0,90,4);
theta2=linspace(0,90,4);
ct=1;
for i=1:length(theta1)
a=theta1(i);
for j=1:length(theta2)
b=theta2(j);
x0=0;
y0=0;
x1=l1*cosd(a);
y1=l1*sind(a);
x2=x1+l2*cosd(b);
y2=x1+l2*sind(b);
%ploting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis([-.1 1.5 0 1.5]);
pause(.3);
M(ct)=getframe(gcf);
ct=ct+1;
end
%creating the movie
movie(M)
videofile = VideoWriter('robotic_anim.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M);
close(videofile)
error occured at line 10 .modifying error with 'end ' comand
modified code
clear all
close all
clc
%inputs
l1=1;
l2=.5;
theta1=linspace(0,90,4);
theta2=linspace(0,90,4);
ct=1;
for i=1:length(theta1)
a=theta1(i);
for j=1:length(theta2)
b=theta2(j);
x0=0;
y0=0;
x1=l1*cosd(a);
y1=l1*sind(a);
x2=x1+l2*cosd(b);
y2=x1+l2*sind(b);
%ploting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis([-.1 1.5 0 1.5]);
pause(.3);
M(ct)=getframe(gcf);
ct=ct+1;
end
end
%creating the movie
movie(M)
videofile = VideoWriter('robotic_anim.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M);
close(videofile)
RESULT:
here is the link for final video animation
https://www.youtube.com/watch?v=t0tZLvIa9kA
conclusion
Thus the simulation is done by providing different angles and lengths of both the arms in coding in matlab.