Week 2- 2R Robotic Arm Challenge
% Forward kinematics of a 2R robotic arm manipulator
clear all
close all
clc
%Inputs
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);
%plotting
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('forward_kinematics.avi','Uncompressed AVI');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)
Explanation of code :
2R Robotic arm manipulator consists of 2 links link1 and link2 and 2 rotational joints. link1 and link2 make angle with x-axis theta1 and theta2. L1 and L2 are the lengths of link1 and link2 respectively. first step is to calculate the position of link1 and second step is to calculate the position of link2. while writing the code gave the inputs of length and theta.values of theta1 and theta2 are specified by using linspace command then used for loop i for the THETA1 and for loop j for the THETA2. for loop used because we get the set of differant values of theta1 and theta 2 respectively. gave the values of every coordinates as a inputs.then plot the coordinates by using plot command.gave the proper axis to the plot. used the pause command.gave ct=1 as a input, ct refers to the each and every frame then used the getframe command to get the current figure then end the loop. created videofile in a movie by using videowriter command('forward kinematics.avi') writevideo in a videofile. close the videofile.then run the code, code succesfully run. Movie created of 2R robotic arm.
Errors occured in running the code but errors overcome by watching the video lecture again and again and also same error resolved in forum also. Screenshots of errors attached below.