Week 2- 2R Robotic Arm Challenge
Hello
In this programm I have learn about the robotic arm.
Program start with clear all ,close all, clc,
For the robotic arm the two length is given which name is l1 and l2 so l1 and l2 id define first.
After that for the arm is move so theta is provide so using the 'linspace' command theta1 and theta2 is define. Linespace command is used because theta is vary 0 to 90 degree.
after that for loop is used because the for loop is store the value so that loop is store the theta1 value in the 'i' and theta2 value in the 'j'.
all Coordinate define in the for loop.
first define the x0 and y0 is 0 because the arm movment with 0.
After that x1 and y1 coordinate is given using the formulas l1*cosd(theta1) and l1*sind(theta1) respectively.
After that again x2 and y2 coordinate is given using the formulas x1+l2*cosd(theta2) and y2+l2*sind(theta2).
All coordinate is given so using the plot command the plot is make.
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2].'linewidth',3)
using the above command the plot is make but plot is not make the animated the single graph is make but i have required the animated plot so I have used the ct(count) commad this command work is to count the fram. after that i have used the pause(-0.03) command also this command work is to stop the animated after the 0.03 time so the animated is so very smoothly very effective way.
After that i will give the axis[-0.1 1.5 0 1.5]
so in the [-0.1 1.5] is the x axis and [0 1.5] is the y axis.
The program is complete so this animated is save in the animated movie so i have use the getframe command because this command is count the frame so make the movie is smoothly.
after the for loop end I have using the movie(M) command for making the movie.
using the Videowrite i have given the video file name in this program i have give the video file name is robotic_arm .avi
after this command open the videofile
video file is write with the M the video file is write then using the close command the video file is close.
So my program is complete and run the program then graph is plot with animation and video is also save.
In this program output is attached in the video.
Youtube like :- https://youtu.be/TpeVyaIa3Y0
Google Drive link :- https://drive.google.com/file/d/1DPz3ikbDDN7PloxkxsFqUXoQ9yqTLkC0/view?usp=sharing
In this program i have make some error and mistake.
1 Error :-
I have using the for loop so in the for loop i = 1:length(theta1) after that THETA1 = theta1(i)
but i have used in the second line THETA1 = theta(i)
then i have run the program so error is show again i have watch the video so i have rigth the my error and program is run.
but i have do not used the theta1 in thr second line (THETA1 = i) then the program is run but i have issued is that arm is not move up to 90 degree. Arm start with 0 but the program is stop upto 30 to 40 degree only. so this also my error.
I have attached this error image also.
2 Error :-
In the 2 error videowriter command i have used the video v is small so the error is show but i have used the v is capitical then the error is remove and the program is run.
I have attached screen shot also for this error.
Program:-
clear all
close all
clc
l1 = 1;
l2 = 0.5;
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);
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('robotic_arm.avi','uncompressed AVI');
open(Videofile);
writeVideo(Videofile,M);
close(Videofile);