Week 2- 2R Robotic Arm Challenge
clear all
close all
clc
% Inputs
l1=1;
l2=0.5;
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
ct=1;
for i=1:length(theta1)
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
x0=0;
y0=0;
x1=l1*cosd(THETA1);
y1=l1*sind(THETA2);
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
movie(M)
vieofile=VideoWriter('Forward kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(Videofile,M)
close(videofile)
Explanation : The above code represents the program to perform forward kinematics of 2R robotic arm.2R Robotic arm contains 2 links and 2 rotational joints.When theta1 and theta2 are given we have to find the final position of the manipulator. Here theta values for both theta1 and theta2 are given in an array format because we are finding it in an interval of 0 to 90. To carry on with the code since theta values are given in a range we have to use for loop to carry on the action.THETA is just a variable to store. On proceeding woth the program code after finding the initial and final points of both the links we are heading with the plot. To get the animation of the manipulator we are creating a video file so that we can get the animated video. To get a movie we are converting movie to avi.And finally the desired output is obtained.
Errors Experienced : While carrying out with the program I encountered at first that all the values of theta were overlapped and the obtained figure looked ugly. Resolving the issue yet while running the program I feel that the output video is running slow and still couldn't figure what how to rectify it. And also along with that I couldn't save the video file to desktop despite tryind it many times .Thus providing the link where I screen recorde the following program along with its output.
https://youtu.be/OrNcD4BmIqE link for the youtube.