Week 2- 2R Robotic Arm Challenge
https://drive.google.com/file/d/1g_FGct7CTCn
clear all
close all
clc
%ARM LENGTH INPUTS
l1=1;
l2=0.5;
%ANGULAR RANGE OF THE ARMS
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
%COUNTER
ct=1;
%NESTED LOOPS FOR INTERMIDIATE POINTS
for i=1:length(theta1)
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
%FIXED POINT
x0=0;
y0=0;
%DETERMINIG THE POINT X1 AND Y1
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
%DETERMINING THE POINT X2 AND Y2
x2=x1+l2*cosd(THETA2);
y2=y1+l2*sind(THETA2);
%PLOT OF THE ARMS
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis([-2 2, -0.5 2]);
pause(0.03);
%GENERATING ANIMATION FILE
printf('Creating GIF- process... %d/%dn',ct,length(ct));
img=print('-RGBImage');
imwrite(img,'animation.gif','DelayTime',.005,'Compression','bzip','WriteMode','Append');
ct=ct+1;
end
end
6l8jKvIYLue3JPJCgbN8H/view?usp=sharing
INPUTS - Length of the two arms is declared with the variables l1 and l2.
RANGE OF THE ARMS - theta1 and theta2 are the two arrays created using the linspace command for the suitable operating range respectively for the arm1 and arm2.
COUNTER - A counter variable is created to keep the count for the for loops, to aid the animation file generation.
NESTED FOR LOOPS-
First for loop is created with the variable i to the length of the theta1.
A local variable THETA1 is created to store the value to theta1(i).
Second for loop is created with the variable to the length of the theta2.
A local variable THETA2 is created to store the value to theta2(j).
INITIAL POINTS - Declaring x0 and y0 as the fixed point.
DETERMING THE JOINT - Points x1 and y1 are calculted with Arm1 length and the corresponding angle THETA1
DETERMINING THE END POINT - Points x2 and y2 are calculated with Arm2 length and the corresponding angle THETA2
PLOT OF THE ARMS - Using the plot function the points are represented. Axis function sets the axis as per suitable values.Pause function can be used to delay the plot for the assigned time in seconds.
WRITING THE ANIMATION FILE
printf('Creating GIF- process... %d/%dn',ct,length(ct)) - This command provies the information regarding the gif creation process, as OCTAVE is not efficient.
img=print('-RGBImage'); - This stores the most recent plot into the variable img in RGB format.
imwrite(img,'animation.gif','DelayTime', .005, 'Compression','bzip','WriteMode','Append'); - This functions writes the individual value of the variable img into the file animation.gif, with a delay time in compressed form and with writemode as append to add the new plot to the same animation file.
ERRORS OCCURED -
The Movie function cannot run on the OCTAVE, and the animation file could not be generated with code shown in the video.
New code was written for the generation of the animation file in the OCTAVE.