Week 2- 2R Robotic Arm Challenge
Aim:
Write a program in MATLAB to simulate the forward kinematics of 2R Robotic Arm.
Solution:
Robot has two arms with length L1 = 1 m and L2 = 0.5 m with angles with base = θ1 and between L1 and L2 = θ2.
Base of the Robot: X0 = 0, Y0 = 0
Link1 and Link2 connector:
X1 = l1*math.cos(t1), Y1 = l1*math.sin(t1)
Coordinates of the manipulator:
X2 = X1 + l2*math.cos(t2), Y2 = Y1 + l2*math.sin(t2)
Program:
% Forward Kinematic of 2R Robotic arm
clear all
close all
clc
% Inputs
l1 = 1
l2 = 0.5
ct = 1
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
for i = 1:length(theta1)
THETA1 = theta1(i)
for j = 1:length(theta2)
THETA2 = theta2(j)
% Coordinates
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)
axis([-0.1 1.5 0 1.5])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct + 1
end
end
movie(M)
videofile = VideoWriter('Forward_kinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Conclusion:
By running this code, we get 100 plots. which helps to analyze the manipulator location with different θ1 and θ2 combinations through the animation.
Link for the Animation :
https://drive.google.com/file/d/1b6_LEn557ey9AdTqYkt4rBqzYq1hwBTa/view?usp=sharing