Week 2- 2R Robotic Arm Challenge
Aim - To Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
Objective - To understand kinematics of linkages and to figure out how the robot is going to move using programing language.
Body of content - Below mentioned is the program that we used in forward kinematics of a 2R Robotic arm manipulator.
% Forward Kinematics Of 2R Robotic Arm Manipulatior.
clear all
close all
clc
% Inputs
L1 = 1;
L2 = 0.5;
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct = 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
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)
Explanation - 1) We have drawn rough diagram on blank paper of linkages i,e 2 links (L1 & L2) with their respective angles (theta1 & theta2) made with X-axis also given cordinates of both the links are (x0 y0 , x1 y1 , x2 y2).
where -
2) we assumed the length of L1 & L2 = (1 & 0.5) also used 'linspace' command for (theta1 & theta2) to get 10 values.
3) For loop - for each value of theta1 & theta2 we need to repeat the whole calculations that is why we used for loop.
4) commands used - figure , hold on , pause
MOVIE CREATION
Explanation -
At the end of for loop --
Movie(M) - Matlab generates movie of all the frames stored in (M)
videofile - variable.
videowriter - To create new avi files to fetch.
we had given file name & profile in video writer command i.e
Result :- Below is the link for the animation of "2R Robotic Arm Manipulator" that i had uploaded in my youtube channel
https://youtu.be/HyHTEIHWdDo