2R Robotic Arm Simulation
Link for the Animated Video - https://youtu.be/rnpldxuLbmU
Step 1 : Position of Link 1
1 ) Giving the various angles for 2 arms by which the one arm is moved with respect to the another arm. So we use linspace command to split the regular intervals between 0 and 90 degrees.
Step 2 : Position of Link 2 (Final position of the manipulator)
2) We use for loop to make the number of combinations as the single position of Arm 1 is rotated in 10 different angles. Hence the 10 position of Arm 1 will have subsequently 100
different position.
3) For generating the animated movie we are using getframe command initially and after that for the video file we are opening and closing the video with commands.
4 ) Using WriteVideo function we are creating the animated movie.
Errors Faced:
Error 1 : Count(ct) is not declared and initialized
Error 2 : For THETA 2 also I had given loop variable as i instead of j .So the plot does not show the different angles
close all
clear all
clc
l1 =1;
l2=0.5;
theta1 =linspace(0,90,15);
theta2 =linspace(0,90,15)
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);
%figure(ct)
%hold on
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)
video_file = VideoWriter('2R_robot_arm.avi','Uncompressed AVI');
open(video_file)
writeVideo(video_file,M)
close(video_file)
Kindly click on the you tube link above to see the result fo this code.