MATLAB program to simulate forward kinematics of a 2R robotic arm.
Aim:
To locate the motion of 2 links of varying length moving in anticlockwise direction from angle 0 to 180 degree.
Assumptions:
Length of the link is taken as:
L1 = 2 metric unit
L2 = 1 metric unit
Angle of first link is assumed as theta1 and angle of second link is assumed as theta2 moving from angle 0 to 180 degree.
The variable ct determines the count of each frame executed in the intervals of the angle subtended.
The for loop "i" is initiated for the first and subsequent values of theta1 for link 1 and defined. As for the variable THETA1, it represents the specific angle under consideration.
Similarly "k" takes in values for link 2 with theta2 and THETA2 for definition.
X0, X1, X2, Y0, Y1, Y2 are the coordinate points of the start and end points of the links 1 and 2 n the XY plane.
X0, Y0 - representing start points of link 1,
X1, Y1 - representing the endpoints of link 1/ start points of link 2.
X2, Y2 - representing the endpoints of link 2.
All these points varying for the length and angles under consideration.
Initiating the plot command represents the above-mentioned points X0 to Y2 on the graph for visual representation with a linewidth of 4.
The axis command assists one to limit the points of representation in the graph generated as output.
Command M(ct) captures each frame with the subsequent ct= ct+1 variable for the compilation of frames to generate the movie with the movie command.
The "videofile" defines the name and type of video to be created with VideoWriter for each frame and compiled.
Video Link:
Program:
% Forward kinematics of a 2R robotic arm challenge
close all
clear all
clc
%inputs
L1 = 2; % Assuming a length of link 1 as 2 m
L2 = 1; % Assuming a length of link 2 as 1 m
theta1= linspace(0,180,20); theta2= linspace(0,180,10) % consider a an angle 180 of the pick and place robot arm
%computation
ct= 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for k = 1:length(theta2)
THETA2 = theta2(k);
X0 = 0; % x coordinate of the start point of link 1
Y0 = 0; % y coordinate of the start point of link 1
X1 = L1*cosd(THETA1); % x coordinate of the end point of link 1
Y1 = L1*sind(THETA1); % y coordinate of the end point of link 1
X2 = X1 + L2*cosd(THETA2); % x coordinate of the end point of link 2
Y2 = Y1 + L2*sind(THETA2); % y coordinate of the end point of link 2
%plotting
plot([X0 X1],[Y0 Y1], [X1 X2], [Y1 Y2], 'linewidth',4); % plotting the x and y axis coordinates
axis([-3 3 0 3]) % axis to plot the values and display the limits
pause = (0.05) % pause time for each frame
xlabel('distance traversed along X axis'); ylabel('distance traversed along Y axis');
M(ct) = getframe(gcf); % for creating the animation
ct= ct+1; %frame of increment 1
end
end
movie(M)
videofile = VideoWriter( 'Forward_kinematics_challenge_week1.avi', 'uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)