Week 2- 2R Robotic Arm Challenge
Simulate the forward kinematics of a 2R Robotic Arm in MATLAB
Aim:
To Write a program to simulate the forward kinematics of a 2R Robotic Arm in MATLAB.
Objective:
The program to simulate the simple animation of forward kinematics of a 2R Robotic Arm to be done with the Plot function in a loop manner, and making frames to take out as a animation using Movie function in MATLAB
Procedure:
To procedure in the MALTAB, is carried out with simple coding, the code for the project is done from assigning the orgin point of the line in the plotting section or said to the base of the 2R Robotic Arm, in coding the point is taken as (0,0).
I.e. x0=0 , y0=0
The length of the first and second arms is taken as L1 & L2 as 1 m
L1= L2= 1
The angle made by the arms are made in a variable setup with arrays. For uniform variation thus setup is done by the linspace function
Theta1 = Theta2 =linspace(0, 90, 150)
Hence the constants are applied and also the variable, the x1, x2 and y1, y2. Are to be made using the loop functions, such a for loop
The assigning x and ys , x1 = l1*cosd(theta1)
y1 = l1*sind(theta1)
x2 = x1+l2*cosd(theta2)
y2 = y1+l2*sind(theta2)
and the are align in two for loop function to make the animation like the question.
And plot function is used and also the get frame function , to collect the images from the plot function and set to a movie, with the help of Movie function.
The code to simulate the forward kinematics of a 2R Robotic Arm in MATLAB is...
clear
close
clc
%2R robotic arm
%starting point taken as (0,0)
x0 = 0;
y0 = 0;
%length of arm 1 L1
l1 = 1;
%length of arm 1 L1
l2 = 1;
%angle made with x axis thetha 1
theta1 = linspace(0,90,150);
%second angle made with x axis thetha 2
theta2 = linspace(0,90,150);
ct = 1
for i = 1:length(theta1)
x1 = l1*cosd(theta1(i));
y1 = l1*sind(theta1(i));
for j = 1: length(theta2)
x2 = x1+l2*cosd(theta2(j));
y2 = y1+l2*sind(theta2(j));
figure(1)
plot([x1 x2],[y1 y2], 'LineWidth', 2, 'color', 'g')
hold on
plot([x0 x1],[y0 y1], 'LineWidth', 2, 'color', 'b')
axis([-0.2 2.2 -0.2 2.2])
M(ct) = getframe(gcf)
hold off
end
end
movie(M)
videofile = VideoWriter ('robotic_arm_mov.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
by using this code, we are able to simulate the forward kinematics of a 2R Robotic Arm in MATLAB .
Conclution:
The out video is
https://drive.google.com/file/d/11BAVtmS-rDGpJwVWK68-PdFaPWLbi8dM/view?usp=sharing
The simulate the forward kinematics of a 2R Robotic Arm in MATLAB is done successfully.
There are limitation in the MATLAB for making the stimulation like this , but with simple coding and it is possible too.