2R Robotic Arm
AIM:
To 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.
PROCEDURE:
The program for executing the task is given below.
close all
clear all
clc
%length of link 1
l1=1;
%length of link 2
l2=0.5;
%Anle link 1 makes with x axis
theta1=linspace(0,90,20);
%Anle link 2 makes with x axis
theta2=linspace(0,90,20);
%counter
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);
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.5 2 0 2])
pause(0.01)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
movie(M);
videofile=VideoWriter('Kinematiclinkage.aci','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation:
The inputs are defined and values are assigneds first.
20 values of Theta are stored in the array usinglinspace command.
The for loop from line 16 to 29 executes the task by incrementing the theta 2 value for every iteration and causes the line to change endpoint of the second lnk to change for all the 20 values of theta2 .
The plot is refined by adding axis to it.
A pause of 0.01 is provide to visualize the transformation.
The getframe command is used stich all the individual plots to a animation movie.
The conter is incremented to access the subsequent plot in the following iterations.
The for loop in line 14 does the same by incrementing the value of theta 2.
The following commands are used to create a video file.
"videofile=VideoWriter('Kinematiclinkage.aci','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)"
Errors faced wile programming
syntax issues due to case sensitive commands.
The command was typed in proper case to rectify it.
Video:
Youtube link :
https://youtu.be/oXyau9zmdDo