Week 2- 2R Robotic Arm Challenge
Green Color = Comments,
Blue Color = Program,
Black Color = Explanations,
Red Color = Instructions
#Youtube Link for the Program = https://youtu.be/WfFKFpSR9LA
#Program
% A Program on Kinematics of Robotic Arm
comment on the name of the Program
close all
To close all the plots in the figure window
clear all
To clear/delete all the saved data in the workspace, editor & command window
clc
To clear/delete all the temporary saved data in the current window
% Input
Comment to specify below are all the input data (taken at random)
Below are the values of all the necessary data required to perform the program
Values such as
Length of the Links (L1, L2)
Angle made by the links with respect to the x-axis (theta1, theta2)
After every value semi-colon is used for not displaying the value in the command window
L1 = 2;
L2 = 2.6;
theta1 = linspace(0,100,15);
theta2 = linspace(0,100,15 );
Here SD is used as a counter and given a value as 1
Here using a counter for plotting with a specific command
SD = 1;
Here in this program, multiple values are being taken also in a specific sequence for the links i.e. L1, L2 without entering them manually, For that 2 for commands are being used for specifying the values i.e. i = from 1 to length of theta1 & j = 1 to length of theta2.
Uppercase THETA1 is specified as theta1 of i & Uppercase THETA2 is specified as theta2 of j
for i = 1 : length(theta1)
THETA1 = theta1(i);
for j = 1 : length(theta2)
THETA2 = theta2(j);
Below are the values of the cordinates of the links with respect to the x-axis & y-axis i.e. (x0 y0), (x1 y1), (x2 y2)
x0 = -1;
y0 = 0;
x1 = L1*cosd(THETA1);
y1 = L1*sind(THETA1);
x2 = x1 + L1*cosd(THETA2);
y2 = y1 + L1*sind(THETA2);
% Plotting
Comment for Plotting
Here 1 plot command is used and add all the coordinates in it to reduce the extra commands such as pause, hold as in every program the last very last plot command gets implemented.
Linewidth is also used to specify the width of the links.
plot ([x0 x1], [y0 y1], [x1 x2], [y1 y2],'linewidth',2)
Axis command is used to specify the values of x-axis & y-axis
axis ([-1.5 4.5 -0.5 5])
Pause command is used to add an interval in the animation and make it more smoother.
pause (0.28)
Here naming the movie/animation/video as A of counter SD as get frame for framing it in one.
A(SD) = getframe(gcf);
This is to specify to add 1 after every plotting
SD = SD + 1;
end of 2nd for command
end
end of 1st for command
end
Specifying movie named as A
movie(A)
Naming the video/animation/movie using VideoWriter command as Robotic_arm.avi and specifying the format of the movie as Uncompressed AVI
videofile = VideoWriter('Robotic_arm.avi','Uncompressed AVI');
specifying to open the program after saving it in a specific name and format
open(videofile)
this command is used to play the video/animation/movie named A in the program
writeVideo(videofile,A)
After successfully playing the video/animation/movie close command is used to close it.
close(videofile)
#Output
- You can find the animation/video/movie in the Youtube link mentioned at the top.
- The video shows the movement of a Robotic-arm shown with the help of 2 links in blue and red color.
- The values are taken randomly such as lengths of the links, angles of both the links made with respect to the x-axis, the coordinates of the links, etc.
- As link 1 (blue-colored link) changes its position, with respect to link 2 (red-colored link) moves its position 15 times with the given range of angles i.e. 0 degrees to 100 degrees.
- Link 1 is also specified with proper range i.e. 15 values between 0 degrees to 100 degrees.
- This program shows that one can make and calculate in Matlab software with ease.
#Errors that were faced during the program
#Error 1
Line no. 40
videofile = Videowriter('Robotic_arm.avi','Uncompressed avi');
write(videofile,A)
The mistake is highlighted
While naming any program the command must be with a capital starting letter i.e. Video Writer
While specifying the format of the program the format must be in the capital letters i.e. AVI
write command is used but not specified what to write, So the solution for this problem is writeVideo
All the errors i.e. 3 errors are covered in 1 single snap (Attached below, named ass Error 1)
At First, I found the Program a bit difficult to understand but after watching the video multiple times and practicing the program was successfully run and the animation/video/movie was created.