Week 2- 2R Robotic Arm Challenge
Video link-
https://www.youtube.com/watch?v=dc7E0WNuEXI
Robotic arm
- Initiating the starting coordinates of arm 1 using x0 & y0.
- Defining the length of arm 1 & 2 using L1 & L2
- Defining the angle of both the robotic arms with respect to x- axis.
The angles can vary from 0 to 90 degrees with a step of 10 degrees between them.
Using command linspace to achieve this. - Starting for loop for the angle of arm1.
starts from 1 to the number of values in the array ‘theta1’, that defines the angle of arm1. - Starting nested for loop 2 for the angle of arm2 staring from 1 to the value range of angle of arm2.
- The nested for loop 2 (i.e the for loop for the second arm) runs for all the values from 1 to 10, everytime the angle of the arm1 changes a value.
This means that the for loop 1 runs for a total of 10 times and for each of those values the for loop 2 runs 10 times. - After this, we calculate the final values of the arm 1.
- Then the length of the arm 2 is calculated in which the previously calculated length of the arm 1 is taken into consideration.
- After this the two arms are plotted. Acis defines the starting point of the arm1 coordinate.
- ‘ Pause’ command helps in the visualization of the graph.
- Then the motion is recorded.
- Initially a video file is defined then its type mentioned.
- After that is is opened, then the code is written on it and then closed back.
Errors

Undefinied variable ct, led to the following error where the arm did not move beyond the first itteration.
To correct this error the variable ct was defined outside the for loop with an initial value of 1
clear all
close all
clc
%initial coordinates of arm 1
x0=0;
y0=0;
%Length of arm 1 & 2
L1=1;
L2=0.5;
%angle of arm 1 & 2 with x-axis
theta1=linspace(0,90,10);
theta2 =linspace(0,90,10);
ct=1;
%For loop for arm1 from 1 to full length of theta1
for i=1:length(theta1)
THETA1=theta1(i);
%For loop for arm2 from 1 to full length of theta2
for j=1:length(theta2)
THETA2=theta2(j);
%Final coordinates of arm 1
x1= L1*cosd(THETA1);
y1= L1*sind(THETA1);
%Final Coordinates of arm 2
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
%Recording the motion
movie(M)
videofile = VideoWriter('Robitic_Arm.avi', 'Uncompressed AVI');
open (videofile)
writeVideo(videofile,M)
close(videofile)