Week 2- 2R Robotic Arm Challenge
EXPLANATION OF THE CODE
1. At first take the input values for link1,link2 and the values for theta1,theta2 in differnt locations(here between 0-90 15values using linspace).
2. For one theta1 value of link1 ten theta2 value is obtained.This can be obtained by the for loop and nested for loop operations.All the coordinate value conditions and plotting commands should be included in the nested for loop.So 225 positions of links will be traced by these loops.
3. For a particular value of theta1 and theta2 the end position of link-1 is calculated by these equations
x1=l1*cosd(THETA1)
y1=l1*sind(THETA1)
4. The end position of link1 is also the start position of link2.The end position for link2 is calculated by these equations.
x2=x1 +l2*cosd(THETA2)
y2=y1 +l2*sind(THETA2)
5. Pause command pauses the code for a particular time period before executing the next incremental step in a for loop
6. for each particular position of link1 and link2 a plot is made which is then captured frame by frame to make a movie
7. A video file of .avi' format is made to save the movie(forwardkinematics2R.avi)
8. The movie is then written into the videofile and the final animation is thus created.
linspace- It generates linearly spaced vectors
getframe- It collects the frame and stores the frame in it
movie- It generates an animation using the frames collected
videofile=videoWriter()- It assigns file name and file format
open(videofile)- It opens the video file write Video
(videofile,M)- It writes the video with plot frames in array M
close(videofile)- It closes the video file
ERROR AND CORRECTIONS MADE
Error-1
videofile=videoWriter('forwardkinematics2R.avi','Uncompressed AVI'); -error
'videowrter' is undefined function
'Videowriter' is defined function
videofile=VideoWriter('forwardkinematics2R.avi','Uncompressed AVI'); -correction made
Error-2
axis[-0.1 1.5 0 1.5] -error
parentheses is not used
axis([-0.1 1.5 0 1.5]) -correction made
for viewing the animation video of 2R robotic arm visit the link given below
% program in Matlab to simulate the forward kinematics of a 2R Robotic Arm
clear all
close all
clc
%taking set of angles theta1 and theta2 with same intervals using linspace
%command
theta1=linspace(0,90,15);
theta2=linspace(0,90,15);
%inputs for link1 and link2
l1=1;
l2=.5;
% initiating the counter variables
ct=1;
% for looping programming
for i=1:length(theta1);
THETA1=theta1(i);
for j=1:length(theta2);
THETA2=theta2(j);
% co ordinate calculation
x0=0;
y0=0;
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
x2=x1 +l2*cosd(THETA2);
y2=y1 +l2*sind(THETA2);
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
% setting the Y axis and X axis limits
axis([-0.1 1.5 0 1.5])
%pausing the code
pause(0.01)
% getting all the frames in a single matrix
M(ct)=getframe(gcf);
%incrementing the counter variable
ct=ct+1;
end
end
% creating the animation and extracting the video file
movie(M)
videofile=VideoWriter('forwardkinematics2R.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
https://drive.google.com/file/d/1AXvOnhTb70jJwBQgAvmCSfD4H8M7Cg1C/view?usp=sharing