Week 2- 2R Robotic Arm Challenge
%ANIMATION OF KINEMATICS OF DOUBLE LINK ROBOTIC ARM
clear all
close all
clc
%inputs
l1=1;
l2=0.5;
theta1=linspace(0,90,40);
theta2=linspace(0,90,40);
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);
%plots
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([0.1 1.5 0 1.5])
pause(0.00000000000000000001)
m(ct)=getframe(gcf);
ct=ct+1;
end
end
movie(m)
video=VideoWriter('animate_robot.avi','Uncompressed.avi');
open(videofile);
writeVideo(videofile,m);
close(videofile);
EXPLANATION
- first i cleared all previous inputs in the program
- then start to provide the necessary inputs such as the length of the links(l1,l2) and the angle they make (theta1 ,theta2).
- for the values of theta1&theta2 i made an array matrix of 1 row and 10 columns ranging from 0-90deg.
- then i given the count value of ct=1
- then i begin typeing a forloop command. for i=1:the length of theta1 which is 10.
- then i do the same for uppercase THETA1=theta1(i).
- then i created a forloop command j=1:the length of theta2 which is 10.
- then the value of uppercase THETA2=theta2(j)
- then i give the secondary inputs such. as, the coordinates of the various points((x0,y0),(x1,y1),(x2,y2)) with their corresponding formulae as shown in the program.
- then using the plot command i started the plotting operation fot the coordinates.
- to play it as a movie i provide the ct and getframe commands.
- ct=ct+1
- i ended the two forloop commands and moved forward to creating the video or movie of the animation.
- first i input the movie(m) command followed by the videowriter command.
- the video file name and profile are given.
- then the writevideo command is used to provide the directory.
- then closed the video file.
ERRORS NOTICED.
- several errors due to improper command execution.
- the video animation overlapping on the previous position of the robotic arm while displaying.
the graph showing from 0-1.5 the right side quadrant is not visible. then altered the axis code to get the result in my favor of displaying the whole graphn by changing the input to 0.1-1.5 in the plot.
google drive link of the output video.
https://drive.google.com/file/d/1iMFaztI1Ji_4dlNVc6EPK3o5mthbnM9Z/view?usp=sharing