Challenge

Week 2- 2R Robotic Arm Challenge

%forward kinematics of 2r robotic arm and animating it using plot
clear all
close all
clc
%input of robotic arm L1 is arm length of first link, L2 second arm link length
% the angle for both the arm changes from 0 to 90 degree at different
% intervals
L1= 1
L2= 0.5
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
ct= 1;
% for loop is used to determine the robatic arm move from 0 to 90 degree
% with respect to angels on both the arms
% THETA1 AND THETA 2 are single variable. theta1 and theta2 are array of 20 value
for i= 1:length(theta1)
THETA1= theta1(i)
for j= 1:length(theta2)
THETA2= theta2(j)
% X0 and Y0 are are the starting point of arm 1 and x1 and y1 are the starting point of arm 2, x2 and y2 are the end of arm 2
% according to angle the arm move from 0 degree to 90 degree position
X0= 0
Y0= 0
X1= L1*cosd(THETA1)
Y1= L1*sind(THETA1)
X2=X1+L2*cosd(THETA2)
Y2=Y1+L2*sind(THETA2)
% now plotting the arm movement using plot command.
% giving the plot (x,y value, with linespace )
% setting the axis from negative so we get the 90 degree arm movement seen
% in the plot inside.
% pause command is given to slow down the movement of arm.
%M(ct) saving the plot in M and getting the frame in by using getframe(gcf)
plot([X0 X1],[Y0 Y1],[X1 X2],[Y1 Y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.1)
M(ct)= getframe(gcf)
ct=ct+1
end
end
movie(M)
videofile= VideoWriter('forward kinamatics.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
%movie (M) the animation is saved like a movie format in avi file.

%Error faced while doing codes

%error 1

%while giving the for loop i had made mistake like giving the variable i for both THETA1 AND THETA2. the plot has not been good.

%error 2

%instead of sind or cosd i have given sin and cos so the values are made in radian.

%error 3

%i had used hold on command so the arm plot in different color.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.