Week 3.2 - 2R Robotic Arm Challenge
clear
close
clc
%Forward kinematics of a 2R robitic arm
%inputs
%lenght of arms
l1 = 10;
l2 = 5;
%angles
theta1 = [50 40 30 20 10];
theta2 = [90 80 70 60 50];
%coordinates
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 + l1*cosd(Theta2);
y2 = y1 + l1*sind(Theta2);
figure(1)
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2]);
axis([0 20 0 20])
A(ct) = getframe(gcf);
ct = ct+1;
end
end
movie(A)
videofile = VideoWriter('Robotic_Arm.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,A)
close(videofile)
first the inputs l1,l2,theta1,theta2 were given. theta1, theta2 were given as arrays as the program has to plot a graph for multiple values and create a movie. for loop is used for performing the iterations and nested for loop is used as it is a two joint rotation as the second for loop inside the primary for loop is performed and then the primary and it continues till the iterations are completed(in this case 5). As it was mentioned forward Kinematics, I have given the angles in a decreasing order so that the arms move in a clockwise direction. To calculate the trignometric operations in degrees, d is given after cos and sin functions.
finally to create a movie, the VideoWriter function is used as explained in the class.
I took so much time and had to clear all the errors and I was asked to submit the task today itself. so I am not adding any screenshots of the errors from command window.
https://drive.google.com/file/d/15Xts-68_Y66aD9wHhDwSI8PHlMWA6hUH/view?usp=sharing