Challenge

Week 2- 2R Robotic Arm Challenge

%Matlab program for Forward Kinematics of a 2R Robotic arm
clear all
close all
clc

%Inputs
l1 = 1; %Length of link1
l2 = 0.5; %Length of link2
theta1 = linspace(0,90,40); % Angle made by link1 with respect to x-axis
theta2 = linspace(0,90,40); % Angle made by link2 with respect to x-axis
ct = 1; % counter variable counts the every event in for loop

%For each angle of THETA1 we need to obtain different angles of THETA2
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);

%co-ordinates
x= 0;
y = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);

%plotting- plot command creates 2D line plot.
plot([x x1],[y y1],[x1 x2],[y1 y2],'linewidth', 3)
axis([-0.1 1.5 0 1.5]);
M(ct) = getframe(gcf); % Assigning current figure window in M.
ct = ct+1;
end
end

movie(M) %movie command to generate movie.
videofile = VideoWriter('Froward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(Videofile)

ERRORS faced while programming

1. Used 'space' instead of ','(coma) in linspace command.

2. Used 'Movie' command instead of 'movie' command, as matlab is case sensitive it shown an error.

Animation video link of 2R robotic arm

https://youtu.be/Rs6EH0r1j88

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.