Week 2- 2R Robotic Arm Challenge
AIM: To Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video.
OBJECTIVE: To write a program to simulate the forward kinematics of 2R robotic arm and to show output as animated video.
PROGRAMME:
clear all
close all
clc
%inputs
L1=1;
L2=2;
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('robotic2RARM.m','Uncompressed AVI');
open(videofile)
writeVideo(videofile,m)
close(videofile)
EXPLANATION:
1. clear all is used to delete all the work space variables.
2. close all used to close all the plot windows.
3. clc is used to clear the command window.
4. Inputs such as link 1 i.e L1 = 1, link 2 i.e L2=2 are given.
5. inputs for theta1 and theta2 are taken by linspace command.
6. for loop is used for execution of the programme.
7. Here i is taken from 1 to length of theta1.
8.THETA1=theta(i) is taken.
9.THETA2= theta2(j) where j varies from 1 to length of theta2.
10.coordinates of link 1 are taken as x0,y0 and x1,y1 where x0=0,y0=0,x1=L1*cos(theta1),y1=L1*sin(theta1).
11.coordinates of link 2 are taken as x1,y1 and x2,y2 where x2=x1+L2*cos(theta2),y2=Y1+L2*sin(theta2).
12.plot is drawn and animation of the output is created by videofile.
OUTPUT:
https://drive.google.com/file/d/1_BwwG5CotR_vNwvB3uADl85qZgg1_H2Q/view?usp=sharing