Week 3.2 - 2R Robotic Arm Challenge
Objective-
Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
MATLAB SCRIPT SYNTAX
% Forward Kinematics of a 2R Robotic Arm
clear
close all
clc
% Inputs
% Length of arms
l1=1; % Length of first arm
l2=0.5; % Length of second arm
% Angular positions of arms
theta1=linspace(0,90,15); % Positions of first arm
theta2=linspace(0,90,15); % Positions of second arm
% Initial position of first arm
x0=0;
y0=0;
% Counter to store every positions of arms
cntr=1;
% Loop to generate simultaneous positions of both arms
for i=1:length(theta1) % For first arm
th1=theta1(i);
for j=1:length(theta2) % For second arm
th2=theta2(j);
% Final position of first arm & Initial position of second arm
x1=l1*cosd(th1);
y1=l1*sind(th1);
% Final position of second arm
x2=x1+l2*cosd(th2);
y2=y1+l2*sind(th2);
% Plot to represent simulation of Robotic Arms
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)% Initial % Final positions
axis([-0.1 1.7 -0.1 1.7]); % axis of plot
pause(0.05); % pause in sec
% K to store frames of figure for every counter
K(cntr)=getframe(gcf);
cntr=cntr+1;
end
end
% To create video file of simulation
video=VideoWriter('FwdKinem_RoboArm','Uncompressed AVI');
open(video);
writeVideo(video,K);
close(video)GOOGLE DRIVE LINK -
Link - https://drive.google.com/file/d/1XeSDbJUGZHhWa8fDv4ZEpSOXqgyDZYyh/view?usp=sharing
Video - FwdKinem_RoboArm
SNAPSHOTS





=======================================