Simulation of the forward kinematics of a 2R robotic arm in MATLAB
AIM : To simulate the forward kinematics of a 2R robotic arm in MATLAB
THEORY:
- Robotic kinematics studies the relationship between the positions, velocities and accelerations of the links of a manipulator which are divided into two types.
- Forward kinematics and the inverse kinematics are the methods to calculate co-ordinates of end effector and joint angles respectively.
- Forward kinematics is used to get the co-ordinates or position of end effector from all the given angles of the links.
- In inverse kinematics, we need to get all the joint angles of the links from a given co-ordinates or given path or trajectory.
MATLAB CODE:
% program to simulate forward kinematics of a 2R robotic arm
clear all
close all
clc
% inputs
l1 = 1.2; % length of first link
l2 = 0.5; % length of second link
theta1 = linspace(0,90,20); % angles traced by the links in degrees from 0 to 90
theta2 = linspace(0,90,20);
count = 1;
for i = 1:20
THETA1 = theta1(i);
for j = 1:20
THETA2 =theta2(j);
x0 = 0; % starting co-ordinates of the 1st link
y0 = 0;
x1 = l1*cosd(THETA1); % starting co-ordinates of the 2nd link
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2); % ending co-ordinates of 2nd link
y2 = y1 + l2*sind(THETA2);
% plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
axis([-0.1 2 0 2]) % specifying the limits for the x axis and y axis
pause(0.05) % pausing time for each frame
M(count) = getframe(gcf) % frames for the animation video
count = count+1; % incrementing for the frames
end
end
movie(M)
videofile = VideoWriter('forward_kinematics_of_2R_Robotic_arm','uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
Result of the animation is uploaded below:
https://www.youtube.com/watch?v=-1ZZhT_siA8&feature=youtu.be
ERRORS:
The errors which I have faced during coding of forward kinematics of a 2R robotic simulator in matlab is as follows:
The above error has occurred due to not assigning the equal (=) operator.
EXPLANATION:
- The lengths (l1,l2) and the angles of two links has been fed as input
- To simulate the movement of the end effector, the angles made by the links i.e., which has been represented in the code as theta1 and theta2 will be varied over a range, hence the linspace command has been used.
- The co-ordinates (x0,y0) of the starting point of the link1 are taken at origin, hence the co-ordinates will be (0,0).
- The co-ordinates of the ending point of 1st link or the starting point of 2nd link have been named as (x1,y1) which are calculated as:
x1 = l1*cosd(theta1)
y1 = l1*sind(theta1)
- The co-ordinates of the ending point of 2nd link have been named as (x2,y2) which are calculated as:
x2 = x1 + l2*cosd(theta2)
y2 = y1 + l2*sind(theta2)
cosd and sind commands are used inorder to incorporate angles in degrees.
- After getting the coordinates the two links will be plotted on the same graph using plot command.
- For each value of theta1, theta2 will be changed over the entire range specified, inorder to incorporate this ‘for’ command have been used.
- The final output will be obtained in the form of an animation video clip.
CONCLUSION:Hence, simulation of forward kinematics of a 2R robotic has been achieved by MATLAB.