Week 3.2 - 2R Robotic Arm Challenge
% This program is to show the moment of the two arms of robot arm
clear
close all
clc
%Angles theta1 and theta 2
theta1 = linspace(0,90,4); % angle at the bottom arm rod 1
theta2 = linspace(0,90,4); % angle at the top arm rod 2
% Lengths of the two rods
l1 = 1; % length of rod 1
l2 = 0.5; % length of rod 2
ct = 1; % This varible is used later in the code to increase count for the videoframe
% for loop is used to calculate the position for each and every angle
% specified
for i = 1 : length(theta1) % for loop used for angle thata 1
THETA1 = theta1(i); % represent and define THETA 1 to each and every value of theta
for j = 1 : length(theta2) % for loop used for angle thata 2
THETA2 = theta2(j); % represent and define THETA 2 to each and every value of theta
x0 = 0; % initial position of the link 1 in x-->base of the robotic arm
y0 = 0; % initial position of the link 1 in y-->base of the robotic arm
x1 = l1*cosd(THETA1); % Middle postion of the arm in x--> End position of arm1 starting of arm2
y1 = l1*sind(THETA1); % Middle postion of the arm in y--> End position of arm1 starting of arm2
x2 = x1 + l2*cosd(THETA2); %End position of the arm2 in x
y2 = y1 + l2*sind(THETA2); %End position of the arm2 in y
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3) % Get the plot for each value of theta
axis([-0.1 1.5 0 1.5]) % limits for the x and y axis
pause(0.3) % To temporarily pause the plot
M(ct) = getframe(gcf); % To get the frame and store it in array called M
ct = ct+1; % Increase the count
end
end
movie(M) % To generate the movie using the frames
videofile = VideoWriter('forward kinematics.avi','uncompressed AVI'); %creates object videofile to read video data from the file named forward kinematics.
open(videofile) % open the videofile
writeVideo(videofile,M) % write all of the frames into the videofile
close(videofile) % close the file
Errors while executing the Program:
Error 1: Unrecognized function or variable linspce
Resolution:it is a unrecognized variable which is sorted out by specifying as "linspace"
Error 2: Unrecognized function or variable THETA
Resolution:it is a unrecognized variable which is sorted out by specifying as "lTHETA1 and THETA2" together without spaces.
Error 3: Cannot find an exact(case-sensitive) match for 'videowriter'
Resolution: the name videowriter is case sensitive. so changed it to VideoWriter where V and W are capital letters.
Error 4:Unrecognized function or variable 'writevideo'
Resolution: the name writevideo is case sensitive. so changed it to writeVideo where V is capital letter.
Output:
link for the video: https://drive.google.com/file/d/1epjl6W2lF3PRQnEXuVlB4kwYkcUJGiWA/view?usp=sharing
The motion of the kinematics of the 2r robotic arm are calculated according to the position of the arm.The translation of the arm is calculated using the position with respect to angulr change of the arm1 and arm 2.All of these are are collected as frames and written into file named forward kinematics and then we can access the video through the videofile . I did attch the output video as a google drive link and i am also attaching the video in files.