Week 3.2 - 2R Robotic Arm Challenge
Aim:
Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm
step wise explanation:
1)Input declaration
l1=1;
l2=0.5;
t1=linspace(0,90,10);
t2=linspace(0,90,10);
ct=1
Linspace function returns a array consisting of 10 elements with values between 0 and 90 interms of angles in degrees.
2)The angles for link1 is varied through "for loop" form 0 to 90
3)The angles for Link2 is varied through "for loop" from 0 to 90
4)with help of plot function-graphs are drawn for the steps 2,3.
5)The speed of simulation is controlled with variable - no of angle values and pause() function as per user inputs
6)Finally all the simulations are captured in a avi -movie file
7)The avi file is played back with suitable mediaplayer.
program code:
clear all
close all
clc
%inputs
l1=1;
l2=0.5;
t1=linspace(0,90,10);
t2=linspace(0,90,10);
ct=1;
for i=1:length(t1)
T1=t1(i);
for j=1:length(t1)
T2=t2(j);
x0=0;
y0=0;
x1=l1*cosd(T1);
y1=l1*sind(T1);
x2=x1+l2*cosd(T2);
y2=y1+l2*sind(T2);
%plotting
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.1)
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)
The AVI animation file is attached in compressed Zip file format.