Week 2- 2R Robotic Arm Challenge
% Challenge 4 - MATLAB Code for Froward Kinematics of 2R robotic arm
% Inputs taken
% Arm length in m
arm1 = 1
arm2 = 0.5
% Arm angle in degrees
angle1 = linspace(0,90,10);
angle2 = linspace(0,90,10);
% Counter for the program
ct = 1
%Operating Conditions for the Robotic Arm
for i = 1:length(angle1)
ANGLE1 = angle1(i);
for j = 1:length(angle2)
ANGLE2 = angle2(j);
x0 = 0;
y0 = 0;
x1 = arm1*cosd(ANGLE1);
y1 = arm1*sind(ANGLE1);
x2 = arm1 + arm2*cosd(ANGLE2);
y2 = arm1 + arm2*sind(ANGLE2);
% Plotting of Robotic Arm
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.2)
M(ct) = getframe(gcf);
%Counter incremented for each execution of the "For"loop
ct = ct+1;
end
end
movie(M)
videofile = VideoWriter ('Forward_Kinematics_2R.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
PROCEDURE TO CODE THE SIMULATION OF FORWARD KINETICS OF 2R ROBOTIC ARM :
- Enter the inputs of arm 1 and arm 2 required to simulate the forward kinetics of 2R robotic arm.
- Give the range of the angles that the arm would have to be simulated for along with the interval, by using 'linspace' command.
- Initiate the counter for the program by entering 'ct=1'.
- Initiate the 'for' loop and give the operating conditions for the robotic arm.
- Enter the initial x and y coordinates, (x0,y0) as 0.
- Give the transformations for the coordinates (x1,y1) and (x2,y2).
- By using 'plot' command, create a plot by using the obtained coordinates, giving a linewidth of 3.
- Enter the range of the axes and give a pause time of 0.2 .
- Use the 'getframe' command and name it as the variable 'M(ct)'.
- Increment the counter for each execution of the 'for' loop.
- End the 'for' loops.
- Use the 'movie' command to initialize the creation of the animation of the obtained frames.
- Use the 'VideoWriter' command to initialize the writing the video. Give the name of the written video and the format of the video.
- By using 'open', 'writeVideo', 'close' commands to open, write and close the video respectively.
ERRORS ENCOUNTERED: - None