2R Robotic Arm Challenge
1.AIM:
To write a Program in Mat lab/Octave to stimulate the forward kinematics of a 2R robotic arm and to plot the positions of arm at various angle.
2.Objective of the program:
The main objective of the program is to plot the arms of the robot to trace the movement of the manipulator. Let, length of arm1 is taken as l1 and length of arm2 is l2. Length of the arm l1 is measured as 1 and length of the arm l2 is measured as 0.5. Angle between the base and arm is referred as ‘theta1’ and angle between arm1 and arm2 is referred as ‘theta2’. To plot the arms of the robot xy coordinates (x0, y0), (x1, y1), (x2, y2) are required which is calculated as follows:
(x0, y0) = (0,0)
(x1, y1) = (l1*cosd(THETA1), l1*sind(THETA1))
(x2, y2) = (x1+l2*cosd(THETA2), y1+l2*sind(THETA2))
Where, l1 = 1;
l2 = 0.5;
THETA1 and THETA2 are 10 values lies between 0 to 90 degrees.
Sind and cosd values should be in degrees.
3.Coding:
% Program to stimulate the forward kinematics of a 2R robotic arm and to plot the postions of arm.
clear all
close all
clc
% Input values
% Length of the arms
l1 = 1;
l2 = 0.5;
% Angle at which arm is to be postioned
theta1 = linspace(0,90,10)
theta2 = linspace(0,90,10)
% Program for loop
ct = 1;
for i = 1:length(theta1)
THETA1 = theta2(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% Calculating the x and y points of the arms
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1+l2*cosd(THETA2);
y2 = y1+l2*sind(THETA2);
% Plotting the x and y values of both arms
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.03)
% Save the plotted figure with different name, each time the loop occurs
text = sprintf('test%d.png',ct);
saveas(gca,text)
ct = ct+1;
end
end
4.Explanation:
The Program is explained below:
Line 1: Aim of the program.
Line 2-4: Clears the previously assigned values to variables, clears the command window.
Line 6-8: Length of two arms are assigned to the variable l1 as 1 and l2 as 0.5.
Line 10: using linspace cmd the values for the variable theta1 is assumed 10 values between 0 to 90degree.
Line 11: using linspace cmd the values for the variable theta2 is assumed 10 values between 0 to 90degree.
Line13: New variable ‘ct’ is created and its value is assigned as 1.
Line 14: For loop is called where value of ‘i’ ranges between 1 to length of theta1 i.e., 10.
Line15: New variable THETA1 is created in which the theta2(i) value is assigned i.e., 90.
Line16: Nested for loop is called which values ranges from 1 to length of theta2.
Line17: New variable THETA2 is created in which the theta2(i) value is assigned i.e., 90.
Line18: Calculation of xy coordinates.
Line19: value of variable x0 is assigned as 0.
Line20: value of variable y0 is assigned as 0.
Line21: Value of variable x1 is assigned by calculating the equation “l1*cosd(THETA1)”.
Line22: Value of variable y1 is assigned by calculating the equation “l1*sind(THETA1)”.
Line23: Value of variable x2 is assigned by calculating the equation “x1+l2*cosd(THETA2)”.
Line24: Value of variable y2 is assigned by calculating the equation “x1+l2*cosd(THETA2)”.
Line26: Plotting of calculated values of x and y coordinates.
Line27: Plot of values occurs.
Line28: Axis end values are determined.
Line29: Pausing the code.
Line30-32: These codes are used to save the plot figures with different names which is plotted with different theta values.
Line33: Value of variable gets increased by 1.
Line35: Nested for loop gets end.
Line36: For loop gets end.
5.Output:
6.Conclusion
The GIF is created which stimulates the movement of both arms at different angle position.