2R Robotic Arm Challenge
AIM: To write a MATLAB code to simulate the forward kinematics of a 2R Robotic Arm.
Stepwise explanation of the code:
- Firstly, the input variables like length of links 1 and 2, i.e., l1 and l2 are allocated.
- And the values of theta 1 and theta 2 are allocated.
- Using for and nested for loops, various coordinates of the two links such as [x0, y0], [x1, y1], and [x2, y2] are found out using the basic trigonometric equations.
- Later, the plots are plotted using plot() syntax.
- Finally, a movie is created using movie() syntax.
Program code:
%robotic arm
clear all
close all
clc
%inputs
theta1 = linspace(0,120,10); %theta1 = 1:120 degrees
theta2 = linspace(0,90,10); %theta2 = 1:90 degrees
l1 = 2.5; %length of link 1
l2 = 1.5; %length of link 2
ct =1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
x0 = 0; %base of robotic arm is fixed
y0 = 0;
x1 = l1*cosd(THETA1); %end coordinates of link 1
y1 = l1*sind(THETA1);
x2 = x1+l2*cosd(THETA2); %end coordinates of link 2
y2 = y1+l2*sind(THETA2);
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-2 5 0 6])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
%to create a movie
movie(M)
videofile = VideoWriter('forward_kinematics.avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
OUTPUT/ANIMATION:
https://drive.google.com/file/d/10MI_084bdwh8ECrrlmBcSoLGxOqwyLsK/view?usp=sharing
CONCLUSION:
This MATLAB code simulates the forward kinematics of a 2R Robotic arm. The input arguments can be varied in order to fix the length of the links and also the angles of the links with respect to the x axis. Another link of the Robotic arm can also be added by adding the 4th coordinates and also another for loop.