Week 2- 2R Robotic Arm Challenge
% Robotic arm movement
% Input
l1 = 2;
l2 = 1;
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);
% Plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
xlabel('x axis')
ylabel('y axis')
grid on
axis ([-3.5 3.5 0 3.5])
pause(0.03)
M(ct) =getframe(gcf);
ct = ct+1;
end
end
% Creating a video of robotic arm movement
movie(M)
videofile = VideoWriter('forward_kinematic.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
INPUT:
"l1 and l2" is said to be the robotic arm.
"theta1" is said to be the angle of the first arm.
"theta2" is said to be the angle of the second arm.
"CT" is said to be the counter variable.
FOR LOOP :
For loop is used in the program.
i and j are the variables.
THETA1 is said to be angular movement of first arm.
THETA2 is said to be angular movement of second arm.
x and y are the points to be the plotted in the graph.
PLOTTING:
Plot command is used to plot the points obtained from the program.
Axis is used to represent the graphical co ordinates.
Pause command is used to pause the movement of the arm.
Getframe command is used to get the movement of the arm by frame by frame picture.
"CT" is said to be the counter variable and also it is used to be increase the value of the counter.
Both for loop is said to be closed by the command end.
CREATING A VIDEO OF THE ROBOTIC ARM:
Video of movement of the arm is created the command movie.
Videofile command is used to write the name of the video.
Open command is to open the file and writevideo command is used to write the video of robotic arm movement.
Colse command is used to close the file.
OUTPUT VIDEO: